name: Sangenpai
card_text: 1 Dragon Tuner + 1+ non-Tuner Dragon monsters
  All monsters your opponent controls must attack, if able. Your opponent cannot activate cards or effects during the Battle Phase. If this card is Synchro Summoned: You can change all monsters on the field to Attack Position. If 3 or more attacks have been declared this turn (Quick Effect): You can Special Summon this card from your GY, then you can destroy 1 card on the field. You can only use this effect of "Sangenpai Transcendent Dragion" once per Duel.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_DRAGON), aux.NonTuner(Card.IsRace, RACE_DRAGON), 1)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.poscon)
  	e1:SetTarget(s.postg)
  	e1:SetOperation(s.posop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_MUST_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(0, LOCATION_MZONE)
  	c:RegisterEffect(e2)
  	--
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(0, 1)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetValue(1)
  	e3:SetCondition(s.actcon)
  	c:RegisterEffect(e3)
  	--
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetHintTiming(0, TIMING_BATTLE_START + TIMING_ATTACK + TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL)
  	e4:SetCondition(s.spcon)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  	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_ATTACK_ANNOUNCE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	Duel.RegisterFlagEffect(1 - tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	local sg = Duel.GetMatchingGroup(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, sg, sg:GetCount(), 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = Duel.GetMatchingGroup(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if sg:GetCount() > 0 then
  		local sc = sg:GetFirst()
  		while sc do
  			Duel.ChangePosition(sc, POS_FACEUP_ATTACK)
  			sc = sg:GetNext()
  		end
  	end
  end
  function s.actcon(e)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) >= 3
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return true
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 4))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_CLIENT_HINT)
  	e1:SetTargetRange(1, 0)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if
  		c:IsRelateToEffect(e)
  		and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0
  		and Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD):GetCount() > 0
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 3))
  	then
  		local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD):Select(tp, 1, 1, nil)
  		if #g > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Sangenpai
  1 Dragon Tuner + 1+ non-Tuner Dragon monsters
  All monsters your opponent controls must attack, if able. Your opponent cannot activate cards or effects during the Battle Phase. If this card is Synchro Summoned: You can change all monsters on the field to Attack Position. If 3 or more attacks have been declared this turn (Quick Effect): You can Special Summon this card from your GY, then you can destroy 1 card on the field. You can only use this effect of "Sangenpai Transcendent Dragion" once per Duel.
target_text: -- Sangenpai
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_DRAGON), aux.NonTuner(Card.IsRace, RACE_DRAGON), 1)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.poscon)
  	e1:SetTarget(s.postg)
  	e1:SetOperation(s.posop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_MUST_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(0, LOCATION_MZONE)
  	c:RegisterEffect(e2)
  	--
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(0, 1)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetValue(1)
  	e3:SetCondition(s.actcon)
  	c:RegisterEffect(e3)
  	--
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetHintTiming(0, TIMING_BATTLE_START + TIMING_ATTACK + TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL)
  	e4:SetCondition(s.spcon)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  	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_ATTACK_ANNOUNCE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	Duel.RegisterFlagEffect(1 - tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	local sg = Duel.GetMatchingGroup(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, sg, sg:GetCount(), 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = Duel.GetMatchingGroup(Card.IsDefensePos, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if sg:GetCount() > 0 then
  		local sc = sg:GetFirst()
  		while sc do
  			Duel.ChangePosition(sc, POS_FACEUP_ATTACK)
  			sc = sg:GetNext()
  		end
  	end
  end
  function s.actcon(e)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFlagEffect(tp, id) >= 3
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return true
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 4))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_CLIENT_HINT)
  	e1:SetTargetRange(1, 0)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if
  		c:IsRelateToEffect(e)
  		and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0
  		and Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD):GetCount() > 0
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 3))
  	then
  		local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD):Select(tp, 1, 1, nil)
  		if #g > 0 then
  			Duel.BreakEffect()
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  
  