Ejemplo n.º 1
0
        /// <summary>
        /// 弃用了原因是太慢
        /// 玩家发来的战斗指令
        /// 根据battleId进行转发
        /// </summary>
        /// <param name="commandBattleLocalMessage"></param>
        private void OnBattleCommand(CommandBattleLocalMessage msg)
        {
            var battleId   = msg.battleId;
            var commandMsg = msg.ICommand;

            if (m_battleDic.TryGetValue(battleId, out Battle battle))
            {
                battle.SendCommandToLevel(commandMsg);
            }
        }
        /// <summary>
        /// 由客户端同步过来的个人指令
        /// 服务器做如下处理
        /// 1 验证 玩家的确定性
        /// 2 分发 至战斗现场
        /// 3 记录 指令
        /// </summary>
        /// <param name="playerContext"></param>
        /// <param name="message">网络消息</param>
        protected override void Run(ISession playerContext, C2S_CommandBattleMessage message)
        {
            CommandBattleLocalMessage localMessage = new CommandBattleLocalMessage {
                battleId = message.BattleId
            };

            using (MemoryStream ms = new MemoryStream(message.Command.ToByteArray()))
            {
                localMessage.ICommand = bf.Deserialize(ms) as ICommand;//将其反序列化
                //Log.Info("服务器收到指令时间:"+ (localMessage.ICommand as Command).currenttime);
                // (localMessage.ICommand as Command).currenttime = DateTime.Now;
                //Log.Debug("接收到一条指令:"+localMessage.ICommand.CommandType);
                //GameServer.Instance.PostMessageToSystem<BattleSystem>(localMessage);
                GameServer.Instance.GetSystem <BattleSystem>().GetBattleEntity(message.BattleId)?.SendCommandToLevel(localMessage.ICommand);
            }
        }