Added new restriction to second target

This commit is contained in:
Zzooouhh 2017-11-19 21:42:31 +01:00 committed by GitHub
parent 4c6b4b9a7e
commit 491eba3910
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,8 @@
*/ */
package mage.cards.b; package mage.cards.b;
import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
@ -46,6 +48,7 @@ import mage.constants.PhaseStep;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterAttackingCreature; import mage.filter.common.FilterAttackingCreature;
import mage.filter.common.FilterBlockingCreature; import mage.filter.common.FilterBlockingCreature;
import mage.filter.predicate.Predicate;
import mage.game.Game; import mage.game.Game;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -126,7 +129,24 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
// Choose new creature to block // Choose new creature to block
if (permanent.isCreature()) { if (permanent.isCreature()) {
TargetAttackingCreature target = new TargetAttackingCreature(1, 1, new FilterAttackingCreature(), true); // according to the following mail response from MTG Rules Management:
// "if Player A attacks Players B and C, Player B's creatures cannot block creatures attacking Player C"
// therefore we need to single out creatures attacking the target blocker's controller (disappointing, I know)
List<Permanent> list = new ArrayList<>();
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getDefendingPlayerId().equals(permanent.getControllerId())) {
for (UUID attackingCreatureId : combatGroup.getAttackers()) {
Permanent targetsControllerAttacker = game.getPermanent(attackingCreatureId);
list.add(targetsControllerAttacker);
}
}
}
Player targetsController = game.getPlayer(permanent.getControllerId());
if (targetsController != null) {
FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
filter.add(new PermanentInListPredicate(list));
TargetAttackingCreature target = new TargetAttackingCreature(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) { if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(controller.getId(), game) && controller.canRespond()) { while (!target.isChosen() && target.canChoose(controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game); controller.chooseTarget(outcome, target, source, game);
@ -142,10 +162,7 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
// 7/15/2006 If an attacking creature has an ability that triggers When this creature becomes blocked, // 7/15/2006 If an attacking creature has an ability that triggers When this creature becomes blocked,
// it triggers when a creature blocks it due to the Warlords ability only if it was unblocked at that point. // it triggers when a creature blocks it due to the Warlords ability only if it was unblocked at that point.
boolean notYetBlocked = true; boolean notYetBlocked = chosenGroup.getBlockers().isEmpty();
if (!chosenGroup.getBlockers().isEmpty()) {
notYetBlocked = false;
}
chosenGroup.addBlocker(permanent.getId(), controller.getId(), game); chosenGroup.addBlocker(permanent.getId(), controller.getId(), game);
if (notYetBlocked) { if (notYetBlocked) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, chosenPermanent.getId(), null)); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, chosenPermanent.getId(), null));
@ -153,9 +170,24 @@ class BalduvianWarlordUnblockEffect extends OneShotEffect {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BLOCKER_DECLARED, chosenPermanent.getId(), permanent.getId(), permanent.getControllerId())); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BLOCKER_DECLARED, chosenPermanent.getId(), permanent.getId(), permanent.getControllerId()));
} }
} }
}
return true; return true;
} }
} }
return false; return false;
} }
} }
class PermanentInListPredicate implements Predicate<Permanent> {
private final List<Permanent> permanents;
public PermanentInListPredicate(List<Permanent> permanents) {
this.permanents = permanents;
}
@Override
public boolean apply(Permanent input, Game game) {
return permanents.contains(input);
}
}