Exemple #1
0
        /// <summary>
        /// 创建玩家
        /// </summary>
        /// <param name="netstate"></param>
        /// <param name="playerName"></param>
        /// <param name="sex"></param>
        public void OnCreatePlayer(NetState netstate, string playerName, Sex sex)
        {
            //  如果已经创建过(例如玩家连续点了两次创建角色)
            var player = WorldEntityManager.PlayerCache.GetEntity(netstate.BizId);
            if (player != null)
            {
                ClientProxy.Login.CreatePlayerResult(netstate, CraetePlayerResult.Fail);
                return;
            }

            player = new Player
            {
                Id = netstate.BizId,
                AccountId = netstate.BizId,
                Name = playerName,
                Sex = sex,
                NetState = netstate
            };

            DB.GameDB.InsertEntity(player);

            WorldEntityManager.PlayerCache.AddOrReplace(player);

            Logs.Info("角色 {0}({1}) 创建成功", playerName, player.Id);

            netstate.Player = player;
            PlayerEnterGame(player);

            ClientProxy.Login.CreatePlayerResult(netstate, CraetePlayerResult.Success);
        }
Exemple #2
0
        /// <summary>
        /// 玩家进入游戏
        /// </summary>
        /// <param name="player"></param>
        private void OnPlayerEnterGame(Player player)
        {
            List<SceneSprite> existsPlayers = new List<SceneSprite>();

            //  广播给场景里的其它玩家有玩家进入
            var onlinePlayer = WorldEntityManager.OnlinePlayers.ToArray();
            foreach (var p in onlinePlayer)
            {
                if (p.Id != player.Id)
                {
                    existsPlayers.Add(p.GetSceneSprite());
                    ClientProxy.Scene.SpriteEnter(p.NetState, player.GetSceneSprite());
                }
            }

            //  给当前进入的玩家当前场景里有的玩家
            ClientProxy.Scene.SpriteEnter(player.NetState, existsPlayers.ToArray());
        }
Exemple #3
0
 void PlayerEnterGame(Player player)
 {
     WorldEntityManager.OnlinePlayers.SetValue(player.Id, player);
     PlayerEvents.OnEnterGame(player);
 }
Exemple #4
0
 /// <summary>
 /// 玩家离开游戏
 /// </summary>
 /// <param name="player"></param>
 private void OnPlayerExitGame(Player player)
 {
     //  广播给场景里的其它玩家有玩家离开
     var onlinePlayer = WorldEntityManager.OnlinePlayers.ToArray();
     foreach (var p in onlinePlayer)
     {
         if (p.Id != player.Id)
         {
             ClientProxy.Scene.SpriteLeave(p.NetState, player.Id);
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// 触发离开游戏事件
 /// </summary>
 /// <param name="player"></param>
 public static void OnExitGame(Player player)
 {
     var temp = ExitGame;
     if (temp != null)
         temp(player);
 }
Exemple #6
0
        void PlayerEnterGame(Player player)
        {
            WorldEntityManager.OnlinePlayers.SetValue(player.Id, player);

            ClientProxy.Scene.EnterSceneInfo(player.NetState, player.GetSimplePlayer());

            PlayerEvents.OnEnterGame(player);

            ClientProxy.Login.SyncInitDataFinish(player.NetState);
        }