Skip to content

Commit

Permalink
* Bushido - Fixed that it triggerd wrongly for each blocker instead o…
Browse files Browse the repository at this point in the history
…f only once if blocked.
  • Loading branch information
LevelX2 committed Feb 4, 2018
1 parent 0044c9d commit 88d4e2b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,24 @@ public void testBlocking() {
assertPermanentCount(playerB, "Elite Vanguard", 0);
}

/**
* Tests boosting on double block, it may only trigger once
*/
@Test
public void testMultipleBlocker() {
addCard(Zone.BATTLEFIELD, playerA, "Llanowar Elves", 1);
addCard(Zone.BATTLEFIELD, playerA, "Quirion Elves", 1);

addCard(Zone.BATTLEFIELD, playerB, "Isao, Enlightened Bushi"); // 2/1 Bushido 2
attack(2, playerB, "Isao, Enlightened Bushi");
block(2, playerA, "Llanowar Elves", "Isao, Enlightened Bushi");
block(2, playerA, "Quirion Elves", "Isao, Enlightened Bushi");

setStopAt(2, PhaseStep.END_COMBAT);
execute();

assertPowerToughness(playerB, "Isao, Enlightened Bushi", 4, 3);
assertPermanentCount(playerA, "Llanowar Elves", 0);
assertPermanentCount(playerA, "Quirion Elves", 0);
}
}
43 changes: 34 additions & 9 deletions Mage/src/main/java/mage/abilities/keyword/BushidoAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,65 @@
package mage.abilities.keyword;

import mage.abilities.Ability;
import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;

public class BushidoAbility extends BlocksOrBecomesBlockedTriggeredAbility {
public class BushidoAbility extends TriggeredAbilityImpl {

private DynamicValue value;
private String rule = null;
private String rulesText = null;

public BushidoAbility(int value) {
this(new StaticValue(value));
rule = "Bushido " + value + getReminder(Integer.toString(value));
rulesText = "Bushido " + value + getReminder(Integer.toString(value));
}

public BushidoAbility(DynamicValue value) {
super(new BoostSourceEffect(value, value, Duration.EndOfTurn, true), false);
super(Zone.BATTLEFIELD, new BoostSourceEffect(value, value, Duration.EndOfTurn, true), false);
if (!(value instanceof StaticValue)) {
rule = "{this} has bushido X, where X is " + value.getMessage() + getReminder(value.toString());
rulesText = "{this} has bushido X, where X is " + value.getMessage() + getReminder(value.toString());
}
this.value = value;
}

static String getReminder(String xValue) {
return " <i>(Whenever this creature blocks or becomes blocked, it gets +" + xValue+ "/+" + xValue + " until end of turn.)</i>";
return " <i>(Whenever this creature blocks or becomes blocked, it gets +" + xValue + "/+" + xValue + " until end of turn.)</i>";
}

public BushidoAbility(final BushidoAbility ability) {
super(ability);
this.value = ability.value;
this.rule = ability.rule;
this.rulesText = ability.rulesText;
}

@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DECLARE_BLOCKERS_STEP;
}

@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent source = game.getPermanent(getSourceId());
if (source != null) {
if (source.isBlocked(game)) {
return true;
}
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getBlockers().contains(getSourceId())) {
return true;
}
}
}
return false;
}

@Override
Expand All @@ -75,6 +100,6 @@ public int getValue(Ability source, Game game, Effect effect) {

@Override
public String getRule() {
return rule;
return rulesText;
}
}

0 comments on commit 88d4e2b

Please sign in to comment.