Fix players list crash

This commit is contained in:
Ilya 2021-03-04 19:48:16 +03:00
parent 96171d4d70
commit 7e6669c01f
2 changed files with 15 additions and 8 deletions

View File

@ -265,20 +265,25 @@ namespace MafiaClient
private void GameDaySelect_OnMouseDoubleClick(object sender, RoutedEventArgs e)
{
ListBoxItem selected = (ListBoxItem)(this.FindControl<ListBox>("GameDaySelect").SelectedItem);
App.Instance.Connection.Vote(Convert.ToInt32(((string)selected.Content).Split(")")[0]));
if (this.FindControl<ListBox>("GameDaySelect").SelectedItem != null)
{
ListBoxItem selected = (ListBoxItem) (this.FindControl<ListBox>("GameDaySelect").SelectedItem);
App.Instance.Connection.Vote(Convert.ToInt32(((string) selected.Content).Split(")")[0]));
}
}
public void ShowDay(bool voting, Role role, List<Player> players)
{
this.FindControl<ListBox>("GameDaySelect").IsEnabled = voting;
if (players.Count != 0)
{
List<ListBoxItem> items = new List<ListBoxItem>();
foreach (Player player in players)
{
items.Add(new ListBoxItem {Content = player.Id.ToString() + ") " + player.Name});
items.Add(new ListBoxItem {Content = player.Id + ") " + player.Name});
}
this.FindControl<ListBox>("GameDaySelect").Items = items;
}
if (role == Role.Died)
{

View File

@ -223,9 +223,11 @@ namespace MafiaServer
_votesRemain.Add(player);
}
List<Player> players = GetPlayersRoles();
foreach (var player in _players)
{
player.SendPacket(new GameStageChangedPacket(GameState.VotingDay, player.Role, GetPlayersRoles()));
player.SendPacket(new GameStageChangedPacket(GameState.VotingDay, player.Role, players));
player.SendPacket(new MessageReceivePacket(ChatType.Day, true, "System", "Начинаем голосование!"));
}
}