name: Masked
card_text: Must be Special Summoned by "Mask Change". This card can attack directly, but when it does so using this effect, the battle damage inflicted to your opponent is halved. When this card destroys an opponent's monster by battle and sends it to the GY: You can add 1 "Change" Quick-Play Spell Card from your Deck to your hand. You can only use this effect of "Masked HERO Anki" once per turn.
external_ids: local SETCARD_ID_0 = 0xa5 --Change
  
lua: local SETCARD_ID_0 = 0xa5 --Change
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.MaskChangeLimit)
  	c:RegisterEffect(e1)
  	--direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_DIRECT_ATTACK)
  	c:RegisterEffect(e2)
  	--damage reduce
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e3:SetCondition(s.rdcon)
  	e3:SetValue(aux.ChangeBattleDamage(1, HALF_DAMAGE))
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.thcon)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.rdcon(e)
  	local c = e:GetHandler()
  	local tp = e:GetHandlerPlayer()
  	return Duel.GetAttackTarget() == nil and c:GetEffectCount(EFFECT_DIRECT_ATTACK) < 2 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return c:IsRelateToBattle() and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_QUICKPLAY) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Masked
  Must be Special Summoned by "Mask Change". This card can attack directly, but when it does so using this effect, the battle damage inflicted to your opponent is halved. When this card destroys an opponent's monster by battle and sends it to the GY: You can add 1 "Change" Quick-Play Spell Card from your Deck to your hand. You can only use this effect of "Masked HERO Anki" once per turn.
target_text: -- Masked
  local SETCARD_ID_0 = 0xa5 --Change
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.MaskChangeLimit)
  	c:RegisterEffect(e1)
  	--direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_DIRECT_ATTACK)
  	c:RegisterEffect(e2)
  	--damage reduce
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e3:SetCondition(s.rdcon)
  	e3:SetValue(aux.ChangeBattleDamage(1, HALF_DAMAGE))
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.thcon)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.rdcon(e)
  	local c = e:GetHandler()
  	local tp = e:GetHandlerPlayer()
  	return Duel.GetAttackTarget() == nil and c:GetEffectCount(EFFECT_DIRECT_ATTACK) < 2 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return c:IsRelateToBattle() and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_QUICKPLAY) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  