-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathExcessDamageSpell.java
More file actions
58 lines (50 loc) · 2.22 KB
/
ExcessDamageSpell.java
File metadata and controls
58 lines (50 loc) · 2.22 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
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.entities.Actor;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import java.util.List;
/**
* Deals {@link SpellArg#VALUE} damage to the {@code target} and any excess to the {@link SpellArg#SECONDARY_TARGET}.
* <p>
* If {@link SpellArg#EXCLUSIVE} is {@code true}, only deals excess damage.
* <p>
* If a {@link SpellArg#SPELL} is provided, cast it with a {@link SpellArg#VALUE} equal to the excess damage dealt
* (ignoring spell damage). Leave {@link SpellArg#SECONDARY_TARGET} undefined unless the spell should be cast on every
* secondary target.
*/
public final class ExcessDamageSpell extends DamageSpell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
SpellDesc toExcess;
if (desc.getSpell() != null) {
toExcess = desc.getSpell().cloneAndUnfreeze();
} else {
toExcess = DamageSpell.create();
}
List<Entity> excessDealtTo;
excessDealtTo = context.resolveTarget(player, source, desc.getSecondaryTarget());
int damage = context.getLogic().applySpellpower(player, source, desc.getValue(SpellArg.VALUE, context, player, target, source, 6));
Actor targetActor = (Actor) target;
int hp = targetActor.getHp();
int damageToTarget = Math.max(0, Math.min(damage, hp));
int damageToExcess = Math.min(damage, Math.max(0, damage - hp));
SpellDesc toTarget = DamageSpell.create(target.getReference(), damageToTarget);
toTarget.put(SpellArg.IGNORE_SPELL_DAMAGE, true);
toExcess.put(SpellArg.VALUE, damageToExcess);
toExcess.put(SpellArg.IGNORE_SPELL_DAMAGE, true);
if (!desc.getBool(SpellArg.EXCLUSIVE)) {
toTarget.remove(SpellArg.SECONDARY_TARGET);
super.onCast(context, player, toTarget, source, target);
}
if (excessDealtTo != null) {
for (Entity excessTarget : excessDealtTo) {
SpellUtils.castChildSpell(context, player, toExcess, source, excessTarget);
}
} else {
SpellUtils.castChildSpell(context, player, toExcess, source, null);
}
}
}