yyl
7 天以前 3bd7f56906e31e8fe0072108c9d4652707b51de8
Main/System/Battle/BattleObject/BattleObject.cs
@@ -30,21 +30,47 @@
{
    public BattleField battleField;
    public int BattleObjectId { get; set; }
    public BattleObjectBuffMgr buffMgr;
    public BattleObjectLayerMgr layerMgr;
    public int ObjID { get; set; }
    public BattleCamp Camp { get; protected set; }
    public TeamHero teamHero { get; protected set; }
    // public BuffMgr buffMgr;
    protected MotionBase motionBase;
    public MotionBase motionBase;
    public GameObject heroGo
    {
        get;
        private set;
    }
    protected BattleDrops battleDrops;
    private RectTransform m_heroRectTrans;
    public RectTransform heroRectTrans
    {
        get
        {
            if (m_heroRectTrans == null)
            {
                m_heroRectTrans = heroGo.GetComponent<RectTransform>();
            }
            return m_heroRectTrans;
        }
    }
    protected Action onDeathAnimationComplete;
    protected Renderer[] renderers;
    private List<HB405_tagMCAddExp> hB405_tagMCAddExps = new List<HB405_tagMCAddExp>();
    public BattleHeroInfoBar heroInfoBar;
    public BattleObject(BattleField _battleField)
    {
@@ -57,14 +83,33 @@
        teamHero = _teamHero;
        Camp = _camp;
        motionBase = new MotionBase();
        motionBase.Init(heroGo.GetComponentInChildren<SkeletonGraphic>(true));
    }
        motionBase.Init(heroGo.GetComponentInChildren<SkeletonAnimation>(true));
        buffMgr = new BattleObjectBuffMgr();
        buffMgr.Init(this);
        layerMgr = new BattleObjectLayerMgr();
        layerMgr.Init(this);
        renderers = heroGo.GetComponentsInChildren<Renderer>(true);
        heroInfoBar = heroGo.GetComponentInChildren<BattleHeroInfoBar>(true);
        heroInfoBar.SetBattleObject(this);
        //  根据阵营翻转血条
        var heroInfoBarScale = heroInfoBar.transform.localScale;
        heroInfoBarScale.x *= Camp == BattleCamp.Red ? 1 : -1;
        heroInfoBar.transform.localScale = heroInfoBarScale;
        heroInfoBar.SetActive(true);
        SetFront();
    }
    public virtual void Run()
    {
        motionBase.Run();
        heroInfoBar.Run();
        buffMgr.Run();
    }
    public virtual void Pause()
@@ -79,16 +124,65 @@
    public virtual void Destroy()
    {
        motionBase.Release();
        motionBase = null;
        teamHero = null;
        ObjID = 0;
        if (heroGo != null)
        {
            GameObject.DestroyImmediate(heroGo);
            heroGo = null;
        }
    }
        motionBase.Release();
        motionBase = null;
        teamHero = null;
        BattleObjectId = 0;
    public void OnObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo)
    {
        switch ((PlayerDataType)_refreshInfo.RefreshType)
        {
            case PlayerDataType.HP:
                long toHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
                teamHero.curHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                break;
            case PlayerDataType.MaxHP:
                teamHero.maxHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
                break;
            case PlayerDataType.XP:
                long toXp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
                teamHero.rage = (int)GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                break;
            default:
                Debug.LogError("BattleObject.ObjInfoRefresh 出现意外类型 " + _refreshInfo.RefreshType.ToString());
                break;
        }
    }
    public void ObjPropertyRefreshView(HB418_tagSCObjPropertyRefreshView vNetData)
    {
        switch ((PlayerDataType)vNetData.RefreshType)
        {
            case PlayerDataType.HP:
                long toHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
                heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
                teamHero.curHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
                break;
            case PlayerDataType.MaxHP:
                teamHero.maxHp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
                heroInfoBar.UpdateHP(teamHero.curHp, teamHero.curHp, teamHero.maxHp);
                break;
            case PlayerDataType.XP:
                long toXp = GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
                heroInfoBar.UpdateXP(teamHero.rage, toXp, 100);
                teamHero.rage = (int)GeneralDefine.GetFactValue(vNetData.Value, vNetData.ValueEx);
                break;
            default:
                Debug.LogError("BattleObject.ObjPropertyRefreshView 出现意外类型 " + vNetData.RefreshType.ToString());
                break;
        }
    }
    //  眩晕
