Exemplo n.º 1
0
 private void Damage(DamageDTO value)
 {
     foreach (int[] target in value.Targets)
     {
         PlayerCtr pc = models[target[0]];
         //实例化掉血数字
         FightScene.Instance.NumUp(pc.transform, target[1].ToString());
         pc.HpChange();
         if (pc.data.Id == GameData.user.ID)
         {
             FightScene.Instance.RefreshView(pc.data);
         }
         if (target[2] == 0)
         {
             if (target[0] >= 0)
             {
                 pc.gameObject.SetActive(false);
                 if (pc.data.Id == GameData.user.ID)
                 {
                     FightScene.Instance.Dead = true;
                 }
             }
             else
             {
                 Destroy(pc.gameObject);
             }
         }
     }
 }
Exemplo n.º 2
0
 void Update()
 {
     if(target != null)
     {
         transform.position = Vector3.Lerp(transform.position, target.position, 0.5f);
         if(Vector3.Distance(transform.position,target.position)< 0.1f)
         {
             //像服务器发送伤害目标
             DamageDTO dto = new DamageDTO();
             dto.UserID = userId;
             dto.Skill = skill;
             dto.Targets = new int[][] { new int[] { target.GetComponent<PlayerCtr>().data.Id } };
             this.Wirte(Protocol.TYPE_FIGHT,0,FightProtocol.DAMAGE_CREQ,dto);
             Destroy(gameObject);
         }
     }
 }
Exemplo n.º 3
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);
        }