--Codice Amministrale - Carità Tiatriana --Scripted by: XGlitchy30 local s,id=GetID() function s.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:Desc(1) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetCode(EVENT_FREE_CHAIN) e1:HOPT() e1:SetCondition(s.condition) e1:SetTarget(s.target) e1:SetOperation(s.activate) c:RegisterEffect(e1) --shuffle local e3=Effect.CreateEffect(c) e3:Desc(2) e3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F) e3:SetProperty(EFFECT_FLAG_CARD_TARGET) e3:SetCode(EVENT_TO_GRAVE) e3:HOPT() e3:SetCondition(s.tgcon) e3:SetTarget(s.tgtg) e3:SetOperation(s.tgop) c:RegisterEffect(e3) end function s.condition(e,tp) return Duel.IsExistingMatchingCard(aux.Faceup(Card.IsSetCard),tp,LOCATION_ONFIELD,0,1,nil,0xd7c) end function s.filter(c,tp) return c:IsSetCard(0xd7c) and c:CheckUniqueOnField(tp) and not c:IsForbidden() end function s.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then local ft=Duel.GetLocationCount(tp,LOCATION_SZONE) if e:IsHasType(EFFECT_TYPE_ACTIVATE) and (not e:GetHandler():IsLocation(LOCATION_SZONE) or e:GetHandler():GetSequence()>4) then ft=ft-1 end if Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)<3 or ft<=0 then return false end return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_DECK,0,1,nil,tp) end Duel.SetTargetPlayer(tp) if e:IsHasType(EFFECT_TYPE_ACTIVATE) and Duel.IsExistingMatchingCard(aux.Faceup(Card.IsCode),tp,LOCATION_ONFIELD,0,1,nil,19782403) then local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetCode(EFFECT_REMAIN_FIELD) e1:SetReset(RESET_EVENT+RESETS_STANDARD) e:GetHandler():RegisterEffect(e1) end end function s.activate(e,tp,eg,ep,ev,re,r,rp) local ft=Duel.GetLocationCount(tp,LOCATION_SZONE) local p=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER) Duel.ConfirmDecktop(p,3) local g=Duel.GetDecktopGroup(p,3):Filter(s.filter,nil,tp) if #g>0 then Duel.Hint(HINT_SELECTMSG,p,HINTMSG_ATOHAND) local sg=g:Select(p,1,1,nil) if #sg>0 then local sc=sg:GetFirst() if ft<=0 or not sc:CheckUniqueOnField(tp) or sc:IsForbidden() then Duel.SendtoGrave(sc,REASON_RULE) else if Duel.MoveToField(sc,tp,tp,LOCATION_SZONE,POS_FACEUP,true) and sc:IsLocation(LOCATION_SZONE) and sc:IsFaceup() then local e1=Effect.CreateEffect(e:GetHandler()) e1:SetDescription(aux.Stringid(id,0)) e1:SetCode(EFFECT_CHANGE_TYPE) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_CLIENT_HINT+EFFECT_FLAG_IGNORE_IMMUNE) e1:SetReset(RESET_EVENT+RESETS_STANDARD-RESET_TURN_SET) e1:SetValue(TYPE_SPELL+TYPE_CONTINUOUS) sc:RegisterEffect(e1) end end end Duel.BreakEffect() Duel.ShuffleDeck(p) end end function s.tgcon(e,tp,eg,ep,ev,re,r,rp) return e:GetHandler():IsReason(REASON_COST) and e:GetHandler():IsPreviousLocation(LOCATION_SZONE) and e:GetHandler():GetPreviousSequence()<5 and re:IsHasType(0x7e0) and re:GetHandler():IsSetCard(0xd7c) end function s.tgtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(1-tp) and chkc:IsLocation(LOCATION_SZONE) and chkc:IsFacedown() end if chk==0 then return true end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEDOWN) local g=Duel.SelectTarget(tp,Card.IsFacedown,tp,0,LOCATION_SZONE,1,1,nil) if #g>0 and e:IsActivated() then Duel.SetChainLimit(s.limit(g:GetFirst())) end end function s.limit(c) return function (e,lp,tp) return tp==lp or e:GetHandler()~=c end end function s.tgop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if tc:IsFacedown() and tc:IsRelateToChain() then local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD) e1:SetCode(EFFECT_CANNOT_ACTIVATE) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetTargetRange(0,1) e1:SetValue(s.aclimit) e1:SetLabelObject(tc) e1:SetReset(RESET_PHASE+PHASE_END) Duel.RegisterEffect(e1,tp) end end function s.aclimit(e,re,tp) return re:GetHandler()==e:GetLabelObject() and not re:GetHandler():IsImmuneToEffect(e) and re:IsHasType(EFFECT_TYPE_ACTIVATE) end