name: Phantasm
card_text: Target 1 "Phantasm Spiral Dragon" you control; when it destroys 3 Effect Monsters your opponent controls, by battle, while equipped with 3 or more "Phantasm Spiral" Equip Spell Cards with different names, you win the Duel. If "Umi" is on the field, you can activate this card from your hand. If a Normal Monster(s) you control would be destroyed by battle or card effect, you can banish this card from your Graveyard instead.
external_ids: local CARD_ID_0 = 56649609 --Phantasm Spiral Dragon
  local CARD_ID_1 = 22702055 --Umi
  local SETCARD_ID_0 = 0xfa --Phantasm
  
lua: local CARD_ID_0 = 56649609 --Phantasm Spiral Dragon
  local CARD_ID_1 = 22702055 --Umi
  local SETCARD_ID_0 = 0xfa --Phantasm
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--act in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	e2:SetCondition(s.handcon)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:GetFlagEffect(97795931) > 0 then
  		return
  	end
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		tc:RegisterFlagEffect(97795931, RESET_EVENT + RESETS_STANDARD, 0, 0)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e1:SetCode(EVENT_BATTLE_DESTROYING)
  		e1:SetCondition(s.wincon)
  		e1:SetOperation(s.winop)
  		e1:SetOwnerPlayer(tp)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.winfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_EQUIP)
  end
  function s.wincon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetEquipGroup():Filter(s.winfilter, nil)
  	return aux.bdocon(e, tp, eg, ep, ev, re, r, rp) and g:GetClassCount(Card.GetCode) > 2 and c:GetBattleTarget():IsType(TYPE_EFFECT) and c:GetControler() == e:GetOwnerPlayer()
  end
  function s.winop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 0)
  	if c:GetFlagEffect(id) > 2 then
  		local WIN_REASON_CELESTIAL_WHIRLPOOL = 0x1c
  		Duel.Win(tp, WIN_REASON_CELESTIAL_WHIRLPOOL)
  	end
  end
  function s.handcon(e)
  	return Duel.IsEnvironment(CARD_ID_1)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_NORMAL) and c:IsLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: Phantasm
  Target 1 "Phantasm Spiral Dragon" you control; when it destroys 3 Effect Monsters your opponent controls, by battle, while equipped with 3 or more "Phantasm Spiral" Equip Spell Cards with different names, you win the Duel. If "Umi" is on the field, you can activate this card from your hand. If a Normal Monster(s) you control would be destroyed by battle or card effect, you can banish this card from your Graveyard instead.
target_text: -- Phantasm
  local CARD_ID_0 = 56649609 --Phantasm Spiral Dragon
  local CARD_ID_1 = 22702055 --Umi
  local SETCARD_ID_0 = 0xfa --Phantasm
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--act in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
  	e2:SetCondition(s.handcon)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:GetFlagEffect(97795931) > 0 then
  		return
  	end
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		tc:RegisterFlagEffect(97795931, RESET_EVENT + RESETS_STANDARD, 0, 0)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  		e1:SetCode(EVENT_BATTLE_DESTROYING)
  		e1:SetCondition(s.wincon)
  		e1:SetOperation(s.winop)
  		e1:SetOwnerPlayer(tp)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.winfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_EQUIP)
  end
  function s.wincon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetEquipGroup():Filter(s.winfilter, nil)
  	return aux.bdocon(e, tp, eg, ep, ev, re, r, rp) and g:GetClassCount(Card.GetCode) > 2 and c:GetBattleTarget():IsType(TYPE_EFFECT) and c:GetControler() == e:GetOwnerPlayer()
  end
  function s.winop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 0)
  	if c:GetFlagEffect(id) > 2 then
  		local WIN_REASON_CELESTIAL_WHIRLPOOL = 0x1c
  		Duel.Win(tp, WIN_REASON_CELESTIAL_WHIRLPOOL)
  	end
  end
  function s.handcon(e)
  	return Duel.IsEnvironment(CARD_ID_1)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_NORMAL) and c:IsLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsReason(REASON_EFFECT + REASON_BATTLE) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemove() and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  end
  
  