-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstrategy.cs
459 lines (423 loc) · 18.8 KB
/
strategy.cs
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
using System;
using System.Collections.Generic;
public class Strategy
{
private enum COOLDOWN { YES, NO, UNKNOWN };
private struct AbilityLinkage
{
public string Hero;
public int Willing;
public int Ability;
public COOLDOWN Cooldown;
};
//struct MercenaryStrategy
//{
// public bool Crit;
// public bool TargetHealthMin; // ture攻击生命值最低;false最高;
// public int AbilityLinkageIndex;
//}
//struct Mercenary
//{
// public string Name;
// public int[] Ability;
// public int[] WillingAbility;
// public int[] WillingTargetType;
// public MercenaryStrategy AttackStrategy;
//};
private List<string> AttackAbility = new List<string>(); // 不考虑抉择
private List<string> AbilityTargetType = new List<string>();
private List<bool> AttackTaunt = new List<bool>();
private List<string> AttackStrategy = new List<string>();
private List<string> FirstAttack = new List<string>();
private List<string> heroNames = new List<string>();
private List<string> FirstHeroNames = new List<string>();
private List<string> ignoreNames = new List<string>();
private List<AbilityLinkage> AbilityWithAnother = new List<AbilityLinkage>();
private List<int> AbilityWithAnotherIndex = new List<int>();
private void InitTeamConifg()
{
AttackAbility.Clear();
AbilityTargetType.Clear();
AttackTaunt.Clear();
AttackStrategy.Clear();
FirstAttack.Clear();
heroNames.Clear();
FirstHeroNames.Clear();
ignoreNames.Clear();
AbilityWithAnotherIndex.Clear();
AbilityWithAnother.Clear();
string teamConfigPath = @"BepInEx\config\MercenaryTeam.cfg";
if (!System.IO.File.Exists(@teamConfigPath))
{
string TeamConifg = "# 佣兵名称-技能顺序-技能指向(默认=>0敌方,1自己,2无指向(尝试指向敌方0),与设定技能顺序对应)-策略(暴击/攻击最大生命值/攻击最小生命值,默认101)-强制嘲讽优先(缺省0=>false)-默认1技能联动(缺省0=>不联动)\n";
TeamConifg += "瓦尔登·晨拥-213-222\n"; // 技能index需要-1
TeamConifg += "冰雪之王洛克霍拉-123-222\n";
TeamConifg += "吉安娜·普罗德摩尔-213-000-101\n";
TeamConifg += "凯恩·血蹄-323-220-001-0-1\n";
TeamConifg += "迪亚波罗-231-200-001\n";
TeamConifg += "希奈丝特拉-232-110-101-1-2\n";
TeamConifg += "# 优先技能英雄,同速先发\n";
TeamConifg += "+瓦尔登·晨拥\n";
TeamConifg += "+迪亚波罗\n";
TeamConifg += "# 忽略上场(跳过衍生物)\n";
TeamConifg += "-小型魔像\n";
TeamConifg += "# 技能联动列表(第一个的index为1,格式英雄-技能顺序)。如果不能联动,则执行技能顺序2\n";
TeamConifg += "~迪亚波罗-2\n";
TeamConifg += "~迪亚波罗-3\n";
TeamConifg += "# 优先目标,如果有则覆盖默认策略,当技能指向为0时,执行。以>开头填写,无空格\n";
TeamConifg += ">玛法里奥·怒风\n";
TeamConifg += ">冰雪之王洛克霍拉\n";
TeamConifg += ">鞭笞者特里高雷\n";
TeamConifg += ">拉格纳罗斯\n";
TeamConifg += ">萨尔\n";
TeamConifg += ">巴琳达·斯通赫尔斯\n";
TeamConifg += ">瓦莉拉·萨古纳尔\n";
TeamConifg += ">迪亚波罗\n";
TeamConifg += ">瓦尔登·晨拥\n";
TeamConifg += ">吉安娜·普罗德摩尔\n";
TeamConifg += ">安度因·乌瑞恩\n";
TeamConifg += ">沃金\n";
TeamConifg += ">迦顿男爵\n";
System.IO.File.WriteAllText(@teamConfigPath, TeamConifg);
//System.Diagnostics.Process.Start("explorer.exe", @"BepInEx\config\");
}
foreach (string line in System.IO.File.ReadLines(@teamConfigPath))
{
if (line[0] == '#') continue; // 跳过注释
if (line[0] == '>')
{
FirstAttack.Add(line.Substring(1));
continue;
}
if (line[0] == '+')
{
FirstHeroNames.Add(line.Substring(1));
continue;
}
if (line[0] == '-')
{
ignoreNames.Add(line.Substring(1));
continue;
}
if (line[0] == '~')
{
string lineCopy = line.Substring(1);
string[] lineSplit0 = lineCopy.Split('-');
if (lineSplit0.Length == 2)
{
AbilityLinkage abilityLinkage;
abilityLinkage.Hero = lineSplit0[0];
abilityLinkage.Willing = int.Parse(lineSplit0[1]);
abilityLinkage.Ability = -1;
abilityLinkage.Cooldown = COOLDOWN.UNKNOWN;
AbilityWithAnother.Add(abilityLinkage);
}
continue;
}
string[] lineSplit = line.Split('-'); // 分割配置
if (lineSplit.Length > 0)
{
heroNames.Add(lineSplit[0]);
AttackAbility.Add(lineSplit[1]);
if (lineSplit.Length == 3) AbilityTargetType.Add(lineSplit[2]);
else AbilityTargetType.Add("000");
if (lineSplit.Length == 4) AttackStrategy.Add(lineSplit[3]);
else AttackStrategy.Add("101");
if (lineSplit.Length == 5) AttackTaunt.Add(lineSplit[4] == "1");
else AttackTaunt.Add(false);
if (lineSplit.Length == 6) AbilityWithAnotherIndex.Add(int.Parse(lineSplit[5]));
else AbilityWithAnotherIndex.Add(0);
}
}
}
public void Nomination()
{
this.InitTeamConifg();
//heroNames.ForEach(i => Console.Write("{0}\t", i));
//AttackAbility.ForEach(i => Console.Write("{0}\t", i));
//AbilityTargetType.ForEach(i => Console.Write("{0}\t", i));
//AttackStrategy.ForEach(i => Console.Write("{0}\t", i));
//AttackTaunt.ForEach(i => Console.Write("{0}\t", i));
MercenariesHelper.MercenariesHelper.BattleQueue.Clear();
ZoneHand zoneHand = ZoneMgr.Get().FindZoneOfType<ZoneHand>(global::Player.Side.FRIENDLY);
if (zoneHand != null)
{
foreach (string hero in heroNames)
{
foreach (string ignoreName in ignoreNames)
{
if (ignoreName == hero) goto tagContinue;
}
foreach (Card card in zoneHand.GetCards())
{
if (hero == card.GetEntity().GetName())
{
MercenariesHelper.MercenariesHelper.EntranceQueue.Enqueue(card.GetEntity());
break;
}
if (MercenariesHelper.MercenariesHelper.EntranceQueue.Count >= 3)
{
return;
}
}
tagContinue:
continue;
}
}
}
public void Combat()
{
this.InitTeamConifg();
MercenariesHelper.MercenariesHelper.BattleQueue.Clear();
ZonePlay friendlyZone = ZoneMgr.Get().FindZoneOfType<ZonePlay>(global::Player.Side.FRIENDLY);
MercenariesHelper.MercenariesHelper.Battles battles = new MercenariesHelper.MercenariesHelper.Battles();
this.SortName(friendlyZone);
for (int i = 0; i < heroNames.Count; i++)
{
foreach (Card card in friendlyZone.GetCards())
{
string firendlyCardName = card.GetEntity().GetName();
if (firendlyCardName == heroNames[i])
{
List<int> lettuceAbilityEntityIDs = card.GetEntity().GetLettuceAbilityEntityIDs();
int AttackAbility1 = int.Parse(AttackAbility[i]) / 100 - 1;
int AttackAbility2 = int.Parse(AttackAbility[i]) / 10 % 10 - 1;
int AttackAbility3 = int.Parse(AttackAbility[i]) % 10 - 1;
int CurrentAbilityCount;
AttackAbility1 = AttackAbility1 < 3 ? AttackAbility1 : 0;
AttackAbility2 = AttackAbility2 < 3 ? AttackAbility2 : 0;
AttackAbility3 = AttackAbility3 < 3 ? AttackAbility3 : 0;
AttackAbility1 = lettuceAbilityEntityIDs[AttackAbility1];
AttackAbility2 = lettuceAbilityEntityIDs[AttackAbility2];
AttackAbility3 = lettuceAbilityEntityIDs[AttackAbility3];
//Console.Write(heroNames[i]);
//Console.Write("\t挑选技能");
Entity CurrentAbility = GameState.Get().GetEntity(AttackAbility1);
CurrentAbilityCount = 1;
if ((CurrentAbility.GetTag(GAME_TAG.LETTUCE_CURRENT_COOLDOWN) != 0))
{
//Console.WriteLine("第一优先技能存在CD,尝试更换!");
CurrentAbility = GameState.Get().GetEntity(AttackAbility2);
CurrentAbilityCount = 2;
}
if (AbilityWithAnotherIndex[i] > 0)
{
this.UpdateAbiliyLinkageStruct(friendlyZone);
COOLDOWN status = AbilityWithAnother[AbilityWithAnotherIndex[i] - 1].Cooldown; // 如果技能存在冷却,或状态未知,优先执行二技能
if (status != COOLDOWN.NO)
{
CurrentAbility = GameState.Get().GetEntity(AttackAbility2);
CurrentAbilityCount = 2;
}
}
if (CurrentAbility.GetTag(GAME_TAG.LETTUCE_CURRENT_COOLDOWN) != 0)
{
//Console.WriteLine("第二优先技能存在CD,尝试更换!");
CurrentAbility = GameState.Get().GetEntity(AttackAbility3);
CurrentAbilityCount = 3;
}
battles.Ability = CurrentAbility;
//GameState.Get().HasResponse(CurrentAbility, new bool?(false));
//Console.WriteLine("技能选择:"+ CurrentAbility.GetName());
int CurrentAbilityTargetType = 0;
switch (CurrentAbilityCount)
{
case 1:
CurrentAbilityTargetType = int.Parse(AbilityTargetType[i]) / 100;
break;
case 2:
CurrentAbilityTargetType = int.Parse(AbilityTargetType[i]) / 10 % 10;
break;
case 3:
CurrentAbilityTargetType = int.Parse(AbilityTargetType[i]) % 10;
break;
}
switch (CurrentAbilityTargetType)
{
case 0:
battles.target = this.HandleCard(i, card.GetEntity().GetMercenaryRole());
break;
case 1:
battles.target = card.GetEntity();
break;
case 2:
break;
}
battles.source = card.GetEntity();
MercenariesHelper.MercenariesHelper.BattleQueue.Enqueue(battles);
break; // 退出循环执行下一个技能设定
}
}
}
this.InitTeamConifg();
}
private void UpdateAbiliyLinkageStruct(ZonePlay zonePlay)
{
for (int i=0;i<AbilityWithAnother.Count;i++)
{
AbilityLinkage abilityLinkageCopy = AbilityWithAnother[i];
if (abilityLinkageCopy.Ability == -1)
{
foreach (Card card in zonePlay.GetCards())
{
string firendlyCardName = card.GetEntity().GetName();
if (firendlyCardName == abilityLinkageCopy.Hero)
{
List<int> lettuceAbilityEntityIDs = card.GetEntity().GetLettuceAbilityEntityIDs();
abilityLinkageCopy.Ability = lettuceAbilityEntityIDs[abilityLinkageCopy.Willing - 1];
Entity CurrentAbility = GameState.Get().GetEntity(abilityLinkageCopy.Ability);
abilityLinkageCopy.Cooldown = CurrentAbility.GetTag(GAME_TAG.LETTUCE_CURRENT_COOLDOWN) == 0 ? COOLDOWN.NO : COOLDOWN.YES;
AbilityWithAnother[i] = abilityLinkageCopy;
goto nextAbilityWithAnother;
}
}
}
nextAbilityWithAnother:
continue;
}
}
private void SortName(ZonePlay zonePlay)
{
for (int j = 0; j < FirstHeroNames.Count; j++)
{
foreach (Card card in zonePlay.GetCards())
{
string firendlyCardName = card.GetEntity().GetName();
if (firendlyCardName == FirstHeroNames[j])
{
for (int i = j + 1; i < heroNames.Count; i++)
{
if (heroNames[i] == FirstHeroNames[j])
{
string tempAttackAbility = AttackAbility[i];
string tempAbilityTargetType = AbilityTargetType[i];
string tempAttackStrategy = AttackStrategy[i];
bool tempAttackTaunt = AttackTaunt[i];
int tempAbilityWithAnotherIndex = AbilityWithAnotherIndex[i];
AttackAbility[i] = AttackAbility[j];
AbilityTargetType[i] = AbilityTargetType[j];
AttackStrategy[i] = AttackStrategy[j];
AttackTaunt[i] = AttackTaunt[j];
heroNames[i] = heroNames[j];
AbilityWithAnotherIndex[i] = AbilityWithAnotherIndex[j];
AttackAbility[j] = tempAttackAbility;
AbilityTargetType[j] = tempAbilityTargetType;
AttackStrategy[j] = tempAttackStrategy;
AttackTaunt[j] = tempAttackTaunt;
heroNames[j] = FirstHeroNames[j];
AbilityWithAnotherIndex[j] = tempAbilityWithAnotherIndex;
goto findFirstHero;
}
}
}
}
findFirstHero:
continue;
}
}
private Entity HandleCard(int idx, TAG_ROLE myRole)
{
ZonePlay opposingZone = ZoneMgr.Get().FindZoneOfType<ZonePlay>(global::Player.Side.OPPOSING);
List<Card> opposingCards = opposingZone.GetCards();
Entity target;
if (AttackTaunt[idx]) // FIXME:从描述中找攻击
{
foreach (Card card in opposingCards)
{
if (card.GetEntity().HasTaunt() && !card.GetEntity().IsStealthed())
{
return card.GetEntity();
}
}
}
for (int i = 0; i < FirstAttack.Count; i++) // 优先攻击
{
foreach (Card card in opposingCards)
{
string opposingCardName = card.GetEntity().GetName();
if (opposingCardName == FirstAttack[i])
{
//Console.WriteLine("尝试优先攻击目标:"+ opposingCardName);
if (!card.GetEntity().IsStealthed()) // 非潜行
return card.GetEntity();
}
}
}
bool crit = (int.Parse(AttackStrategy[idx]) / 100) == 1;
bool healthMax = (int.Parse(AttackStrategy[idx]) / 10 % 10) == 1;
bool healthMin = (int.Parse(AttackStrategy[idx]) % 10) == 1;
int health = -1;
TAG_ROLE enemyRole = TAG_ROLE.INVALID;
if (crit)
{
target = null;
if (myRole == TAG_ROLE.CASTER) enemyRole = TAG_ROLE.TANK;
if (myRole == TAG_ROLE.TANK) enemyRole = TAG_ROLE.FIGHTER;
if (myRole == TAG_ROLE.FIGHTER) enemyRole = TAG_ROLE.CASTER;
foreach (Card card in opposingCards)
{
if ((card.GetEntity().GetMercenaryRole() == enemyRole) && (enemyRole != TAG_ROLE.INVALID) && (!card.GetEntity().IsStealthed()))
{
if (health == -1)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
if (healthMax && (health != -1))
{
if (card.GetEntity().GetCurrentHealth() > health)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
}
if (healthMin && (health != -1))
{
if (card.GetEntity().GetCurrentHealth() < health)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
}
}
}
if (target != null)
{
return target;
}
}
target = null;
foreach (Card card in opposingCards)
{
if (!card.GetEntity().IsStealthed())
{
if (health == -1)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
if (healthMax && (health != -1))
{
if (card.GetEntity().GetCurrentHealth() > health)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
}
if (healthMin && (health != -1))
{
if (card.GetEntity().GetCurrentHealth() < health)
{
target = card.GetEntity();
health = target.GetCurrentHealth();
}
}
}
}
if (target != null)
{
return target;
}
return opposingCards[0].GetEntity();
}
}