name: 御前試合
card_text: 1:このカードが魔法&罠ゾーンに存在する限り、お互いのフィールドにそれぞれ1種類の属性のモンスターしか表側表示で存在できない。
  お互いのプレイヤーは自身のフィールドの表側表示モンスターの属性が2種類以上の場合には1種類になるように墓地へ送らなければならない。
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)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetTarget(s.acttg)
  	c:RegisterEffect(e1)
  	--adjust
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EVENT_ADJUST)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetOperation(s.adjustop)
  	c:RegisterEffect(e2)
  	--cannot summon,spsummon,flipsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EFFECT_LIMIT_SPECIAL_SUMMON_POSITION)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetTargetRange(1, 1)
  	e4:SetTarget(s.sumlimit)
  	c:RegisterEffect(e4)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCode(EFFECT_CANNOT_SUMMON)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetTargetRange(1, 1)
  	e5:SetTarget(s.sumlimit)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	e6:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e6:SetTargetRange(1, 1)
  	e6:SetTarget(s.sumlimit)
  	c:RegisterEffect(e6)
  end
  s[0] = 0
  s[1] = 0
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	s[0] = 0
  	s[1] = 0
  end
  function s.limfilter(c)
  	return c:IsFaceup() and c:IsStatus(STATUS_EFFECT_ENABLED)
  end
  function s.sumlimit(e, c, sump, sumtype, sumpos, targetp)
  	if sumpos and bit.band(sumpos, POS_FACEDOWN) > 0 then
  		return false
  	end
  	local at = s.getattribute(Duel.GetMatchingGroup(s.limfilter, targetp or sump, LOCATION_MZONE, 0, nil))
  	if at == 0 then
  		return false
  	end
  	return c:GetAttribute() ~= at
  end
  function s.getattribute(g)
  	local aat = 0
  	local tc = g:GetFirst()
  	while tc do
  		aat = bit.bor(aat, tc:GetAttribute())
  		tc = g:GetNext()
  	end
  	return aat
  end
  function s.rmfilter(c, at)
  	return c:GetAttribute() == at
  end
  function s.isonlyone(val)
  	return val & (val - 1) == 0
  end
  function s.tgselect(sg, g)
  	local att = s.getattribute(g - sg)
  	return att > 0 and s.isonlyone(att) and not sg:IsExists(s.rmfilter, 1, nil, att)
  end
  function s.adjustop(e, tp, eg, ep, ev, re, r, rp)
  	local phase = Duel.GetCurrentPhase()
  	if (phase == PHASE_DAMAGE and not Duel.IsDamageCalculated()) or phase == PHASE_DAMAGE_CAL then
  		return
  	end
  	local g1 = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	local c = e:GetHandler()
  	if g1:GetCount() == 0 then
  		s[tp] = 0
  	else
  		local att = s.getattribute(g1)
  		if not s.isonlyone(att) then
  			if s[tp] == 0 or bit.band(s[tp], att) == 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  				local sg = g1:SelectSubGroup(tp, s.tgselect, false, 1, #g1, g1)
  				if not sg then
  					att = 0
  				else
  					att = s.getattribute(g1 - sg)
  				end
  			else
  				att = s[tp]
  			end
  		end
  		g1:Remove(s.rmfilter, nil, att)
  		s[tp] = att
  	end
  	if g2:GetCount() == 0 then
  		s[1 - tp] = 0
  	else
  		local att = s.getattribute(g2)
  		if not s.isonlyone(att) then
  			if s[1 - tp] == 0 or bit.band(s[1 - tp], att) == 0 then
  				Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_TOGRAVE)
  				local sg = g2:SelectSubGroup(1 - tp, s.tgselect, false, 1, #g2, g2)
  				if not sg then
  					att = 0
  				else
  					att = s.getattribute(g2 - sg)
  				end
  			else
  				att = s[1 - tp]
  			end
  		end
  		g2:Remove(s.rmfilter, nil, att)
  		s[1 - tp] = att
  	end
  	g1:Merge(g2)
  	if g1:GetCount() > 0 then
  		Duel.SendtoGrave(g1, REASON_RULE)
  		Duel.Readjust()
  	end
  end
  
  
source_text: 御前試合
  1:このカードが魔法&罠ゾーンに存在する限り、お互いのフィールドにそれぞれ1種類の属性のモンスターしか表側表示で存在できない。
  お互いのプレイヤーは自身のフィールドの表側表示モンスターの属性が2種類以上の場合には1種類になるように墓地へ送らなければならない。
target_text: -- 御前試合
  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)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetTarget(s.acttg)
  	c:RegisterEffect(e1)
  	--adjust
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EVENT_ADJUST)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetOperation(s.adjustop)
  	c:RegisterEffect(e2)
  	--cannot summon,spsummon,flipsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EFFECT_LIMIT_SPECIAL_SUMMON_POSITION)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetTargetRange(1, 1)
  	e4:SetTarget(s.sumlimit)
  	c:RegisterEffect(e4)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCode(EFFECT_CANNOT_SUMMON)
  	e5:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e5:SetTargetRange(1, 1)
  	e5:SetTarget(s.sumlimit)
  	c:RegisterEffect(e5)
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	e6:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e6:SetTargetRange(1, 1)
  	e6:SetTarget(s.sumlimit)
  	c:RegisterEffect(e6)
  end
  s[0] = 0
  s[1] = 0
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	s[0] = 0
  	s[1] = 0
  end
  function s.limfilter(c)
  	return c:IsFaceup() and c:IsStatus(STATUS_EFFECT_ENABLED)
  end
  function s.sumlimit(e, c, sump, sumtype, sumpos, targetp)
  	if sumpos and bit.band(sumpos, POS_FACEDOWN) > 0 then
  		return false
  	end
  	local at = s.getattribute(Duel.GetMatchingGroup(s.limfilter, targetp or sump, LOCATION_MZONE, 0, nil))
  	if at == 0 then
  		return false
  	end
  	return c:GetAttribute() ~= at
  end
  function s.getattribute(g)
  	local aat = 0
  	local tc = g:GetFirst()
  	while tc do
  		aat = bit.bor(aat, tc:GetAttribute())
  		tc = g:GetNext()
  	end
  	return aat
  end
  function s.rmfilter(c, at)
  	return c:GetAttribute() == at
  end
  function s.isonlyone(val)
  	return val & (val - 1) == 0
  end
  function s.tgselect(sg, g)
  	local att = s.getattribute(g - sg)
  	return att > 0 and s.isonlyone(att) and not sg:IsExists(s.rmfilter, 1, nil, att)
  end
  function s.adjustop(e, tp, eg, ep, ev, re, r, rp)
  	local phase = Duel.GetCurrentPhase()
  	if (phase == PHASE_DAMAGE and not Duel.IsDamageCalculated()) or phase == PHASE_DAMAGE_CAL then
  		return
  	end
  	local g1 = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	local c = e:GetHandler()
  	if g1:GetCount() == 0 then
  		s[tp] = 0
  	else
  		local att = s.getattribute(g1)
  		if not s.isonlyone(att) then
  			if s[tp] == 0 or bit.band(s[tp], att) == 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  				local sg = g1:SelectSubGroup(tp, s.tgselect, false, 1, #g1, g1)
  				if not sg then
  					att = 0
  				else
  					att = s.getattribute(g1 - sg)
  				end
  			else
  				att = s[tp]
  			end
  		end
  		g1:Remove(s.rmfilter, nil, att)
  		s[tp] = att
  	end
  	if g2:GetCount() == 0 then
  		s[1 - tp] = 0
  	else
  		local att = s.getattribute(g2)
  		if not s.isonlyone(att) then
  			if s[1 - tp] == 0 or bit.band(s[1 - tp], att) == 0 then
  				Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_TOGRAVE)
  				local sg = g2:SelectSubGroup(1 - tp, s.tgselect, false, 1, #g2, g2)
  				if not sg then
  					att = 0
  				else
  					att = s.getattribute(g2 - sg)
  				end
  			else
  				att = s[1 - tp]
  			end
  		end
  		g2:Remove(s.rmfilter, nil, att)
  		s[1 - tp] = att
  	end
  	g1:Merge(g2)
  	if g1:GetCount() > 0 then
  		Duel.SendtoGrave(g1, REASON_RULE)
  		Duel.Readjust()
  	end
  end
  
  