--NREM Nemesis local cid,id=GetID() function cid.initial_effect(c) c:EnableReviveLimit() --negate local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,0)) e1:SetCategory(CATEGORY_TODECK+CATEGORY_REMOVE) e1:SetType(EFFECT_TYPE_QUICK_O) e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL) e1:SetCode(EVENT_CHAINING) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1) e1:SetCondition(cid.negcon) e1:SetCost(cid.negcost) e1:SetTarget(cid.negtg) e1:SetOperation(cid.negop) c:RegisterEffect(e1) --Protect Nightmare local e9=Effect.CreateEffect(c) e9:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e9:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY) e9:SetCode(EVENT_RELEASE) e9:SetCondition(cid.indcon) e9:SetOperation(cid.atop) c:RegisterEffect(e9) end function cid.negcon(e,tp,eg,ep,ev,re,r,rp) return not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and (re:IsActiveType(TYPE_MONSTER) or re:IsHasType(EFFECT_TYPE_ACTIVATE)) and Duel.IsChainNegatable(ev) end function cid.cfilter(c,rtype) return c:IsType(rtype) and c:IsAbleToGraveAsCost() end function cid.negcost(e,tp,eg,ep,ev,re,r,rp,chk) local rtype=bit.band(re:GetActiveType(),0x7) if chk==0 then return Duel.IsExistingMatchingCard(cid.cfilter,tp,LOCATION_HAND,0,1,nil,rtype) end Duel.DiscardHand(tp,cid.cfilter,1,1,REASON_COST,nil,rtype) end function cid.negtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return aux.nbcon(tp,re) end Duel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0) if re:GetHandler():IsRelateToEffect(re) then Duel.SetOperationInfo(0,CATEGORY_TODECK,eg,1,0,0) end end function cid.negop(e,tp,eg,ep,ev,re,r,rp) if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then Duel.SendtoDeck(eg,nil,2,REASON_EFFECT) end end function cid.indcon(e,tp,eg,ep,ev,re,r,rp) return Duel.IsExistingTarget(cid.filter2,tp,LOCATION_MZONE,0,1,nil,tp) end function cid.filter2(c) return c:IsFaceup() and c:IsType(TYPE_RITUAL) end function cid.atop(e,tp,eg,ep,ev,re,r,rp) local g=Duel.GetMatchingGroup(cid.filter2,tp,LOCATION_MZONE,0,nil) local tc=g:GetFirst() local c=e:GetHandler() while tc do --indes local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_SINGLE) e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE) e2:SetRange(LOCATION_MZONE) e2:SetReset(RESET_EVENT+RESETS_STANDARD) e2:SetValue(1) tc:RegisterEffect(e2) tc=g:GetNext() end end