mirror of
https://github.com/correl/mage.git
synced 2025-03-07 20:53:18 -10:00
Refactor addCounters to fix bugs in edge cases. (#5154)
Add code to check the controller of abilities on the stack instead of the controller of their source card or object. This fixes https://github.com/magefree/mage/issues/5152
This commit is contained in:
parent
3278139da3
commit
3875f42bac
2 changed files with 65 additions and 1 deletions
|
@ -0,0 +1,56 @@
|
|||
package org.mage.test.cards.triggers;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
public class AbilityOwnershipTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testOwned() {
|
||||
addCard(Zone.GRAVEYARD, playerB, "Soul Snuffers");
|
||||
addCard(Zone.GRAVEYARD, playerB, "Minister of Pain");
|
||||
|
||||
addCard(Zone.HAND, playerA, "Rise of the Dark Realms");
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 9);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Obelisk Spider");
|
||||
|
||||
setLife(playerA, 20);
|
||||
setLife(playerB, 20);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Rise of the Dark Realms");
|
||||
setChoice(playerA, "Yes");
|
||||
addTarget(playerA, "Soul Snuffers"); // sacrifice to Exploit
|
||||
|
||||
setStopAt(1, PhaseStep.END_COMBAT);
|
||||
execute();
|
||||
|
||||
// Obelisk Spider Triggers twice once for the counter on Obelisk Spider. Once for the counter on Minister of Pain.
|
||||
assertLife(playerA, 22);
|
||||
assertLife(playerB, 18);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToGraveyard() {
|
||||
addCard(Zone.GRAVEYARD, playerB, "Soul Snuffers");
|
||||
addCard(Zone.GRAVEYARD, playerB, "Minister of Pain");
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Obelisk Spider");
|
||||
|
||||
addCard(Zone.HAND, playerA, "Rise of the Dark Realms");
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 9);
|
||||
|
||||
setLife(playerA, 20);
|
||||
setLife(playerB, 20);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Rise of the Dark Realms");
|
||||
setChoice(playerA, "Yes");
|
||||
addTarget(playerA, "Soul Snuffers"); // sacrifice to Exploit
|
||||
|
||||
setStopAt(1, PhaseStep.END_COMBAT);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
}
|
||||
}
|
|
@ -779,7 +779,15 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
@Override
|
||||
public boolean addCounters(Counter counter, Ability source, Game game, List<UUID> appliedEffects, boolean isEffect) {
|
||||
boolean returnCode = true;
|
||||
UUID sourceId = (source == null ? getId() : source.getSourceId());
|
||||
UUID sourceId = getId();
|
||||
if (source != null) {
|
||||
MageObject object = game.getObject(source.getId());
|
||||
if (object instanceof StackObject) {
|
||||
sourceId = source.getId();
|
||||
} else {
|
||||
sourceId = source.getSourceId();
|
||||
}
|
||||
}
|
||||
GameEvent countersEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, sourceId, getControllerOrOwner(), counter.getName(), counter.getCount());
|
||||
countersEvent.setAppliedEffects(appliedEffects);
|
||||
countersEvent.setFlag(isEffect);
|
||||
|
|
Loading…
Add table
Reference in a new issue