yyl
8 天以前 cec8b67d82c2c2c1662d55c818c4a46bcc0487db
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using Spine.Unity;
using UnityEngine.UI;
using System.Linq;
 
public enum BattleCamp
{
    Red,
    Blue
}
 
public enum BattleState
{
    None = 0,
    Stunned = 1 << 0,
    Poisoned = 1 << 1,
    Bleeding = 1 << 2,
    Silenced = 1 << 3,
    Frozen = 1 << 4,
    Burned = 1 << 5
}
 
public class BattleObject
{
    public BattleField battleField;
 
    public BattleObjectBuffMgr buffMgr;
 
    public int ObjID { get; set; }
 
    public BattleCamp Camp { get; protected set; }
 
    public TeamHero teamHero { get; protected set; }
 
    // public BuffMgr buffMgr;
 
    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;
 
    public Transform effectNode;
 
    private List<HB405_tagMCAddExp> hB405_tagMCAddExps = new List<HB405_tagMCAddExp>();
 
    public BattleObject(BattleField _battleField)
    {
        battleField = _battleField;
    }
 
    public virtual void Init(GameObject _heroGo, TeamHero _teamHero, BattleCamp _camp)
    {
        heroGo = _heroGo;
        teamHero = _teamHero;
        Camp = _camp;
        motionBase = new MotionBase();
        motionBase.Init(heroGo.GetComponentInChildren<SkeletonGraphic>(true));
        motionBase.onAnimationComplete += OnAnimationComplete;
        buffMgr = new BattleObjectBuffMgr();
        buffMgr.Init(this);
 
        renderers = heroGo.GetComponentsInChildren<Renderer>(true);
    }
 
 
 
    public virtual void Run()
    {
        motionBase.Run();
    }
 
    public virtual void Pause()
    {
        motionBase.Pause();
    }
 
    public virtual void Resume()
    {
        motionBase.Resume();
    }
 
    public virtual void Destroy()
    {
        motionBase.onAnimationComplete -= OnAnimationComplete;
 
        motionBase.Release();
        motionBase = null;
        teamHero = null;
        ObjID = 0;
 
        if (heroGo != null)
        {
            GameObject.DestroyImmediate(heroGo);
            heroGo = null;
        }
    }
 
    public void OnObjInfoRefresh(H0418_tagObjInfoRefresh _refreshInfo)
    {
        switch ((PlayerDataType)_refreshInfo.RefreshType)
        {
            case PlayerDataType.HP:
                teamHero.curHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                break;
            case PlayerDataType.MaxHP:
                teamHero.maxHp = GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                break;
            case PlayerDataType.XP:
                teamHero.rage = (int)GeneralDefine.GetFactValue(_refreshInfo.Value, _refreshInfo.ValueEx);
                break;
            default:
                BattleDebug.LogError("BattleObject.ObjInfoRefresh 出现意外类型 " + _refreshInfo.RefreshType.ToString());
                break;
        }
    }
 
    //  眩晕
    public bool IsStunned()
    {
        return teamHero.isStunned;
    }
 
    //  冰冻
    public bool IsFrozen()
    {
        return teamHero.isFrozen;
    }
 
    //  石化
    public bool IsStoned()
    {
        return teamHero.isStoned;
    }
 
    //  被沉默
    public bool IsSlient()
    {
        return teamHero.isSlient;
    }
 
    //  被缴械
    public bool IsDisarmed()
    {
        return teamHero.isDisarmed;
    }
 
    //  是否无敌
    public bool IsInvincable()
    {
        return teamHero.isInvinceble;
    }
 
    //  是否死亡
    public bool IsDead()
    {
        return teamHero.isDead;
    }
 
    //  是否被控住了
    public bool IsCrowdControlled()
    {
        return IsStunned() || IsStoned() || IsFrozen();
    }
 
    public virtual bool IsCanCastSkill()
    {
        //  被控住
        if (IsCrowdControlled())
        {
            return false;
        }
 
        //  被沉默
        if (IsSlient())
        {
            return false;
        }
 
        //  看看怒气是否达到释放要求
        return teamHero.rage >= 100;
    }
 
    public virtual bool IsCanNormalAttack()
    {
        //  被控住
        if (IsCrowdControlled())
        {
            return false;
        }
 
        //  缴械
        if (IsDisarmed())
        {
            return false;
        }
 
        return true;
    }
 
    public virtual void Hurt(List<long> damageValues, long _totalDamage, uint attackType)
    {
        PopDamage(teamHero.curHp, damageValues, attackType);
 
        motionBase.PlayAnimation(MotionName.hit, false);
 
        //  扣血
        teamHero.curHp -= _totalDamage;
    }
 
