name: Final
card_text: During your turn, if a Synchro Monster(s) was sent to your GY this turn: Target 1 Synchro Monster you control; it can make a second attack during each Battle Phase this turn, also, if you activated this card by targeting a Synchro Monster with "Warrior", "Synchron", or "Stardust" in its original name, you can make it gain ATK equal to the ATK of 1 Synchro Monster in your GY. You can only activate 1 "Final Cross" per turn.
external_ids: local SETCARD_ID_0 = 0x66 --Warrior
  
lua: local SETCARD_ID_0 = 0x66 --Warrior
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.atkcon)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetCondition(s.checkcon)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsType, 1, nil, TYPE_SYNCHRO)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = eg:Filter(Card.IsType, nil, TYPE_SYNCHRO)
  	local tc = g:GetFirst()
  	while tc do
  		if Duel.GetFlagEffect(tc:GetControler(), id) == 0 then
  			Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		if Duel.GetFlagEffect(0, id) > 0 and Duel.GetFlagEffect(1, id) > 0 then
  			break
  		end
  		tc = g:GetNext()
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetFlagEffect(tp, id)
  	return Duel.GetTurnPlayer() == tp and aux.bpcon(e, tp, eg, ep, ev, re, r, rp) and ct > 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and not c:IsHasEffect(EFFECT_EXTRA_ATTACK)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc:IsOriginalSetCard(SETCARD_ID_0, 0x1017, 0xa3) then
  		Duel.SetTargetParam(1)
  	end
  end
  function s.atkfilter(c)
  	return c:IsType(TYPE_SYNCHRO) and c:GetAttack() > 0
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local num = Duel.GetChainInfo(0, CHAININFO_TARGET_PARAM)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		if num > 0 and Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  			local ag = Duel.SelectMatchingCard(tp, s.atkfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  			Duel.HintSelection(ag)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetValue(ag:GetFirst():GetAttack())
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  		end
  	end
  end
  
  
source_text: Final
  During your turn, if a Synchro Monster(s) was sent to your GY this turn: Target 1 Synchro Monster you control; it can make a second attack during each Battle Phase this turn, also, if you activated this card by targeting a Synchro Monster with "Warrior", "Synchron", or "Stardust" in its original name, you can make it gain ATK equal to the ATK of 1 Synchro Monster in your GY. You can only activate 1 "Final Cross" per turn.
target_text: -- Final
  local SETCARD_ID_0 = 0x66 --Warrior
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.atkcon)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_TO_GRAVE)
  		ge1:SetCondition(s.checkcon)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsType, 1, nil, TYPE_SYNCHRO)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = eg:Filter(Card.IsType, nil, TYPE_SYNCHRO)
  	local tc = g:GetFirst()
  	while tc do
  		if Duel.GetFlagEffect(tc:GetControler(), id) == 0 then
  			Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		if Duel.GetFlagEffect(0, id) > 0 and Duel.GetFlagEffect(1, id) > 0 then
  			break
  		end
  		tc = g:GetNext()
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetFlagEffect(tp, id)
  	return Duel.GetTurnPlayer() == tp and aux.bpcon(e, tp, eg, ep, ev, re, r, rp) and ct > 0
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and not c:IsHasEffect(EFFECT_EXTRA_ATTACK)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc:IsOriginalSetCard(SETCARD_ID_0, 0x1017, 0xa3) then
  		Duel.SetTargetParam(1)
  	end
  end
  function s.atkfilter(c)
  	return c:IsType(TYPE_SYNCHRO) and c:GetAttack() > 0
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local num = Duel.GetChainInfo(0, CHAININFO_TARGET_PARAM)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		if num > 0 and Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  			local ag = Duel.SelectMatchingCard(tp, s.atkfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  			Duel.HintSelection(ag)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetValue(ag:GetFirst():GetAttack())
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  		end
  	end
  end
  
  