name: Advanced
card_text: If "Advanced Dark" is not in a Field Zone, send this monster to the GY. Your "Advanced Crystal Beast" monsters can attack directly, but when they do so using this effect, the battle damage inflicted to your opponent is halved. If this face-up card is destroyed in a Monster Zone, you can place it face-up in your Spell & Trap Zone as a Continuous Spell, instead of sending it to the GY.
external_ids: local CARD_ID_0 = 12644061 --Advanced Dark
  local SETCARD_ID_0 = 0x5034 --Advanced
  
lua: local CARD_ID_0 = 12644061 --Advanced Dark
  local SETCARD_ID_0 = 0x5034 --Advanced
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	Duel.EnableGlobalFlag(GLOBALFLAG_SELF_TOGRAVE)
  	--self to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SELF_TOGRAVE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCondition(s.tgcon)
  	c:RegisterEffect(e1)
  	--send replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TO_GRAVE_REDIRECT_CB)
  	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e2:SetCondition(s.repcon)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  	--direct attack
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DIRECT_ATTACK)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(s.atktg)
  	c:RegisterEffect(e3)
  	--damage reduce
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.atkcon)
  	e4:SetTarget(s.atktg)
  	e4:SetValue(aux.ChangeBattleDamage(1, HALF_DAMAGE))
  	c:RegisterEffect(e4)
  end
  function s.tgcon(e)
  	return not Duel.IsEnvironment(CARD_ID_0)
  end
  function s.repcon(e)
  	local c = e:GetHandler()
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsReason(REASON_DESTROY)
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCode(EFFECT_CHANGE_TYPE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  	c:RegisterEffect(e1)
  end
  function s.atktg(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkcon(e)
  	local tp = e:GetHandlerPlayer()
  	return Duel.GetAttackTarget() == nil and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0
  end
  
  
source_text: Advanced
  If "Advanced Dark" is not in a Field Zone, send this monster to the GY. Your "Advanced Crystal Beast" monsters can attack directly, but when they do so using this effect, the battle damage inflicted to your opponent is halved. If this face-up card is destroyed in a Monster Zone, you can place it face-up in your Spell & Trap Zone as a Continuous Spell, instead of sending it to the GY.
target_text: -- Advanced
  local CARD_ID_0 = 12644061 --Advanced Dark
  local SETCARD_ID_0 = 0x5034 --Advanced
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	Duel.EnableGlobalFlag(GLOBALFLAG_SELF_TOGRAVE)
  	--self to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SELF_TOGRAVE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCondition(s.tgcon)
  	c:RegisterEffect(e1)
  	--send replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_TO_GRAVE_REDIRECT_CB)
  	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e2:SetCondition(s.repcon)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  	--direct attack
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DIRECT_ATTACK)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(s.atktg)
  	c:RegisterEffect(e3)
  	--damage reduce
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.atkcon)
  	e4:SetTarget(s.atktg)
  	e4:SetValue(aux.ChangeBattleDamage(1, HALF_DAMAGE))
  	c:RegisterEffect(e4)
  end
  function s.tgcon(e)
  	return not Duel.IsEnvironment(CARD_ID_0)
  end
  function s.repcon(e)
  	local c = e:GetHandler()
  	return c:IsFaceup() and c:IsLocation(LOCATION_MZONE) and c:IsReason(REASON_DESTROY)
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCode(EFFECT_CHANGE_TYPE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  	e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  	c:RegisterEffect(e1)
  end
  function s.atktg(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkcon(e)
  	local tp = e:GetHandlerPlayer()
  	return Duel.GetAttackTarget() == nil and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0
  end
  
  