blob: 663d6b09b85a2ce67070ed997f4f6728a09fc069 (
plain)
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
|
import '../enums.dart';
import '../game_methods.dart';
import '../state/game_state.dart';
import 'command_l10n.dart';
class AddConditionCommand extends Command {
final Condition condition;
final String? ownerId;
final String figureId;
final GameState _gameState;
AddConditionCommand(
this.condition,
this.figureId,
this.ownerId, {
required GameState gameState,
}) : _gameState = gameState;
@override
void execute() {
FigureState? figure = GameMethods.getFigure(ownerId, figureId);
if (figure != null) {
List<Condition> newList = [];
newList.addAll(figure.conditions);
if (!newList.contains(condition) || //block from adding same condition
condition == Condition.chill ||
condition == Condition.plague) {
newList.add(condition);
}
figure.setConditions(stateAccess, newList);
if (condition == Condition.chill) {
figure.setChill(stateAccess, figure.chill + 1);
}
if (condition == Condition.plague) {
figure.setPlague(stateAccess, figure.plague + 1);
}
//only added this turn if is current or done
for (final item in _gameState.currentList) {
if (item.id == ownerId) {
if (item.turnState != TurnsState.notDone &&
_gameState.roundState == RoundState.playTurns) {
figure.addToConditionsThisTurn(stateAccess, condition);
}
}
}
_gameState.notifyListeners();
}
}
@override
String describe() {
return commandL10n.cmdAddCondition(condition.getName());
}
}
|