refactor of watchers to use map functions

This commit is contained in:
ingmargoudt 2017-02-15 23:19:40 +01:00
parent fbbfc6c611
commit 4aa51210f9
18 changed files with 69 additions and 158 deletions

View file

@ -31,17 +31,16 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
* * <p>
* Amount of damage received by a player this turn * Amount of damage received by a player this turn
*
*/ */
public class AmountOfDamageAPlayerReceivedThisTurnWatcher extends Watcher { public class AmountOfDamageAPlayerReceivedThisTurnWatcher extends Watcher {
@ -63,23 +62,14 @@ public class AmountOfDamageAPlayerReceivedThisTurnWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) { if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
UUID playerId = event.getTargetId(); UUID playerId = event.getTargetId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfDamageReceivedThisTurn.get(playerId); amountOfDamageReceivedThisTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfDamageReceivedThisTurn.compute(playerId, (k, v) -> v + event.getAmount());
amount = event.getAmount();
} else {
amount = amount + event.getAmount();
}
amountOfDamageReceivedThisTurn.put(playerId, amount);
} }
} }
} }
public int getAmountOfDamageReceivedThisTurn(UUID playerId) { public int getAmountOfDamageReceivedThisTurn(UUID playerId) {
Integer amount = amountOfDamageReceivedThisTurn.get(playerId); return amountOfDamageReceivedThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -38,7 +38,6 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author Quercitron * @author Quercitron
* @author LevelX2 * @author LevelX2
* @author jeffwadsworth * @author jeffwadsworth
@ -61,11 +60,8 @@ public class CardsAmountDrawnThisTurnWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD) { if (event.getType() == GameEvent.EventType.DREW_CARD) {
if (amountOfCardsDrawnThisTurn.containsKey(event.getPlayerId())) { amountOfCardsDrawnThisTurn.putIfAbsent(event.getPlayerId(), 0);
amountOfCardsDrawnThisTurn.put(event.getPlayerId(), amountOfCardsDrawnThisTurn.get(event.getPlayerId()) + 1); amountOfCardsDrawnThisTurn.compute(event.getPlayerId(), (k, amount) -> amount += 1);
} else {
amountOfCardsDrawnThisTurn.put(event.getPlayerId(), 1);
}
} }
} }
@ -90,11 +86,7 @@ public class CardsAmountDrawnThisTurnWatcher extends Watcher {
} }
public int getAmountCardsDrawn(UUID playerId) { public int getAmountCardsDrawn(UUID playerId) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId); return amountOfCardsDrawnThisTurn.getOrDefault(playerId,0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
@ -39,11 +40,9 @@ import mage.game.events.GameEvent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
*
* @author LevelX2 * @author LevelX2
* * <p>
* Counts cards drawn during draw step * Counts cards drawn during draw step
*
*/ */
public class CardsDrawnDuringDrawStepWatcher extends Watcher { public class CardsDrawnDuringDrawStepWatcher extends Watcher {
@ -65,26 +64,18 @@ public class CardsDrawnDuringDrawStepWatcher extends Watcher {
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD if (event.getType() == GameEvent.EventType.DREW_CARD
&& game.getPhase() != null && game.getPhase() != null
&& game.getPhase().getStep().getType().equals(PhaseStep.DRAW)) { && game.getPhase().getStep().getType() == PhaseStep.DRAW) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId); amountOfCardsDrawnThisTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfCardsDrawnThisTurn.compute(playerId, (k, amount) -> amount + 1);
amount = 1;
} else {
amount++;
}
amountOfCardsDrawnThisTurn.put(playerId, amount);
} }
} }
} }
public int getAmountCardsDrawn(UUID playerId) { public int getAmountCardsDrawn(UUID playerId) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId); return amountOfCardsDrawnThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -74,13 +74,9 @@ public class CardsPutIntoGraveyardWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null && game.getCard(event.getTargetId()) != null) { if (playerId != null && game.getCard(event.getTargetId()) != null) {
Integer amount = amountOfCardsThisTurn.get(playerId); amountOfCardsThisTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfCardsThisTurn.compute(playerId, (k, amount) -> amount += 1);
amount = 1;
} else {
++amount;
}
amountOfCardsThisTurn.put(playerId, amount);
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) { if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
cardsPutToGraveyardFromBattlefield.add(new MageObjectReference(event.getTargetId(), game)); cardsPutToGraveyardFromBattlefield.add(new MageObjectReference(event.getTargetId(), game));
} }
@ -89,11 +85,7 @@ public class CardsPutIntoGraveyardWatcher extends Watcher {
} }
public int getAmountCardsPutToGraveyard(UUID playerId) { public int getAmountCardsPutToGraveyard(UUID playerId) {
Integer amount = amountOfCardsThisTurn.get(playerId); return amountOfCardsThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
public Set<MageObjectReference> getCardsPutToGraveyardFromBattlefield() { public Set<MageObjectReference> getCardsPutToGraveyardFromBattlefield() {

View file

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
@ -37,7 +38,7 @@ public class CastFromHandWatcher extends Watcher {
spellsCastFromHand.clear(); spellsCastFromHand.clear();
step = null; step = null;
} }
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone().equals(Zone.HAND)) { if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) {
if (step == null) { if (step == null) {
step = game.getTurn().getStep(); step = game.getTurn().getStep();
} }

View file

@ -27,20 +27,16 @@
*/ */
package mage.watchers.common; package mage.watchers.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.*;
import java.util.Map.Entry;
/** /**
*
* @author nantuko, BetaSteward_at_googlemail.com * @author nantuko, BetaSteward_at_googlemail.com
*/ */
public class CastSpellLastTurnWatcher extends Watcher { public class CastSpellLastTurnWatcher extends Watcher {
@ -70,13 +66,9 @@ public class CastSpellLastTurnWatcher extends Watcher {
spellsCastThisTurnInOrder.add(new MageObjectReference(event.getTargetId(), game)); spellsCastThisTurnInOrder.add(new MageObjectReference(event.getTargetId(), game));
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfSpellsCastOnCurrentTurn.get(playerId); amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
amount = 1;
} else {
amount = amount + 1;
}
amountOfSpellsCastOnCurrentTurn.put(playerId, amount);
} }
} }
} }
@ -98,20 +90,11 @@ public class CastSpellLastTurnWatcher extends Watcher {
} }
public int getAmountOfSpellsAllPlayersCastOnCurrentTurn() { public int getAmountOfSpellsAllPlayersCastOnCurrentTurn() {
int totalAmount = 0; return amountOfSpellsCastOnCurrentTurn.values().stream().mapToInt(Integer::intValue).sum();
for (Integer amount : amountOfSpellsCastOnCurrentTurn.values()) {
totalAmount += amount;
}
return totalAmount;
} }
public int getAmountOfSpellsPlayerCastOnCurrentTurn(UUID playerId) { public int getAmountOfSpellsPlayerCastOnCurrentTurn(UUID playerId) {
Integer value = amountOfSpellsCastOnCurrentTurn.get(playerId); return amountOfSpellsCastOnCurrentTurn.getOrDefault(playerId, 0);
if (value != null) {
return value;
} else {
return 0;
}
} }
public int getSpellOrder(MageObjectReference spell, Game game) { public int getSpellOrder(MageObjectReference spell, Game game) {

View file

@ -77,10 +77,7 @@ public class CommanderInfoWatcher extends Watcher {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event; DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
if (damageEvent.isCombatDamage()) { if (damageEvent.isCombatDamage()) {
UUID playerUUID = event.getTargetId(); UUID playerUUID = event.getTargetId();
Integer damage = damageToPlayer.get(playerUUID); Integer damage = damageToPlayer.getOrDefault(playerUUID,0);
if (damage == null) {
damage = 0;
}
damage += damageEvent.getAmount(); damage += damageEvent.getAmount();
damageToPlayer.put(playerUUID, damage); damageToPlayer.put(playerUUID, damage);
Player player = game.getPlayer(playerUUID); Player player = game.getPlayer(playerUUID);

View file

@ -81,10 +81,7 @@ public class CreaturesDiedWatcher extends Watcher {
} }
public int getAmountOfCreaturesDiesThisTurn(UUID playerId) { public int getAmountOfCreaturesDiesThisTurn(UUID playerId) {
if (amountOfCreaturesThatDiedByController.containsKey(playerId)) { return amountOfCreaturesThatDiedByController.getOrDefault(playerId, 0);
return amountOfCreaturesThatDiedByController.get(playerId);
}
return 0;
} }
@Override @Override

View file

@ -5,17 +5,17 @@
*/ */
package mage.watchers.common; package mage.watchers.common;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class DamageDoneWatcher extends Watcher { public class DamageDoneWatcher extends Watcher {
@ -50,12 +50,12 @@ public class DamageDoneWatcher extends Watcher {
case DAMAGED_PLANESWALKER: case DAMAGED_PLANESWALKER:
case DAMAGED_PLAYER: { case DAMAGED_PLAYER: {
MageObjectReference damageSourceRef = new MageObjectReference(event.getSourceId(), game); MageObjectReference damageSourceRef = new MageObjectReference(event.getSourceId(), game);
int damageDone = damagingObjects.containsKey(damageSourceRef) ? damagingObjects.get(damageSourceRef) : 0; damagingObjects.putIfAbsent(damageSourceRef, 0);
damagingObjects.put(damageSourceRef, damageDone + event.getAmount()); damagingObjects.compute(damageSourceRef, (k, damage) -> damage + event.getAmount());
MageObjectReference damageTargetRef = new MageObjectReference(event.getTargetId(), game); MageObjectReference damageTargetRef = new MageObjectReference(event.getTargetId(), game);
int damageReceived = damagedObjects.containsKey(damageTargetRef) ? damagedObjects.get(damageTargetRef) : 0; damagedObjects.putIfAbsent(damageTargetRef, 0);
damagedObjects.put(damageTargetRef, damageReceived + event.getAmount()); damagedObjects.compute(damageTargetRef, (k, damage) -> damage + event.getAmount());
} }
} }
} }
@ -69,12 +69,12 @@ public class DamageDoneWatcher extends Watcher {
public int damageDoneBy(UUID objectId, int zoneChangeCounter, Game game) { public int damageDoneBy(UUID objectId, int zoneChangeCounter, Game game) {
MageObjectReference mor = new MageObjectReference(objectId, zoneChangeCounter, game); MageObjectReference mor = new MageObjectReference(objectId, zoneChangeCounter, game);
return damagingObjects.containsKey(mor) ? damagingObjects.get(mor) : 0; return damagingObjects.getOrDefault(mor, 0);
} }
public int damageDoneTo(UUID objectId, int zoneChangeCounter, Game game) { public int damageDoneTo(UUID objectId, int zoneChangeCounter, Game game) {
MageObjectReference mor = new MageObjectReference(objectId, zoneChangeCounter, game); MageObjectReference mor = new MageObjectReference(objectId, zoneChangeCounter, game);
return damagedObjects.containsKey(mor) ? damagedObjects.get(mor) : 0; return damagedObjects.getOrDefault(mor, 0);
} }
public boolean isDamaged(UUID objectId, int zoneChangeCounter, Game game) { public boolean isDamaged(UUID objectId, int zoneChangeCounter, Game game) {

View file

@ -30,6 +30,7 @@ package mage.watchers.common;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
@ -40,7 +41,6 @@ import mage.game.permanent.Permanent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class DamagedByWatcher extends Watcher { public class DamagedByWatcher extends Watcher {
@ -75,9 +75,8 @@ public class DamagedByWatcher extends Watcher {
(watchPlaneswalkers && event.getType() == EventType.DAMAGED_PLANESWALKER); (watchPlaneswalkers && event.getType() == EventType.DAMAGED_PLANESWALKER);
if (eventHasAppropriateType && sourceId.equals(event.getSourceId())) { if (eventHasAppropriateType && sourceId.equals(event.getSourceId())) {
MageObjectReference mor = new MageObjectReference(event.getTargetId(), game); MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
if (!damagedBySource.contains(mor)) {
damagedBySource.add(mor); damagedBySource.add(mor);
}
} }
} }

View file

@ -3,6 +3,7 @@ package mage.watchers.common;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -12,7 +13,6 @@ import mage.watchers.Watcher;
/** /**
* @author jeffwadsworth * @author jeffwadsworth
*
*/ */
public class FirstSpellCastThisTurnWatcher extends Watcher { public class FirstSpellCastThisTurnWatcher extends Watcher {
@ -36,9 +36,9 @@ public class FirstSpellCastThisTurnWatcher extends Watcher {
case CAST_SPELL: case CAST_SPELL:
Spell spell = (Spell) game.getObject(event.getTargetId()); Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null && !playerFirstSpellCast.containsKey(spell.getControllerId())) { if (spell != null && !playerFirstSpellCast.containsKey(spell.getControllerId())) {
if (event.getType().equals(EventType.SPELL_CAST)) { if (event.getType() == EventType.SPELL_CAST) {
playerFirstSpellCast.put(spell.getControllerId(), spell.getId()); playerFirstSpellCast.put(spell.getControllerId(), spell.getId());
} else if (event.getType().equals(EventType.CAST_SPELL)) { } else if (event.getType() == EventType.CAST_SPELL) {
playerFirstCastSpell.put(spell.getControllerId(), spell.getId()); playerFirstCastSpell.put(spell.getControllerId(), spell.getId());
} }
} }
@ -58,10 +58,6 @@ public class FirstSpellCastThisTurnWatcher extends Watcher {
} }
public UUID getIdOfFirstCastSpell(UUID playerId) { public UUID getIdOfFirstCastSpell(UUID playerId) {
if (playerFirstSpellCast.get(playerId) == null) { return playerFirstSpellCast.getOrDefault(playerId, playerFirstSpellCast.get(playerId));
return playerFirstCastSpell.get(playerId);
} else {
return playerFirstSpellCast.get(playerId);
}
} }
} }

View file

@ -39,7 +39,6 @@ import mage.watchers.Watcher;
/** /**
* Watcher saves the mana that was spent to cast a spell * Watcher saves the mana that was spent to cast a spell
* *
*
* @author LevelX2 * @author LevelX2
*/ */
public class ManaSpentToCastWatcher extends Watcher { public class ManaSpentToCastWatcher extends Watcher {
@ -64,7 +63,7 @@ public class ManaSpentToCastWatcher extends Watcher {
} }
} }
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && this.getSourceId().equals(event.getSourceId())) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && this.getSourceId().equals(event.getSourceId())) {
if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) { if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
payment = null; payment = null;
} }
} }

