--created by ZEN, coded by TaxingCorn117 local s,id=GetID() function s.initial_effect(c) local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) c:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e2:SetCode(EVENT_DAMAGE) e2:SetRange(LOCATION_FZONE) e2:SetOperation(s.op) c:RegisterEffect(e2) local e4=Effect.CreateEffect(c) e4:SetDescription(aux.Stringid(math.floor(id/100),1)) e4:SetCategory(CATEGORY_DAMAGE+CATEGORY_DICE+CATEGORY_SPECIAL_SUMMON) e4:SetType(EFFECT_TYPE_IGNITION) e4:SetRange(LOCATION_FZONE) e4:SetCountLimit(1) e4:SetTarget(s.sptg) e4:SetOperation(s.spop) c:RegisterEffect(e4) local e5=Effect.CreateEffect(c) e5:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e5:SetCode(EVENT_LEAVE_FIELD) e5:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY) e5:SetCondition(s.actcon) e5:SetCost(s.actcost) e5:SetTarget(s.acttg) e5:SetOperation(s.actop) c:RegisterEffect(e5) end function s.filter(c) return c:IsFaceup() and c:IsSetCard(0x52f) end function s.op(e,tp,eg,ep,ev,re,r,rp) if ep~=tp then return end local g=Duel.GetMatchingGroup(s.filter,tp,LOCATION_MZONE,0,nil) if #g>0 then Duel.Hint(HINT_CARD,0,id) end for tc in aux.Next(g) do local e2=Effect.CreateEffect(e:GetHandler()) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_UPDATE_ATTACK) e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e2:SetReset(RESET_EVENT+RESETS_STANDARD) e2:SetValue(100) tc:RegisterEffect(e2) local e3=e2:Clone() e3:SetCode(EFFECT_UPDATE_DEFENSE) tc:RegisterEffect(e3) end end function s.spfilter(c,e,tp,lv) return c:IsSetCard(0x52f) and c:IsLevel(lv) and not c:IsType(TYPE_LINK) and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP) end function s.sptg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return true end Duel.SetOperationInfo(0,CATEGORY_DICE,nil,0,tp,1) Duel.SetOperationInfo(0,CATEGORY_DAMAGE,nil,0,tp,100) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,0,tp,LOCATION_GRAVE+LOCATION_REMOVED) end function s.spop(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local dc=Duel.TossDice(tp,1) local g=Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter),tp,LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_REMOVED,nil,e,tp,dc) if Duel.Damage(tp,dc*100,REASON_EFFECT)~=0 and Duel.GetLP(tp)>0 and #g>0 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then Duel.BreakEffect() Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local sg=g:Select(tp,1,1,nil) Duel.SpecialSummon(sg,0,tp,tp,false,false,POS_FACEUP) end end function s.actcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD) end function s.actfilter(c,tp) return c:IsCode(id) and c:GetActivateEffect():IsActivatable(tp,true,true) and (Duel.GetFlagEffect(tp,id)==0 or c:IsLocation(LOCATION_DECK)) end function s.actcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(Card.IsDiscardable,tp,LOCATION_HAND,0,1,e:GetHandler()) end Duel.DiscardHand(tp,Card.IsDiscardable,1,1,REASON_COST+REASON_DISCARD) end function s.acttg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(s.actfilter,tp,LOCATION_DECK+LOCATION_GRAVE,0,1,nil,tp) end if not Duel.CheckPhaseActivity() then e:SetLabel(1) else e:SetLabel(0) end Duel.SetOperationInfo(0,CATEGORY_DAMAGE,nil,0,tp,100) end function s.actop(e,tp,eg,ep,ev,re,r,rp) if Duel.Damage(tp,100,REASON_EFFECT)==0 or Duel.GetLP(tp)<=0 then return end Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(math.floor(id/100),0)) if e:GetLabel()==1 then Duel.RegisterFlagEffect(tp,id,RESET_CHAIN,0,1) end local tc=Duel.SelectMatchingCard(tp,s.actfilter,tp,LOCATION_DECK+LOCATION_GRAVE,0,1,1,nil,tp):GetFirst() Duel.ResetFlagEffect(tp,id) if tc then Duel.BreakEffect() local fc=Duel.GetFieldCard(tp,LOCATION_SZONE,5) if fc then Duel.SendtoGrave(fc,REASON_RULE) Duel.BreakEffect() end Duel.MoveToField(tc,tp,tp,LOCATION_SZONE,POS_FACEUP,true) local te=tc:GetActivateEffect() te:UseCountLimit(tp,1,true) local tep=tc:GetControler() local cost=te:GetCost() if cost then cost(te,tep,eg,ep,ev,re,r,rp,1) end Duel.RaiseEvent(tc,id,te,0,tp,tp,Duel.GetCurrentChain()) end end