--NREM Cthulhu local cid,id=GetID() function cid.initial_effect(c) c:EnableReviveLimit() --attribute id local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,0)) e1:SetType(EFFECT_TYPE_QUICK_O) e1:SetCode(EVENT_FREE_CHAIN) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_END_PHASE) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1) e1:SetTarget(cid.attg) e1:SetOperation(cid.atop) c:RegisterEffect(e1) --cannot attack local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD) e2:SetCode(EFFECT_CANNOT_ATTACK) e2:SetRange(LOCATION_MZONE) e2:SetTargetRange(0,LOCATION_MZONE) e2:SetTarget(cid.atktarget) c:RegisterEffect(e2) --Undo Nightmare local e9=Effect.CreateEffect(c) e9:SetCategory(CATEGORY_TODECK) 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.target) e9:SetOperation(cid.activate) c:RegisterEffect(e9) end function cid.atktarget(e,c) return c:IsType(TYPE_SPIRIT) end function cid.rmfilter1(c,tp) return c:IsSetCard(0x505) and c:IsType(TYPE_MONSTER) and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsAbleToRemove() and Duel.IsExistingMatchingCard(cid.rmfilter2,tp,0,LOCATION_MZONE,1,nil) end function cid.rmfilter2(c) return c:IsFaceup() end function cid.attg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_MZONE+LOCATION_GRAVE) and chkc:IsControler(tp) and cid.rmfilter1(chkc,tp) end if chk==0 then return Duel.IsExistingTarget(cid.rmfilter1,tp,LOCATION_MZONE+LOCATION_GRAVE,0,1,nil,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g1=Duel.SelectTarget(tp,cid.rmfilter1,tp,LOCATION_MZONE+LOCATION_GRAVE,0,1,1,nil,tp) local gr=false if g1:GetFirst():IsLocation(LOCATION_GRAVE) then gr=true end if gr then Duel.SetOperationInfo(0,CATEGORY_REMOVE,g1,g1:GetCount(),tp,LOCATION_GRAVE) else Duel.SetOperationInfo(0,CATEGORY_REMOVE,g1,g1:GetCount(),0,0) end end function cid.filter2(c) return c:IsFaceup() end function cid.atop(e,tp,eg,ep,ev,re,r,rp) local fc=Duel.GetFirstTarget() if fc and fc:IsRelateToEffect(e) then Duel.Remove(fc,POS_FACEUP,REASON_EFFECT) end local g=Duel.GetMatchingGroup(cid.filter2,tp,0,LOCATION_MZONE,nil) local tc=g:GetFirst() while tc do local c=e:GetHandler() local fid=c:GetFieldID() tc:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD,0,1,fid) local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE) e1:SetCode(EFFECT_ADD_TYPE) e1:SetValue(TYPE_SPIRIT) e1:SetReset(RESET_EVENT+RESETS_STANDARD) tc:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE) e2:SetCode(EVENT_PHASE+PHASE_END) e2:SetCountLimit(1) e2:SetLabel(fid) e2:SetLabelObject(tc) e2:SetCondition(cid.retcon) e2:SetOperation(cid.retop) Duel.RegisterEffect(e2,tp) tc=g:GetNext() end end function cid.retcon(e,tp,eg,ep,ev,re,r,rp) if not (e:GetLabelObject():GetFlagEffectLabel(id)==e:GetLabel()) then e:Reset() return false else return true end end function cid.retop(e,tp,eg,ep,ev,re,r,rp) local tc=e:GetLabelObject() Duel.SendtoHand(tc,nil,REASON_EFFECT) end function cid.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToDeck,tp,LOCATION_REMOVED,LOCATION_REMOVED,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,1,tp,LOCATION_REMOVED) end function cid.activate(e,tp,eg,ep,ev,re,r,rp) local g=Duel.GetFieldGroup(tp,LOCATION_REMOVED,LOCATION_REMOVED) Duel.SendtoDeck(g,nil,2,REASON_EFFECT) end