Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }