-
Notifications
You must be signed in to change notification settings - Fork 5
/
SerpentSpearInitiateAttackOperation.java
80 lines (64 loc) · 2.13 KB
/
SerpentSpearInitiateAttackOperation.java
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
package core.client.game.operations.equipment;
import java.util.Set;
import java.util.stream.Collectors;
import cards.Card;
import cards.equipments.Equipment.EquipmentType;
import commands.server.ingame.InGameServerCommand;
import commands.server.ingame.SerpentSpearInitiateAttackInGameServerCommand;
import core.client.game.operations.AbstractMultiCardMultiTargetOperation;
import core.player.PlayerSimple;
import ui.game.interfaces.EquipmentUI;
public class SerpentSpearInitiateAttackOperation extends AbstractMultiCardMultiTargetOperation {
private final EquipmentUI activator;
public SerpentSpearInitiateAttackOperation(EquipmentUI source) {
super(2, 1);
this.activator = source;
}
@Override
protected boolean isConfirmEnabled() {
return this.cards.size() == 2 && this.targets.size() == 1;
}
@Override
protected boolean isCancelEnabled() {
return true;
}
@Override
protected boolean isEquipmentTypeActivatable(EquipmentType type) {
return false;
}
@Override
protected boolean isCardActivatable(Card card) {
return true;
}
@Override
protected boolean isPlayerActivatable(PlayerSimple player) {
if (this.getSelf().equals(player)) {
return false;
}
return this.getSelf().isPlayerInAttackRange(player, panel.getGameState().getNumberOfPlayersAlive());
}
@Override
protected String getMessage() {
return "Select 2 cards to use as an Attack on 1 target";
}
@Override
protected void onLoadedCustom() {
this.activator.setActivatable(true);
this.activator.setActivated(true);
// By implementation, this must be the SerpentSpear itself
// Behave as if CANCEL is clicked
this.panel.getGameUI().getEquipmentRackUI().setActivatable(Set.of(EquipmentType.WEAPON), equipment -> this.onCanceled());
}
@Override
protected void onUnloadedCustom() {
this.activator.setActivatable(false);
this.activator.setActivated(false);
}
@Override
protected InGameServerCommand getCommandOnConfirm() {
return new SerpentSpearInitiateAttackInGameServerCommand(
Set.of(this.targets.peek().getPlayer().getPlayerInfo()),
this.cards.keySet().stream().map(ui -> ui.getCard()).collect(Collectors.toSet())
);
}
}