Allow single observers to use spectator team chat in mp
This commit is contained in:
@@ -49,10 +49,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
|
var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
|
||||||
var isObserver = orderManager.LocalClient != null && orderManager.LocalClient.IsObserver;
|
var isObserver = orderManager.LocalClient != null && orderManager.LocalClient.IsObserver;
|
||||||
var isOnlyObserver = isObserver && orderManager.LobbyInfo.Clients.All(c => c == orderManager.LocalClient || !c.IsObserver);
|
|
||||||
var observersExist = orderManager.LobbyInfo.Clients.Any(c => c.IsObserver);
|
|
||||||
var alwaysDisabled = world.IsReplay || world.LobbyInfo.NonBotClients.Count() == 1;
|
var alwaysDisabled = world.IsReplay || world.LobbyInfo.NonBotClients.Count() == 1;
|
||||||
var disableTeamChat = alwaysDisabled || isOnlyObserver || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
|
var disableTeamChat = alwaysDisabled || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
|
||||||
var teamChat = !disableTeamChat;
|
var teamChat = !disableTeamChat;
|
||||||
|
|
||||||
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
|
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
|
||||||
@@ -73,47 +71,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
chatMode.GetText = () => teamChat && !disableTeamChat ? "Team" : "All";
|
chatMode.GetText = () => teamChat && !disableTeamChat ? "Team" : "All";
|
||||||
chatMode.OnClick = () => teamChat ^= true;
|
chatMode.OnClick = () => teamChat ^= true;
|
||||||
|
|
||||||
// Team chat is disabled if we are the only spectator
|
// Enable teamchat if we are a player and die,
|
||||||
// This changes as soon as a defeated player can talk in the spectator chat
|
// or disable it when we are the only one left in the team
|
||||||
if (!alwaysDisabled && isOnlyObserver)
|
if (!alwaysDisabled && world.LocalPlayer != null)
|
||||||
{
|
{
|
||||||
chatMode.IsDisabled = () =>
|
chatMode.IsDisabled = () =>
|
||||||
{
|
{
|
||||||
if (world.IsGameOver)
|
if (world.IsGameOver)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
disableTeamChat = players.All(p => p.WinState == WinState.Undefined);
|
// The game is over for us, join spectator team chat
|
||||||
return disableTeamChat;
|
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (!alwaysDisabled && world.LocalPlayer != null)
|
|
||||||
{
|
|
||||||
chatMode.IsDisabled = () =>
|
|
||||||
{
|
|
||||||
if (world.IsGameOver)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Check if we are the only living team member
|
|
||||||
if (players.All(p => p.WinState != WinState.Undefined || !p.IsAlliedWith(world.LocalPlayer)))
|
|
||||||
{
|
|
||||||
disableTeamChat = true;
|
|
||||||
return disableTeamChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still alive and nothing changed since the start
|
|
||||||
if (world.LocalPlayer.WinState == WinState.Undefined)
|
|
||||||
return disableTeamChat;
|
|
||||||
|
|
||||||
// At this point our player is dead
|
|
||||||
// Allow to chat with existing spectators
|
|
||||||
if (observersExist)
|
|
||||||
{
|
{
|
||||||
disableTeamChat = false;
|
disableTeamChat = false;
|
||||||
return disableTeamChat;
|
return disableTeamChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Or wait until another player died
|
// If team chat isn't already disabled, check if we are the only living team member
|
||||||
disableTeamChat = players.All(p => p.WinState == WinState.Undefined);
|
if (!disableTeamChat)
|
||||||
|
disableTeamChat = players.All(p => p.WinState != WinState.Undefined || !p.IsAlliedWith(world.LocalPlayer));
|
||||||
|
|
||||||
return disableTeamChat;
|
return disableTeamChat;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user