name: Ancient
card_text: If this card that was Tribute Summoned by Tributing an "Ancient Gear" monster attacks a Defense Position monster, inflict piercing battle damage. If this card was Tribute Summoned by Tributing a "Gadget" monster, it can make a second attack during each Battle Phase. If this card attacks, your opponent cannot activate Spell/Trap Cards and monster effects until the end of the Damage Step. At the end of the Damage Step, if this card attacked: You can destroy 1 Spell/Trap on the field.
external_ids: local SETCARD_ID_0 = 0x7 --Ancient
  local SETCARD_ID_1 = 0x51 --Gadget
  
lua: local SETCARD_ID_0 = 0x7 --Ancient
  local SETCARD_ID_1 = 0x51 --Gadget
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--mat check
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MATERIAL_CHECK)
  	e1:SetValue(s.valcheck)
  	c:RegisterEffect(e1)
  	--summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	e2:SetLabelObject(e1)
  	--actlimit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(0, 1)
  	e3:SetValue(s.aclimit)
  	e3:SetCondition(s.actcon)
  	c:RegisterEffect(e3)
  	--Destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.condition)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.valcheck(e, c)
  	local g = c:GetMaterial()
  	local flag = 0
  	local tc = g:GetFirst()
  	while tc do
  		if tc:IsSetCard(SETCARD_ID_1) and tc:IsType(TYPE_MONSTER) then
  			flag = bit.bor(flag, 0x1)
  		end
  		if tc:IsSetCard(SETCARD_ID_1) and tc:IsType(TYPE_MONSTER) then
  			flag = bit.bor(flag, 0x2)
  		end
  		tc = g:GetNext()
  	end
  	e:SetLabel(flag)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = e:GetLabelObject():GetLabel()
  	local c = e:GetHandler()
  	if bit.band(flag, 0x1) ~= 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_PIERCE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  	if bit.band(flag, 0x2) ~= 0 then
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_EXTRA_ATTACK)
  		e2:SetValue(1)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e2)
  	end
  end
  function s.aclimit(e, re, tp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) or re:IsActiveType(TYPE_MONSTER)
  end
  function s.actcon(e)
  	return Duel.GetAttacker() == e:GetHandler()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp) and Duel.GetAttacker() == e:GetHandler()
  end
  function s.desfilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Ancient
  If this card that was Tribute Summoned by Tributing an "Ancient Gear" monster attacks a Defense Position monster, inflict piercing battle damage. If this card was Tribute Summoned by Tributing a "Gadget" monster, it can make a second attack during each Battle Phase. If this card attacks, your opponent cannot activate Spell/Trap Cards and monster effects until the end of the Damage Step. At the end of the Damage Step, if this card attacked: You can destroy 1 Spell/Trap on the field.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x7 --Ancient
  local SETCARD_ID_1 = 0x51 --Gadget
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--mat check
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MATERIAL_CHECK)
  	e1:SetValue(s.valcheck)
  	c:RegisterEffect(e1)
  	--summon success
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	e2:SetLabelObject(e1)
  	--actlimit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(0, 1)
  	e3:SetValue(s.aclimit)
  	e3:SetCondition(s.actcon)
  	c:RegisterEffect(e3)
  	--Destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.condition)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.valcheck(e, c)
  	local g = c:GetMaterial()
  	local flag = 0
  	local tc = g:GetFirst()
  	while tc do
  		if tc:IsSetCard(SETCARD_ID_1) and tc:IsType(TYPE_MONSTER) then
  			flag = bit.bor(flag, 0x1)
  		end
  		if tc:IsSetCard(SETCARD_ID_1) and tc:IsType(TYPE_MONSTER) then
  			flag = bit.bor(flag, 0x2)
  		end
  		tc = g:GetNext()
  	end
  	e:SetLabel(flag)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_ADVANCE)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = e:GetLabelObject():GetLabel()
  	local c = e:GetHandler()
  	if bit.band(flag, 0x1) ~= 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_PIERCE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e1)
  	end
  	if bit.band(flag, 0x2) ~= 0 then
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_EXTRA_ATTACK)
  		e2:SetValue(1)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		c:RegisterEffect(e2)
  	end
  end
  function s.aclimit(e, re, tp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) or re:IsActiveType(TYPE_MONSTER)
  end
  function s.actcon(e)
  	return Duel.GetAttacker() == e:GetHandler()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp) and Duel.GetAttacker() == e:GetHandler()
  end
  function s.desfilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  