-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathInvokeSpell.java
46 lines (40 loc) · 1.7 KB
/
InvokeSpell.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
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.cards.Attribute;
import net.demilich.metastone.game.cards.Card;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
/**
* When the player has at least {@link Attribute#INVOKE} additional unspent mana, source an extra bonus effect for that
* cost.
* <p>
* By default, casts the effect in {@link SpellArg#SPELL1}. If the player can afford the extra cost, {@link
* SpellArg#SPELL2} is printed on a card, and the player is given a discover choice between the two effects.
*/
public class InvokeSpell extends ChooseOneSpell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
var manaRemaining = player.getMana();
var invoke = source.getAttributeValue(Attribute.INVOKE);
if (source.hasAttribute(Attribute.AURA_INVOKE)) {
invoke = Math.min(invoke, source.getAttributeValue(Attribute.AURA_INVOKE));
}
if (manaRemaining < invoke) {
if (desc.containsKey(SpellArg.SPELL)) {
SpellUtils.castChildSpell(context, player, desc.getSpell(), source, target);
}
return;
}
super.onCast(context, player, desc, source, target);
}
@Override
public boolean shouldRemoveCard(Card card, Player player, GameContext context) {
return card.getBaseManaCost() > player.getMana();
}
@Override
public Card getTempCard(GameContext context, SpellDesc spellDesc, Card sourceCard) {
return ChooseOneOptionSpell.getTempCard(context, spellDesc, sourceCard, "invoke_");
}
}