Example #1
0
        /// <summary>
        /// 计算伤害、存储结果、并向客户端发送消息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="damageDTO"></param>
        private void Damage(UserToken token, DamageDTO damageDTO)
        {
            int userId = GetUserId(token);
            AbsFightInstance atkInstance;
            int skillLevel = 0;

            //判断攻击者是玩家英雄 还是小兵
            if (damageDTO.userId >= 0)//是英雄
            {
                if (damageDTO.userId != userId)
                {
                    return;
                }
                atkInstance = instances[userId];
                if (damageDTO.skill > 0)
                {
                    skillLevel = (atkInstance as HeroInstance).SkillLevel(damageDTO.skill);
                    if (skillLevel == -1)
                    {
                        return;
                    }
                    else
                    {
                    }
                }
            }
            else//是兵或者建筑
            {
                //TODO:
                atkInstance = instances[userId];
            }

            if (!SkillData.SkillModels.ContainsKey(damageDTO.skill))
            {
                return;
            }

            //1.获取技能方法
            ISkill       skill   = SkillProcessMap.Get(damageDTO.skill);
            List <int[]> damages = new List <int[]>();

            //2.根据技能定义,获取目标数据和攻击者数据,计算伤害值
            foreach (int[] item in damageDTO.targetDamages)
            {
                AbsFightInstance target = instances[item[0]];
                //计算伤害值并存储
                skill.Damage(skillLevel, ref atkInstance, ref target, ref damages);
                if (target.hp == 0)
                {
                    switch (target.fightModel.category)
                    {
                    case (byte)ModelType.Hero:
                        //击杀英雄
                        //奖励玩家
                        //启动定时任务 指定时间之后发送英雄复活信息 并且将英雄数据设置为满状态


                        break;

                    case (byte)ModelType.Creature:
                        //发送消息
                        //TODO 给钱、经验
                        //移除生物数据

                        break;

                    case (byte)ModelType.Building:
                        //摧毁建筑 给钱,通知进攻树变更

                        break;
                    }
                }
            }
            damageDTO.targetDamages = damages.ToArray();
            brocast(FightProtocol.DAMAGE_BRO, damageDTO);
        }
Example #2
0
        private void Damage(UserToken token, DamageDTO value)
        {
            int           userId = GetUserId(token);
            AbsFightModel atkModel;
            int           skillLevel = 0;

            //判断攻击者是玩家英雄 还是小兵
            if (value.UserID >= 0)
            {
                if (value.UserID != userId)
                {
                    return;
                }
                atkModel = GetPlayer(userId);
                if (value.Skill > 0)
                {
                    skillLevel = (atkModel as FightPlayerModel).SkillLevel(value.Skill);
                    if (skillLevel == -1)
                    {
                        return;
                    }
                }
            }
            else
            {
                //TODO:
                atkModel = GetPlayer(userId);
            }
            //获取技能算法
            //循环获取目标数据 和攻击者数据 进行伤害计算 得出伤害数值
            if (!SkillProcessMap.Has(value.Skill))
            {
                return;
            }
            ISkill       skill   = SkillProcessMap.Get(value.Skill);
            List <int[]> damages = new List <int[]>();

            foreach (int[] item in value.Targets)
            {
                AbsFightModel target = GetPlayer(item[0]);
                skill.Damage(skillLevel, ref atkModel, ref target, ref damages);
                if (target.Hp == 0)
                {
                    switch (target.Type)
                    {
                    case ModelType.HUMAN:
                        if (target.Id > 0)
                        {
                            //击杀英雄
                            //启动定时任务 指定时间之后发送英雄复活信息 并且将英雄数据设置为满状态
                        }
                        else
                        {
                            //击杀小兵
                            //移除小兵数据
                        }
                        break;

                    case ModelType.BUILD:
                        //打破了建筑 给钱

                        break;
                    }
                }
            }
            value.Targets = damages.ToArray();
            Brocast(FightProtocol.DAMAGE_BRO, value);
        }