Exemplo n.º 1
0
    /// <summary>
    ///  处理计算伤害的响应
    /// </summary>
    /// <param name="response"></param>
    public override void OnOperationResponse(OperationResponse response)
    {
        DtoDamage[] damages = JsonMapper.ToObject <DtoDamage[]>(response[(byte)ParameterCode.DtoDamages] as string);
        DtoDamage   item    = null;

        for (int i = 0; i < damages.Length; i++)
        {
            item = damages[i];
            if (item == null)
            {
                continue;
            }

            int toId = item.ToId;
            // 获取目标控制器
            AIBaseCtrl toCtrl = BattleData.Instance.CtrlDict.ExTryGet(toId);
            if (toCtrl == null)
            {
                return;
            }

            toCtrl.Model.CurHp -= item.Damage;
            toCtrl.OnHpChange();

            // 显示伤害数值
            BattlePanel panel = UIManager.Instance.GetPanel(UIPanelType.Battle) as BattlePanel;
            panel.FloatDamage(item.Damage, toCtrl.transform);

            // 如果被攻击的是自己
            if (toId == GameData.HeroData.Id)
            {
                GameData.HeroData = toCtrl.Model as DtoHero;
                // 更新ui界面
                panel.UpdateView();
                if (item.IsDead)
                {
                    // 开始复活倒计时
                    (UIManager.Instance.GetPanel(UIPanelType.Battle) as BattlePanel).StartRebirthCD();
                    // 遮罩
                    UIManager.Instance.ShopPanel(UIPanelType.Mask);
                    toCtrl.DeathResponse();
                }
            }
            else
            {
                // 如果目标死亡了
                if (item.IsDead)
                {
                    toCtrl.DeathResponse();
                }
            }
        }
    }