Exemplo n.º 1
0
        public bool AddBattleFrame(int playerId, TBattleFrame frame)
        {
            var player = GetBattlePlayer(playerId);

            if (player == null)
            {
                return(false);
            }

            player.PlayerFrame.FrameList.Add(frame);
            return(true);
        }
Exemplo n.º 2
0
        // 执行战斗操作
        public ErrorCode ExecBattleOperation(int userId, int frameCount, int frameType, string param1, string param2, int point, int frameId)
        {
            var room = GetRoomByUserId(userId);

            if (room == null)
            {
                return(ErrorCode.RoomNotFound);
            }

            var roomUser = room.GetRoomUser(userId);

            if (roomUser == null)
            {
                return(ErrorCode.InvalidRoomUser);
            }

            // 已上报战斗结果,无法继续上传战斗帧
            if (roomUser.ReportResult != null)
            {
                return(ErrorCode.AllreadySendBattleResult);
            }

            // 回合上报
            if (frameType == BattleFrameType.REPORT.ToInt())
            {
                if (room.Record.BattleType == BattleType.COOP.ToInt())
                {
                    if (roomUser.CoopReport == null)
                    {
                        roomUser.CoopReport = new RoomUserCoopReport();
                    }
                    roomUser.CoopReport.FrameCount = room.Record.IsRealTime ? room.BattleFrame : frameCount;
                    roomUser.CoopReport.RoundNum   = param1.ToInt();
                }
                return(ErrorCode.Success);
            }

            var frame = new TBattleFrame()
            {
                FrameCount = room.Record.IsRealTime ? room.BattleFrame : frameCount,
                FrameType  = frameType,
                Param1     = param1,
                Param2     = param2,
                Point      = point,
                FrameId    = frameId,
            };

            if (room.Record.IsRealTime && (room.PendFrame == 0 || room.State == RoomState.Pause))
            {
                frame.FrameCount = room.BattleFrame + 1;
            }
            if (frame.FrameCount <= 0)
            {
                frame.FrameCount = 1;
            }

            // 真人PK,插入缓存队列
            if (room.Record.IsRealTime)
            {
                var frameDetail = new TBattleFrameDetail()
                {
                    PlayerId = userId,
                    Frame    = frame,
                };
                room.PendingList.Add(frameDetail);

                // 非投降帧,将帧数提前至帧包开始
                if (frameType != BattleFrameType.SURRENDER.ToInt())
                {
                    frameDetail.Frame.FrameCount = room.LastPackageBattleFrame + 1;
                }

                // 立即广播
                room.PendFrame = room.FramePackageLength - 1;
            }

            // 插入战斗记录
            room.Record.AddBattleFrame(userId, frame);

            // 记录操作时间
            room.UpdateTime = GetTime();

            return(ErrorCode.Success);
        }