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
|
part of '../state/game_state.dart';
// ignore_for_file: library_private_types_in_public_api
class MonsterMethods {
static const int _kMinLevel = 0;
static const int _kMaxLevel = 7;
static const int _kMinCharacters = 2;
static const int _kMaxCharacters = 4;
static const int _kCharIndexOffset = 2;
static const int _kTrailingCommaLength = 2;
static void showAllyDeck(_StateModifier _, {GameState? gameState}) {
final gs = gameState ?? getIt<GameState>();
gs._showAllyDeck = true;
}
static void hideAllyDeck(_StateModifier _, {GameState? gameState}) {
final gs = gameState ?? getIt<GameState>();
gs._showAllyDeck = false;
}
static Monster? createMonster(
_StateModifier _,
String name,
int? level,
bool isAlly, {
GameState? gameState,
GameData? gameData,
}) {
final gd = gameData ?? getIt<GameData>();
Map<String, MonsterModel> monsters = {};
final modelData = gd.modelData;
for (String key in modelData.keys) {
monsters.addAll(modelData[key]?.monsters ?? {});
}
level ??= (gameState ?? getIt<GameState>()).level;
return Monster(name, level, isAlly);
}
static void removeMonsters(
_StateModifier _,
List<Monster> items, {
GameState? gameState,
}) {
List<String> deckIds = [];
List<ListItemData> newList = [];
final gs = gameState ?? getIt<GameState>();
for (final item in gs.currentList) {
if (item is Monster) {
bool remove = false;
for (final name in items) {
if (item.id == name.id) {
remove = true;
deckIds.add(item.type.deck);
}
}
if (!remove) {
newList.add(item);
}
} else {
newList.add(item);
}
}
gs._currentList = newList;
for (final deck in deckIds) {
bool removeDeck = true;
for (final item in gs.currentList) {
if (item is Monster) {
if (item.type.deck == deck) {
removeDeck = false;
}
}
}
if (removeDeck) {
for (final item in gs.currentAbilityDecks) {
if (item.name == deck) {
gs._currentAbilityDecks.remove(item);
break;
}
}
}
}
gs._notifyCurrentList();
}
static void executeAddStandee(
_StateModifier s,
final int nr,
final SummonData? summon,
final MonsterType type,
final String ownerId,
final bool addAsSummon, {
GameState? gameState,
}) {
final gs = gameState ?? getIt<GameState>();
MonsterInstance instance;
Monster? monster;
if (summon == null) {
for (final item in gs.currentList) {
if (item.id == ownerId && item is Monster) {
monster = item;
monster._isActive = true;
break;
}
}
if (monster == null) return;
instance = MonsterInstance(nr, type, addAsSummon, monster);
} else {
instance = MonsterInstance.summon(
summon.standeeNr,
type,
summon.name,
summon.health,
summon.move,
summon.attack,
summon.range,
summon.gfx,
gs.round,
);
}
List<MonsterInstance> monsterList = [];
Character? character;
//find list
if (monster != null) {
monsterList = monster._monsterInstances;
} else {
for (final item in gs.currentList) {
if (item.id == ownerId) {
character = item as Character;
monsterList = character.characterState._summonList;
break;
}
}
}
//make sure summons can not have same gfx and nr:
if (instance.standeeNr != 0 && summon != null) {
bool ok = false;
while (!ok) {
ok = true;
for (final item in monsterList) {
if (item.standeeNr == instance.standeeNr) {
if (item.gfx == instance.gfx) {
//can not have same gfx and nr
instance = MonsterInstance.summon(
instance.standeeNr + 1,
type,
summon.name,
summon.health,
summon.move,
summon.attack,
summon.range,
summon.gfx,
gs.round,
);
ok = false;
}
}
}
}
}
monsterList.add(instance);
if (monster != null) {
RoundMethods.sortMonsterInstances(s, monsterList);
monster._notifyMonsterInstances();
} else {
character?.characterState._notifySummonList();
}
if (monsterList.length == 1 && monster != null) {
//first added
final roundState = gs.roundState;
if (roundState == RoundState.chooseInitiative) {
RoundMethods.sortCharactersFirst(s);
} else if (roundState == RoundState.playTurns) {
DeckMethods.drawAbilityCardFromInactiveDeck(s);
RoundMethods.sortItemToPlace(
s,
monster.id,
GameMethods.getInitiative(monster),
); //need to only sort this one item to place
}
}
}
static void addStandee(
int? nr,
Monster data,
MonsterType type,
bool addAsSummon, {
GameState? gameState,
}) {
final gs = gameState ?? getIt<GameState>();
if (nr != null) {
gs.action(
AddStandeeCommand(nr, null, data.id, type, addAsSummon, gameState: gs),
);
} else {
//add first un added nr
for (int i = 1; i <= data.type.count; i++) {
bool added = false;
for (final item in data.monsterInstances) {
if (item.standeeNr == i) {
added = true;
break;
}
}
if (!added) {
gs.action(
AddStandeeCommand(
i,
null,
data.id,
type,
addAsSummon,
gameState: gs,
),
);
return;
}
}
}
}
static void addMonster(
_StateModifier s,
String monster,
List<SpecialRule> specialRules, {
GameState? gameState,
}) {
int levelAdjust = 0;
Set<String> alliedMonsters = {};
for (final rule in specialRules) {
if (rule.name == monster || rule.name == "Enemies") {
if (rule.type == "LevelAdjust") {
levelAdjust = rule.level;
}
}
if (rule.type == "Allies") {
for (String item in rule.list.cast<String>()) {
alliedMonsters.add(item);
}
}
}
final gs = gameState ?? getIt<GameState>();
bool add = true;
for (final item in gs.currentList) {
//don't add duplicates
if (item.id == monster) {
add = false;
break;
}
}
if (add) {
bool isAlly = false;
if (alliedMonsters.contains(monster)) {
isAlly = true;
}
final munster = createMonster(
s,
monster,
(gs.level + levelAdjust).clamp(_kMinLevel, _kMaxLevel),
isAlly,
);
if (munster != null) {
gs._currentList.add(munster);
}
}
}
static String autoAddStandees(
_StateModifier stateModifier,
List<RoomMonsterData> roomMonsterData,
String initMessage, {
GameState? gameState,
Settings? settings,
}) {
final gs = gameState ?? getIt<GameState>();
//handle room data
int characterIndex =
GameMethods.getCurrentCharacterAmount().clamp(
_kMinCharacters,
_kMaxCharacters,
) -
_kCharIndexOffset;
for (int i = 0; i < roomMonsterData.length; i++) {
final roomMonsters = roomMonsterData[i];
addMonster(stateModifier, roomMonsters.name, gs._scenarioSpecialRules);
}
bool addSorted = gs.currentCampaign == "Buttons and Bugs";
final s = settings ?? getIt<Settings>();
if (!s.noStandees && s.autoAddStandees) {
if (s.randomStandees || addSorted) {
if (initMessage.isNotEmpty && !addSorted) {
initMessage += "\n";
}
for (int i = 0; i < roomMonsterData.length; i++) {
List<int> normals = [];
List<int> elites = [];
final roomMonsters = roomMonsterData[i];
Monster data =
gs.currentList.firstWhereOrNull(
(element) => element.id == roomMonsters.name,
)
as Monster;
int eliteAmount = roomMonsters.elite[characterIndex];
int normalAmount = roomMonsters.normal[characterIndex];
bool isBoss = false;
if (data.type.levels.first.boss != null) {
isBoss = true;
}
for (int i = 0; i < eliteAmount; i++) {
int randomNr = GameMethods.getRandomStandee(data);
if (randomNr != 0) {
elites.add(randomNr);
executeAddStandee(
stateModifier,
randomNr,
null,
MonsterType.elite,
data.id,
false,
);
}
}
for (int i = 0; i < normalAmount; i++) {
int randomNr = GameMethods.getRandomStandee(data);
if (addSorted) {
randomNr = GameMethods.getNextAvailableBnBStandee(data);
}
if (randomNr != 0) {
normals.add(randomNr);
executeAddStandee(
stateModifier,
randomNr,
null,
isBoss ? MonsterType.boss : MonsterType.normal,
data.id,
false,
);
}
}
if (!addSorted && (elites.isNotEmpty || normals.isNotEmpty)) {
elites.sort();
normals.sort();
if (i != 0) {
initMessage += "\n";
}
initMessage += "${data.type.display} added - ";
if (elites.isNotEmpty) {
initMessage += "Elite: ";
for (int i = 0; i < elites.length; i++) {
initMessage += "${elites[i]}, ";
if (i == elites.length - 1) {
initMessage = initMessage.substring(
0,
initMessage.length - _kTrailingCommaLength,
);
}
}
}
if (normals.isNotEmpty) {
if (!isBoss) {
if (elites.isNotEmpty) {
initMessage += ", ";
}
initMessage += "Normal: ";
}
for (int i = 0; i < normals.length; i++) {
initMessage += "${normals[i]}, ";
if (i == normals.length - 1) {
initMessage = initMessage.substring(
0,
initMessage.length - _kTrailingCommaLength,
);
}
}
}
}
}
} else {
if (roomMonsterData.isNotEmpty) {
gs.pendingAutoAddDialog = roomMonsterData;
}
}
}
return initMessage;
}
}
|