--Automate ID local s,id=GetID() function s.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetHintTiming(TIMING_DESTROY) e1:SetTarget(s.target) e1:SetOperation(s.activate) e1:SetCountLimit(1,id+EFFECT_COUNT_CODE_OATH) c:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_CUSTOM+id) e2:SetRange(LOCATION_GRAVE+LOCATION_REMOVED) e2:SetProperty(EFFECT_FLAG_DELAY) e2:SetTarget(s.attarget) e2:SetOperation(s.operation) c:RegisterEffect(e2) local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(45950291,0)) e2:SetCategory(CATEGORY_TOHAND) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e2:SetCode(EVENT_PREDRAW) e2:SetRange(LOCATION_GRAVE) e2:SetCondition(s.thcon) e2:SetTarget(s.thtg) e2:SetOperation(s.thop) c:RegisterEffect(e2) end function s.filter1(c,e,tp) return c:IsAttribute(ATTRIBUTE_WATER) and c:IsType(TYPE_XYZ) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) and Duel.IsExistingMatchingCard(s.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,c,c:GetRank()+1) end function s.filter2(c,e,tp,mc,rk) if c:GetOriginalCode()==6165656 then return false end return c:IsAttribute(ATTRIBUTE_WATER) and c:IsRank(rk) and mc:IsCanBeXyzMaterial(c) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_XYZ,tp,false,false) end function s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter1(chkc,e,tp) end if chk==0 then return Duel.IsPlayerCanSpecialSummonCount(tp,2) and Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.GetLocationCountFromEx(tp)>0 and aux.MustMaterialCheck(nil,tp,EFFECT_MUST_BE_XMATERIAL) and Duel.IsExistingTarget(s.filter1,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,s.filter1,tp,LOCATION_GRAVE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,2,tp,LOCATION_EXTRA) if Duel.GetLP(tp)>Duel.GetLP(1-tp) then e:SetLabel(1) end end function s.activate(e,tp,eg,ep,ev,re,r,rp) if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end local tc=Duel.GetFirstTarget() if not tc:IsRelateToEffect(e) or tc:IsImmuneToEffect(e) then return end if Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)==0 then return end if Duel.GetLocationCountFromEx(tp,tp,tc)<=0 or not aux.MustMaterialCheck(tc,tp,EFFECT_MUST_BE_XMATERIAL) then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,s.filter2,tp,LOCATION_EXTRA,0,1,1,nil,e,tp,tc,tc:GetRank()+1) local sc=g:GetFirst() if sc then Duel.BreakEffect() sc:SetMaterial(Group.FromCards(tc)) Duel.Overlay(sc,Group.FromCards(tc)) Duel.SpecialSummon(sc,SUMMON_TYPE_XYZ,tp,tp,false,false,POS_FACEUP) sc:CompleteProcedure() e:SetLabelObject(sc) if e:GetLabel()==1 then Duel.RaiseSingleEvent(e:GetHandler(),EVENT_CUSTOM+id,e,0,0,0,0) end end end function s.attarget(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chk==0 then local tc=re:GetLabelObject() return tc and tc:IsLocation(LOCATION_MZONE) end if e:GetHandler():IsLocation(LOCATION_GRAVE) then Duel.SetOperationInfo(0,CATEGORY_LEAVE_GRAVE,e:GetHandler(),1,0,0) end end function s.operation(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local tc=re:GetLabelObject() if tc:IsFaceup() and not tc:IsImmuneToEffect(e) then Duel.Overlay(tc,Group.FromCards(c)) end end function s.thcon(e,tp,eg,ep,ev,re,r,rp) return tp==Duel.GetTurnPlayer() and Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>0 and Duel.GetDrawCount(tp)>0 end function s.thtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToHand() end local dt=Duel.GetDrawCount(tp) if dt~=0 then _replace_count=0 _replace_max=dt local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetCode(EFFECT_DRAW_COUNT) e1:SetTargetRange(1,0) e1:SetReset(RESET_PHASE+PHASE_DRAW) e1:SetValue(0) Duel.RegisterEffect(e1,tp) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0) end function s.thop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() _replace_count=_replace_count+1 if _replace_count<=_replace_max and c:IsRelateToEffect(e) then Duel.SendtoHand(c,nil,REASON_EFFECT) Duel.BreakEffect() local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_PUBLIC) e1:SetReset(RESET_EVENT+0x1fe0000+RESET_PHASE+PHASE_END) c:RegisterEffect(e1) end end