mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
rewrites to getOrDefault
This commit is contained in:
parent
f69ff3aca9
commit
3e5ff8ccb2
15 changed files with 41 additions and 97 deletions
|
@ -47,7 +47,6 @@ 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 {
|
||||||
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
|
|
@ -44,7 +44,6 @@ 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 {
|
||||||
|
@ -95,12 +94,9 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ 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 {
|
||||||
|
@ -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
|
||||||
|
|
|
@ -45,7 +45,6 @@ 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 {
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,7 +53,6 @@ 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 {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue