-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAddQuestSpell.java
More file actions
92 lines (81 loc) · 2.99 KB
/
AddQuestSpell.java
File metadata and controls
92 lines (81 loc) · 2.99 KB
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
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.trigger.secrets.Quest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
/**
* Adds the specified {@link SpellArg#QUEST} for the specified {@link SpellArg#TARGET_PLAYER}.
* <p>
* For <b>example</b>, a spell may create a quest for both players that reads, "After your characters have been damaged
* 10 times, lose the game."
* <pre>
* {
* "class": "AddQuestSpell",
* "targetPlayer": "BOTH",
* "quest": {
* "countUntilCast": 10,
* "eventTrigger": {
* "class": "DamageReceivedTrigger",
* "targetPlayer": "SELF"
* },
* "spell": {
* "class": "DestroySpell",
* "target": "FRIENDLY_HERO"
* },
* "maxFires": 10
* }
* }
* </pre>
*
* @see Quest for more about quests and the format for specifying them.
*/
public class AddQuestSpell extends Spell {
private static Logger logger = LoggerFactory.getLogger(AddQuestSpell.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 quest The quest.
* @return The spell
*/
public static SpellDesc create(TargetPlayer target, Quest quest) {
Map<SpellArg, Object> arguments = new SpellDesc(AddQuestSpell.class);
arguments.put(SpellArg.QUEST, quest);
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.QUEST);
final Object questObject = desc.get(SpellArg.QUEST);
if (questObject == null) {
logger.error("onCast {} {}: The specified QUEST argument is null", context.getGameId(), source);
return;
}
if (!(questObject instanceof Quest)) {
logger.error("onCast {} {}: The specified QUEST argument {} is not a Quest object, it is a {}", context.getGameId(), source, questObject, questObject.getClass());
return;
}
Quest quest = ((Quest) questObject).clone();
if (quest.getSourceCard() == null) {
quest.setSourceCard(source.getSourceCard());
}
if (context.getLogic().canPlayQuest(player, quest.getSourceCard())) {
context.getLogic().playQuest(player, quest.clone());
}
}
}