--Psychostizia Squadrone --Scripted by: XGlitchy30 local s,id=GetID() function s.initial_effect(c) --activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_SEARCH+CATEGORY_TOHAND) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetOperation(s.activate) c:RegisterEffect(e1) --set local e2=Effect.CreateEffect(c) e2:GLString(1) e2:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DESTROY) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetRange(LOCATION_SZONE) e2:SetCountLimit(1,id) e2:SetCondition(s.stcon) e2:SetTarget(s.sttg) e2:SetOperation(s.stop) c:RegisterEffect(e2) --shuffle local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(id,3)) e3:SetCategory(CATEGORY_TODECK+CATEGORY_DRAW) e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e3:SetProperty(EFFECT_FLAG_DELAY) e3:SetRange(LOCATION_SZONE) e3:SetCode(EVENT_CUSTOM+id) e3:SetCountLimit(1,id+100) e3:SetCondition(s.tdcon) e3:SetTarget(s.tdtg) e3:SetOperation(s.tdop) c:RegisterEffect(e3) if not s.global_check then s.global_check=true local ge1=Effect.CreateEffect(c) ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) ge1:SetCode(EVENT_DESTROYED) ge1:SetCondition(s.regcon) ge1:SetOperation(s.regop) Duel.RegisterEffect(ge1,0) end end function s.cfilter(c,tp) return c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousSetCard(0x2c2) end function s.regcon(e,tp,eg,ep,ev,re,r,rp) local v=0 if eg:IsExists(s.cfilter,1,nil,0) then v=v+1 end if eg:IsExists(s.cfilter,1,nil,1) then v=v+2 end if v==0 then return false end e:SetLabel(({0,1,PLAYER_ALL})[v]) return true end function s.regop(e,tp,eg,ep,ev,re,r,rp) Duel.RaiseEvent(eg,EVENT_CUSTOM+id,re,r,rp,ep,e:GetLabel()) end function s.thfilter(c) return c:IsSetCard(0x2c2) and c:IsAbleToHand() end function s.activate(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) or Duel.GetFlagEffect(tp,id)>0 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,0)) then Duel.RegisterFlagEffect(tp,id,RESET_PHASE+PHASE_END,0,1) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local sg=g:Select(tp,1,1,nil) Duel.SendtoHand(sg,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,sg) end end function s.filter(c) return c:IsFaceup() and c:IsSetCard(0x2c2) end function s.stcon(e,tp,eg,ep,ev,re,r,rp) return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_MZONE,0,1,nil) end function s.spfilter2(c,tp) if not c:IsFacedown() then return false end local check1=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and c:IsSetCard(0x2c2) and c:IsType(TYPE_PANDEMONIUM) and Duel.IsPlayerCanSpecialSummonMonster(tp,c:GetCode(),0x2c2,c:GetType(),c:GetTextAttack(),c:GetTextDefense(),c:GetOriginalLevel(),c:GetOriginalRace(),c:GetOriginalAttribute()) return check1 or not (c:IsSetCard(0x2c2) and c:IsType(TYPE_PANDEMONIUM)) end function s.sttg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_SZONE) and s.spfilter2(chkc,tp) end if chk==0 then return Duel.IsExistingTarget(s.spfilter2,tp,LOCATION_SZONE,0,1,nil,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TARGET) Duel.SelectTarget(tp,s.spfilter2,tp,LOCATION_SZONE,0,1,1,nil,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,0,0) end function s.spfilter(c,e,tp) return c:IsSetCard(0x2c2) and c:IsType(TYPE_MONSTER) and (c:IsLocation(LOCATION_HAND) and Duel.GetLocationCount(tp,LOCATION_MZONE)>0 or c:IsLocation(LOCATION_EXTRA) and c:IsFaceup() and Duel.GetLocationCountFromEx(tp,tp,nil,c)>0) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function s.stop(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local tc=Duel.GetFirstTarget() if not tc or not tc:IsRelateToEffect(e) or not tc:IsFacedown() then return end Duel.ConfirmCards(1-tp,Group.FromCards(tc)) local check1=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsPlayerCanSpecialSummonMonster(tp,tc:GetCode(),0x2c2,tc:GetType(),tc:GetTextAttack(),tc:GetTextDefense(),tc:GetOriginalLevel(),tc:GetOriginalRace(),tc:GetOriginalAttribute()) local check2=Duel.IsExistingMatchingCard(s.spfilter,tp,LOCATION_HAND+LOCATION_EXTRA,0,1,nil,e,tp) if tc:IsSetCard(0x2c2) and tc:IsType(TYPE_PANDEMONIUM) then if not check1 then return end tc:AddMonsterAttribute(TYPE_EFFECT+TYPE_PANDEMONIUM) Duel.SpecialSummon(tc,0,tp,tp,true,false,POS_FACEUP) elseif Duel.Destroy(tc,REASON_EFFECT)>0 and check2 and Duel.SelectYesNo(tp,aux.Stringid(id,2)) then Duel.BreakEffect() Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,s.spfilter,tp,LOCATION_HAND+LOCATION_EXTRA,0,1,1,nil,e,tp) if #g>0 then Duel.SpecialSummon(g,0,tp,tp,true,false,POS_FACEUP) end end end function s.tdcon(e,tp,eg,ep,ev,re,r,rp) return ev==tp or ev==PLAYER_ALL end function s.tdfilter(c) return c:IsSetCard(0x2c2) and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsAbleToDeck() end function s.tdtg(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsPlayerCanDraw(tp,1) and Duel.IsExistingMatchingCard(s.tdfilter,tp,LOCATION_EXTRA+LOCATION_GRAVE,0,5,nil) end Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,5,0,0) Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1) end function s.tdop(e,tp,eg,ep,ev,re,r,rp) if not e:GetHandler():IsRelateToEffect(e) then return end local g=Duel.GetMatchingGroup(aux.NecroValleyFilter(s.tdfilter),tp,LOCATION_EXTRA+LOCATION_GRAVE,0,nil) if #g<5 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK) local sg=g:Select(tp,5,5,nil) Duel.SendtoDeck(sg,nil,0,REASON_EFFECT) local og=Duel.GetOperatedGroup() if og:IsExists(Card.IsLocation,1,nil,LOCATION_DECK) then Duel.ShuffleDeck(tp) end local ct=og:FilterCount(Card.IsLocation,nil,LOCATION_DECK+LOCATION_EXTRA) if ct==5 then Duel.Draw(tp,1,REASON_EFFECT) end end