--Etherveil Decay local cid,id=GetID() function cid.initial_effect(c) c:SetUniqueOnField(1,0,id) --Activate local e0=Effect.CreateEffect(c) e0:SetCategory(CATEGORY_REMOVE) e0:SetType(EFFECT_TYPE_ACTIVATE) e0:SetCode(EVENT_FREE_CHAIN) e0:SetCountLimit(1,id) e0:SetTarget(cid.target) e0:SetOperation(cid.activate) c:RegisterEffect(e0) --special summon local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetCountLimit(1) e1:SetRange(LOCATION_SZONE) e1:SetTarget(cid.sptg) e1:SetOperation(cid.spop) c:RegisterEffect(e1) --recover local e4=Effect.CreateEffect(c) e4:SetDescription(aux.Stringid(id,1)) e4:SetType(EFFECT_TYPE_IGNITION) e4:SetRange(LOCATION_GRAVE) e4:SetCategory(CATEGORY_TOHAND) e4:SetCost(cid.tdcost) e4:SetTarget(cid.thtg) e4:SetOperation(cid.thop) c:RegisterEffect(e4) --remove local e6=Effect.CreateEffect(c) e6:SetDescription(aux.Stringid(id,2)) e6:SetCategory(CATEGORY_TODECK+CATEGORY_TOGRAVE) e6:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F) e6:SetCode(EVENT_PHASE+PHASE_END) e6:SetRange(LOCATION_SZONE) e6:SetCondition(cid.rmcon) e6:SetCountLimit(1) e6:SetTarget(cid.rmtg) e6:SetOperation(cid.rmop) c:RegisterEffect(e6) end function cid.target(e,tp,eg,ep,ev,re,r,rp,chk) local g=Duel.GetDecktopGroup(tp,5) if chk==0 then return g:FilterCount(Card.IsAbleToRemove,nil,tp,POS_FACEDOWN)==5 end Duel.SetOperationInfo(0,CATEGORY_REMOVE,nil,3,tp,LOCATION_DECK) end function cid.activate(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local ct=Duel.GetFieldGroupCount(tp,LOCATION_DECK,0) if ct==0 then return end if ct>5 then ct=5 end local g=Duel.GetDecktopGroup(tp,ct) Duel.DisableShuffleCheck() Duel.Remove(g,POS_FACEDOWN,REASON_EFFECT) end function cid.filter(c,e,sp) return c:IsSetCard(0x312) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e,0,sp,false,false) end function cid.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingMatchingCard(cid.filter,tp,LOCATION_HAND,0,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND) end function cid.spop(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,cid.filter,tp,LOCATION_HAND,0,1,1,nil,e,tp) if g:GetCount()>0 then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end end function cid.cfilter(c) return c:IsFacedown() and c:IsAbleToDeckAsCost() end function cid.tdcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(cid.cfilter,tp,LOCATION_REMOVED,0,3,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK) local g=Duel.SelectMatchingCard(tp,cid.cfilter,tp,LOCATION_REMOVED,0,3,3,nil) if #g>0 then Duel.SendtoDeck(g,nil,2,REASON_COST) end end function cid.thtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToHand() end Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0) end function cid.thop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) then Duel.SendtoHand(c,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,c) end end function cid.rmcon(e,tp,eg,ep,ev,re,r,rp) return Duel.GetTurnPlayer()==tp end function cid.rmtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,3,tp,LOCATION_REMOVED) Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,e:GetHandler(),1,0,0) end function cid.rmop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local res=false local g=Duel.IsExistingMatchingCard(cid.cfilter,tp,LOCATION_REMOVED,0,3,nil) if g then local sg=Duel.SelectMatchingCard(tp,cid.cfilter,tp,LOCATION_REMOVED,0,3,3,nil) if #sg>0 and Duel.SendtoDeck(sg,nil,2,REASON_COST)==3 then res=true end end if not res and c:IsRelateToEffect(e) then Duel.SendtoGrave(c,REASON_EFFECT) end end