rewrites to getOrDefault

This commit is contained in:
igoudt 2017-04-28 13:27:22 +02:00
parent f69ff3aca9
commit 3e5ff8ccb2
15 changed files with 41 additions and 97 deletions

View file

@ -47,13 +47,12 @@ import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class AlphaAuthority extends CardImpl { public class AlphaAuthority extends CardImpl {
public AlphaAuthority(UUID ownerId, CardSetInfo setInfo) { public AlphaAuthority(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{G}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}");
this.subtype.add("Aura"); this.subtype.add("Aura");
@ -66,7 +65,7 @@ public class AlphaAuthority extends CardImpl {
// Enchanted creature has hexproof and can't be blocked by more than one creature. // Enchanted creature has hexproof and can't be blocked by more than one creature.
ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HexproofAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield)); ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HexproofAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield));
Effect effect = new CantBeBlockedByMoreThanOneAttachedEffect(AttachmentType.AURA,1); Effect effect = new CantBeBlockedByMoreThanOneAttachedEffect(AttachmentType.AURA, 1);
effect.setText("and can't be blocked by more than one creature"); effect.setText("and can't be blocked by more than one creature");
ability.addEffect(effect); ability.addEffect(effect);
this.addAbility(ability); this.addAbility(ability);
@ -95,7 +94,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl {
super(duration, Outcome.Benefit); super(duration, Outcome.Benefit);
this.amount = amount; this.amount = amount;
this.attachmentType = attachmentType; this.attachmentType = attachmentType;
staticText = (attachmentType == AttachmentType.AURA ? "Enchanted" : "Equipped") + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s"); staticText = attachmentType.verb() + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount == 1 ? "" : "s");
} }
public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) { public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) {

View file

@ -136,10 +136,7 @@ class CerebralVortexWatcher extends Watcher {
} }
public int getDraws(UUID playerId) { public int getDraws(UUID playerId) {
if (draws.containsKey(playerId)) { return draws.getOrDefault(playerId, 0);
return draws.get(playerId);
}
return 0;
} }
@Override @Override

View file

@ -56,7 +56,6 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class ConduitOfRuin extends CardImpl { public class ConduitOfRuin extends CardImpl {
@ -71,7 +70,7 @@ public class ConduitOfRuin extends CardImpl {
} }
public ConduitOfRuin(UUID ownerId, CardSetInfo setInfo) { public ConduitOfRuin(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{6}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{6}");
this.subtype.add("Eldrazi"); this.subtype.add("Eldrazi");
this.power = new MageInt(5); this.power = new MageInt(5);
this.toughness = new MageInt(5); this.toughness = new MageInt(5);
@ -117,20 +116,13 @@ class ConduitOfRuinWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.SPELL_CAST) { if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = (Spell) game.getObject(event.getTargetId()); Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null && spell.isCreature()) { if (spell != null && spell.isCreature()) {
if (playerCreatureSpells.containsKey(event.getPlayerId())) { playerCreatureSpells.put(event.getPlayerId(), creatureSpellsCastThisTurn(event.getPlayerId()) + 1);
playerCreatureSpells.put(event.getPlayerId(), playerCreatureSpells.get(event.getPlayerId()) + 1);
} else {
playerCreatureSpells.put(event.getPlayerId(), 1);
}
} }
} }
} }
public int creatureSpellsCastThisTurn(UUID playerId) { public int creatureSpellsCastThisTurn(UUID playerId) {
if (playerCreatureSpells.containsKey(playerId)) { return playerCreatureSpells.getOrDefault(playerId, 0);
return playerCreatureSpells.get(playerId);
}
return 0;
} }
@Override @Override

View file

@ -44,13 +44,12 @@ import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public class DescentOfTheDragons extends CardImpl { public class DescentOfTheDragons extends CardImpl {
public DescentOfTheDragons(UUID ownerId, CardSetInfo setInfo) { public DescentOfTheDragons(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{4}{R}{R}"); super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{R}{R}");
// Destroy any number of target creatures. For each creature destroyed this way, its controller creates a 4/4 red Dragon creature token with flying. // Destroy any number of target creatures. For each creature destroyed this way, its controller creates a 4/4 red Dragon creature token with flying.
this.getSpellAbility().addEffect(new DescentOfTheDragonsEffect()); this.getSpellAbility().addEffect(new DescentOfTheDragonsEffect());
@ -95,18 +94,15 @@ class DescentOfTheDragonsEffect extends OneShotEffect {
if (permanent != null) { if (permanent != null) {
UUID controllerOfTargetId = permanent.getControllerId(); UUID controllerOfTargetId = permanent.getControllerId();
if (permanent.destroy(source.getSourceId(), game, false)) { if (permanent.destroy(source.getSourceId(), game, false)) {
if(playersWithTargets.containsKey(controllerOfTargetId)) { int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0);
playersWithTargets.put(controllerOfTargetId, playersWithTargets.get(controllerOfTargetId) + 1); playersWithTargets.put(controllerOfTargetId, count + 1);
}
else {
playersWithTargets.put(controllerOfTargetId, 1);
}
} }
} }
} }
} }
DragonToken dragonToken = new DragonToken(); DragonToken dragonToken = new DragonToken();
for(UUID playerId : playersWithTargets.keySet()) { for (UUID playerId : playersWithTargets.keySet()) {
dragonToken.putOntoBattlefield(playersWithTargets.get(playerId), game, source.getSourceId(), playerId); dragonToken.putOntoBattlefield(playersWithTargets.get(playerId), game, source.getSourceId(), playerId);
} }
return true; return true;

