--Leviathan Keeper local ref,id=GetID() function ref.initial_effect(c) c:EnableReviveLimit() local magick=Effect.CreateEffect(c) magick:SetDescription(aux.Stringid(id,0)) magick:SetCategory(CATEGORY_SPECIAL_SUMMON) magick:SetType(EFFECT_TYPE_TRIGGER_O) magick:SetProperty(EFFECT_FLAG_DELAY+EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_SET_AVAILABLE) magick:SetTarget(ref.sstg) magick:SetOperation(ref.ssop) aux.AddMagickProcCustom(c,ref.magcon,aux.MagickMatCost,magick,aux.TRUE,3) aux.AddXyzProcedure(c,nil,5,2) --Attach local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,1)) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetCode(EVENT_SPSUMMON_SUCCESS) e1:SetCountLimit(1,id) e1:SetTarget(ref.mattg) e1:SetOperation(ref.matop) c:RegisterEffect(e1) --Salvage local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(id,2)) e2:SetCategory(CATEGORY_TOHAND) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetType(EFFECT_TYPE_QUICK_O) e2:SetRange(LOCATION_MZONE) e2:SetCountLimit(1,id+1000) e2:SetCode(EVENT_FREE_CHAIN) e2:SetHintTiming(0,TIMING_END_PHASE) e2:SetCost(ref.thcost) e2:SetTarget(ref.thtg) e2:SetOperation(ref.thop) c:RegisterEffect(e2) end function ref.magcon(e,tp,eg,ep,ev,re,r,rp) return re:GetActivateLocation()==LOCATION_HAND and not re:IsHasType(EFFECT_TYPE_ACTIVATE) end function ref.ssfilter(c,e,tp) return c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function ref.sstg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and ref.ssfilter(chkc,e,tp) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(ref.ssfilter,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectTarget(tp,ref.ssfilter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0) if g:GetFirst():IsRace(RACE_SEASERPENT) then e:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DRAW) else e:SetCategory(CATEGORY_SPECIAL_SUMMON) end end function ref.ssop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) and Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)~=0 and tc:IsRace(RACE_SEASERPENT) then Duel.Draw(tp,1,REASON_EFFECT) end end --Attach function ref.xfilter(c) return c:IsFaceup() and c:IsType(TYPE_XYZ) end function ref.mattg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and ref.filter(chkc) end if chk==0 then return e:GetHandler():IsType(TYPE_XYZ) and Duel.IsExistingTarget(Card.IsCanOverlay,tp,LOCATION_GRAVE,LOCATION_GRAVE,1,nil) and Duel.IsExistingMatchingCard(ref.xfilter,tp,LOCATION_MZONE,0,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL) Duel.SelectTarget(tp,Card.IsCanOverlay,tp,LOCATION_GRAVE,LOCATION_GRAVE,1,1,nil) end function ref.matop(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) local c=Duel.SelectMatchingCard(tp,ref.xfilter,tp,LOCATION_MZONE,0,1,1,nil):GetFirst() local tc=Duel.GetFirstTarget() if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then local og=tc:GetOverlayGroup() if og:GetCount()>0 then Duel.SendtoGrave(og,REASON_RULE) end Duel.Overlay(c,Group.FromCards(tc)) if tc:IsLocation(LOCATION_OVERLAY) and not e:GetHandler():GetOverlayGroup():IsContains(tc) then Duel.Draw(tp,1,REASON_EFFECT) end end end --Salvage function ref.thcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,1,REASON_COST) end e:GetHandler():RemoveOverlayCard(tp,1,1,REASON_COST) end function ref.thfilter(c) return c:IsAttribute(ATTRIBUTE_WATER) and c:IsAbleToHand() end function ref.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and ref.thfilter(chkc,e,tp) end if chk==0 then return Duel.IsExistingTarget(ref.thfilter,tp,LOCATION_GRAVE,0,1,nil) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RTOHAND) local g=Duel.SelectTarget(tp,ref.thfilter,tp,LOCATION_GRAVE,0,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_TOHAND,g,1,0,0) end function ref.thop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsRelateToEffect(e) then Duel.SendtoHand(tc,nil,REASON_EFFECT) end end