lcy
1 天以前 ca577b96e0022e0ddaa8e106e147e53d8166df1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using UnityEngine;
using UnityEngine.UI;
 
public class TianziDamageBar : MonoBehaviour
{
    [SerializeField] IntensifySmoothSlider m_IntensifySlider;
    [SerializeField] Text m_HurtInfo;
    [SerializeField] Text m_BoxCount;
 
    int bossId;
    ulong nowHunt;    // 当前对Boss的伤害
    ulong nowHpMax; // 当前Boss最大血量
    int nowHpNum;   // 当前是Boss第几条血
    public event Action<int> StageUp;
    public event Action<float, int> ValueChangeAction;
    public event Action<ulong, ulong> ChangeEndAction;
 
    public void Awake()
    {
        m_IntensifySlider.StageUpAction += OnStageUp;
        m_IntensifySlider.ValueChangeAction += OnValueChange;
        m_IntensifySlider.ChangeEndAction += OnChangeEndAction;
 
    }
    public void OnDestroy()
    {
        m_IntensifySlider.StageUpAction -= OnStageUp;
        m_IntensifySlider.ValueChangeAction -= OnValueChange;
        m_IntensifySlider.ChangeEndAction -= OnChangeEndAction;
    }
 
    private void OnChangeEndAction()
    {
        ChangeEndAction.Invoke(nowHunt, nowHpMax);
        m_HurtInfo.text = Language.Get("BoneField09", nowHunt, UIHelper.ReplaceLargeNum(nowHpMax));
    }
 
    private void OnValueChange(float nowValue, int CurrentStage)
    {
        int hpNum = CurrentStage;
        if (!TianziConfig.TryGetTianziConfigByBossIDAndHPNum(bossId, hpNum, out TianziConfig tianziConfig))
            return;
        ulong hpMax = (ulong)tianziConfig.MaxHP;
        if (hpMax > 0)
        {
            m_HurtInfo.text = Language.Get("BoneField09", (int)(nowValue * hpMax), UIHelper.ReplaceLargeNum(hpMax));
        }
        //Debug.Log($"TianziDamageBar nowValue {nowValue} CurrentStage {CurrentStage} 时间: {DateTime.Now:HH:mm:ss}");
        ValueChangeAction?.Invoke(nowValue, CurrentStage);
    }
 
    private void OnStageUp(int stage)
    {
        m_BoxCount.text = Language.Get("TianziBillborad07", Mathf.Max(stage - 1, 0));
        StageUp?.Invoke(stage);
    }
 
    public void Init()
    {
        if (TianziBillboradManager.Instance.loaclMaxHp > 0)
        {
            nowHunt = TianziBillboradManager.Instance.loaclNowHunt;
            nowHpMax = TianziBillboradManager.Instance.loaclMaxHp;
            nowHpNum = TianziBillboradManager.Instance.loaclHpNum;
            Show(nowHunt, nowHpMax, nowHpNum);
        }
        else
        {
            int dataMapID = TianziBillboradManager.Instance.DataMapID;
            int lineID = TianziBillboradManager.Instance.todayLineID;
            if (!TianziBillboradManager.Instance.TryGetBossConfig(dataMapID, lineID, out DungeonConfig dungeonConfig, out NPCLineupConfig npcLineupConfig, out NPCConfig npcConfig))
                return;
            bossId = npcConfig.NPCID;
            nowHpNum = 1; // 默认从第1条血开始
            if (!TianziConfig.TryGetTianziConfigByBossIDAndHPNum(bossId, nowHpNum, out TianziConfig tianziConfig))
                return;
            m_IntensifySlider.stage = 0;
            m_IntensifySlider.ResetStage();
            nowHunt = 0; // 初始血量为0
            nowHpMax = (ulong)tianziConfig.MaxHP;
            m_BoxCount.text = Language.Get("TianziBillborad07", 0);
            Show(nowHunt, nowHpMax, nowHpNum);
        }
    }
 
    public void Show(ulong hunt, ulong maxHp, int hpNum)
    {
        nowHunt = hunt;
        nowHpMax = maxHp;
        nowHpNum = hpNum;
        // 除零保护
        float percentage = 0f;
        if (nowHpMax > 0)
        {
            percentage = Mathf.Clamp(nowHunt, 0, nowHpMax) / (float)nowHpMax;
        }
        m_IntensifySlider.value = percentage;
        m_IntensifySlider.stage = nowHpNum;
        m_HurtInfo.text = Language.Get("BoneField09", nowHunt, UIHelper.ReplaceLargeNum(nowHpMax));
    }
}