name: Metamorphosed
card_text: Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. If another Insect monster is on the field, your opponent cannot target Insect monsters you control with card effects, also they cannot be destroyed by your opponent's card effects. At the end of the Damage Step, if this card attacked: You can Tribute 1 monster; this card can attack an opponent's monster again in a row. Once per turn, during the End Phase: You can Special Summon 1 "Insect Monster Token" (Insect/EARTH/Level 1/ATK 100/DEF 100).
external_ids: local CARD_ID_0 = 41456842 --Insect Monster Token
  local CARD_ID_1 = 91512836 --Insect Monster Token
  
lua: local CARD_ID_0 = 41456842 --Insect Monster Token
  local CARD_ID_1 = 91512836 --Insect Monster Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCondition(s.indcon)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_INSECT))
  	e2:SetValue(aux.indoval)
  	c:RegisterEffect(e2)
  	--cannot be target
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.indcon)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_INSECT))
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--chain attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.atcon)
  	e4:SetCost(s.atcost)
  	e4:SetOperation(s.atop)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetCountLimit(1)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.splimit(e, se, sp, st)
  	return se:IsHasType(EFFECT_TYPE_ACTIONS)
  end
  function s.indfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.indcon(e)
  	return Duel.IsExistingMatchingCard(s.indfilter, e:GetHandlerPlayer(), LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetAttacker() == c and c:IsChainAttackable(0, true)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, nil, 1, e:GetHandler())
  	end
  	local g = Duel.SelectReleaseGroup(tp, nil, 1, 1, e:GetHandler())
  	Duel.Release(g, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToBattle() then
  		return
  	end
  	Duel.ChainAttack()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE + PHASE_DAMAGE_CAL)
  	c:RegisterEffect(e1)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  
source_text: Metamorphosed
  Cannot be Normal Summoned/Set. Must be Special Summoned by a card effect. If another Insect monster is on the field, your opponent cannot target Insect monsters you control with card effects, also they cannot be destroyed by your opponent's card effects. At the end of the Damage Step, if this card attacked: You can Tribute 1 monster; this card can attack an opponent's monster again in a row. Once per turn, during the End Phase: You can Special Summon 1 "Insect Monster Token" (Insect/EARTH/Level 1/ATK 100/DEF 100).
target_text: -- Metamorphosed
  local CARD_ID_0 = 41456842 --Insect Monster Token
  local CARD_ID_1 = 91512836 --Insect Monster Token
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCondition(s.indcon)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_INSECT))
  	e2:SetValue(aux.indoval)
  	c:RegisterEffect(e2)
  	--cannot be target
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.indcon)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_INSECT))
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--chain attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.atcon)
  	e4:SetCost(s.atcost)
  	e4:SetOperation(s.atop)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetCountLimit(1)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.splimit(e, se, sp, st)
  	return se:IsHasType(EFFECT_TYPE_ACTIONS)
  end
  function s.indfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.indcon(e)
  	return Duel.IsExistingMatchingCard(s.indfilter, e:GetHandlerPlayer(), LOCATION_MZONE, LOCATION_MZONE, 1, e:GetHandler())
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return Duel.GetAttacker() == c and c:IsChainAttackable(0, true)
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, nil, 1, e:GetHandler())
  	end
  	local g = Duel.SelectReleaseGroup(tp, nil, 1, 1, e:GetHandler())
  	Duel.Release(g, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToBattle() then
  		return
  	end
  	Duel.ChainAttack()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE + PHASE_DAMAGE_CAL)
  	c:RegisterEffect(e1)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, CARD_ID_1, 0, TYPES_TOKEN_MONSTER, 100, 100, 1, RACE_INSECT, ATTRIBUTE_EARTH) then
  		return
  	end
  	local token = Duel.CreateToken(tp, id + 1)
  	Duel.SpecialSummon(token, 0, tp, tp, false, false, POS_FACEUP)
  end
  
  