name: Heavy
card_text: When this card is activated: You can add 1 "Infinitrack" monster from your Deck to your hand. Once per turn: You can target 1 Machine Xyz Monster you control, then activate 1 of these effects;
  ● Change its battle position.
  ● Attach this card to it as material.
  You can only activate 1 "Heavy Forward" per turn.
external_ids: local SETCARD_ID_0 = 0x127 --Infinitrack
  
lua: local SETCARD_ID_0 = 0x127 --Infinitrack
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	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)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.postg)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) 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, 0)) 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.pfilter1(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ) and c:IsCanChangePosition()
  end
  function s.pfilter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ)
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local b1 = Duel.IsExistingTarget(s.pfilter1, tp, LOCATION_MZONE, 0, 1, nil)
  	local b2 = Duel.IsExistingTarget(s.pfilter2, tp, LOCATION_MZONE, 0, 1, nil) and e:GetHandler():IsCanOverlay()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and (s.pfilter1(chkc) or s.pfilter2(chkc) and e:GetHandler():IsCanOverlay())
  	end
  	if chk == 0 then
  		return b1 or b2
  	end
  	local opt = 0
  	local g = nil
  	if b1 and not b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	end
  	if not b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	if b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	end
  	e:SetLabel(opt)
  	if opt == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = Duel.SelectTarget(tp, s.pfilter1, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = Duel.SelectTarget(tp, s.pfilter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	end
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local opt = e:GetLabel()
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	if opt == 0 then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEDOWN_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK)
  	else
  		if c:IsRelateToEffect(e) and c:IsCanOverlay() and not tc:IsImmuneToEffect(e) then
  			Duel.Overlay(tc, c)
  		end
  	end
  end
  
  
source_text: Heavy
  When this card is activated: You can add 1 "Infinitrack" monster from your Deck to your hand. Once per turn: You can target 1 Machine Xyz Monster you control, then activate 1 of these effects;
  ● Change its battle position.
  ● Attach this card to it as material.
  You can only activate 1 "Heavy Forward" per turn.
target_text: -- Heavy
  local SETCARD_ID_0 = 0x127 --Infinitrack
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	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)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.postg)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) 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, 0)) 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.pfilter1(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ) and c:IsCanChangePosition()
  end
  function s.pfilter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE) and c:IsType(TYPE_XYZ)
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local b1 = Duel.IsExistingTarget(s.pfilter1, tp, LOCATION_MZONE, 0, 1, nil)
  	local b2 = Duel.IsExistingTarget(s.pfilter2, tp, LOCATION_MZONE, 0, 1, nil) and e:GetHandler():IsCanOverlay()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and (s.pfilter1(chkc) or s.pfilter2(chkc) and e:GetHandler():IsCanOverlay())
  	end
  	if chk == 0 then
  		return b1 or b2
  	end
  	local opt = 0
  	local g = nil
  	if b1 and not b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	end
  	if not b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	if b1 and b2 then
  		opt = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	end
  	e:SetLabel(opt)
  	if opt == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = Duel.SelectTarget(tp, s.pfilter1, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		g = Duel.SelectTarget(tp, s.pfilter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	end
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local opt = e:GetLabel()
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	if opt == 0 then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE, POS_FACEDOWN_DEFENSE, POS_FACEUP_ATTACK, POS_FACEUP_ATTACK)
  	else
  		if c:IsRelateToEffect(e) and c:IsCanOverlay() and not tc:IsImmuneToEffect(e) then
  			Duel.Overlay(tc, c)
  		end
  	end
  end
  
  