function TeamManager.ClearTeamScores(U)for U,A in ipairs(Teams:GetTeams())do TeamScores[A]=0 DisplayManager:UpdateScore(A,0)end end function TeamManager.HasTeamWon(U)for U,A in ipairs(Teams:GetTeams())do if TeamScores[A]>=Configurations.MainGameConfig["\067\097\112\116\117\114\101\115 \084\111 \087\105\110"]then return A end end return false end function TeamManager.GetWinningTeam(U)local A=0 local O=nil for U,p in ipairs(Teams:GetTeams())do if TeamScores[p]>A then A=TeamScores[p]O=p for U,A in ipairs(TeamPlayers[O])do A.leaderstats.Cash.Value+=100 end end end return O end function TeamManager.AreTeamsTied(U)local A=Teams:GetTeams()local O=0 local p=false for U,A in ipairs(A)do if TeamScores[A]==O then p=true elseif TeamScores[A]>O then p=false O=TeamScores[A]end end return p end function TeamManager.AssignPlayerToTeam(A,U)local O local p=math.huge for U,A in pairs(TeamPlayers)do if#A<p then O=U p=#A end end table.insert(TeamPlayers[O],U)U.Neutral=false U.TeamColor=O.TeamColor end function TeamManager.RemovePlayer(A,U)local O=GetTeamFromColor(U.TeamColor)local p=TeamPlayers[O]for A=1,#p,1 do if p[A]==U then table.remove(p,A)return end end end function TeamManager.ShuffleTeams(U)for U,A in ipairs(Teams:GetTeams())do TeamPlayers[A]={}end local A=Players:GetPlayers()while#A>0 do local U=math.random(1,#A)local O=table.remove(A,U)TeamManager:AssignPlayerToTeam(O)end end function TeamManager.AddTeamScore(O,U,A)local p=GetTeamFromColor(U)TeamScores[p]=TeamScores[p]+A DisplayManager:UpdateScore(p,TeamScores[p])end return TeamManager


function TeamManager:ClearTeamScores()
	for _, team in ipairs(Teams:GetTeams()) do
		TeamScores[team] = 0
		DisplayManager:UpdateScore(team, 0)
	end
end

function TeamManager:HasTeamWon()
	for _, team in ipairs(Teams:GetTeams()) do
		if TeamScores[team] >= Configurations.MainGameConfig["Captures To Win"] then
			return team
		end
	end
	return false
end

function TeamManager:GetWinningTeam()
	local highestScore = 0
	local winningTeam = nil
	for _, team in ipairs(Teams:GetTeams()) do
		if TeamScores[team] > highestScore then
			highestScore = TeamScores[team]
			winningTeam = team
			for i, winningPlayer in ipairs(TeamPlayers[winningTeam]) do
				winningPlayer.leaderstats.Cash.Value += 100
			end
		end
	end
	return winningTeam
end

function TeamManager:AreTeamsTied()
	local teams = Teams:GetTeams()
	local highestScore = 0
	local tied = false
	for _, team in ipairs(teams) do
		if TeamScores[team] == highestScore then
			tied = true
		elseif TeamScores[team] > highestScore then
			tied = false
			highestScore = TeamScores[team]
		end
	end
	return tied
end

function TeamManager:AssignPlayerToTeam(player)
	local smallestTeam
	local lowestCount = math.huge
	for team, playerList in pairs(TeamPlayers) do
		if #playerList < lowestCount then
			smallestTeam = team
			lowestCount = #playerList
		end
	end
	table.insert(TeamPlayers[smallestTeam], player)
	player.Neutral = false
	player.TeamColor = smallestTeam.TeamColor
end

function TeamManager:RemovePlayer(player)
	local team = GetTeamFromColor(player.TeamColor)
	local teamTable = TeamPlayers[team]
	for i = 1, #teamTable do
		if teamTable[i] == player then
			table.remove(teamTable, i)
			return
		end
	end
end

function TeamManager:ShuffleTeams()
	for _, team in ipairs(Teams:GetTeams()) do
		TeamPlayers[team] = {}
	end
	local players = Players:GetPlayers()
	while #players > 0 do
		local rIndex = math.random(1, #players)
		local player = table.remove(players, rIndex)
		TeamManager:AssignPlayerToTeam(player)
	end
end

function TeamManager:AddTeamScore(teamColor, score)
	local team = GetTeamFromColor(teamColor)
	TeamScores[team] = TeamScores[team] + score
	DisplayManager:UpdateScore(team, TeamScores[team])
end

return TeamManager