View file

@ -46,13 +46,12 @@ import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public class DreamSalvage extends CardImpl { public class DreamSalvage extends CardImpl {
public DreamSalvage(UUID ownerId, CardSetInfo setInfo) { public DreamSalvage(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{U/B}"); super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U/B}");
// Draw cards equal to the number of cards target opponent discarded this turn. // Draw cards equal to the number of cards target opponent discarded this turn.
@ -92,23 +91,13 @@ class CardsDiscardedThisTurnWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.DISCARDED_CARD) { if (event.getType() == GameEvent.EventType.DISCARDED_CARD) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null) { if (playerId != null) {
Integer amount = amountOfCardsDiscardedThisTurn.get(playerId); amountOfCardsDiscardedThisTurn.put(playerId, getAmountCardsDiscarded(playerId) + 1);
if (amount == null) {
amount = 1;
} else {
amount++;
}
amountOfCardsDiscardedThisTurn.put(playerId, amount);
} }
} }
} }
public int getAmountCardsDiscarded(UUID playerId) { public int getAmountCardsDiscarded(UUID playerId) {
Integer amount = amountOfCardsDiscardedThisTurn.get(playerId); return amountOfCardsDiscardedThisTurn.getOrDefault(playerId, 0);
if (amount != null) {
return amount;
}
return 0;
} }
@Override @Override

View file

@ -45,13 +45,12 @@ import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class ErdwalIlluminator extends CardImpl { public class ErdwalIlluminator extends CardImpl {
public ErdwalIlluminator(UUID ownerId, CardSetInfo setInfo) { public ErdwalIlluminator(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}");
this.subtype.add("Spirit"); this.subtype.add("Spirit");
this.power = new MageInt(1); this.power = new MageInt(1);
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
@ -126,11 +125,8 @@ class InvestigatedWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == EventType.INVESTIGATED) { if (event.getType() == EventType.INVESTIGATED) {
if (!timesInvestigated.containsKey(event.getPlayerId())) { timesInvestigated.put(event.getPlayerId(), getTimesInvestigated(event.getPlayerId()) + 1);
timesInvestigated.put(event.getPlayerId(), 1);
} else {
timesInvestigated.put(event.getPlayerId(), timesInvestigated.get(event.getPlayerId()) + 1);
}
} }
} }
@ -141,9 +137,6 @@ class InvestigatedWatcher extends Watcher {
} }
public int getTimesInvestigated(UUID playerId) { public int getTimesInvestigated(UUID playerId) {
if (timesInvestigated.containsKey(playerId)) { return timesInvestigated.getOrDefault(playerId, 0);
return timesInvestigated.get(playerId);
}
return 0;
} }
} }

View file

@ -152,10 +152,7 @@ class GontisMachinationsFirstLostLifeThisTurnWatcher extends Watcher {
} }
public int timesLostLifeThisTurn(UUID playerId) { public int timesLostLifeThisTurn(UUID playerId) {
if (playersLostLife.containsKey(playerId)) { return playersLostLife.getOrDefault(playerId, 0);
return playersLostLife.get(playerId);
}
return 0;
} }
} }

View file

@ -205,10 +205,7 @@ class JelevaNephaliasWatcher extends Watcher {
} }
public int getManaSpentToCastLastTime(int zoneChangeCounter) { public int getManaSpentToCastLastTime(int zoneChangeCounter) {
if (manaSpendToCast.containsKey(zoneChangeCounter)) { return manaSpendToCast.getOrDefault(zoneChangeCounter, 0);
return manaSpendToCast.get(zoneChangeCounter);
}
return 0;
} }
@Override @Override

View file

@ -84,7 +84,7 @@ class CardsDrawnThisTurnDynamicValue implements DynamicValue {
@Override @Override
public int calculate(Game game, Ability sourceAbility, Effect effect) { public int calculate(Game game, Ability sourceAbility, Effect effect) {
KydeleCardsDrawnThisTurnWatcher watcher = (KydeleCardsDrawnThisTurnWatcher) game.getState().getWatchers().get(KydeleCardsDrawnThisTurnWatcher.class.getName()); KydeleCardsDrawnThisTurnWatcher watcher = (KydeleCardsDrawnThisTurnWatcher) game.getState().getWatchers().get(KydeleCardsDrawnThisTurnWatcher.class.getName());
return watcher.getNumCardsDrawnThisTurn(sourceAbility.getControllerId()); return watcher.getCardsDrawnThisTurn(sourceAbility.getControllerId()).size();
} }
@Override @Override
@ -119,20 +119,14 @@ class KydeleCardsDrawnThisTurnWatcher 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 (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) { Set<UUID> cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId());
Set<UUID> cardsDrawn = new LinkedHashSet<>();
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
}
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
cardsDrawn.add(event.getTargetId()); cardsDrawn.add(event.getTargetId());
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
} }
} }
public int getNumCardsDrawnThisTurn(UUID playerId) { public Set<UUID> getCardsDrawnThisTurn(UUID playerId) {
if (cardsDrawnThisTurn.get(playerId) == null) { return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
return 0;
}
return cardsDrawnThisTurn.get(playerId).size();
} }
@Override @Override

