예제 #1
0
        public void Handle(object sender, Packet packet)
        {
            S2C100010 rep = S2C100010.Parser.ParseFrom(((MOPacket)packet).Packet.Content);

            if (GlobalGame.FrameCount != 0)
            {
                var nextFrameCount = GlobalGame.FrameCount + 1;
                if (nextFrameCount != rep.FrameCount)
                {
                    Log.Info("丢帧");
                }
            }
            GlobalGame.FrameCount = rep.FrameCount;
            PlayerData player;

            foreach (var command in rep.Commands)
            {
                if (GameUser.Instance.Players.TryGetValue(command.UserId, out player))
                {
                    if (command.UserId == GameUser.Instance.UserId)
                    {
                        continue;
                    }

                    switch (command.CommandId)
                    {
                    case (int)CommandType.BigSkill:
                        player.ShowBigSkill();
                        break;

                    case (int)CommandType.Jump:
                        player.Jump();
                        break;

                    case (int)CommandType.SkillC:
                        player.ShowSkillC();
                        break;

                    case (int)CommandType.SkillX:
                        player.ShowSkillX();
                        break;

                    case (int)CommandType.SkillZ:
                        player.ShowSkillZ();
                        break;
                    }
                }
            }

            var stateInfoList = StateInfoList.Parser.ParseFrom(rep.CommandResult);

            foreach (var stateInfo in stateInfoList.StateInfos)
            {
                if (GameUser.Instance.Players.TryGetValue(stateInfo.UserId, out player))
                {
                    player.CurBlood = stateInfo.BloodValue;
                    if (player.CurBlood == 0)
                    {
                        player.Reset();
                    }
                    player.KillCount = stateInfo.KillCount;
                    player.DeadCount = stateInfo.DeadCount;

                    player.Position = new Vector3(
                        stateInfo.Transform.Position.X,
                        stateInfo.Transform.Position.Y,
                        stateInfo.Transform.Position.Z);
                    player.Rotate = new Vector3(
                        stateInfo.Transform.Rotation.X,
                        stateInfo.Transform.Rotation.Y,
                        stateInfo.Transform.Rotation.Z);
                }
            }
        }
예제 #2
0
        public Task Update()
        {
            _frameCount++;
            MOMsg notify = new MOMsg();

            notify.ActionId = 100010;
            S2C100010 content = new S2C100010();

            content.FrameCount = _frameCount;
            if (_commands.Count != 0)
            {
                List <CommandInfo> commands = new List <CommandInfo>();
                while (_commands.Count != 0)
                {
                    var command = _commands.Dequeue();
                    if (DoCommand(command))
                    {
                        if (command.CommandId == (int)CommandType.Transform)
                        {
                            continue;
                        }
                        commands.Add(command);
                    }
                }
                content.Commands.AddRange(commands);
            }
            StateInfoList stateList = new StateInfoList();

            foreach (var player in _players)
            {
                var transform = new TransformInfo();
                transform.Position = new MsgVector3()
                {
                    X = player.Value.Position.X,
                    Y = player.Value.Position.Y,
                    Z = player.Value.Position.Z
                };
                transform.Rotation = new MsgVector3()
                {
                    X = player.Value.Rotate.X,
                    Y = player.Value.Rotate.Y,
                    Z = player.Value.Rotate.Z
                };
                stateList.StateInfos.Add(new StateInfo()
                {
                    UserId     = player.Key,
                    BloodValue = player.Value.CurBlood,
                    KillCount  = player.Value.KillCount,
                    DeadCount  = player.Value.DeadCount,
                    Transform  = transform
                });
            }
            content.CommandResult = stateList.ToByteString();
            notify.Content        = content.ToByteString();
            foreach (var player in _players)
            {
                if (player.Value.CurBlood == 0)
                {
                    player.Value.Reset();
                }
            }
            RoomNotify(notify);
            return(Task.CompletedTask);
        }