-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathGainManaSpell.java
More file actions
55 lines (49 loc) · 1.71 KB
/
GainManaSpell.java
File metadata and controls
55 lines (49 loc) · 1.71 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
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.targeting.EntityReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
/**
* Gives the player a temporary amount of {@link SpellArg#VALUE} mana.
* <p>
* To give the player 1 mana, like the coin:
* <pre>
* {
* "class": "GainManaSpell",
* "value": 1
* }
* </pre>
*
* @see RefreshManaSpell to refresh existing, empty mana crystals.
*/
public class GainManaSpell extends Spell {
private static Logger logger = LoggerFactory.getLogger(GainManaSpell.class);
/**
* Gain a fixed amount of mana.
*
* @param mana The amount of mana the player should gain this turn.
* @return The spell
*/
public static SpellDesc create(int mana) {
Map<SpellArg, Object> arguments = new SpellDesc(GainManaSpell.class);
arguments.put(SpellArg.VALUE, mana);
arguments.put(SpellArg.TARGET, EntityReference.NONE);
return new SpellDesc(arguments);
}
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
checkArguments(logger, context, source, desc, SpellArg.VALUE);
int mana = desc.getValue(SpellArg.VALUE, context, player, target, source, 0);
if (mana <= 0) {
logger.debug("onCast {} {}: Player loses mana ({}) in this spell.", context.getGameId(), source, mana);
}
if (mana != 0) {
context.getLogic().modifyCurrentMana(player.getId(), mana, mana < 0);
}
}
}