name: Mask
card_text: Discard 1 card, then target 1 face-up monster you control that has a Level; send it to the GY, also, after that, if it left the field by this effect, Special Summon from your Extra Deck, 1 "Masked HERO" monster with the same Attribute, but a higher Level than, the Attribute/Level the monster had when it was on the field (its original Attribute/Level, if face-down). (This is treated as a Special Summon with "Mask Change".) You can only activate 1 "Mask Change II" per turn.
external_ids: local SETCARD_ID_0 = 0xa008 --Masked
  
lua: local SETCARD_ID_0 = 0xa008 --Masked
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c, e, tp)
  	local lv = c:GetLevel()
  	local att = c:GetAttribute()
  	return lv > 0 and c:IsFaceup() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, lv, att, c)
  end
  function s.spfilter(c, e, tp, lv, att, mc)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:GetLevel() > lv
  		and c:IsAttribute(att)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_VALUE_MASK_CHANGE, tp, false, true)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.chkfilter(c, tc)
  	local lv = tc:GetLevel()
  	local att = tc:GetAttribute()
  	return c:IsFaceup() and c:IsLevelBelow(lv) and (c:GetAttribute() & att) == att
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.chkfilter(chkc, e:GetLabelObject())
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	e:SetLabelObject(g:GetFirst())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	local att = tc:GetAttribute()
  	local lv = tc:GetLevel()
  	if Duel.SendtoGrave(tc, REASON_EFFECT) == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, lv, att, nil)
  	if g:GetCount() > 0 then
  		Duel.BreakEffect()
  		Duel.SpecialSummon(g, SUMMON_VALUE_MASK_CHANGE, tp, tp, false, true, POS_FACEUP)
  		g:GetFirst():CompleteProcedure()
  	end
  end
  
  
source_text: Mask
  Discard 1 card, then target 1 face-up monster you control that has a Level; send it to the GY, also, after that, if it left the field by this effect, Special Summon from your Extra Deck, 1 "Masked HERO" monster with the same Attribute, but a higher Level than, the Attribute/Level the monster had when it was on the field (its original Attribute/Level, if face-down). (This is treated as a Special Summon with "Mask Change".) You can only activate 1 "Mask Change II" per turn.
target_text: -- Mask
  local SETCARD_ID_0 = 0xa008 --Masked
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c, e, tp)
  	local lv = c:GetLevel()
  	local att = c:GetAttribute()
  	return lv > 0 and c:IsFaceup() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, lv, att, c)
  end
  function s.spfilter(c, e, tp, lv, att, mc)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:GetLevel() > lv
  		and c:IsAttribute(att)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_VALUE_MASK_CHANGE, tp, false, true)
  		and Duel.GetLocationCountFromEx(tp, tp, mc, c) > 0
  end
  function s.chkfilter(c, tc)
  	local lv = tc:GetLevel()
  	local att = tc:GetAttribute()
  	return c:IsFaceup() and c:IsLevelBelow(lv) and (c:GetAttribute() & att) == att
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.chkfilter(chkc, e:GetLabelObject())
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	e:SetLabelObject(g:GetFirst())
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	local att = tc:GetAttribute()
  	local lv = tc:GetLevel()
  	if Duel.SendtoGrave(tc, REASON_EFFECT) == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, lv, att, nil)
  	if g:GetCount() > 0 then
  		Duel.BreakEffect()
  		Duel.SpecialSummon(g, SUMMON_VALUE_MASK_CHANGE, tp, tp, false, true, POS_FACEUP)
  		g:GetFirst():CompleteProcedure()
  	end
  end
  
  