public async Task PlayerEnterRoom(IUserGrain user) { if (!_players.ContainsKey(user.GetPrimaryKeyLong())) { _players[user.GetPrimaryKeyLong()] = new PlayerData(user); } await user.SubscribeRoom(_stream.Guid); { S2C100001 content = new S2C100001(); content.RoomId = (int)this.GetPrimaryKeyLong(); foreach (var item in _players) { PlayerData player = null; if (_players.TryGetValue(item.Key, out player)) { var userPoint = new UserTransform(); userPoint.UserId = item.Key; userPoint.UserName = await player.User.GetNickName(); userPoint.Position = new MsgVector3(); userPoint.Position.X = player.Position.X; userPoint.Position.Y = player.Position.Y; userPoint.Position.Z = player.Position.Z; userPoint.Rotation = new MsgVector3(); userPoint.Rotation.X = player.Rotate.X; userPoint.Rotation.Y = player.Rotate.Y; userPoint.Rotation.Z = player.Rotate.Z; content.UserTransforms.Add(userPoint); } } MOMsg msg = new MOMsg(); msg.ActionId = 100001; msg.Content = content.ToByteString(); await user.Notify(msg); } { S2C100002 content = new S2C100002(); content.UserId = user.GetPrimaryKeyLong(); content.RoomId = (int)this.GetPrimaryKeyLong(); content.UserName = await user.GetNickName(); MOMsg msg = new MOMsg(); msg.ActionId = 100002; msg.Content = content.ToByteString(); await RoomNotify(msg); } }
public void Handle(object sender, Packet packet) { S2C100002 rep = S2C100002.Parser.ParseFrom(((MOPacket)packet).Packet.Content); if (rep.UserId == GameUser.Instance.UserId) { return; } if (!GameUser.Instance.Players.ContainsKey(rep.UserId)) { var newPlayer = new PlayerData(); newPlayer.UserId = rep.UserId; newPlayer.UserName = rep.UserName; GameUser.Instance.Players.Add(rep.UserId, newPlayer); newPlayer.ShowEntity(); } }