@@ -108,12 +202,6 @@
    {
        return teamHero.isStoned;
    }
    // //   禁锢
    // public bool IsConfined()
    // {
    //     return false;
    // }
    //  被沉默
    public bool IsSlient()
@@ -180,199 +268,210 @@
        return true;
    }
    public virtual void TakeDamage(List<int> damageValues)
    public virtual void Hurt(List<long> damageValues, long _totalDamage,
        HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig, int hitIndex,
        BattleDrops battleDrops, HB422_tagMCTurnFightObjDead deadPack)
    {
        if (IsDead())
            return;
        bool isLastHit = hitIndex >= skillConfig.DamageDivide.Length - 1;
        bool firstHit = hitIndex == 0;
        BattleDmgInfo dmgInfo = PopDamage(damageValues, _totalDamage, hurt, skillConfig, isLastHit);
        PopDamage(damageValues);
        motionBase.PlayAnimation(MotionName.hit, false);
        //  计算伤害
        int totalDamage = 0;
        foreach (var damage in damageValues)
        //  这里
        if (dmgInfo.IsType(DamageType.Dodge))
        {
            totalDamage += damage;
            if (isLastHit)
            {
                DodgeFinishAction dodgeFinish = new DodgeFinishAction(battleField, this);
                battleField.recordPlayer.InsertRecord(dodgeFinish);
            }
            if (firstHit)
            {
                OnDodgeBegin();
            }
        }
        bool isFatalAttack = (null != deadPack) && isLastHit;
        if (isFatalAttack)
        {
            if (null != battleDrops)
            {
                PushDropItems(battleDrops);
            }
            battleField.OnObjsDead(new List<HB422_tagMCTurnFightObjDead>() { deadPack });
        }
        else
        {
            if ((dmgInfo.IsType(DamageType.Damage) || dmgInfo.IsRealdamage()))
            {
                motionBase.PlayAnimation(MotionName.hit, false);
            }
        }
        //  扣血
        teamHero.curHp -= totalDamage;
        //  其实这里应该是等服务器发death的action
        // if (IsDead())
        // {
        //     OnDeath();
        // }
    }
    public void SuckHp(uint suckHP, SkillConfig skillConfig)
    {
        teamHero.curHp = Math.Min(teamHero.maxHp, teamHero.curHp + (int)suckHP);
    }
    public void HurtByReflect(uint bounceHP, SkillConfig skillConfig)
    {
        teamHero.curHp = Math.Max(0, teamHero.curHp - (int)bounceHP);
    }
    const float pingpongTime = 0.4f;
    //  闪避开始
    public virtual void OnDodgeBegin()
    {
        float pingpongTime = 0.2f;
        RectTransform rectTrans = heroGo.GetComponent<RectTransform>();
        rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime)
        RectTransform rectTrans = heroRectTrans;
        var tween = rectTrans.DOAnchorPos(new Vector3(-30, 0, 0), pingpongTime)
            .SetEase(Ease.OutCubic);
        motionBase.ShowIllusionShadow(true);
        tween.onComplete += () =>
        {
            motionBase.ShowIllusionShadow(false);
        };
        battleField.battleTweenMgr.OnPlayTween(tween);
    }
    //  闪避结束
    public virtual void OnDodgeEnd()
    public virtual void OnDodgeEnd(Action _complete = null)
    {
        float pingpongTime = 0.2f;
        RectTransform rectTrans = heroGo.GetComponent<RectTransform>();
        rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
        RectTransform rectTrans = heroRectTrans;
        var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
                            .SetEase(Ease.OutCubic);
    }
    protected virtual void OnDeath()
    {
        motionBase.OnOtherAnimationComplete = OnOtherAnimationComplete;
        motionBase.PlayAnimation(MotionName.dead, false);
    }
    protected virtual void OnOtherAnimationComplete(MotionName motionName)
    {
        if (motionName == MotionName.dead)
        tween.onComplete += () =>
        {
            _complete?.Invoke();
        };
        battleField.battleTweenMgr.OnPlayTween(tween);
    }
    public virtual void OnDeath(Action _onDeathAnimationComplete)
    {
        motionBase.PlayAnimation(MotionName.dead, false, () =>
        {
            teamHero.isDead = true;
            OnDeadAnimationComplete();
        }
            _onDeathAnimationComplete?.Invoke();
        });
    }
    protected virtual void OnDeadAnimationComplete()
    {
        //  或许看看溶解特效? YYL TODO
        heroGo.SetActive(false);
        buffMgr.RemoveAllBuff();
    }
     // 伤害还要看 是否闪避 暴击 and so on 需要有一个DamageType 服务器应该会给
    protected virtual void PopDamage(List<int> damageValues)
    public void OnReborn(HB423_tagMCTurnFightObjReborn vNetData)
    {
        //  其实应该通知出去给UI界面解耦 让UI界面自己来显示的 YYL TODO
        //  播放伤害数字
        //  这里可以实现一个伤害数字的弹出效果
        //  比如使用一个UI组件来显示伤害数字
        foreach (var damage in damageValues)
        // 处理复活逻辑
        teamHero.curHp = GeneralDefine.GetFactValue(vNetData.HP, vNetData.HPEx);
        heroGo.SetActive(true);
        motionBase.PlayAnimation(MotionName.idle, true);
    }
    // 伤害还要看 是否闪避 暴击 and so on 需要有一个DamageType 服务器应该会给
    protected virtual BattleDmgInfo PopDamage(List<long> damageValues, long _totalDamage, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, SkillConfig skillConfig, bool isLastHit)
    {
        BattleDmgInfo battleDmgInfo = new BattleDmgInfo(battleField.guid, damageValues, this, hurt, skillConfig, isLastHit);
        int currentHurtHp = 0;
        for (int i = 0; i < damageValues.Count; i++)
        {
            Debug.Log($"Damage: {damage}");
            currentHurtHp += (int)damageValues[i];
        }
        EventBroadcast.Instance.Broadcast<BattleObject, List<int>>(EventName.BATTLE_DAMAGE_TAKEN, this, damageValues);
        bool isRecovery = battleDmgInfo.IsType(DamageType.Recovery);
        long toHp = Math.Max(0, teamHero.curHp + (isRecovery ? currentHurtHp : -currentHurtHp));
        heroInfoBar.UpdateHP(teamHero.curHp, toHp, teamHero.maxHp);
        teamHero.curHp = toHp;
        // YYL TODO 是否需要挂在在自身的follow点上
        EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleDmgInfo);
        return battleDmgInfo;
    }
    public void PlaySkill(SkillConfig skillConfig, List<Dictionary<int, List<int>>> damageList, Action _onComplete)
    public RectTransform GetAliasTeamNode()
    {
        bool moveToTarget = true;
        if (moveToTarget)
        {
            int targetId = damageList[0].First().Key;
            BattleObject _targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
            RectTransform selfRect = heroGo.GetComponent<RectTransform>();
            RectTransform targetRect = _targetObj.heroGo.GetComponent<RectTransform>();
            Vector2 curAnchoredPos = selfRect.anchoredPosition;
            MoveToTargetUI(selfRect, targetRect, new Vector2(100f, 0f), () =>
            {
                PlaySkillAnimation(skillConfig, damageList, () =>
                {
                    // 回到原位置
                    selfRect.DOAnchorPos(curAnchoredPos, 0.2f)
                        .SetEase(Ease.Linear)
                        .OnComplete(() => {
                            _onComplete?.Invoke();
                        });
                });
            });
        }
        else
        {
            PlaySkillAnimation(skillConfig, damageList, _onComplete);
        }
        return battleField.GetTeamNode(Camp);
    }
    protected void MoveToTargetUI(RectTransform selfRect, RectTransform targetRect, Vector2 offset, Action _onComplete)
    public RectTransform GetEnemyTeamNode()
    {
        // 1. 目标的本地坐标转为世界坐标
        Vector3 targetWorldPos = targetRect.TransformPoint(targetRect.anchoredPosition + offset);
        // 2. 世界坐标转为自己父节点下的本地坐标
        RectTransform parentRect = selfRect.parent as RectTransform;
        Vector2 targetAnchoredPos;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            parentRect,
            RectTransformUtility.WorldToScreenPoint(null, targetWorldPos),
            null,
            out targetAnchoredPos);
        // 3. DOTween 移动
        selfRect.DOAnchorPos(targetAnchoredPos, 0.2f)
            .SetEase(Ease.Linear)
            .OnComplete(() => _onComplete?.Invoke());
        return battleField.GetTeamNode(Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red);
    }
    protected void PlaySkillAnimation(SkillConfig skillConfig, List<Dictionary<int, List<int>>> damageList, Action _onComplete)
    public BattleCamp GetEnemyCamp()
    {
        //  关键帧列表
        List<int> keyFrameList = new List<int>() { 15 };
        motionBase.OnAttackHitEvent = (int _frame) =>
        {
            Dictionary<int, List<int>> oneRoundDamage = damageList[keyFrameList.IndexOf(_frame)];
            foreach (var kvp in oneRoundDamage)
            {
                int targetId = kvp.Key;
                List<int> damageValues = kvp.Value;
                BattleObject targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
                if (targetObj != null && !targetObj.IsDead())
                {
                    targetObj.TakeDamage(damageValues);
                }
            }
        };
        motionBase.OnAttackAnimationComplete = () =>
        {
            _onComplete?.Invoke();
            motionBase.OnAttackHitEvent = null;
            motionBase.OnAttackAnimationComplete = null;
            //  死亡确定其实不应该在这里进行触发 应该由服务器下发 YYL TODO
#if UNITY_EDITOR
            //  暂时的处理
            HashSet<int> hitTargets = new HashSet<int>();
            foreach (var dmgDict in damageList)
            {
                foreach (var kvp in dmgDict)
                {
                    int targetId = kvp.Key;
                    hitTargets.Add(targetId);
                }
            }
            foreach (int targetId in hitTargets)
            {
                BattleObject targetObj = battleField.battleObjMgr.GetBattleObject(targetId);
                if (targetObj != null && targetObj.IsDead())
                {
                    targetObj.OnDeath();
                }
            }
#endif
        };
        motionBase.PlayAnimationEx(MotionName.attack, false, keyFrameList);
        return Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red;
    }
