Skip to content

Commit

Permalink
Allow single observers to use spectator team chat in mp
Browse files Browse the repository at this point in the history
  • Loading branch information
abcdefg30 authored and teinarss committed Aug 19, 2019
1 parent 3fe78a8 commit 8cf6aa2
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs
Expand Up @@ -49,10 +49,8 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo

var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot);
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 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;

tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
Expand All @@ -73,47 +71,26 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo
chatMode.GetText = () => teamChat && !disableTeamChat ? "Team" : "All";
chatMode.OnClick = () => teamChat ^= true;

// Team chat is disabled if we are the only spectator
// This changes as soon as a defeated player can talk in the spectator chat
if (!alwaysDisabled && isOnlyObserver)
// Enable teamchat if we are a player and die,
// or disable it when we are the only one left in the team
if (!alwaysDisabled && world.LocalPlayer != null)
{
chatMode.IsDisabled = () =>
{
if (world.IsGameOver)
return true;
disableTeamChat = players.All(p => p.WinState == WinState.Undefined);
return disableTeamChat;
};
}
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)
// The game is over for us, join spectator team chat
if (world.LocalPlayer.WinState != WinState.Undefined)
{
disableTeamChat = false;
return disableTeamChat;
}
// Or wait until another player died
disableTeamChat = players.All(p => p.WinState == WinState.Undefined);
// If team chat isn't already disabled, check if we are the only living team member
if (!disableTeamChat)
disableTeamChat = players.All(p => p.WinState != WinState.Undefined || !p.IsAlliedWith(world.LocalPlayer));
return disableTeamChat;
};
}
Expand Down

0 comments on commit 8cf6aa2

Please sign in to comment.