name: Mecha
card_text: This card cannot attack your opponent directly. If you have a monster in your Graveyard that is not a "Mecha Phantom Beast" monster, this card cannot attack. This card's Level is increased by the total Levels of all "Mecha Phantom Beast Tokens" you control. While you control a Token, this card cannot be destroyed by battle or card effects. Once per turn: You can Tribute 1 Token, then target 1 card in either player's Graveyard; banish that target.
external_ids: local CARD_ID_0 = 31533705 --Mecha Phantom Beast Token
  local SETCARD_ID_0 = 0x101b --Mecha
  
lua: local CARD_ID_0 = 31533705 --Mecha Phantom Beast Token
  local SETCARD_ID_0 = 0x101b --Mecha
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--level
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_UPDATE_LEVEL)
  	e1:SetValue(s.lvval)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetCondition(aux.tkfcon)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCost(s.rmcost)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  	--atklimit
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_CANNOT_ATTACK)
  	e6:SetCondition(s.atcon)
  	c:RegisterEffect(e6)
  end
  function s.lvval(e, c)
  	local tp = c:GetControler()
  	return Duel.GetMatchingGroup(Card.IsCode, tp, LOCATION_MZONE, 0, nil, CARD_ID_0):GetSum(Card.GetLevel)
  end
  function s.rmcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsType, 1, nil, TYPE_TOKEN)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsType, 1, 1, nil, TYPE_TOKEN)
  	Duel.Release(g, REASON_COST)
  end
  function s.rmfilter(c)
  	return c:IsAbleToRemove()
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.rmfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.rmfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.rmfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil)
  	local p = g:GetFirst():GetControler()
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, p, LOCATION_GRAVE)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.atfilter(c)
  	return not c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(s.atfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, 1, nil)
  end
  
  
source_text: Mecha
  This card cannot attack your opponent directly. If you have a monster in your Graveyard that is not a "Mecha Phantom Beast" monster, this card cannot attack. This card's Level is increased by the total Levels of all "Mecha Phantom Beast Tokens" you control. While you control a Token, this card cannot be destroyed by battle or card effects. Once per turn: You can Tribute 1 Token, then target 1 card in either player's Graveyard; banish that target.
target_text: -- Mecha
  local CARD_ID_0 = 31533705 --Mecha Phantom Beast Token
  local SETCARD_ID_0 = 0x101b --Mecha
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--level
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_UPDATE_LEVEL)
  	e1:SetValue(s.lvval)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetCondition(aux.tkfcon)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetCost(s.rmcost)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  	--atklimit
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_CANNOT_ATTACK)
  	e6:SetCondition(s.atcon)
  	c:RegisterEffect(e6)
  end
  function s.lvval(e, c)
  	local tp = c:GetControler()
  	return Duel.GetMatchingGroup(Card.IsCode, tp, LOCATION_MZONE, 0, nil, CARD_ID_0):GetSum(Card.GetLevel)
  end
  function s.rmcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsType, 1, nil, TYPE_TOKEN)
  	end
  	local g = Duel.SelectReleaseGroup(tp, Card.IsType, 1, 1, nil, TYPE_TOKEN)
  	Duel.Release(g, REASON_COST)
  end
  function s.rmfilter(c)
  	return c:IsAbleToRemove()
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.rmfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.rmfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.rmfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil)
  	local p = g:GetFirst():GetControler()
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, p, LOCATION_GRAVE)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.atfilter(c)
  	return not c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(s.atfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, 1, nil)
  end
  
  