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

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