View file

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.keyword.MiracleAbility; import mage.abilities.keyword.MiracleAbility;
import mage.cards.Card; import mage.cards.Card;
@ -74,14 +75,9 @@ public class MiracleWatcher extends Watcher {
if (game.getPhase() != null && event.getType() == GameEvent.EventType.DREW_CARD) { if (game.getPhase() != null && event.getType() == GameEvent.EventType.DREW_CARD) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfCardsDrawnThisTurn.get(playerId); amountOfCardsDrawnThisTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfCardsDrawnThisTurn.compute(playerId, (p, amount) -> amount + 1);
amount = 1; if (amountOfCardsDrawnThisTurn.get(playerId) == 1) {
} else {
amount++;
}
amountOfCardsDrawnThisTurn.put(playerId, amount);
if (amount == 1) {
checkMiracleAbility(event, game); checkMiracleAbility(event, game);
} }
} }

View file

@ -66,8 +66,8 @@ public class PlayerAttackedWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
int numberAttackers = playerAttacked.containsKey(event.getPlayerId()) ? playerAttacked.get(event.getPlayerId()) : 0; playerAttacked.putIfAbsent(event.getPlayerId(), 0);
playerAttacked.put(event.getPlayerId(), numberAttackers + 1); playerAttacked.compute(event.getPlayerId(), (p,amount)->amount + 1);
} }
} }
@ -78,6 +78,6 @@ public class PlayerAttackedWatcher extends Watcher {
} }
public int getNumberOfAttackersCurrentTurn(UUID playerId) { public int getNumberOfAttackersCurrentTurn(UUID playerId) {
return playerAttacked.containsKey(playerId) ? playerAttacked.get(playerId) : 0; return playerAttacked.getOrDefault(playerId, 0);
} }
} }

