public override void PlayerLeave(CoreGameRootViewModel viewModel) { base.PlayerLeave(viewModel); // 在 PlayerCollection 中查找 LBRoom 中没有的, 删除 List <PlayerViewModel> player_need_remove = new List <PlayerViewModel> (); viewModel.PlayerCollection.ToList().ForEach(vm => { if (Network.Client.CurrentRoom.Players.ToList().Exists(kv => kv.Value.ID == vm.ActorId) == false) { player_need_remove.Add(vm); } }); foreach (var vm in player_need_remove) { viewModel.PlayerCollection.Remove(vm); } viewModel.ExecuteCalcPosIdAndRepos(); viewModel.ExecuteRefreshCoreGame(); }
public override void PlayerJoin(CoreGameRootViewModel viewModel) { base.PlayerJoin(viewModel); // 在 LBRoom 中查找 PlayerCollection 中没有的, 加入 Network.Client.CurrentRoom.Players.OrderBy(_ => _.Key).ToList().ForEach(kv => { int actorId = kv.Key; Player player = kv.Value; if (viewModel.PlayerCollection.ToList().Exists(vm => vm.ActorId == actorId) == false) { PlayerViewModel playerVM = MVVMKernelExtensions.CreateViewModel <PlayerViewModel> (); playerVM.ActorId = player.ID; playerVM.PlayerName = player.Name; playerVM.IsSelf = player.IsLocal; playerVM.PlayerRoomIdentity = player.IsMasterClient ? RoomIdentity.RoomMaster : RoomIdentity.RoomGuest; playerVM.LBPlayer = player; viewModel.PlayerCollection.Add(playerVM); } }); viewModel.ExecuteCalcPosIdAndRepos(); viewModel.ExecuteRefreshCoreGame(); }