yyl
2025-06-17 007fbd542c30f5fa8308128aac26ce6584b3067a
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
 
public enum BattleCamp
{
    Friendly,
    Enemy
}
 
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 string BattleObjectId { get; protected set; }
    
    public BattleCamp Camp { get; protected set; } = BattleCamp.Friendly;
    
    public TeamHero teamHero { get; protected set; }
 
    protected MotionBase motionBase;
 
    protected GameObject cardGO;
    
    public virtual void Init(TeamHero _teamHero)
    {
        this.teamHero = _teamHero;
        motionBase = new MotionBase();
    }
 
    protected void LoadHero()
    {
        
    }
    
    
    #region 战斗相关函数
    
    public virtual void AttackTarget(List<BattleObject> targets)
    {
        // 找离自己最近的
 
        if (0 == targets.Count) return;
 
        BattleObject target = targets[0];
 
        if (1 != targets.Count)
        {
            for (int i = 1; i < targets.Count; i++)
            {
                if (Vector3.Distance(cardGO.transform.position, targets[i].cardGO.transform.position) < Vector3.Distance(cardGO.transform.position, target.cardGO.transform.position))
                {
                    target = targets[i];
                }
            }
        }
 
        Vector3 tempPos = cardGO.transform.position;
 
        motionBase.OnAttackAnimationComplete = () => {
            // 攻击动画结束之后 回到原来的位置
 
            cardGO.transform.DOMove(tempPos, 1f).OnComplete(() => {
                // motionBase.ClearEvent();// = null;
 
                //  通知本次攻击行动结束
                //  通过battleFieldId来告知BattleFieldMgr
            });  
        };
 
        cardGO.transform.DOMove(target.cardGO.transform.position, 1f).OnComplete(() => {
            // 播放攻击动画
            motionBase.OnAttackHitEvent = (int attackIndex) => {
                for (int i = 0; i < targets.Count; i++)
                {
                    targets[i].UnderAttack(this);
                }
            };
 
            //普攻是hit1
 
            motionBase.PlayAnimationEx(MotionName.atk1, false, new List<int>(){
                5//假设是5帧 目前还没有数据
            });
        });
    }
 
    public virtual void CastSkill(List<BattleObject> targets)
    {
        //  需不需要move 攻击目标是谁 
    }
    
    public virtual float UnderAttack(BattleObject attacker)
    {
        return 0;
    }
    
    public virtual float HealTargets(List<BattleObject> targets)
    {
        return 0;
    }
    
    public virtual float BeHealed(BattleObject healer, float healAmount)
    {
        return 0;
    }
    
    public virtual bool Revive(BattleObject target)
    {
        return false;
    }
    
    public virtual bool BeRevived(BattleObject reviver, float healthPercent = 0.5f)
    {
        return false;
    }
    
    #endregion
    
    #region 辅助函数
    
    public virtual bool IsEnemy(BattleObject other)
    {
        if (other == null) return false;
        
        return Camp != other.Camp;
    }
    
    public virtual bool IsFriendly(BattleObject other)
    {
        if (other == null) return false;
        
        return Camp == other.Camp;
    }
 
    public virtual void Run()
    {
        motionBase.Run();
    }
 
    public virtual void PauseGame()
    {
        
    }
 
    public virtual void ResumeGame()
    {
        
    }
 
    #endregion
}