--Ezyat - The Elemental Magician function c212031.initial_effect(c) --special summon local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(212031,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_HAND) e1:SetCost(c212031.spcost) e1:SetTarget(c212031.sptg) e1:SetOperation(c212031.spop) c:RegisterEffect(e1) --synchro level local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_SINGLE) e3:SetCode(EFFECT_SYNCHRO_MATERIAL_CUSTOM) e3:SetTarget(c212031.syntg) e3:SetValue(1) e3:SetOperation(c212031.synop) c:RegisterEffect(e3) local e4=Effect.CreateEffect(c) e4:SetType(EFFECT_TYPE_SINGLE) e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE) e4:SetCode(212031) e4:SetRange(LOCATION_MZONE) c:RegisterEffect(e4) --tohand local e5=Effect.CreateEffect(c) e5:SetDescription(aux.Stringid(212031,1)) e5:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e5:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e5:SetProperty(EFFECT_FLAG_DELAY) e5:SetCode(EVENT_TO_GRAVE) e5:SetCountLimit(1,54088069) e5:SetCondition(c212031.thcon) e5:SetTarget(c212031.thtg) e5:SetOperation(c212031.thop) c:RegisterEffect(e5) end function c212031.cfilter(c) return c:IsAbleToGraveAsCost() end function c212031.spcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c212031.cfilter,tp,LOCATION_HAND,0,1,e:GetHandler()) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE) local g=Duel.SelectMatchingCard(tp,c212031.cfilter,tp,LOCATION_HAND,0,1,1,e:GetHandler()) Duel.SendtoGrave(g,REASON_COST) end function c212031.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0) end function c212031.spop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if not c:IsRelateToEffect(e) then return end Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP) end function c212031.cardiansynlevel(c) return 3 end function c212031.synfilter(c,syncard,tuner,f) return c:IsFaceup() and c:IsCanBeSynchroMaterial(syncard,tuner) and (f==nil or f(c)) end function c212031.syncheck(c,g,mg,tp,lv,syncard,minc,maxc) g:AddCard(c) local ct=g:GetCount() local res=c212031.syngoal(g,tp,lv,syncard,minc,ct) or (ct=minc and Duel.GetLocationCountFromEx(tp,tp,g,syncard)>0 and (g:CheckWithSumEqual(Card.GetSynchroLevel,lv,ct,ct,syncard) or g:CheckWithSumEqual(c212031.cardiansynlevel,lv,ct,ct,syncard)) end function c212031.syntg(e,syncard,f,min,max) local minc=min+1 local maxc=max+1 local c=e:GetHandler() local tp=syncard:GetControler() local lv=syncard:GetLevel() if lv<=c:GetLevel() and lv<=c212031.cardiansynlevel(c) then return false end local g=Group.FromCards(c) local mg=Duel.GetMatchingGroup(c212031.synfilter,tp,LOCATION_MZONE,LOCATION_MZONE,c,syncard,c,f) return mg:IsExists(c212031.syncheck,1,g,g,mg,tp,lv,syncard,minc,maxc) end function c212031.synop(e,tp,eg,ep,ev,re,r,rp,syncard,f,min,max) local minc=min+1 local maxc=max+1 local c=e:GetHandler() local lv=syncard:GetLevel() local g=Group.FromCards(c) local mg=Duel.GetMatchingGroup(c212031.synfilter,tp,LOCATION_MZONE,LOCATION_MZONE,c,syncard,c,f) for i=1,maxc do local cg=mg:Filter(c212031.syncheck,g,g,mg,tp,lv,syncard,minc,maxc) if cg:GetCount()==0 then break end local minct=1 if c212031.syngoal(g,tp,lv,syncard,minc,i) then if not Duel.SelectYesNo(tp,210) then break end minct=0 end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL) local sg=cg:Select(tp,minct,1,nil) if sg:GetCount()==0 then break end g:Merge(sg) end Duel.SetSynchroMaterial(g) end function c212031.thcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD) end function c212031.thfilter(c) return c:IsLevel(1) and c:IsAbleToHand() end function c212031.thtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c212031.thfilter,tp,LOCATION_GRAVE,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_GRAVE) end function c212031.thop(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,c212031.thfilter,tp,LOCATION_GRAVE,0,1,1,nil) if g:GetCount()>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end end