-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathAddPactSpell.java
98 lines (88 loc) · 3.41 KB
/
AddPactSpell.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import net.demilich.metastone.game.spells.desc.trigger.EnchantmentDescArg;
import net.demilich.metastone.game.spells.desc.trigger.EventTriggerArg;
import net.demilich.metastone.game.spells.trigger.secrets.Quest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
/**
* Adds the specified {@link SpellArg#PACT} for the specified {@link SpellArg#TARGET_PLAYER}.
* <p>
* A pact is a permanent that triggers its written effect when <b>either</b> player performs the action written on the
* card. Their {@link EnchantmentDescArg#EVENT_TRIGGER} event trigger should have {@link EventTriggerArg#TARGET_PLAYER}
* set to {@link TargetPlayer#BOTH}.
* <p>
* For <b>example</b>, a spell may create a pact for both players that reads, "After your characters have been damaged
* 10 times, lose the game."
* <pre>
* {
* "class": "AddQuestSpell",
* "targetPlayer": "BOTH",
* "pact": {
* "countUntilCast": 10,
* "eventTrigger": {
* "class": "DamageReceivedTrigger",
* "targetPlayer": "BOTH"
* },
* "spell": {
* "class": "DestroySpell",
* "target": "FRIENDLY_HERO"
* },
* "maxFires": 10
* }
* }
* </pre>
*
* @see Quest for more about quests and the format for specifying them.
*/
public class AddPactSpell extends AddQuestSpell {
private static Logger logger = LoggerFactory.getLogger(AddPactSpell.class);
/**
* Creates this spell for the casting player and the specified {@link Quest}.
*
* @param quest The quest object to use for this spell.
* @return The spell
*/
public static SpellDesc create(Quest quest) {
return create(TargetPlayer.SELF, quest);
}
/**
* Creates this spell for the specified {@link TargetPlayer} and {@link Quest}.
*
* @param target The {@link TargetPlayer} interpreted from the caster's point of view.
* @param pact The pact.
* @return The spell
*/
public static SpellDesc create(TargetPlayer target, Quest pact) {
Map<SpellArg, Object> arguments = new SpellDesc(AddPactSpell.class);
arguments.put(SpellArg.PACT, pact);
arguments.put(SpellArg.TARGET_PLAYER, target);
return new SpellDesc(arguments);
}
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
checkArguments(logger, context, source, desc, SpellArg.PACT);
final Object pactObject = desc.get(SpellArg.PACT);
if (pactObject == null) {
logger.error("onCast {} {}: The specified PACT argument is null", context.getGameId(), source);
return;
}
if (!(pactObject instanceof Quest)) {
logger.error("onCast {} {}: The specified PACT argument {} is not a Quest object, it is a {}", context.getGameId(), source, pactObject, pactObject.getClass());
return;
}
Quest pact = ((Quest) pactObject).clone();
pact.setPact(true);
if (pact.getSourceCard() == null) {
pact.setSourceCard(source.getSourceCard());
}
if (context.getLogic().canPlayPact(player, pact.getSourceCard())) {
context.getLogic().playPact(player, pact.clone());
}
}
}