Fixes for Vessel of the all-consuming (#10306)

* Added some tests for Vessel of the All-Consuming
* Fixed Vessel of the All-consuming
Fixes magefree/mage#10283

Added more commentsto the test.

The bug was for a few reasons. The map was keeping track of how many times a player was dealt damage, not how much damage was being dealt. As well, creating a MageObjectReference from an ability doesn't seem like it works properly, so retrieving from the map never worked.

---------

Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
This commit is contained in:
Alexander Novotny 2023-05-12 00:45:45 -07:00 committed by GitHub
parent f5ab5a8caf
commit c45a546526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 8 deletions

View file

@ -22,9 +22,11 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
/**
* @author TheElk801
@ -104,8 +106,7 @@ class VesselOfTheAllConsumingTriggeredAbility extends TriggeredAbilityImpl {
class VesselOfTheAllConsumingWatcher extends Watcher {
private final Map<MageObjectReference, Map<UUID, Integer>> morMap = new HashMap<>();
private static final Map<UUID, Integer> emptyMap = new HashMap<>();
private final Map<Entry<MageObjectReference, UUID>, Integer> morMap = new HashMap<>();
VesselOfTheAllConsumingWatcher() {
super(WatcherScope.GAME);
@ -118,8 +119,9 @@ class VesselOfTheAllConsumingWatcher extends Watcher {
}
Permanent permanent = game.getPermanent(event.getSourceId());
if (permanent != null) {
morMap.computeIfAbsent(new MageObjectReference(permanent, game), x -> new HashMap<>())
.compute(event.getTargetId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1));
int damage = event.getAmount();
morMap.compute(new AbstractMap.SimpleImmutableEntry(new MageObjectReference(permanent, game), event.getTargetId()),
(u, i) -> i == null ? damage : Integer.sum(i, damage));
}
}
@ -130,10 +132,12 @@ class VesselOfTheAllConsumingWatcher extends Watcher {
}
static boolean checkPermanent(Game game, Ability source) {
return game.getState()
Map<Entry<MageObjectReference, UUID>, Integer> morMap = game.getState()
.getWatcher(VesselOfTheAllConsumingWatcher.class)
.morMap
.getOrDefault(new MageObjectReference(source), emptyMap)
.getOrDefault(source.getEffects().get(0).getTargetPointer().getFirst(game, source), 0) >= 10;
.morMap;
Entry<MageObjectReference, UUID> key = new AbstractMap.SimpleImmutableEntry(
new MageObjectReference(game.getPermanent(source.getSourceId()), game),
source.getEffects().get(0).getTargetPointer().getFirst(game, source));
return morMap.getOrDefault(key, 0) >= 10;
}
}

View file

@ -0,0 +1,61 @@
package org.mage.test.cards.single.neo;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
/**
* {@link mage.cards.v.VesselOfTheAllConsuming Vessel of the All-Consuming}
* Enchantment Creature Ogre Shaman
* Trample
* Whenever Vessel of the All-Consuming deals damage, put a +1/+1 counter on it.
* Whenever Vessel of the All-Consuming deals damage to a player, if it has dealt 10 or more damage to that player this turn, they lose the game.
* 3/3
*
* @author alexander-novo
*/
public class VesselOfTheAllConsumingTest extends CardTestPlayerBase {
private static final String vessel = "Vessel of the All-Consuming";
private static final String hidetsugu = "Hidetsugu Consumes All";
/**
* Reported bug: https://github.com/magefree/mage/issues/10283
*
* Vessel doesn't seem to be tracking damage properly. It should work with 5 power and double strike.
*/
@Test
public void doubleStrike() {
String conviction = "True Conviction";
// Cards necessary for test
addCard(Zone.BATTLEFIELD, playerA, hidetsugu);
addCard(Zone.BATTLEFIELD, playerA, conviction);
// Flip hidetsugu
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, hidetsugu, CounterType.LORE, 3);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, 1);
checkPermanentCount("post flip", 1, PhaseStep.PRECOMBAT_MAIN, playerA, vessel, 1);
// Make vessel a 5/5
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, vessel, CounterType.P1P1, 2);
checkPT("precombat", 1, PhaseStep.PRECOMBAT_MAIN, playerA, vessel, 5, 5);
// Wait until turn 3 because no haste
attack(3, playerA, vessel, playerB);
// -5 -6 because it gets a +1/+1 on the first strike damage
checkLife("post damage", 3, PhaseStep.COMBAT_DAMAGE, playerB, 20 - 5 - 6);
checkStackObject("post damage", 3, PhaseStep.COMBAT_DAMAGE, playerA,
"Whenever {this} deals damage to a player", 1);
setStopAt(3, PhaseStep.COMBAT_DAMAGE);
execute();
// Player B should have lost the game because they took 11 damage from vessel this turn
assertLostTheGame(playerB);
}
}