--重起士道-镜战车
local s,id,o=GetID()
function s.initial_effect(c)
	aux.EnableDualAttribute(c)
	--destroy
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetCategory(CATEGORY_DESTROY)
	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
	e1:SetProperty(EFFECT_FLAG_DELAY)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetCountLimit(1,id)
	e1:SetCondition(aux.IsDualState)
	e1:SetTarget(s.destg)
	e1:SetOperation(s.desop)
	c:RegisterEffect(e1)
	local e2=e1:Clone()
	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
	c:RegisterEffect(e2)
	--change race
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_SINGLE)
	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e3:SetCode(EFFECT_CHANGE_RACE)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCondition(aux.IsDualState)
	e3:SetValue(RACE_MACHINE)
	c:RegisterEffect(e3)
	--atk up
	local e4=e3:Clone()
	e4:SetCode(EFFECT_UPDATE_ATTACK)
	e4:SetValue(500)
	c:RegisterEffect(e4)
end
s.has_text_type=TYPE_DUAL
function s.filter(c)
	return (c:IsType(TYPE_NORMAL) or c:IsType(TYPE_DUAL)) and c:IsType(TYPE_MONSTER) and c:IsFaceup()
end
function s.descheck(g,tp)
	if g:GetCount()>0 then
		local ct=g:GetFirst()
		while ct do
			local dg=ct:GetColumnGroup():Filter(Card.IsControler,nil,1-tp)
			if dg:GetCount()>0 then
				return true 
			end
			ct=g:GetNext()
		end
	end
end
function s.destg(e,tp,eg,ep,ev,re,r,rp,chk)
	local g=Duel.GetMatchingGroup(s.filter,tp,LOCATION_MZONE,0,nil)
	if chk==0 then return s.descheck(g,tp) end
	local desnumber=0
	local dg=nil
	if g:GetCount()>0 then
		local ct=g:GetFirst()
		local dg1=ct:GetColumnGroup():Filter(Card.IsControler,nil,1-tp)
		desnumber=dg1:GetCount()+desnumber
		dg=dg1
		ct=g:GetNext()
		while ct do
			local dg1=ct:GetColumnGroup():Filter(Card.IsControler,nil,1-tp)
			desnumber=dg1:GetCount()+desnumber
			dg=dg+dg1
			ct=g:GetNext()
		end
	end
	Duel.SetOperationInfo(0,CATEGORY_DESTROY,dg,desnumber,0,0)
end
function s.desop(e,tp,eg,ep,ev,re,r,rp)
	local g=Duel.GetMatchingGroup(s.filter,tp,LOCATION_MZONE,0,nil)
	if g:GetCount()>0 then
		local desnumber=0
		local dg=nil
		if g:GetCount()>0 then
			local ct=g:GetFirst()
			local dg1=ct:GetColumnGroup():Filter(Card.IsControler,nil,1-tp)
			desnumber=dg1:GetCount()+desnumber
			dg=dg1
			ct=g:GetNext()
			while ct do
				local dg1=ct:GetColumnGroup():Filter(Card.IsControler,nil,1-tp)
				desnumber=dg1:GetCount()+desnumber
				dg=dg+dg1
				ct=g:GetNext()
			end
		end
		if desnumber>0 then
			Duel.Destroy(dg,REASON_EFFECT)
		end
	end
end