name: Future
card_text: Target 1 "Utopic Future" Xyz Monster you control; apply the following effect(s) to that monster you control for the rest of this turn.
  ● It can attack all monsters your opponent controls once each.
  ● If it battles an opponent's monster, that monster's effects are negated during the Damage Step only.
  ● Each time it destroys an opponent's monster by battle, inflict damage to your opponent equal to the destroyed monster's original ATK.
  You can only activate 1 "Future Drive" per turn.
external_ids: local SETCARD_ID_0 = 0x207f --Utopic
  
lua: local SETCARD_ID_0 = 0x207f --Utopic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_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 c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFacedown() or not tc:IsRelateToEffect(e) or tc:IsControler(1 - tp) then
  		return
  	end
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, tc:GetFieldID())
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_ATTACK_ALL)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	e1:SetCondition(s.atkcon)
  	e1:SetOwnerPlayer(tp)
  	tc:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_BATTLE_START)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	e2:SetLabelObject(tc)
  	e2:SetCondition(s.discon)
  	e2:SetOperation(s.disop)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_BATTLE_DESTROYING)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	e3:SetLabelObject(tc)
  	e3:SetCondition(s.damcon)
  	e3:SetOperation(s.damop)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.atkcon(e)
  	return e:GetHandlerPlayer() == e:GetOwnerPlayer()
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local fid = tc:GetFlagEffectLabel(id)
  	return fid and fid == tc:GetFieldID()
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	local tc = e:GetLabelObject()
  	if not ac or not bc then
  		return
  	end
  	if ac ~= tc then
  		ac, bc = bc, ac
  	end
  	if ac == tc and bc:IsControler(1 - tp) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e2)
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local fid = tc:GetFlagEffectLabel(id)
  	local bc = tc:GetBattleTarget()
  	return fid and fid == tc:GetFieldID() and tc == eg:GetFirst() and tc:IsRelateToBattle() and bc and bc:IsPreviousControler(1 - tp)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local bc = tc:GetBattleTarget()
  	if not bc then
  		return
  	end
  	local dam = math.max(bc:GetBaseAttack(), 0)
  	if dam > 0 then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.Damage(1 - tp, dam, REASON_EFFECT)
  	end
  end
  
  
source_text: Future
  Target 1 "Utopic Future" Xyz Monster you control; apply the following effect(s) to that monster you control for the rest of this turn.
  ● It can attack all monsters your opponent controls once each.
  ● If it battles an opponent's monster, that monster's effects are negated during the Damage Step only.
  ● Each time it destroys an opponent's monster by battle, inflict damage to your opponent equal to the destroyed monster's original ATK.
  You can only activate 1 "Future Drive" per turn.
target_text: -- Future
  local SETCARD_ID_0 = 0x207f --Utopic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and c:IsSetCard(SETCARD_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 c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFacedown() or not tc:IsRelateToEffect(e) or tc:IsControler(1 - tp) then
  		return
  	end
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, tc:GetFieldID())
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_ATTACK_ALL)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetValue(1)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	e1:SetCondition(s.atkcon)
  	e1:SetOwnerPlayer(tp)
  	tc:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_BATTLE_START)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	e2:SetLabelObject(tc)
  	e2:SetCondition(s.discon)
  	e2:SetOperation(s.disop)
  	Duel.RegisterEffect(e2, tp)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_BATTLE_DESTROYING)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	e3:SetLabelObject(tc)
  	e3:SetCondition(s.damcon)
  	e3:SetOperation(s.damop)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.atkcon(e)
  	return e:GetHandlerPlayer() == e:GetOwnerPlayer()
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local fid = tc:GetFlagEffectLabel(id)
  	return fid and fid == tc:GetFieldID()
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	local tc = e:GetLabelObject()
  	if not ac or not bc then
  		return
  	end
  	if ac ~= tc then
  		ac, bc = bc, ac
  	end
  	if ac == tc and bc:IsControler(1 - tp) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  		bc:RegisterEffect(e2)
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local fid = tc:GetFlagEffectLabel(id)
  	local bc = tc:GetBattleTarget()
  	return fid and fid == tc:GetFieldID() and tc == eg:GetFirst() and tc:IsRelateToBattle() and bc and bc:IsPreviousControler(1 - tp)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	local bc = tc:GetBattleTarget()
  	if not bc then
  		return
  	end
  	local dam = math.max(bc:GetBaseAttack(), 0)
  	if dam > 0 then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.Damage(1 - tp, dam, REASON_EFFECT)
  	end
  end
  
  