name: Marshalling
card_text: You cannot Special Summon monsters, except Machine monsters. Once per turn: You can declare a Level from 5 to 9; all Level 5 or higher Machine monsters you control become that Level. If a Machine Xyz Monster(s) you control would be destroyed, you can send this card to the GY instead. If this card is sent from the field to the GY: You can add 1 "Rank-Up-Magic Argent Chaos Force" from your Deck or GY to your hand.
external_ids: local CARD_ID_0 = 94220427 --Rank-Up-Magic Argent Chaos Force
  
lua: local CARD_ID_0 = 94220427 --Rank-Up-Magic Argent Chaos Force
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--disable spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	c:RegisterEffect(e2)
  	--lv change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTarget(s.reptg)
  	e4:SetValue(s.repval)
  	e4:SetOperation(s.repop)
  	c:RegisterEffect(e4)
  	--tohand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  function s.splimit(e, c)
  	return c:GetRace() ~= RACE_MACHINE
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(5) and c:IsRace(RACE_MACHINE)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local lv = Duel.AnnounceLevel(tp, 5, 9)
  	e:SetLabel(lv)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(e:GetLabel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		tc = g:GetNext()
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsControler(tp)
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsType(TYPE_XYZ)
  		and c:IsRace(RACE_MACHINE)
  		and c:IsReason(REASON_EFFECT + REASON_BATTLE)
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_DESTROY_CONFIRMED) and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Marshalling
  You cannot Special Summon monsters, except Machine monsters. Once per turn: You can declare a Level from 5 to 9; all Level 5 or higher Machine monsters you control become that Level. If a Machine Xyz Monster(s) you control would be destroyed, you can send this card to the GY instead. If this card is sent from the field to the GY: You can add 1 "Rank-Up-Magic Argent Chaos Force" from your Deck or GY to your hand.
target_text: -- Marshalling
  local CARD_ID_0 = 94220427 --Rank-Up-Magic Argent Chaos Force
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--disable spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	c:RegisterEffect(e2)
  	--lv change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetTarget(s.lvtg)
  	e3:SetOperation(s.lvop)
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTarget(s.reptg)
  	e4:SetValue(s.repval)
  	e4:SetOperation(s.repop)
  	c:RegisterEffect(e4)
  	--tohand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 3))
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  function s.splimit(e, c)
  	return c:GetRace() ~= RACE_MACHINE
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(5) and c:IsRace(RACE_MACHINE)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 1))
  	local lv = Duel.AnnounceLevel(tp, 5, 9)
  	e:SetLabel(lv)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_MZONE, 0, nil)
  	local tc = g:GetFirst()
  	while tc do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_LEVEL)
  		e1:SetValue(e:GetLabel())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		tc = g:GetNext()
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsControler(tp)
  		and c:IsLocation(LOCATION_MZONE)
  		and c:IsType(TYPE_XYZ)
  		and c:IsRace(RACE_MACHINE)
  		and c:IsReason(REASON_EFFECT + REASON_BATTLE)
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsStatus(STATUS_DESTROY_CONFIRMED) and eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  