mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
Fixed Panharmonicon triggering for opponents abilities. Added tests.
This commit is contained in:
parent
b89822a655
commit
120d7612f6
7 changed files with 178 additions and 15 deletions
|
|
@ -41,6 +41,7 @@ import mage.cards.Card;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.NumberOfTriggersEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
|
||||
|
|
@ -124,7 +125,12 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
|
|||
}
|
||||
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
ability.trigger(game, ability.getControllerId());
|
||||
NumberOfTriggersEvent numberOfTriggersEvent = new NumberOfTriggersEvent(ability.getControllerId(), event);
|
||||
if (!game.replaceEvent(numberOfTriggersEvent)) {
|
||||
for (int i = 0; i < numberOfTriggersEvent.getAmount(); i++) {
|
||||
ability.trigger(game, ability.getControllerId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,17 +43,17 @@ public class EntersTheBattlefieldEvent extends GameEvent {
|
|||
private Permanent target;
|
||||
|
||||
public EntersTheBattlefieldEvent(Permanent target, UUID sourceId, UUID playerId, Zone fromZone) {
|
||||
this(target, sourceId, playerId, fromZone, null);
|
||||
super(EventType.ENTERS_THE_BATTLEFIELD, target.getId(), sourceId, playerId);
|
||||
this.fromZone = fromZone;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public EntersTheBattlefieldEvent(Permanent target, UUID sourceId, UUID playerId, Zone fromZone, ArrayList<UUID> appliedEffects) {
|
||||
super(EventType.ENTERS_THE_BATTLEFIELD, target.getId(), sourceId, playerId);
|
||||
this.fromZone = fromZone;
|
||||
this.target = target;
|
||||
if (appliedEffects != null) {
|
||||
this.appliedEffects = appliedEffects;
|
||||
}
|
||||
this.amount = 1; // Number of times to trigger (Panharmonicon can change that value)
|
||||
}
|
||||
|
||||
public Zone getFromZone() {
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ public class GameEvent implements Serializable {
|
|||
REGENERATE,
|
||||
REGENERATED,
|
||||
CHANGE_COLOR, COLOR_CHANGED,
|
||||
NUMBER_OF_TRIGGERS,
|
||||
//combat events
|
||||
COMBAT_DAMAGE_APPLIED,
|
||||
SELECTED_ATTACKER, SELECTED_BLOCKER;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.game.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class NumberOfTriggersEvent extends GameEvent {
|
||||
|
||||
private final GameEvent sourceEvent;
|
||||
|
||||
public NumberOfTriggersEvent(UUID controllerOfAbilityId, GameEvent sourceEvent) {
|
||||
super(EventType.NUMBER_OF_TRIGGERS, null, null, controllerOfAbilityId);
|
||||
this.sourceEvent = sourceEvent;
|
||||
this.amount = 1; // Number of times to trigger. Panharmonicon can change this.
|
||||
}
|
||||
|
||||
public GameEvent getSourceEvent() {
|
||||
return sourceEvent;
|
||||
}
|
||||
}
|
||||
|
|
@ -881,12 +881,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
EntersTheBattlefieldEvent event = new EntersTheBattlefieldEvent(this, sourceId, getControllerId(), fromZone);
|
||||
if (!game.replaceEvent(event)) {
|
||||
if (fireEvent) {
|
||||
// Trigger multiple times with Panharmonicon.
|
||||
for (int i = 0; i < event.getAmount(); i++) {
|
||||
game.addSimultaneousEvent(event);
|
||||
}
|
||||
game.addSimultaneousEvent(event);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue