--Cyberdark Portal function c212720.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH+CATEGORY_SUMMON) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetCountLimit(1,212720+EFFECT_COUNT_CODE_OATH) e1:SetTarget(c212720.target) e1:SetOperation(c212720.activate) c:RegisterEffect(e1) --destroy local e2=Effect.CreateEffect(c) e2:SetCategory(CATEGORY_DESTROY) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_TO_GRAVE) e2:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_DELAY) e2:SetCondition(c212720.dthcon) e2:SetTarget(c212720.destg) e2:SetOperation(c212720.desop) c:RegisterEffect(e2) --protection local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_IGNITION) e3:SetRange(LOCATION_GRAVE) e3:SetCost(aux.bfgcost) e3:SetOperation(c212720.operation) c:RegisterEffect(e3) end function c212720.thfilter(c) return c:IsSetCard(0x4093) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() end function c212720.filter(c) return c:IsSetCard(0x4093) and c:IsSummonable(true,nil) end function c212720.target(e,tp,eg,ep,ev,re,r,rp,chk) local b1=Duel.IsExistingMatchingCard(c212720.thfilter,tp,LOCATION_DECK,0,1,nil) local b2=Duel.IsExistingMatchingCard(c212720.filter,tp,LOCATION_HAND,0,1,nil) if chk==0 then return b1 or b2 end local op=0 if b1 and b2 then op=Duel.SelectOption(tp,aux.Stringid(212720,0),aux.Stringid(212720,1)) elseif b1 then op=Duel.SelectOption(tp,aux.Stringid(212720,0)) else op=Duel.SelectOption(tp,aux.Stringid(212720,1))+1 end e:SetLabel(op) if op==0 then Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK) else Duel.SetOperationInfo(0,CATEGORY_SUMMON,nil,1,0,0) end end function c212720.activate(e,tp,eg,ep,ev,re,r,rp) if e:GetLabel()==0 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,c212720.thfilter,tp,LOCATION_DECK,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end else Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SUMMON) local g=Duel.SelectMatchingCard(tp,c212720.filter,tp,LOCATION_HAND,0,1,1,nil) local tc=g:GetFirst() if tc then Duel.Summon(tp,tc,true,nil) end end end function c212720.hcfilter(c) return c:IsFaceup() and c:IsSetCard(0x4093) and c:IsType(TYPE_MONSTER) end function c212720.handcon(e) return Duel.IsExistingMatchingCard(c212720.hcfilter,e:GetHandlerPlayer(),LOCATION_MZONE,0,1,nil) end function c212720.dthcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsPreviousLocation(LOCATION_DECK) and re:GetHandler():IsSetCard(0x4093) and bit.band(r,REASON_EFFECT)~=0 end function c212720.destg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsOnField() end if chk==0 then return Duel.IsExistingTarget(aux.TRUE,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY) local g=Duel.SelectTarget(tp,aux.TRUE,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0) end function c212720.desop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.Destroy(tc,REASON_EFFECT) end end function c212720.operation(e,tp,eg,ep,ev,re,r,rp) local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e1:SetCode(EVENT_CHAINING) e1:SetOperation(c212720.actop) e1:SetReset(RESET_PHASE+PHASE_END) Duel.RegisterEffect(e1,tp) end function c212720.actop(e,tp,eg,ep,ev,re,r,rp) local rc=re:GetHandler() if rc:IsSetCard(0x4093) and ep==tp then Duel.SetChainLimit(c212720.chainlm) end end function c212720.chainlm(e,rp,tp) return tp==rp end