Ancient
"Ancient Gear Golem", and monsters that mention it, in your Monster Zone are unaffected by your opponent's activated monster effects. If your opponent controls a monster: You can Fusion Summon 1 Fusion Monster that mentions "Ancient Gear Golem" from your Extra Deck, by banishing monsters from your field or GY as material, including "Ancient Gear Golem" you control, and if you do, it can make up to 3 attacks during each Battle Phase. You can only use this effect of "Ancient Gear Duel" once per turn.
local CARD_ID_0 = 83104731 --Ancient Gear Golem

local CARD_ID_0 = 83104731 --Ancient Gear Golem
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_0)
	-- activate
	local e0 = Effect.CreateEffect(c)
	e0:SetType(EFFECT_TYPE_ACTIVATE)
	e0:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e0)
	-- immune to activated monster effect
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_IMMUNE_EFFECT)
	e1:SetRange(LOCATION_SZONE)
	e1:SetTargetRange(LOCATION_MZONE, 0)
	e1:SetTarget(s.indtg)
	e1:SetValue(s.efilter)
	c:RegisterEffect(e1)
	-- fusion summon
	local e2 = FusionSpell.CreateSummonEffect(c, {
		fusfilter = s.fusfilter,
		pre_select_mat_location = LOCATION_MZONE | LOCATION_GRAVE,
		mat_operation_code_map = {
			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
		},
		additional_fcheck = s.fcheck,
		extra_target = s.extra_target,
		stage_x_operation = s.stage_x_operation,
	})
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_REMOVE)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_SZONE)
	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
	e2:SetCountLimit(1, id)
	e2:SetCondition(s.condition)
	c:RegisterEffect(e2)
end

function s.indtg(e, c)
	return c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0)
end

function s.efilter(e, re)
	return e:GetHandlerPlayer() ~= re:GetOwnerPlayer() and re:IsActivated() and re:IsActiveType(TYPE_MONSTER)
end

function s.fusfilter(c)
	return aux.IsCodeListed(c, CARD_ID_0) == true
end

function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return Duel.IsExistingMatchingCard(nil, tp, 0, LOCATION_MZONE, 1, nil)
end

function s.fcheck(tp, mg, fc, mg_all)
	--- Must include a 古代の機械巨人 you control
	--- @param c Card
	if not mg_all:IsExists(function(c)
		return c:IsControler(tp) and c:IsOnField() and c:IsFusionCode(CARD_ID_0)
	end, 1, nil) then
		return false
	end
	return true
end

function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_ONFIELD + LOCATION_GRAVE)
end

function s.stage_x_operation(e, tc, tp, stage)
	if stage == FusionSpell.STAGE_BEFORE_SUMMON_COMPLETE then
		local e1 = Effect.CreateEffect(e:GetHandler())
		e1:SetDescription(aux.Stringid(id, 2))
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetProperty(EFFECT_FLAG_CLIENT_HINT)
		e1:SetCode(EFFECT_EXTRA_ATTACK)
		e1:SetValue(2)
		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
		tc:RegisterEffect(e1, true)
	end
end


Ancient
"Ancient Gear Golem", and monsters that mention it, in your Monster Zone are unaffected by your opponent's activated monster effects. If your opponent controls a monster: You can Fusion Summon 1 Fusion Monster that mentions "Ancient Gear Golem" from your Extra Deck, by banishing monsters from your field or GY as material, including "Ancient Gear Golem" you control, and if you do, it can make up to 3 attacks during each Battle Phase. You can only use this effect of "Ancient Gear Duel" once per turn.
-- Ancient
local CARD_ID_0 = 83104731 --Ancient Gear Golem
local s, id, o = GetID()
function s.initial_effect(c)
	aux.AddCodeList(c, CARD_ID_0)
	-- activate
	local e0 = Effect.CreateEffect(c)
	e0:SetType(EFFECT_TYPE_ACTIVATE)
	e0:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e0)
	-- immune to activated monster effect
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_IMMUNE_EFFECT)
	e1:SetRange(LOCATION_SZONE)
	e1:SetTargetRange(LOCATION_MZONE, 0)
	e1:SetTarget(s.indtg)
	e1:SetValue(s.efilter)
	c:RegisterEffect(e1)
	-- fusion summon
	local e2 = FusionSpell.CreateSummonEffect(c, {
		fusfilter = s.fusfilter,
		pre_select_mat_location = LOCATION_MZONE | LOCATION_GRAVE,
		mat_operation_code_map = {
			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
		},
		additional_fcheck = s.fcheck,
		extra_target = s.extra_target,
		stage_x_operation = s.stage_x_operation,
	})
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_REMOVE)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_SZONE)
	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
	e2:SetCountLimit(1, id)
	e2:SetCondition(s.condition)
	c:RegisterEffect(e2)
end

function s.indtg(e, c)
	return c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0)
end

function s.efilter(e, re)
	return e:GetHandlerPlayer() ~= re:GetOwnerPlayer() and re:IsActivated() and re:IsActiveType(TYPE_MONSTER)
end

function s.fusfilter(c)
	return aux.IsCodeListed(c, CARD_ID_0) == true
end

function s.condition(e, tp, eg, ep, ev, re, r, rp)
	return Duel.IsExistingMatchingCard(nil, tp, 0, LOCATION_MZONE, 1, nil)
end

function s.fcheck(tp, mg, fc, mg_all)
	--- Must include a 古代の機械巨人 you control
	--- @param c Card
	if not mg_all:IsExists(function(c)
		return c:IsControler(tp) and c:IsOnField() and c:IsFusionCode(CARD_ID_0)
	end, 1, nil) then
		return false
	end
	return true
end

function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_ONFIELD + LOCATION_GRAVE)
end

function s.stage_x_operation(e, tc, tp, stage)
	if stage == FusionSpell.STAGE_BEFORE_SUMMON_COMPLETE then
		local e1 = Effect.CreateEffect(e:GetHandler())
		e1:SetDescription(aux.Stringid(id, 2))
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetProperty(EFFECT_FLAG_CLIENT_HINT)
		e1:SetCode(EFFECT_EXTRA_ATTACK)
		e1:SetValue(2)
		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
		tc:RegisterEffect(e1, true)
	end
end

