public bool Modify(uint id, HappyPlayer data) { if(PlayerDictionary.ContainsKey(id)) { PlayerDictionary[id] = data; return true; } return false; }
private static bool OnProcessHappyLogin(NetServer server, int id, NetIncomingMessage msg) { var r = new Msg_HappyPlayerLogin(); r.R(msg); uint uid = HappyGameId; int x = RandomMaker.Next(10); int y = RandomMaker.Next(10); uint sid = (uint)RandomMaker.Next(83); var selfMsg = new Msg_HappyPlayerLoginRsp(); selfMsg.Uid = uid; selfMsg.X = x; selfMsg.Y = y; selfMsg.SpriteId = sid; SendMessage(server, selfMsg, msg.SenderConnection); // 更新链接对应的ID HappyConnMgr.Modify(msg.SenderConnection, uid); var playerPackMsg = new Msg_HappyPlayerPack(); // 为新玩家推送旧玩家信息 var playerList = HappyPlayerMgr.ToList(); var playerPackList = from f in playerList select Tuple.Create<uint, int, int, bool, uint>(f.Key, f.Value.X, f.Value.Y, f.Value.IsAlive, f.Value.SpriteId); playerPackMsg.PlayerPack = playerPackList.ToList(); SendMessage(server, playerPackMsg, msg.SenderConnection); // 为旧玩家推送新玩家信息 var otherMsg = new Msg_HappyOtherPlayerLogin(); otherMsg.Uid = uid; otherMsg.X = x; otherMsg.Y = y; otherMsg.SpriteId = sid; SendMessageExceptOne(server, otherMsg, msg.SenderConnection); // 添加新玩家到玩家管理中 var player = new HappyPlayer(); player.X = x; player.Y = y; player.IsAlive = true; player.SpriteId = sid; HappyPlayerMgr.Add(uid, player); return true; }
public void Add(uint id, HappyPlayer player) { PlayerDictionary[id] = player; }