Skip to content

Commit

Permalink
Fixed a couple of bugs
Browse files Browse the repository at this point in the history
- minions summoned by Summoning Stone should now appear next to it
- FatalDamageTrigger (Ice Block) now correctly respects armor
- Enraged minions are now correctly affected by SetAttack spells, i.e. Aldor Peacekeeper
  • Loading branch information
demilich1 committed Jul 14, 2016
1 parent d96da47 commit 9e192dc
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"spell": {
"class": "SummonRandomMinionFilteredSpell",
"boardPositionRelative": "RIGHT",
"cardFilter": {
"class": "CardFilter",
"manaCost": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected void onCast(GameContext context, Player player, SpellDesc desc, Entity
target.setAttribute(Attribute.ATTACK, value);
target.removeAttribute(Attribute.TEMPORARY_ATTACK_BONUS);
target.removeAttribute(Attribute.ATTACK_BONUS);
target.removeAttribute(Attribute.CONDITIONAL_ATTACK_BONUS);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package net.demilich.metastone.game.spells.trigger;

import net.demilich.metastone.game.entities.Actor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.entities.heroes.Hero;
import net.demilich.metastone.game.entities.minions.Minion;
import net.demilich.metastone.game.events.GameEvent;
import net.demilich.metastone.game.events.PreDamageEvent;
import net.demilich.metastone.game.spells.desc.trigger.EventTriggerDesc;

public class FatalDamageTrigger extends PreDamageTrigger {

private static Logger logger = LoggerFactory.getLogger(FatalDamageTrigger.class);

public FatalDamageTrigger(EventTriggerDesc desc) {
super(desc);
Expand All @@ -18,8 +24,21 @@ protected boolean fire(GameEvent event, Entity host) {
return false;
} else {
PreDamageEvent preDamageEvent = (PreDamageEvent) event;
return ((Actor) preDamageEvent.getVictim()).getHp() <= event.getGameContext().getDamageStack().peek();
Entity victim = preDamageEvent.getVictim();
switch (victim.getEntityType()) {
case HERO:
Hero hero = (Hero) victim;
return hero.getEffectiveHp() <= event.getGameContext().getDamageStack().peek();
case MINION:
Minion minion = (Minion) victim;
return minion.getHp() <= event.getGameContext().getDamageStack().peek();
default:
logger.warn("Invalid entity type in FatalDamageTrigger: {}", victim);
break;
}

}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public void testEnrage() {
context.getLogic().performGameAction(priest.getId(), healAction);
Assert.assertEquals(defender.getAttack(), BASE_ATTACK);
Assert.assertEquals(defender.hasAttribute(Attribute.ENRAGED), false);

// attack once more - should enrage again
context.getLogic().performGameAction(mage.getId(), attackAction);
Assert.assertEquals(defender.getAttack(), BASE_ATTACK + ENRAGE_ATTACK_BONUS);
Assert.assertEquals(defender.hasAttribute(Attribute.ENRAGED), true);

// attack should be set to 1
playCardWithTarget(context, mage, CardCatalogue.getCardById("spell_humility"), defender);
Assert.assertEquals(defender.getAttack(), 1);
Assert.assertEquals(defender.hasAttribute(Attribute.ENRAGED), true);
}

@Test
Expand Down
18 changes: 18 additions & 0 deletions game/src/test/java/net/demilich/metastone/tests/SecretTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import net.demilich.metastone.game.Attribute;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.actions.GameAction;
Expand Down Expand Up @@ -166,5 +167,22 @@ public void testFreezingPlusBearTrap() {
Assert.assertEquals(player.getMinions().size(), 0);
Assert.assertEquals(opponent.getSecrets().size(), 1);
}

@Test
public void testIceBlockWithArmor() {
GameContext context = createContext(HeroClass.MAGE, HeroClass.WARRIOR);
Player player = context.getPlayer1();
Player opponent = context.getPlayer2();

player.getHero().setHp(3);
player.getHero().setAttribute(Attribute.ARMOR, 10);
playCard(context, player, CardCatalogue.getCardById("secret_ice_block"));
context.endTurn();

playCardWithTarget(context, opponent, CardCatalogue.getCardById("spell_bash"), player.getHero());
// Ice block should not have triggered, as the Mage had enough armor to prevent fatal damage
Assert.assertEquals(player.getSecrets().size(), 1);
Assert.assertFalse(player.getHero().hasAttribute(Attribute.IMMUNE));
}

}

0 comments on commit 9e192dc

Please sign in to comment.