-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathClientField.cs
357 lines (298 loc) · 11.4 KB
/
ClientField.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
using System.Collections.Generic;
using System.Linq;
using WindBot.Game.AI;
using YGOSharp.OCGWrapper.Enums;
namespace WindBot.Game
{
public class ClientField
{
public IList<ClientCard> Hand { get; private set; }
public ClientCard[] MonsterZone { get; private set; }
public ClientCard[] SpellZone { get; private set; }
public IList<ClientCard> Graveyard { get; private set; }
public IList<ClientCard> Banished { get; private set; }
public IList<ClientCard> Deck { get; private set; }
public IList<ClientCard> ExtraDeck { get; private set; }
public int LifePoints;
public ClientCard BattlingMonster;
public bool UnderAttack;
public ClientField()
{
}
public void Init(int deck, int extra)
{
Hand = new List<ClientCard>();
MonsterZone = new ClientCard[7];
SpellZone = new ClientCard[8];
Graveyard = new List<ClientCard>();
Banished = new List<ClientCard>();
Deck = new List<ClientCard>();
ExtraDeck = new List<ClientCard>();
for (int i = 0; i < deck; ++i)
Deck.Add(new ClientCard(0, CardLocation.Deck, -1));
for (int i = 0; i < extra; ++i)
ExtraDeck.Add(new ClientCard(0, CardLocation.Extra, -1));
}
public int GetMonstersExtraZoneCount()
{
int count = 0;
if (MonsterZone[5] != null)
count++;
if (MonsterZone[6] != null)
count++;
return count;
}
public int GetMonsterCount()
{
return GetCount(MonsterZone);
}
public int GetSpellCount()
{
return GetCount(SpellZone);
}
public int GetHandCount()
{
return GetCount(Hand);
}
public int GetSpellCountWithoutField()
{
int count = 0;
for (int i = 0; i < 5; ++i)
{
if (SpellZone[i] != null)
++count;
}
return count;
}
/// <summary>
/// Count Column
/// </summary>
/// <param zone>range of zone 0-4</param>
public int GetColumnCount(int zone, bool IncludeExtraMonsterZone = true)
{
int count = 0;
if (SpellZone[zone] != null)
count++;
if (MonsterZone[zone] != null)
count++;
if(zone == 1 && IncludeExtraMonsterZone)
{
if (MonsterZone[5] != null)
count++;
}
if (zone == 3 && IncludeExtraMonsterZone)
{
if (MonsterZone[6] != null)
count++;
}
return count;
}
public int GetFieldCount()
{
return GetSpellCount() + GetMonsterCount();
}
public int GetFieldHandCount()
{
return GetSpellCount() + GetMonsterCount() + GetHandCount();
}
public bool IsFieldEmpty()
{
return GetMonsters().Count == 0 && GetSpells().Count == 0;
}
public int GetLinkedZones()
{
int zones = 0;
for (int i = 0; i < 7; i++)
{
zones |= MonsterZone[i]?.GetLinkedZones() ?? 0;
}
return zones;
}
public List<ClientCard> GetMonsters()
{
return GetCards(MonsterZone);
}
public List<ClientCard> GetGraveyardMonsters()
{
return GetCards(Graveyard, CardType.Monster);
}
public List<ClientCard> GetGraveyardSpells()
{
return GetCards(Graveyard, CardType.Spell);
}
public List<ClientCard> GetGraveyardTraps()
{
return GetCards(Graveyard, CardType.Trap);
}
public List<ClientCard> GetSpells()
{
return GetCards(SpellZone);
}
public List<ClientCard> GetMonstersInExtraZone()
{
return GetMonsters().Where(card => card.Sequence >= 5).ToList();
}
public List<ClientCard> GetMonstersInMainZone()
{
return GetMonsters().Where(card => card.Sequence < 5).ToList();
}
public ClientCard GetFieldSpellCard()
{
return SpellZone[5];
}
public bool HasInHand(int cardId)
{
return HasInCards(Hand, cardId);
}
public bool HasInHand(IList<int> cardId)
{
return HasInCards(Hand, cardId);
}
public bool HasInGraveyard(int cardId)
{
return HasInCards(Graveyard, cardId);
}
public bool HasInGraveyard(IList<int> cardId)
{
return HasInCards(Graveyard, cardId);
}
public bool HasInBanished(int cardId)
{
return HasInCards(Banished, cardId);
}
public bool HasInBanished(IList<int> cardId)
{
return HasInCards(Banished, cardId);
}
public bool HasInExtra(int cardId)
{
return HasInCards(ExtraDeck, cardId);
}
public bool HasInExtra(IList<int> cardId)
{
return HasInCards(ExtraDeck, cardId);
}
public bool HasAttackingMonster()
{
return GetMonsters().Any(card => card.IsAttack());
}
public bool HasDefendingMonster()
{
return GetMonsters().Any(card => card.IsDefense());
}
public bool HasInMonstersZone(int cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{
return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial, faceUp);
}
public bool HasInMonstersZone(IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{
return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial, faceUp);
}
public bool HasInSpellZone(int cardId, bool notDisabled = false, bool faceUp = false)
{
return HasInCards(SpellZone, cardId, notDisabled, false, faceUp);
}
public bool HasInSpellZone(IList<int> cardId, bool notDisabled = false, bool faceUp = false)
{
return HasInCards(SpellZone, cardId, notDisabled, false, faceUp);
}
public bool HasInHandOrInSpellZone(int cardId)
{
return HasInHand(cardId) || HasInSpellZone(cardId);
}
public bool HasInHandOrHasInMonstersZone(int cardId)
{
return HasInHand(cardId) || HasInMonstersZone(cardId);
}
public bool HasInHandOrInGraveyard(int cardId)
{
return HasInHand(cardId) || HasInGraveyard(cardId);
}
public bool HasInGraveyardOrInBanished(int cardId)
{
return HasInBanished(cardId) || HasInGraveyard(cardId);
}
public bool HasInMonstersZoneOrInGraveyard(int cardId)
{
return HasInMonstersZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInSpellZoneOrInGraveyard(int cardId)
{
return HasInSpellZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInHandOrInMonstersZoneOrInGraveyard(int cardId)
{
return HasInHand(cardId) || HasInMonstersZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInHandOrInSpellZoneOrInGraveyard(int cardId)
{
return HasInHand(cardId) || HasInSpellZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInHandOrInSpellZone(IList<int> cardId)
{
return HasInHand(cardId) || HasInSpellZone(cardId);
}
public bool HasInHandOrHasInMonstersZone(IList<int> cardId)
{
return HasInHand(cardId) || HasInMonstersZone(cardId);
}
public bool HasInHandOrInGraveyard(IList<int> cardId)
{
return HasInHand(cardId) || HasInGraveyard(cardId);
}
public bool HasInMonstersZoneOrInGraveyard(IList<int> cardId)
{
return HasInMonstersZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInSpellZoneOrInGraveyard(IList<int> cardId)
{
return HasInSpellZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInHandOrInMonstersZoneOrInGraveyard(IList<int> cardId)
{
return HasInHand(cardId) || HasInMonstersZone(cardId) || HasInGraveyard(cardId);
}
public bool HasInHandOrInSpellZoneOrInGraveyard(IList<int> cardId)
{
return HasInHand(cardId) || HasInSpellZone(cardId) || HasInGraveyard(cardId);
}
public int GetRemainingCount(int cardId, int initialCount)
{
int remaining = initialCount;
remaining = remaining - Hand.Count(card => card != null && card.IsOriginalCode(cardId));
remaining = remaining - SpellZone.Count(card => card != null && card.IsOriginalCode(cardId));
remaining = remaining - MonsterZone.Count(card => card != null && card.IsOriginalCode(cardId));
remaining = remaining - Graveyard.Count(card => card != null && card.IsOriginalCode(cardId));
remaining = remaining - Banished.Count(card => card != null && card.IsOriginalCode(cardId));
return (remaining < 0) ? 0 : remaining;
}
private static int GetCount(IEnumerable<ClientCard> cards)
{
return cards.Count(card => card != null);
}
public int GetCountCardInZone(IEnumerable<ClientCard> cards, int cardId)
{
return cards.Count(card => card != null && card.IsCode(cardId));
}
public int GetCountCardInZone(IEnumerable<ClientCard> cards, List<int> cardId)
{
return cards.Count(card => card != null && card.IsCode(cardId));
}
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards, CardType type)
{
return cards.Where(card => card != null && card.HasType(type)).ToList();
}
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards)
{
return cards.Where(card => card != null).ToList();
}
private static bool HasInCards(IEnumerable<ClientCard> cards, int cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{
return cards.Any(card => card != null && card.IsCode(cardId) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
}
private static bool HasInCards(IEnumerable<ClientCard> cards, IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{
return cards.Any(card => card != null && card.IsCode(cardId) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
}
}
}