-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathMissilesSpell.java
92 lines (81 loc) · 4.2 KB
/
MissilesSpell.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
package net.demilich.metastone.game.spells;
import com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType;
import com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType;
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.Actor;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.logic.GameLogic;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import net.demilich.metastone.game.spells.desc.filter.EntityFilter;
import net.demilich.metastone.game.targeting.EntityReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
/**
* This spell casts {@link SpellArg#HOW_MANY} missiles, each dealing {@link SpellArg#VALUE} damage (with spell damage)
* to random targets.
* <p>
* When a target becomes mortally wounded ({@link Actor#isDestroyed()} resolves to {@code true}), it is no longer
* eligible to receive missiles.
* <p>
* When the amount of damage a missile deals is 1, the spell damage modifier is interpreted to increase the number of
* missiles. In all other instances, spell damage increases the damage <b>per missile.</b>
* <p>
* Every target hit by a missile will have {@link SpellArg#SPELL} cast on it if specified, with the hit target as the
* {@code target}. {@link EntityReference#OUTPUT} will not be set.
* <p>
* When {@link SpellArg#EXCLUSIVE} is set to {@code true}, applies spell damage to the number of missiles (the {@link
* SpellArg#HOW_MANY} value).
*/
public class MissilesSpell extends DamageSpell {
private static Logger logger = LoggerFactory.getLogger(MissilesSpell.class);
@Override
public void cast(GameContext context, Player player, SpellDesc desc, Entity source, List<Entity> targets) {
if (desc.getTarget() == null
|| desc.getTarget().equals(EntityReference.TARGET)) {
logger.warn("cast {} {}: Probable incorrect usage of MissilesSpell.", context.getGameId(), source);
}
int missiles = desc.getValue(SpellArg.HOW_MANY, context, player, null, source, 2);
int damage = desc.getValue(SpellArg.VALUE, context, player, null, source, 1);
SpellDesc subSpell = desc.getSpell();
if ((damage == 1 || desc.getBool(SpellArg.EXCLUSIVE))
&& ((source.getEntityType() == EntityType.CARD && GameLogic.isCardType(((Card) source).getCardType(), CardType.SPELL))
|| source.getEntityType() == EntityType.SECRET)) {
missiles = context.getLogic().applySpellpower(player, source, missiles);
missiles = context.getLogic().applyAmplify(player, missiles, Attribute.SPELL_DAMAGE_AMPLIFY_MULTIPLIER);
} else if (source.getEntityType() == EntityType.CARD && GameLogic.isCardType(((Card) source).getCardType(), CardType.SPELL)) {
damage = context.getLogic().applySpellpower(player, source, damage);
damage = context.getLogic().applyAmplify(player, damage, Attribute.SPELL_DAMAGE_AMPLIFY_MULTIPLIER);
}
for (int i = 0; i < missiles; i++) {
List<Entity> validTargets;
if (desc.containsKey(SpellArg.FILTER)) {
EntityFilter targetFilter = desc.getEntityFilter();
List<Entity> filteredTargets = SpellUtils.getValidTargets(context, player, targets, targetFilter, source);
validTargets = SpellUtils.getValidRandomTargets(filteredTargets);
} else {
validTargets = SpellUtils.getValidRandomTargets(targets);
}
if (validTargets.isEmpty()) {
return;
}
Actor randomTarget = getRandomTarget(context, validTargets);
GameLogic.fireMissileEvent(context, player, source, Collections.singletonList(randomTarget), getDamageType(context, player, source));
context.getLogic().damage(player, randomTarget, damage, source, true);
if (subSpell != null) {
SpellUtils.castChildSpell(context, player, subSpell, source, randomTarget);
}
}
}
public Actor getRandomTarget(GameContext context, List<Entity> validTargets) {
return (Actor) context.getLogic().getRandom(validTargets);
}
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
}
}