name: Advance
card_text: Once per turn, during the End Phase of any turn in which you Tribute Summoned a monster(s): You can apply these effects, in sequence, based on the number of monsters you Tributed for Tribute Summons this turn.
  ● 1 or more: Destroy 1 Set card your opponent controls.
  ● 2 or more: Draw 1 card.
  ● 3 or more: Add 1 monster from your Graveyard to your hand.
lua: 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)
  	--destroy/draw/salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = 0
  		s[1] = 0
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SUMMON_SUCCESS)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_MSET)
  		ge2:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge2, 0)
  		local ge3 = Effect.CreateEffect(c)
  		ge3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge3:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge3:SetOperation(s.clear)
  		Duel.RegisterEffect(ge3, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if tc:IsSummonType(SUMMON_TYPE_ADVANCE) then
  		s[ep] = s[ep] + tc:GetMaterial():FilterCount(Card.IsType, nil, TYPE_MONSTER)
  	end
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = 0
  	s[1] = 0
  end
  function s.filter1(c)
  	return c:IsFacedown()
  end
  function s.filter2(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = s[tp] > 0 and Duel.IsExistingMatchingCard(s.filter1, tp, 0, LOCATION_ONFIELD, 1, nil)
  	local b2 = s[tp] > 1 and Duel.IsPlayerCanDraw(tp, 1)
  	local b3 = s[tp] > 2 and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_GRAVE, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	if b1 then
  		local g = Duel.GetMatchingGroup(s.filter1, tp, 0, LOCATION_ONFIELD, nil)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  	if b2 then
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	end
  	if b3 then
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local act = false
  	if s[tp] > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.filter1, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.Destroy(g, REASON_EFFECT)
  			act = true
  		end
  	end
  	if s[tp] > 1 and Duel.IsPlayerCanDraw(tp, 1) then
  		if act then
  			Duel.BreakEffect()
  		end
  		Duel.Draw(tp, 1, REASON_EFFECT)
  		act = true
  	end
  	if s[tp] > 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			if act then
  				Duel.BreakEffect()
  			end
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  
  
source_text: Advance
  Once per turn, during the End Phase of any turn in which you Tribute Summoned a monster(s): You can apply these effects, in sequence, based on the number of monsters you Tributed for Tribute Summons this turn.
  ● 1 or more: Destroy 1 Set card your opponent controls.
  ● 2 or more: Draw 1 card.
  ● 3 or more: Add 1 monster from your Graveyard to your hand.
target_text: -- Advance
  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)
  	--destroy/draw/salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = 0
  		s[1] = 0
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SUMMON_SUCCESS)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_MSET)
  		ge2:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge2, 0)
  		local ge3 = Effect.CreateEffect(c)
  		ge3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge3:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge3:SetOperation(s.clear)
  		Duel.RegisterEffect(ge3, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if tc:IsSummonType(SUMMON_TYPE_ADVANCE) then
  		s[ep] = s[ep] + tc:GetMaterial():FilterCount(Card.IsType, nil, TYPE_MONSTER)
  	end
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = 0
  	s[1] = 0
  end
  function s.filter1(c)
  	return c:IsFacedown()
  end
  function s.filter2(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = s[tp] > 0 and Duel.IsExistingMatchingCard(s.filter1, tp, 0, LOCATION_ONFIELD, 1, nil)
  	local b2 = s[tp] > 1 and Duel.IsPlayerCanDraw(tp, 1)
  	local b3 = s[tp] > 2 and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_GRAVE, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	if b1 then
  		local g = Duel.GetMatchingGroup(s.filter1, tp, 0, LOCATION_ONFIELD, nil)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  	if b2 then
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	end
  	if b3 then
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local act = false
  	if s[tp] > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.filter1, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.Destroy(g, REASON_EFFECT)
  			act = true
  		end
  	end
  	if s[tp] > 1 and Duel.IsPlayerCanDraw(tp, 1) then
  		if act then
  			Duel.BreakEffect()
  		end
  		Duel.Draw(tp, 1, REASON_EFFECT)
  		act = true
  	end
  	if s[tp] > 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			if act then
  				Duel.BreakEffect()
  			end
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  
  