--Sigil Awakening function c213350.initial_effect(c) aux.AddCodeList(c,213355) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetTarget(c213350.target) e1:SetOperation(c213350.activate) c:RegisterEffect(e1) --todeck local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(213350,1)) e2:SetCategory(CATEGORY_TODECK) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetRange(LOCATION_GRAVE) e2:SetCountLimit(1,213350) e2:SetCondition(c213350.tdcon) e2:SetTarget(c213350.tdtg) e2:SetOperation(c213350.tdop) c:RegisterEffect(e2) end function c213350.spfilter(c,e,tp,mc) return c:IsLevel(1) and bit.band(c:GetType(),0x81)==0x81 and (not c.mat_filter or c.mat_filter(mc,tp)) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_RITUAL,tp,false,true) and mc:IsCanBeRitualMaterial(c) end function c213350.rfilter(c,mc) local mlv=mc:GetRitualLevel(c) if mlv==mc:GetLevel() then return false end local lv=c:GetLevel() return lv==bit.band(mlv,0xffff) or lv==bit.rshift(mlv,16) end function c213350.filter(c,e,tp) local sg=Duel.GetMatchingGroup(c213350.spfilter,tp,LOCATION_HAND,0,c,e,tp,c) local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) if c:IsLocation(LOCATION_MZONE) then ft=ft+1 end if Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end return sg:IsExists(c213350.rfilter,1,nil,c) or sg:CheckWithSumEqual(Card.GetLevel,c:GetLevel(),1,ft) end function c213350.mfilter(c) return c:GetLevel()>0 and c:IsAbleToGrave() end function c213350.mzfilter(c,tp) return c:IsLocation(LOCATION_MZONE) and c:IsControler(tp) and c:GetSequence()<5 end function c213350.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) if ft<0 then return false end local mg=Duel.GetRitualMaterial(tp) if ft>0 then local mg2=Duel.GetMatchingGroup(c213350.mfilter,tp,LOCATION_EXTRA,0,nil) mg:Merge(mg2) else mg=mg:Filter(c213350.mzfilter,nil,tp) end return mg:IsExists(c213350.filter,1,nil,e,tp) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_HAND) end function c213350.activate(e,tp,eg,ep,ev,re,r,rp) local ft=Duel.GetLocationCount(tp,LOCATION_MZONE) if ft<0 then return end local mg=Duel.GetRitualMaterial(tp) if ft>0 then local mg2=Duel.GetMatchingGroup(c213350.mfilter,tp,LOCATION_EXTRA,0,nil) mg:Merge(mg2) else mg=mg:Filter(c213350.mzfilter,nil,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE) local mat=mg:FilterSelect(tp,c213350.filter,1,1,nil,e,tp) local mc=mat:GetFirst() if not mc then return end local sg=Duel.GetMatchingGroup(c213350.spfilter,tp,LOCATION_HAND,0,mc,e,tp,mc) if mc:IsLocation(LOCATION_MZONE) then ft=ft+1 end if Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end local b1=sg:IsExists(c213350.rfilter,1,nil,mc) local b2=sg:CheckWithSumEqual(Card.GetLevel,mc:GetLevel(),1,ft) if b1 and (not b2 or Duel.SelectYesNo(tp,aux.Stringid(213350,0))) then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local tg=sg:FilterSelect(tp,c213350.rfilter,1,1,nil,mc) local tc=tg:GetFirst() tc:SetMaterial(mat) if not mc:IsLocation(LOCATION_EXTRA) then Duel.ReleaseRitualMaterial(mat) else Duel.SendtoGrave(mat,REASON_EFFECT+REASON_MATERIAL+REASON_RITUAL) end Duel.BreakEffect() Duel.SpecialSummon(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP) tc:CompleteProcedure() else Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local tg=sg:SelectWithSumEqual(tp,Card.GetLevel,mc:GetLevel(),1,ft) local tc=tg:GetFirst() while tc do tc:SetMaterial(mat) tc=tg:GetNext() end if not mc:IsLocation(LOCATION_EXTRA) then Duel.ReleaseRitualMaterial(mat) else Duel.SendtoGrave(mat,REASON_EFFECT+REASON_MATERIAL+REASON_RITUAL) end Duel.BreakEffect() tc=tg:GetFirst() while tc do Duel.SpecialSummonStep(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP) tc:CompleteProcedure() tc=tg:GetNext() end Duel.SpecialSummonComplete() end end function c213350.tdfilter(c) return c:IsFaceup() and c:IsCode(213355) end function c213350.tdcon(e,tp,eg,ep,ev,re,r,rp) return Duel.IsExistingMatchingCard(c213350.tdfilter,tp,LOCATION_ONFIELD,0,1,nil) end function c213350.tdtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToDeck() end Duel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0) end function c213350.tdop(e,tp,eg,ep,ev,re,r,rp) if e:GetHandler():IsRelateToEffect(e) then Duel.SendtoDeck(e:GetHandler(),nil,SEQ_DECKSHUFFLE,REASON_EFFECT) end end