--created by Hoshi, coded by Lyris local s,id=GetID() function s.initial_effect(c) c:SetUniqueOnField(1,0,id) aux.AddCodeList(c,id-3) local e1=Effect.CreateEffect(c) e1:SetDescription(1109) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_HAND) e1:SetCountLimit(1,id) e1:SetCost(s.cost) e1:SetTarget(s.target) e1:SetOperation(s.operation) c:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F) e2:SetCode(EVENT_BATTLE_DESTROYED) e2:SetRange(LOCATION_HAND+LOCATION_GRAVE) e2:SetCountLimit(1,id+100) e2:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_EQUIP) e2:SetCondition(function(e,tp,eg) return eg:IsExists(s.cfilter,1,nil,tp) end) e2:SetTarget(s.sptg) e2:SetOperation(s.spop) c:RegisterEffect(e2) local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS) e3:SetCode(EVENT_CUSTOM+id) e3:SetCondition(function(e,tp) return Duel.IsExistingMatchingCard(s.qfilter,tp,LOCATION_ONFIELD,0,1,nil) and not e:GetHandler():IsForbidden() and e:GetHandler():IsLocation(LOCATION_HAND+LOCATION_GRAVE) and Duel.GetFlagEffect(tp,id)==0 end) e3:SetOperation(s.equip) c:RegisterEffect(e3) if not s.global_check then s.global_check=true local e5=Effect.CreateEffect(c) e5:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e5:SetCode(EVENT_ADJUST) e5:SetLabel(0) e5:SetOperation(s.count) Duel.RegisterEffect(e5,0) end local e4=Effect.CreateEffect(c) e4:SetType(EFFECT_TYPE_EQUIP) e4:SetCode(EFFECT_INDESTRUCTABLE_BATTLE) e4:SetCondition(function(e) return e:GetHandler():GetEquipTarget():IsCode(id-3) end) e4:SetValue(1) c:RegisterEffect(e4) end function s.cost(e,tp,eg,ep,ev,re,r,rp,chk) local c=e:GetHandler() if chk==0 then return c:IsDiscardable() end Duel.SendtoGrave(c,REASON_COST+REASON_DISCARD) end function s.filter(c) return c:IsCode(id-3) and (c:IsLocation(LOCATION_DECK) and c:IsAbleToHand() or (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsAbleToDeck()) end function s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chk==0 then return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_DECK+LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_REMOVED,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK+LOCATION_GRAVE+LOCATION_REMOVED) end function s.operation(e,tp,eg,ep,ev,re,r,rp,chk) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local tg=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(s.filter),tp,LOCATION_DECK+LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_REMOVED,1,1,nil):GetFirst() if tg and tg:IsLocation(LOCATION_DECK) then Duel.SendtoHand(tg,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,tg) elseif tg then Duel.SendtoDeck(tg,nil,2,REASON_EFFECT) end end function s.cfilter(c,tp) return c:GetPreviousCodeOnField()==id-3 and c:IsPreviousLocation(LOCATION_ONFIELD) and c:GetPreviousControler()==tp end function s.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE) Duel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0) if e:GetHandler():IsLocation(LOCATION_GRAVE) then Duel.SetOperationInfo(0,CATEGORY_LEAVE_GRAVE,e:GetHandler(),1,0,0) end if Duel.IsPlayerAffectedByEffect(tp,id+11) then Duel.SetChainLimit(function(e,rpr,p) return rpr==p end) end end function s.spfilter(c,e,tp) return c:IsCode(id-3) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function s.spop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if not c:IsRelateToEffect(e) or Duel.GetLocationCount(tp,LOCATION_SZONE)<=0 or Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local tc=Duel.SelectMatchingCard(tp,s.spfilter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp):GetFirst() if tc and Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)~=0 then if not Duel.Equip(tp,c,tc) then return end local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_EQUIP_LIMIT) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e1:SetReset(RESET_EVENT+RESETS_STANDARD) e1:SetValue(function(ef,cc) return tc==cc end) c:RegisterEffect(e1) end end function s.qfilter(c) return c:IsFaceup() and c:IsCode(id-3) and not c:IsStatus(STATUS_BATTLE_DESTROYED) end function s.equip(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_CARD,0,id) local c=e:GetHandler() Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) local tc=Duel.SelectMatchingCard(tp,s.qfilter,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil):GetFirst() if not tc then return end Duel.RegisterFlagEffect(tp,id,RESET_PHASE+PHASE_END,0,1) if not Duel.Equip(tp,c,tc) then return end local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e1:SetCode(EFFECT_EQUIP_LIMIT) e1:SetReset(RESET_EVENT+RESETS_STANDARD) e1:SetValue(function(ef,cc) return cc==tc end) c:RegisterEffect(e1) end function s.count(e,tp,eg,ep,ev,re,r,rp) local p=e:GetOwner():GetControler() local plp,clp=e:GetLabel(),Duel.GetLP(p) e:SetLabel(clp) if plp<=clp then return end Duel.RaiseSingleEvent(e:GetOwner(),EVENT_CUSTOM+id,re,r,rp,p,plp-clp) end