View file

@ -167,10 +167,7 @@ class MoltenPsycheWatcher extends Watcher {
} }
public int getDraws(UUID playerId) { public int getDraws(UUID playerId) {
if (draws.containsKey(playerId)) { return draws.getOrDefault(playerId, 0);
return draws.get(playerId);
}
return 0;
} }
@Override @Override

View file

@ -157,17 +157,15 @@ class SylvanLibraryCardsDrawnThisTurnWatcher 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 (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) {
Set<UUID> cardsDrawn = new LinkedHashSet<>(); Set<UUID> cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId());
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
}
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
cardsDrawn.add(event.getTargetId()); cardsDrawn.add(event.getTargetId());
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
} }
} }
public Set<UUID> getCardsDrawnThisTurn(UUID playerId) { public Set<UUID> getCardsDrawnThisTurn(UUID playerId) {
return cardsDrawnThisTurn.get(playerId); return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
} }
@Override @Override

View file

@ -106,10 +106,7 @@ class TerastodonEffect extends OneShotEffect {
if (permanent != null) { if (permanent != null) {
if (permanent.destroy(source.getSourceId(), game, false)) { if (permanent.destroy(source.getSourceId(), game, false)) {
if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) { if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
int numberPermanents = 0; int numberPermanents = destroyedPermanents.getOrDefault(permanent.getControllerId(), 0);
if (destroyedPermanents.containsKey(permanent.getControllerId())) {
numberPermanents = destroyedPermanents.get(permanent.getControllerId());
}
destroyedPermanents.put(permanent.getControllerId(), numberPermanents + 1); destroyedPermanents.put(permanent.getControllerId(), numberPermanents + 1);
} }
} }

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.MageInt; import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
@ -53,7 +54,7 @@ import mage.watchers.Watcher;
public class TunnelIgnus extends CardImpl { public class TunnelIgnus extends CardImpl {
public TunnelIgnus(UUID ownerId, CardSetInfo setInfo) { public TunnelIgnus(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}");
this.subtype.add("Elemental"); this.subtype.add("Elemental");
this.power = new MageInt(2); this.power = new MageInt(2);
@ -98,11 +99,9 @@ class TunnelIgnusWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.isLand() && game.getOpponents(this.controllerId).contains(permanent.getControllerId())) { if (permanent.isLand() && game.getOpponents(this.controllerId).contains(permanent.getControllerId())) {
int count = 1;
if (counts.containsKey(permanent.getControllerId())) { int count = counts.getOrDefault(permanent.getControllerId(), 0);
count += counts.get(permanent.getControllerId()); counts.put(permanent.getControllerId(), count + 1);
}
counts.put(permanent.getControllerId(), count);
} }
} }
} }

View file

@ -29,6 +29,7 @@ package mage.cards.v;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
@ -52,13 +53,12 @@ import mage.players.Player;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class VileRedeemer extends CardImpl { public class VileRedeemer extends CardImpl {
public VileRedeemer(UUID ownerId, CardSetInfo setInfo) { public VileRedeemer(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}");
this.subtype.add("Eldrazi"); this.subtype.add("Eldrazi");
this.power = new MageInt(3); this.power = new MageInt(3);
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
@ -136,8 +136,7 @@ class VileRedeemerNonTokenCreaturesDiedWatcher extends Watcher {
if (zEvent.isDiesEvent() && zEvent.getTarget() != null if (zEvent.isDiesEvent() && zEvent.getTarget() != null
&& zEvent.getTarget().isCreature() && zEvent.getTarget().isCreature()
&& !(zEvent.getTarget() instanceof PermanentToken)) { && !(zEvent.getTarget() instanceof PermanentToken)) {
int count = amountOfCreaturesThatDied.containsKey(zEvent.getTarget().getControllerId()) int count = getAmountOfNontokenCreatureDiedThisTurn(zEvent.getTargetId());
? amountOfCreaturesThatDied.get(zEvent.getTarget().getControllerId()) : 0;
amountOfCreaturesThatDied.put(zEvent.getTarget().getControllerId(), ++count); amountOfCreaturesThatDied.put(zEvent.getTarget().getControllerId(), ++count);
} }
} }

View file

@ -93,7 +93,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl {
super(duration, Outcome.Benefit); super(duration, Outcome.Benefit);
this.amount = amount; this.amount = amount;
this.attachmentType = attachmentType; this.attachmentType = attachmentType;
staticText = (attachmentType == AttachmentType.AURA ? "Enchanted" : "Equipped") + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s"); staticText = attachmentType.verb() + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s");
} }
public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) { public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) {