--Opening the Gates function c9945320.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetCode(EVENT_FREE_CHAIN) e1:SetTarget(c9945320.target) e1:SetOperation(c9945320.operation) c:RegisterEffect(e1) --Banish local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(9945320,0)) e2:SetCategory(CATEGORY_REMOVE) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetType(EFFECT_TYPE_QUICK_O) e2:SetRange(LOCATION_GRAVE) e2:SetCountLimit(1,9945320) e2:SetCode(EVENT_FREE_CHAIN) e2:SetCost(c9945320.rmcost) e2:SetCondition(c9945320.rmcon) e2:SetTarget(c9945320.rmtg) e2:SetOperation(c9945320.rmop) c:RegisterEffect(e2) end function c9945320.filter(c,e,tp) return c:IsSetCard(0x204F) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function c9945320.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingMatchingCard(c9945320.filter,tp,LOCATION_HAND,0,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND) end function c9945320.operation(e,tp,eg,ep,ev,re,r,rp) local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) if ft<=0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) if Duel.IsPlayerAffectedByEffect(tp,9945320) then ft=1 end local g=Duel.SelectMatchingCard(tp,c9945320.filter,tp,LOCATION_HAND,0,1,ft,nil,e,tp) if g:GetCount()>0 then local fid=e:GetHandler():GetFieldID() local tc=g:GetFirst() while tc do Duel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP) tc:RegisterFlagEffect(9945320,RESET_EVENT+0x1fe0000,0,1,fid) tc:RegisterFlagEffect(0,RESET_EVENT+0x1fe0000,EFFECT_FLAG_CLIENT_HINT,1,0,aux.Stringid(9945320,0)) tc=g:GetNext() end Duel.SpecialSummonComplete() g:KeepAlive() local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e1:SetCode(EVENT_PHASE+PHASE_END) e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE) e1:SetCountLimit(1) e1:SetLabel(fid) e1:SetLabelObject(g) e1:SetCondition(c9945320.retcon) e1:SetOperation(c9945320.retop) Duel.RegisterEffect(e1,tp) end end function c9945320.retfilter(c,fid) return c:GetFlagEffectLabel(9945320)==fid end function c9945320.retcon(e,tp,eg,ep,ev,re,r,rp) local g=e:GetLabelObject() if not g:IsExists(c9945320.retfilter,1,nil,e:GetLabel()) then g:DeleteGroup() e:Reset() return false else return true end end function c9945320.retop(e,tp,eg,ep,ev,re,r,rp) local g=e:GetLabelObject() local tg=g:Filter(c9945320.retfilter,nil,e:GetLabel()) Duel.SendtoHand(tg,nil,REASON_EFFECT) end function c9945320.rmcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToRemoveAsCost() end Duel.Remove(e:GetHandler(),POS_FACEUP,REASON_COST) end function c9945320.rmfilter(c) return c:IsFaceup() and c:IsSetCard(0x204F) and c:IsAbleToRemove() end function c9945320.rmtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and c9945320.rmfilter(chkc) end if chk==0 then return Duel.IsExistingTarget(c9945320.rmfilter,tp,LOCATION_MZONE,0,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g=Duel.SelectTarget(tp,c9945320.rmfilter,tp,LOCATION_MZONE,0,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_REMOVE,g,1,0,0) end function c9945320.rmop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) and Duel.Remove(tc,tc:GetPosition(),REASON_EFFECT+REASON_TEMPORARY)~=0 then local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e1:SetCode(EVENT_PHASE+PHASE_STANDBY) e1:SetRange(LOCATION_REMOVED) e1:SetCountLimit(1) if Duel.GetTurnPlayer()==tp then if Duel.GetCurrentPhase()==PHASE_DRAW then e1:SetLabel(Duel.GetTurnCount()) else e1:SetLabel(Duel.GetTurnCount()+2) end else e1:SetLabel(Duel.GetTurnCount()+1) end e1:SetReset(RESET_EVENT+0x1fe0000) e1:SetCondition(c9945320.retcon2) e1:SetOperation(c9945320.retop2) tc:RegisterEffect(e1) end end function c9945320.retcon2(e,tp,eg,ep,ev,re,r,rp) return Duel.GetTurnCount()==e:GetLabel() end function c9945320.retop2(e,tp,eg,ep,ev,re,r,rp) Duel.ReturnToField(e:GetHandler()) e:Reset() end function c9945320.rmcon(e,tp,eg,ep,ev,re,r,rp) return not aux.exccon(e) end