--次元誘爆
function c87593014.initial_effect(c)
	--activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCondition(c87593014.con)
	e1:SetTarget(c87593014.target)
	e1:SetOperation(c87593014.operation)
	c:RegisterEffect(e1)
end
function c87593014.con(e,tp,eg,ep,ev,re,r,rp)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil,87593200):GetFirst()
	if f:GetControler()==tp then cou=0x871 else cou=0x872 end
	return f:GetCounter(cou)>=4
end
function c87593014.filter(c,e,tp)
	return c:IsFaceup() and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c87593014.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	if chkc then return false end
	if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>-1 and Duel.GetLocationCount(1-tp,LOCATION_MZONE)>-1
	 and Duel.IsExistingMatchingCard(Card.IsDestructable,tp,LOCATION_MZONE,0,1,nil)
	  and Duel.IsExistingMatchingCard(Card.IsDestructable,tp,0,LOCATION_MZONE,1,nil)
		and Duel.IsExistingTarget(c87593014.filter,tp,LOCATION_REMOVED,0,1,nil,e,tp)
		and Duel.IsExistingTarget(c87593014.filter,1-tp,LOCATION_REMOVED,0,1,nil,e,1-tp) end
	Duel.SetOperationInfo(0,CATEGORY_DESTROY,nil,1,0,LOCATION_MZONE)
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,nil,0,LOCATION_REMOVED)
end
function c87593014.operation(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
	local dc1=Duel.SelectMatchingCard(tp,Card.IsDestructable,tp,LOCATION_MZONE,0,1,1,nil)
	Duel.Hint(HINT_SELECTMSG,1-tp,HINTMSG_DESTROY)
	local dc2=Duel.SelectMatchingCard(1-tp,Card.IsDestructable,1-tp,LOCATION_MZONE,0,1,1,nil)
	local dy1=Duel.Destroy(dc1,REASON_EFFECT)
	local dy2=Duel.Destroy(dc2,REASON_EFFECT)
	if dy1~=0 then
	local ft1=Duel.GetLocationCount(tp,LOCATION_MZONE)
	if ft1>2 then ft1=2 end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local g1=Duel.SelectMatchingCard(tp,c87593014.filter,tp,LOCATION_REMOVED,0,1,ft1,nil,e,tp)
	Duel.SpecialSummon(g1,0,tp,tp,false,false,POS_FACEUP)
	end
	if dy2~=0 then
	local ft2=Duel.GetLocationCount(1-tp,LOCATION_MZONE)
	if ft2>2 then ft2=2 end
	Duel.Hint(HINT_SELECTMSG,1-tp,HINTMSG_SPSUMMON)
	local g2=Duel.SelectMatchingCard(1-tp,c87593014.filter,1-tp,LOCATION_REMOVED,0,1,ft2,nil,e,1-tp)
	Duel.SpecialSummon(g2,0,1-tp,1-tp,false,false,POS_FACEUP)
	end
end
