yyl
昨天 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
 
public class BattleObjMgr
{
    //  死亡不可以将BattleObject移出字典/列表
    public List<BattleObject> redCampList => new List<BattleObject>(redCampDict.Values);
    public List<BattleObject> blueCampList => new List<BattleObject>(blueCampDict.Values);
    private Dictionary<int, BattleObject> redCampDict = new Dictionary<int, BattleObject>();
    private Dictionary<int, BattleObject> blueCampDict = new Dictionary<int, BattleObject>();
 
    protected Dictionary<int, BattleObject> allBattleObjDict = new Dictionary<int, BattleObject>();
 
    protected BattleField battleField;
 
    public void Init(BattleField _battleField, TeamBase _redTeam, TeamBase _blueTeam)
    {
        battleField = _battleField;
        CreateTeam(battleField.battleRootNode.redTeamNodeList, redCampDict, _redTeam, BattleCamp.Red);
        CreateTeam(battleField.battleRootNode.blueTeamNodeList, blueCampDict, _blueTeam, BattleCamp.Blue);
    } 
 
    protected void CreateTeam(List<GameObject> posNodeList, Dictionary<int, BattleObject> campDict, TeamBase teamBase, BattleCamp _Camp)
    {
        DestroyTeam(campDict);
        for (int i = 0; i < teamBase.teamHeros.Length; i++)
        {
            TeamHero teamHero = teamBase.teamHeros[i];
            if (teamHero != null)
            {
                BattleObject battleObj = BattleObjectFactory.CreateBattleObject(battleField, posNodeList, teamHero, _Camp);
                allBattleObjDict.Add(battleObj.BattleObjectId, battleObj);
                campDict.Add(teamHero.heroIndex, battleObj);
            }
        }
    }
    
    public BattleObject GetBattleObject(int battleObjId)
    {
        if (allBattleObjDict.TryGetValue(battleObjId, out BattleObject battleObj))
        {
            return battleObj;
        }
        return null;
    }
 
    protected void DestroyTeam(Dictionary<int, BattleObject> campDict)
    {
        foreach (var item in campDict)
        {
            BattleObject battleObj = item.Value;
            if (battleObj != null)
            {
                allBattleObjDict.Remove(battleObj.BattleObjectId);
                BattleObjectFactory.DestroyBattleObject(item.Key, battleObj);
            }
        }
        campDict.Clear();
 
    }
 
    public void Release()
    {
        DestroyTeam(redCampDict);
        DestroyTeam(blueCampDict);
    }
 
    public void Run()
    {
        foreach (var item in redCampDict)
        {
            item.Value.Run();
        }
 
        foreach (var item in blueCampDict)
        {
            item.Value.Run();
        }
    }
 
    public virtual void ResumeGame()
    {
        foreach (var obj in redCampDict.Values)
        {
            obj.Resume();
        }
 
        foreach(var obj in blueCampDict.Values)
        {
            obj.Resume();
        }
    }
 
    public virtual void PauseGame()
    {
        foreach (var obj in redCampDict.Values)
        {
            obj.Pause();
        }
 
        foreach(var obj in blueCampDict.Values)
        {
            obj.Pause();
        }
    }
 
    public List<BattleObject> GetEnemyList(BattleObject _battleObj)
    {
        if (_battleObj.Camp == BattleCamp.Red)
        {
            return blueCampList;
        }
 
        return redCampList;
    }
 
    public List<BattleObject> GetFriendlyList(BattleObject _battleObj)
    {
        if (_battleObj.Camp == BattleCamp.Red)
        {
            return redCampList;
        }
 
        return blueCampList;
    }
 
#if UNITY_EDITOR
    public void ReviveAll()
    {
        foreach (var kv in allBattleObjDict)
        {
            kv.Value.EditorRevive();
        }
    }
 
    public List<BattleObject> GetTargetList(BattleObject battleObj, SkillTargetType targetType, SkillTargetRangeType rangeType)
    {
        List<BattleObject> returnList = new List<BattleObject>();
 
        switch (targetType)
        {
            case SkillTargetType.Self:
                returnList.Add(battleObj);
                break;
            case SkillTargetType.Own:
                returnList.AddRange(GetFriendlyList(battleObj));
                break;
            case SkillTargetType.Enemy:
                returnList.AddRange(GetEnemyList(battleObj));
                break;
            case SkillTargetType.OwnExceptSelf:
                List<BattleObject> friendlyList = GetFriendlyList(battleObj);
                friendlyList.Remove(battleObj);
                returnList.AddRange(friendlyList);
                break;
            default:
                break;
        }
 
        //普攻为群攻时,以当前单体时默认攻击对象为主对象,其它为溅射单位;
 
        switch (rangeType)
        {
            case SkillTargetRangeType.Front:
                //暂时没有召唤物
                // 放在第7格的BOSS后排的。。位置放在正中间
                // a)前排,1、2、3号为前排,前排全部阵亡后,4、5、6号即是前排也是后排 7其实也是后排
                List<BattleObject> frontList = new List<BattleObject>(from BO in returnList where BO.teamHero.heroIndex < 3 && !BO.IsDead() select BO);
                if (frontList.Count == 0)
                {
                    frontList.AddRange(returnList);
                }
                returnList = frontList;                
                break;
            case SkillTargetRangeType.Back:
                List<BattleObject> backList = new List<BattleObject>(from BO in returnList where BO.teamHero.heroIndex >= 3 && !BO.IsDead() select BO);
                if (backList.Count == 0)
                {
                    backList.AddRange(returnList);
                }
                returnList = backList;     
                break;
            case SkillTargetRangeType.Random:
 
                int randomNumber = 3;
                returnList = new List<BattleObject>(from BO in returnList where !BO.IsDead() select BO);
                returnList = returnList.Shuffle();
                while (returnList.Count > randomNumber)
                {
                    returnList.RemoveAt(0);
                }
                break;
            case SkillTargetRangeType.All:
                break;
            case SkillTargetRangeType.HighestAttack:
                returnList = new List<BattleObject>(from BO in returnList where !BO.IsDead() select BO);
                BattleObject mostHighestAttckObj = null;
                for (int i = 0; i < returnList.Count; i++)
                {
                    if (mostHighestAttckObj == null)
                    {
                        mostHighestAttckObj = returnList[i];
                        continue;
                    }
                    if (returnList[i].teamHero.attack > mostHighestAttckObj.teamHero.attack)
                    {
                        mostHighestAttckObj = returnList[i];
                    }
                }
                returnList.Clear();
                if (mostHighestAttckObj != null)
                    returnList.Add(mostHighestAttckObj);
                break;
            case SkillTargetRangeType.LowestHP:
                returnList = new List<BattleObject>(from BO in returnList where !BO.IsDead() select BO);
                BattleObject loweastHpObj = null;
                for (int i = 0; i < returnList.Count; i++)
                {
                    if (loweastHpObj == null)
                    {
                        loweastHpObj = returnList[i];
                        continue;
                    }
                    if (returnList[i].teamHero.curHp < loweastHpObj.teamHero.curHp)
                    {
                        loweastHpObj = returnList[i];
                    }
                }
                returnList.Clear();
                if (null != loweastHpObj)
                    returnList.Add(loweastHpObj);
                break;
            case SkillTargetRangeType.Deadman:
                returnList = new List<BattleObject>(from BO in returnList where BO.IsDead() select BO);
                break;
            default:
                break;
        }
 
        return returnList;
    }
#endif
}