--Sagra Dorein Sotto il Chiaro di Luna --Scripted by: XGlitchy30 local s,id=GetID() function s.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,0)) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetOperation(s.activate) c:RegisterEffect(e1) --retrieve spell local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(id,2)) e2:SetCategory(CATEGORY_TODECK) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetRange(LOCATION_FZONE) e2:SetCountLimit(1) e2:SetCondition(s.damchk(1000)) e2:SetTarget(s.target) e2:SetOperation(s.operation) e2:SetLabel(TYPE_SPELL) c:RegisterEffect(e2) --retrieve trap local e3=e2:Clone() e3:SetDescription(aux.Stringid(id,3)) e3:SetCondition(s.damchk(2000)) e3:SetLabel(TYPE_TRAP) c:RegisterEffect(e3) --draw local e4=Effect.CreateEffect(c) e4:SetDescription(aux.Stringid(id,4)) e4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e4:SetProperty(EFFECT_FLAG_DELAY+EFFECT_FLAG_PLAYER_TARGET) e4:SetCode(EVENT_TO_DECK) e4:SetRange(LOCATION_FZONE) e4:SetCountLimit(1) e4:SetCondition(s.drawcon) e4:SetTarget(s.drawtg) e4:SetOperation(s.drawop) c:RegisterEffect(e4) --count damage if not s.global_check then s.global_check=true s[0]=0 s[1]=0 local ge1=Effect.CreateEffect(c) ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) ge1:SetCode(EVENT_DAMAGE) ge1:SetOperation(s.checkop) Duel.RegisterEffect(ge1,0) end end function s.checkop(e,tp,eg,ep,ev,re,r,rp) if bit.band(r,REASON_EFFECT)~=0 and rp==1-ep then s[rp]=s[rp]+ev end end function s.damchk(val) return function(e,tp,eg,ep,ev,re,r,rp) if not tp then tp=e:GetHandlerPlayer() end return s[tp]>=val end end function s.thfilter(c) return c:IsSetCard(0xd04) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() end function s.activate(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local g=Duel.GetMatchingGroup(s.thfilter,tp,LOCATION_DECK,0,nil) if g:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(id,1)) then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local sg=g:Select(tp,1,1,nil) if #sg>0 then Duel.SendtoHand(sg,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,sg) end end end function s.filter(c,typ) return c:IsType(typ) and c:IsAbleToDeck() end function s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc,e:GetLabel()) end if chk==0 then return Duel.IsExistingTarget(s.filter,tp,LOCATION_GRAVE,0,1,nil,e:GetLabel()) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK) local g=Duel.SelectTarget(tp,aux.NecroValleyFilter(s.filter),tp,LOCATION_GRAVE,0,1,1,nil,e:GetLabel()) Duel.SetOperationInfo(0,CATEGORY_TODECK,g,#g,0,0) end function s.operation(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local tc=Duel.GetFirstTarget() if tc and tc:IsRelateToEffect(e) then Duel.SendtoDeck(tc,nil,2,REASON_EFFECT) end end function s.cf(c,tp) return c:IsPreviousControler(tp) and c:IsControler(tp) and c:IsPreviousLocation(LOCATION_GRAVE) and c:IsLocation(LOCATION_DECK) end function s.drawcon(e,tp,eg,ep,ev,re,r,rp) return s.damchk(3000)(e,tp) and eg:IsExists(s.cf,1,nil,tp) end function s.drawtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsPlayerCanDraw(tp,1) end Duel.SetTargetPlayer(tp) Duel.SetTargetParam(1) Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1) end function s.drawop(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local p,d=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER,CHAININFO_TARGET_PARAM) Duel.Draw(p,d,REASON_EFFECT) end