-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDiscardCardsFromDeckSpell.java
47 lines (40 loc) · 1.42 KB
/
DiscardCardsFromDeckSpell.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
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
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;
import net.demilich.metastone.game.targeting.EntityReference;
import java.util.Map;
/**
* Discards or removes all cards from {@link SpellArg#TARGET_PLAYER}'s deck, up to {@link SpellArg#VALUE} random cards.
* <p>
* To discard the caster's entire deck:
* <pre>
* {
* "class": "DiscardCardsFromDeckSpell",
* "value": 60,
* "targetPlayer": "SELF"
* }
* </pre>
*/
public class DiscardCardsFromDeckSpell extends Spell {
public static SpellDesc create(int howMany) {
Map<SpellArg, Object> arguments = new SpellDesc(DiscardCardsFromDeckSpell.class);
arguments.put(SpellArg.VALUE, howMany);
arguments.put(SpellArg.TARGET, EntityReference.NONE);
return new SpellDesc(arguments);
}
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
int howMany = desc.getValue(SpellArg.VALUE, context, player, target, source, 0);
for (int i = 0; i < howMany; i++) {
if (player.getDeck().isEmpty()) {
return;
}
Card card = player.getDeck().peek();
context.getLogic().discardCard(player, card);
}
}
}