--Mage-Guild Seer function c249000893.initial_effect(c) --gain effect local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_IGNITION) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1,2490008931) e1:SetCost(c249000893.cost) e1:SetTarget(c249000893.target) e1:SetOperation(c249000893.operation) c:RegisterEffect(e1) end function c249000893.costfilter(c) return c:IsSetCard(0x1F9) and c:IsAbleToRemoveAsCost() and c:IsType(TYPE_MONSTER) end function c249000893.costfilter2(c) return c:IsSetCard(0x1F9) and not c:IsPublic() and c:IsType(TYPE_MONSTER) end function c249000893.cost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return (Duel.IsExistingMatchingCard(c249000893.costfilter,tp,LOCATION_GRAVE,0,1,nil) or Duel.IsExistingMatchingCard(c249000893.costfilter2,tp,LOCATION_HAND,0,1,nil)) end local option if Duel.IsExistingMatchingCard(c249000893.costfilter2,tp,LOCATION_HAND,0,1,nil) then option=0 end if Duel.IsExistingMatchingCard(c249000893.costfilter,tp,LOCATION_GRAVE,0,1,nil) then option=1 end if Duel.IsExistingMatchingCard(c249000893.costfilter,tp,LOCATION_GRAVE,0,1,nil) and Duel.IsExistingMatchingCard(c249000893.costfilter2,tp,LOCATION_HAND,0,1,nil) then option=Duel.SelectOption(tp,526,1102) end if option==0 then g=Duel.SelectMatchingCard(tp,c249000893.costfilter2,tp,LOCATION_HAND,0,1,1,nil) Duel.ConfirmCards(1-tp,g) Duel.ShuffleHand(tp) end if option==1 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g=Duel.SelectMatchingCard(tp,c249000893.costfilter,tp,LOCATION_GRAVE,0,1,1,nil) Duel.Remove(g,POS_FACEUP,REASON_COST) end end function c249000893.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>0 end end function c249000893.operation(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local e3=Effect.CreateEffect(c) e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS) e3:SetCode(EVENT_ADJUST) e3:SetRange(LOCATION_MZONE) e3:SetOperation(c249000893.op) e3:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) c:RegisterEffect(e3) end function c249000893.op(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() local g=Duel.GetDecktopGroup(tp,1) local tc=g:GetFirst() if e:GetLabelObject() then e:GetLabelObject():Reset() end if not tc:IsFaceup() then tc:ReverseInDeck() end local e2=Effect.CreateEffect(tc) e2:SetType(EFFECT_TYPE_IGNITION) e2:SetRange(LOCATION_DECK) e2:SetCountLimit(2,2490008932) e2:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END) e2:SetTarget(c249000893.target2) e2:SetOperation(c249000893.operation2) tc:RegisterEffect(e2) e:SetLabelObject(e2) end function c249000893.filter1(c,e,tp,eg,ep,ev,re,r,rp) local te=c:CheckActivateEffect(false,false,false) if c:IsType(TYPE_SPELL) and te then if c:IsSetCard(0x95) then local tg=te:GetTarget() return not tg or tg(e,tp,eg,ep,ev,re,r,rp,0) else return true end end return false end function c249000893.filter2(c,e,tp,eg,ep,ev,re,r,rp) local te=c:CheckActivateEffect(false,false,false) if c:IsType(TYPE_SPELL) and not c:IsType(TYPE_EQUIP+TYPE_CONTINUOUS) and te then if c:IsSetCard(0x95) then local tg=te:GetTarget() return not tg or tg(e,tp,eg,ep,ev,re,r,rp,0) else return true end end return false end function c249000893.target2(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return false end local c=e:GetHandler() if chk==0 then if c:IsType(TYPE_SPELL) then local b=e:GetHandler():IsLocation(LOCATION_HAND) local ft=Duel.GetLocationCount(tp,LOCATION_SZONE) if (b and ft>1) or (not b and ft>0) then return c249000893.filter1(c,e,tp,eg,ep,ev,re,r,rp) else return c249000893.filter2(c,e,tp,eg,ep,ev,re,r,rp) end elseif c:IsType(TYPE_MONSTER) then return c:IsSummonable(true,nil) elseif c:IsType(TYPE_TRAP) then return c:IsSSetable() else return false end end end function c249000893.operation2(e,tp,eg,ep,ev,re,r,rp) local tc=e:GetHandler() if not tc or not tc:IsRelateToEffect(e) then return end if tc:IsType(TYPE_MONSTER) then if not tc:IsSummonable(true,nil) then return else Duel.Summon(tp,tc,true,nil) return end end if tc:IsType(TYPE_TRAP) then if not tc:IsSSetable() then return else Duel.SSet(tp,tc) return end end local tpe=tc:GetType() local te=tc:GetActivateEffect() local tg=te:GetTarget() local co=te:GetCost() local op=te:GetOperation() e:SetCategory(te:GetCategory()) e:SetProperty(te:GetProperty()) Duel.ClearTargetCard() if bit.band(tpe,TYPE_EQUIP+TYPE_CONTINUOUS)~=0 or tc:IsHasEffect(EFFECT_REMAIN_FIELD) then if Duel.GetLocationCount(tp,LOCATION_SZONE)<=0 then return end Duel.MoveToField(tc,tp,tp,LOCATION_SZONE,POS_FACEUP,true) elseif bit.band(tpe,TYPE_FIELD)~=0 then Duel.MoveToField(tc,tp,tp,LOCATION_SZONE,POS_FACEUP,true) else Duel.SendtoGrave(tc,REASON_EFFECT) end tc:CreateEffectRelation(te) if co then co(te,tp,eg,ep,ev,re,r,rp,1) end if tg then if tc:IsSetCard(0x95) then tg(e,tp,eg,ep,ev,re,r,rp,1) else tg(te,tp,eg,ep,ev,re,r,rp,1) end end Duel.BreakEffect() local g=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS) if g then local etc=g:GetFirst() while etc do etc:CreateEffectRelation(te) etc=g:GetNext() end end if op then if tc:IsSetCard(0x95) then op(e,tp,eg,ep,ev,re,r,rp) else op(te,tp,eg,ep,ev,re,r,rp) end end tc:ReleaseEffectRelation(te) if g then etc=g:GetFirst() while etc do etc:ReleaseEffectRelation(te) etc=g:GetNext() end end end