name: Artmage
card_text: When this card is activated: You can add 1 "Medius the Pure" from your Deck to your hand. You can target 1 face-up monster you control; if that face-up monster would be used as Fusion Material this turn, it can be treated as an "Artmage" monster. You can only use this effect of "Artmage Vandalism -Assault-" once per turn. If "Artmage Academic Arcane Arts Acropolis" you control would be destroyed by card effect, you can send this card you control to the GY instead. You can only activate 1 "Artmage Vandalism -Assault-" per turn.
external_ids: local CARD_ID_0 = 74733322 --Artmage Academic Arcane Arts Acropolis
  local CARD_ID_1 = 97556336 --Medius the Pure
  local SETCARD_ID_0 = 0x1cd --Artmage
  
lua: local CARD_ID_0 = 74733322 --Artmage Academic Arcane Arts Acropolis
  local CARD_ID_1 = 97556336 --Medius the Pure
  local SETCARD_ID_0 = 0x1cd --Artmage
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--add setcode
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.fstg)
  	e2:SetOperation(s.fsop)
  	c:RegisterEffect(e2)
  	--replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_1) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		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 not c:IsSetCard(SETCARD_ID_0)
  end
  function s.fstg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and chkc:IsFaceup()
  	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.fsop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToChain() and tc:IsFaceup() and tc:IsType(TYPE_MONSTER) then
  		tc:RegisterFlagEffect(0, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_ADD_FUSION_SETCODE)
  		e1:SetRange(LOCATION_MZONE)
  		e1:SetValue(0x1cd)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsControler(tp) and c:IsReason(REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_DESTROY_CONFIRMED) 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.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  end
  
  
source_text: Artmage
  When this card is activated: You can add 1 "Medius the Pure" from your Deck to your hand. You can target 1 face-up monster you control; if that face-up monster would be used as Fusion Material this turn, it can be treated as an "Artmage" monster. You can only use this effect of "Artmage Vandalism -Assault-" once per turn. If "Artmage Academic Arcane Arts Acropolis" you control would be destroyed by card effect, you can send this card you control to the GY instead. You can only activate 1 "Artmage Vandalism -Assault-" per turn.
target_text: -- Artmage
  local CARD_ID_0 = 74733322 --Artmage Academic Arcane Arts Acropolis
  local CARD_ID_1 = 97556336 --Medius the Pure
  local SETCARD_ID_0 = 0x1cd --Artmage
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--add setcode
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.fstg)
  	e2:SetOperation(s.fsop)
  	c:RegisterEffect(e2)
  	--replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.reptg)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop)
  	c:RegisterEffect(e3)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_1) and c:IsAbleToHand()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		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 not c:IsSetCard(SETCARD_ID_0)
  end
  function s.fstg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and chkc:IsFaceup()
  	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.fsop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToChain() and tc:IsFaceup() and tc:IsType(TYPE_MONSTER) then
  		tc:RegisterFlagEffect(0, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_ADD_FUSION_SETCODE)
  		e1:SetRange(LOCATION_MZONE)
  		e1:SetValue(0x1cd)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsCode(CARD_ID_0) and c:IsControler(tp) and c:IsReason(REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_DESTROY_CONFIRMED) 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.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  end
  
  