    //  闪避开始
    public virtual void OnDodgeBegin()
    {
        float pingpongTime = 0.2f;
        RectTransform rectTrans = heroRectTrans;
        var tween = rectTrans.DOAnchorPos(new Vector3(-50, 50, 0), pingpongTime)
            .SetEase(Ease.OutCubic);
 
        battleField.battleTweenMgr.OnPlayTween(tween);
    }
 
    //  闪避结束
    public virtual void OnDodgeEnd()
    {
        float pingpongTime = 0.2f;
        RectTransform rectTrans = heroRectTrans;
 
        var tween = rectTrans.DOAnchorPos(Vector3.zero, pingpongTime)
                            .SetEase(Ease.OutCubic);
 
        battleField.battleTweenMgr.OnPlayTween(tween);
    }
 
    public virtual void OnDeath(Action _onDeathAnimationComplete)
    {
        BattleDebug.LogError(ObjID + " OnDeath called");
        onDeathAnimationComplete = _onDeathAnimationComplete;
        motionBase.PlayAnimation(MotionName.dead, false);
    }
 
    protected virtual void OnAnimationComplete(MotionName motionName)
    {
        if (motionName == MotionName.dead)
        {
            OnDeadAnimationComplete();
            onDeathAnimationComplete?.Invoke();
            onDeathAnimationComplete = null;
        }
    }
 
    protected virtual void OnDeadAnimationComplete()
    {
        //  或许看看溶解特效? YYL TODO
        heroGo.SetActive(false);
    }
 
    public void OnReborn(HB423_tagMCTurnFightObjReborn vNetData)
    {
        // 处理复活逻辑
        teamHero.curHp = GeneralDefine.GetFactValue(vNetData.HP, vNetData.HPEx);
        heroGo.SetActive(true);
        motionBase.PlayAnimation(MotionName.idle, true);
    }
 
    // 伤害还要看 是否闪避 暴击 and so on 需要有一个DamageType 服务器应该会给
    protected virtual void PopDamage(long curHp, List<long> damageValues, uint attackType)
    {
        //  其实应该通知出去给UI界面解耦 让UI界面自己来显示的 YYL TODO
        //  播放伤害数字
        //  这里可以实现一个伤害数字的弹出效果
        //  比如使用一个UI组件来显示伤害数字
        foreach (var damage in damageValues)
        {
            Debug.Log($"Damage: {damage}");
        }
 
        // YYL TODO 是否需要挂在在自身的follow点上
        EventBroadcast.Instance.Broadcast(EventName.BATTLE_DAMAGE_TAKEN, battleField.guid, this, damageValues);
    }
 
    public RectTransform GetAliasTeamNode()
    {
        return battleField.GetTeamNode(Camp);
    }
 
    public RectTransform GetEnemyTeamNode()
    {
        return battleField.GetTeamNode(Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red);
    }
 
    public BattleCamp GetEnemyCamp()
    {
        return Camp == BattleCamp.Red ? BattleCamp.Blue : BattleCamp.Red;
    }
 
    public void HaveRest()
    {
        // YYL TODO
        //  休息状态
        //  多一个zzz的一个特效
        heroGo.SetActive(true);
        motionBase.PlayAnimation(MotionName.idle, true);
        heroRectTrans.anchoredPosition = Vector2.zero;
    }
 
    public void PushDropItems(BattleDrops _battleDrops)
    {
        battleDrops = _battleDrops;
    }
 
    public void PerformDrop()
    {
        if (null == battleDrops)
            return;
 
        EventBroadcast.Instance.Broadcast<string, BattleDrops, Action>(
            EventName.BATTLE_DROP_ITEMS, battleField.guid, battleDrops, OnPerformDropFinish);
    }
 
    protected void OnPerformDropFinish()
    {
        battleDrops = null;
    }
 
 
 
#if UNITY_EDITOR_STOP_USING
    public void EditorRevive()
    {
        teamHero.curHp = 100;
        heroGo.SetActive(true);
        motionBase.PlayAnimation(MotionName.idle, true);
    }
 
    public List<int> TryAttack(BattleObject obj, SkillConfig skillConfig)
    {
        List<int> damageList = new List<int>();
 
        int totalDamage = 100;
 
        int damage1 = (int)((float)totalDamage * 0.3f);
 
        int damage2 = (int)((float)totalDamage * 0.25f);
 
        int damage3 = totalDamage - damage1 - damage2;
 
        damageList.Add(damage1);
        damageList.Add(damage2);
        damageList.Add(damage3);
 
        return damageList;
    }
#endif
 
}