#if UNITY_EDITOR
    public void HaveRest()
    {
        // YYL TODO
        //  休息状态
        //  多一个zzz的一个特效
        heroGo.SetActive(true);
        motionBase.HaveRest();
        heroRectTrans.anchoredPosition = Vector2.zero;
        heroInfoBar.SetActive(false);
        SetFront();
    }
    public void PushDropItems(BattleDrops _battleDrops)
    {
        battleDrops = _battleDrops;
    }
    public void PerformDrop()
    {
        if (null == battleDrops || battleDrops.dropItemPackIndex.Count == 0)
            return;
        EventBroadcast.Instance.Broadcast<string, BattleDrops, Action>(
            EventName.BATTLE_DROP_ITEMS, battleField.guid, battleDrops, OnPerformDropFinish);
    }
    protected void OnPerformDropFinish()
    {
        battleDrops = null;
    }
    public void SetBack()
    {
        layerMgr.SetBack();
    }
    public void SetFront()
    {
        layerMgr.SetFront();
    }
    public void SetSpeedRatio(float ratio)
    {
        motionBase.SetSpeedRatio(ratio);
    }
#if UNITY_EDITOR_STOP_USING
    public void EditorRevive()
    {
        teamHero.curHp = 100;
@@ -384,7 +483,7 @@
    {
        List<int> damageList = new List<int>();
        int totalDamage = teamHero.attack - obj.teamHero.defense;
        int totalDamage = 100;
        int damage1 = (int)((float)totalDamage * 0.3f);