View file

@ -65,23 +65,14 @@ public class PlayerGainedLifeWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.GAINED_LIFE) { if (event.getType() == GameEvent.EventType.GAINED_LIFE) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfLifeGainedThisTurn.get(playerId); amountOfLifeGainedThisTurn.putIfAbsent(playerId, 0);
if (amount == null) { amountOfLifeGainedThisTurn.compute(playerId, (p, amount) -> amount +event.getAmount());
amount = event.getAmount();
} else {
amount = amount + event.getAmount();
}
amountOfLifeGainedThisTurn.put(playerId, amount);
} }
} }
} }
public int getLiveGained(UUID playerId) { public int getLiveGained(UUID playerId) {
Integer amount = amountOfLifeGainedThisTurn.get(playerId); return amountOfLifeGainedThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -75,19 +75,11 @@ public class PlayerLostLifeWatcher extends Watcher {
} }
public int getLiveLost(UUID playerId) { public int getLiveLost(UUID playerId) {
Integer amount = amountOfLifeLostThisTurn.get(playerId); return amountOfLifeLostThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
public int getLiveLostLastTurn(UUID playerId) { public int getLiveLostLastTurn(UUID playerId) {
Integer amount = amountOfLifeLostLastTurn.get(playerId); return amountOfLifeLostLastTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -80,10 +80,8 @@ public class ProwlWatcher extends Watcher {
if (creature.getAbilities().containsKey(ChangelingAbility.getInstance().getId()) || creature.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) { if (creature.getAbilities().containsKey(ChangelingAbility.getInstance().getId()) || creature.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) {
allSubtypes.add(creature.getControllerId()); allSubtypes.add(creature.getControllerId());
} else { } else {
Set<String> subtypes = damagingSubtypes.get(creature.getControllerId()); Set<String> subtypes = damagingSubtypes.getOrDefault(creature.getControllerId(), new LinkedHashSet<>());
if (subtypes == null) {
subtypes = new LinkedHashSet<>();
}
subtypes.addAll(creature.getSubtype(game)); subtypes.addAll(creature.getSubtype(game));
damagingSubtypes.put(creature.getControllerId(), subtypes); damagingSubtypes.put(creature.getControllerId(), subtypes);
} }

View file

@ -33,9 +33,7 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
/** /**
* Watcher stores which sources did damage to anything. * Watcher stores which sources did damage to anything.
@ -44,7 +42,7 @@ import java.util.UUID;
*/ */
public class SourceDidDamageWatcher extends Watcher { public class SourceDidDamageWatcher extends Watcher {
public final List<UUID> damageSources = new ArrayList<>(); public final Set<UUID> damageSources = new HashSet<>();
public SourceDidDamageWatcher() { public SourceDidDamageWatcher() {
super("SourceDidDamageWatcher", WatcherScope.GAME); super("SourceDidDamageWatcher", WatcherScope.GAME);
@ -65,9 +63,8 @@ public class SourceDidDamageWatcher extends Watcher {
if (event.getType() == EventType.DAMAGED_CREATURE if (event.getType() == EventType.DAMAGED_CREATURE
|| event.getType() == EventType.DAMAGED_PLANESWALKER || event.getType() == EventType.DAMAGED_PLANESWALKER
|| event.getType() == EventType.DAMAGED_PLAYER) { || event.getType() == EventType.DAMAGED_PLAYER) {
if (!damageSources.contains(event.getSourceId())) {
damageSources.add(event.getSourceId()); damageSources.add(event.getSourceId());
}
} }
} }