Пример #1
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            //MobaServer.LogInfo("处理使用技能的请求");

            // 获取房间
            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            // 获取使用者数据
            int       fromId = (int)request[(byte)ParameterCode.FromId];
            DtoMinion from   = room.GetDto(fromId);

            // 获取目标数据
            DtoMinion[] to = null;
            if (request.Parameters.ContainsKey((byte)ParameterCode.TargetArray))
            {
                int[] toIds = JsonMapper.ToObject <int[]>(request[(byte)ParameterCode.TargetArray] as string);
                to = room.GetDtos(toIds);
            }

            // 获取技能id和等级
            int skillId = (int)request[(byte)ParameterCode.SkillId];
            int level   = (int)request[(byte)ParameterCode.SkillLevel];

            // 使用技能
            SkillManager.Instance.UseSkill(skillId, level, from, to, room);
            // 广播谁使用了技能
            room.Brocast(OpCode, request.Parameters);
        }
Пример #2
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理进入战斗房间的请求");

            int        plyaerId = (int)UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.Enter(plyaerId, peer);

            // 判断是否全部进入
            if (!room.IsAllEnter)
            {
                return;
            }

            // 发送给所有客户端 英雄,建筑,装备的数据
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.HerosArray, JsonMapper.ToJson(room.HerosArray));
            data.Add((byte)ParameterCode.BuildsArray, JsonMapper.ToJson(room.BuildsArray));
            data.Add((byte)ParameterCode.ItemArray, JsonMapper.ToJson(ItemData.GetArray()));

            // 发送当前游戏内用到的技能数据
            data.Add((byte)ParameterCode.SkillArray, JsonMapper.ToJson(SkillData.GetSkillByHeros(room.HerosArray)));

            room.Brocast(OperationCode.EnterBattle, data);
        }
Пример #3
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            //MobaServer.LogInfo("处理计算伤害的请求");

            // 获取房间
            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            // 获取技能id
            int skillId = (int)request[(byte)ParameterCode.SkillId];

            // 获取攻击者数据
            int       fromId = (int)request[(byte)ParameterCode.FromId];
            DtoMinion from   = room.GetDto(fromId);

            if (from == null)
            {
                return;
            }

            // 获取被攻击者的数据
            int[]       toIds = JsonMapper.ToObject <int[]>(request[(byte)ParameterCode.TargetArray] as string);
            DtoMinion[] to    = room.GetDtos(toIds);

            // 使用技能 获取伤害数据
            DtoDamage[] damages = null;
            damages = SkillManager.Instance.Damage(room, skillId, 1, from, to);

            // 广播伤害数据传输对象
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.DtoDamages, JsonMapper.ToJson(damages));
            room.Brocast(OperationCode.Damage, data);
        }
Пример #4
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理购买道具的请求");

            // 获取道具
            int       itemId = (int)request[(byte)ParameterCode.ItemId];
            ItemModel item   = ItemData.GetItem(itemId);

            if (item == null)
            {
                return;
            }

            // 获取房间
            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                return;
            }

            // 获取英雄
            DtoHero hero = room.GetDtoHero(playerId);

            // 金币不足
            if (hero.Money < item.Price)
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "金币不足");
                return;
            }

            // 开始购买
            if (hero.BuyItem(item))
            {
                // 给所有客户端发送消息 谁买了什么装备
                Dictionary <byte, object> data = new Dictionary <byte, object>();
                data.Add((byte)ParameterCode.DtoHero, JsonMapper.ToJson(hero));
                room.Brocast(OpCode, data);
            }
            else
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "装备已满");
            }
        }
Пример #5
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            //MobaServer.LogInfo("处理移动的请求");

            // 获取玩家id
            int playerId = UserManager.GetPlayer(peer.Username).Identification;

            // 获取战斗的房间
            BattleRoom room = Caches.Battle.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                return;
            }

            // 添加玩家的id 玩家id就是英雄的唯一标识id
            request.Parameters[(byte)ParameterCode.PlayerId] = playerId;
            // 告诉其他客户端:谁移动到哪
            room.Brocast(OpCode, request.Parameters);
        }