mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
rewrites to getOrDefault
This commit is contained in:
parent
f69ff3aca9
commit
3e5ff8ccb2
15 changed files with 41 additions and 97 deletions
|
@ -47,13 +47,12 @@ import mage.util.CardUtil;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class AlphaAuthority extends CardImpl {
|
||||
|
||||
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");
|
||||
|
||||
|
@ -66,7 +65,7 @@ public class AlphaAuthority extends CardImpl {
|
|||
|
||||
// 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));
|
||||
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");
|
||||
ability.addEffect(effect);
|
||||
this.addAbility(ability);
|
||||
|
@ -95,7 +94,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl {
|
|||
super(duration, Outcome.Benefit);
|
||||
this.amount = amount;
|
||||
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) {
|
||||
|
|
|
@ -136,10 +136,7 @@ class CerebralVortexWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public int getDraws(UUID playerId) {
|
||||
if (draws.containsKey(playerId)) {
|
||||
return draws.get(playerId);
|
||||
}
|
||||
return 0;
|
||||
return draws.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,7 +56,6 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class ConduitOfRuin extends CardImpl {
|
||||
|
@ -71,7 +70,7 @@ public class ConduitOfRuin extends CardImpl {
|
|||
}
|
||||
|
||||
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.power = new MageInt(5);
|
||||
this.toughness = new MageInt(5);
|
||||
|
@ -117,20 +116,13 @@ class ConduitOfRuinWatcher extends Watcher {
|
|||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||
if (spell != null && spell.isCreature()) {
|
||||
if (playerCreatureSpells.containsKey(event.getPlayerId())) {
|
||||
playerCreatureSpells.put(event.getPlayerId(), playerCreatureSpells.get(event.getPlayerId()) + 1);
|
||||
} else {
|
||||
playerCreatureSpells.put(event.getPlayerId(), 1);
|
||||
}
|
||||
playerCreatureSpells.put(event.getPlayerId(), creatureSpellsCastThisTurn(event.getPlayerId()) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int creatureSpellsCastThisTurn(UUID playerId) {
|
||||
if (playerCreatureSpells.containsKey(playerId)) {
|
||||
return playerCreatureSpells.get(playerId);
|
||||
}
|
||||
return 0;
|
||||
return playerCreatureSpells.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,13 +44,12 @@ import java.util.HashMap;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public class DescentOfTheDragons extends CardImpl {
|
||||
|
||||
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.
|
||||
this.getSpellAbility().addEffect(new DescentOfTheDragonsEffect());
|
||||
|
@ -95,18 +94,15 @@ class DescentOfTheDragonsEffect extends OneShotEffect {
|
|||
if (permanent != null) {
|
||||
UUID controllerOfTargetId = permanent.getControllerId();
|
||||
if (permanent.destroy(source.getSourceId(), game, false)) {
|
||||
if(playersWithTargets.containsKey(controllerOfTargetId)) {
|
||||
playersWithTargets.put(controllerOfTargetId, playersWithTargets.get(controllerOfTargetId) + 1);
|
||||
}
|
||||
else {
|
||||
playersWithTargets.put(controllerOfTargetId, 1);
|
||||
}
|
||||
int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0);
|
||||
playersWithTargets.put(controllerOfTargetId, count + 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DragonToken dragonToken = new DragonToken();
|
||||
for(UUID playerId : playersWithTargets.keySet()) {
|
||||
for (UUID playerId : playersWithTargets.keySet()) {
|
||||
dragonToken.putOntoBattlefield(playersWithTargets.get(playerId), game, source.getSourceId(), playerId);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -46,13 +46,12 @@ import java.util.Map.Entry;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public class DreamSalvage extends CardImpl {
|
||||
|
||||
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.
|
||||
|
@ -92,23 +91,13 @@ class CardsDiscardedThisTurnWatcher extends Watcher {
|
|||
if (event.getType() == GameEvent.EventType.DISCARDED_CARD) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
Integer amount = amountOfCardsDiscardedThisTurn.get(playerId);
|
||||
if (amount == null) {
|
||||
amount = 1;
|
||||
} else {
|
||||
amount++;
|
||||
}
|
||||
amountOfCardsDiscardedThisTurn.put(playerId, amount);
|
||||
amountOfCardsDiscardedThisTurn.put(playerId, getAmountCardsDiscarded(playerId) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getAmountCardsDiscarded(UUID playerId) {
|
||||
Integer amount = amountOfCardsDiscardedThisTurn.get(playerId);
|
||||
if (amount != null) {
|
||||
return amount;
|
||||
}
|
||||
return 0;
|
||||
return amountOfCardsDiscardedThisTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,13 +45,12 @@ import java.util.HashMap;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class ErdwalIlluminator extends CardImpl {
|
||||
|
||||
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.power = new MageInt(1);
|
||||
this.toughness = new MageInt(3);
|
||||
|
@ -126,11 +125,8 @@ class InvestigatedWatcher extends Watcher {
|
|||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.INVESTIGATED) {
|
||||
if (!timesInvestigated.containsKey(event.getPlayerId())) {
|
||||
timesInvestigated.put(event.getPlayerId(), 1);
|
||||
} else {
|
||||
timesInvestigated.put(event.getPlayerId(), timesInvestigated.get(event.getPlayerId()) + 1);
|
||||
}
|
||||
timesInvestigated.put(event.getPlayerId(), getTimesInvestigated(event.getPlayerId()) + 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,9 +137,6 @@ class InvestigatedWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public int getTimesInvestigated(UUID playerId) {
|
||||
if (timesInvestigated.containsKey(playerId)) {
|
||||
return timesInvestigated.get(playerId);
|
||||
}
|
||||
return 0;
|
||||
return timesInvestigated.getOrDefault(playerId, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,10 +152,7 @@ class GontisMachinationsFirstLostLifeThisTurnWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public int timesLostLifeThisTurn(UUID playerId) {
|
||||
if (playersLostLife.containsKey(playerId)) {
|
||||
return playersLostLife.get(playerId);
|
||||
}
|
||||
return 0;
|
||||
return playersLostLife.getOrDefault(playerId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -205,10 +205,7 @@ class JelevaNephaliasWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public int getManaSpentToCastLastTime(int zoneChangeCounter) {
|
||||
if (manaSpendToCast.containsKey(zoneChangeCounter)) {
|
||||
return manaSpendToCast.get(zoneChangeCounter);
|
||||
}
|
||||
return 0;
|
||||
return manaSpendToCast.getOrDefault(zoneChangeCounter, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,7 +84,7 @@ class CardsDrawnThisTurnDynamicValue implements DynamicValue {
|
|||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
KydeleCardsDrawnThisTurnWatcher watcher = (KydeleCardsDrawnThisTurnWatcher) game.getState().getWatchers().get(KydeleCardsDrawnThisTurnWatcher.class.getName());
|
||||
return watcher.getNumCardsDrawnThisTurn(sourceAbility.getControllerId());
|
||||
return watcher.getCardsDrawnThisTurn(sourceAbility.getControllerId()).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,20 +119,14 @@ class KydeleCardsDrawnThisTurnWatcher extends Watcher {
|
|||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DREW_CARD) {
|
||||
if (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) {
|
||||
Set<UUID> cardsDrawn = new LinkedHashSet<>();
|
||||
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
|
||||
}
|
||||
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
|
||||
Set<UUID> cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId());
|
||||
cardsDrawn.add(event.getTargetId());
|
||||
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumCardsDrawnThisTurn(UUID playerId) {
|
||||
if (cardsDrawnThisTurn.get(playerId) == null) {
|
||||
return 0;
|
||||
}
|
||||
return cardsDrawnThisTurn.get(playerId).size();
|
||||
public Set<UUID> getCardsDrawnThisTurn(UUID playerId) {
|
||||
return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -167,10 +167,7 @@ class MoltenPsycheWatcher extends Watcher {
|
|||
}
|
||||
|
||||
public int getDraws(UUID playerId) {
|
||||
if (draws.containsKey(playerId)) {
|
||||
return draws.get(playerId);
|
||||
}
|
||||
return 0;
|
||||
return draws.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -157,17 +157,15 @@ class SylvanLibraryCardsDrawnThisTurnWatcher extends Watcher {
|
|||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DREW_CARD) {
|
||||
if (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) {
|
||||
Set<UUID> cardsDrawn = new LinkedHashSet<>();
|
||||
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
|
||||
}
|
||||
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
|
||||
|
||||
Set<UUID> cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId());
|
||||
cardsDrawn.add(event.getTargetId());
|
||||
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<UUID> getCardsDrawnThisTurn(UUID playerId) {
|
||||
return cardsDrawnThisTurn.get(playerId);
|
||||
return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,10 +106,7 @@ class TerastodonEffect extends OneShotEffect {
|
|||
if (permanent != null) {
|
||||
if (permanent.destroy(source.getSourceId(), game, false)) {
|
||||
if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
|
||||
int numberPermanents = 0;
|
||||
if (destroyedPermanents.containsKey(permanent.getControllerId())) {
|
||||
numberPermanents = destroyedPermanents.get(permanent.getControllerId());
|
||||
}
|
||||
int numberPermanents = destroyedPermanents.getOrDefault(permanent.getControllerId(), 0);
|
||||
destroyedPermanents.put(permanent.getControllerId(), numberPermanents + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
|
@ -53,7 +54,7 @@ import mage.watchers.Watcher;
|
|||
public class TunnelIgnus extends CardImpl {
|
||||
|
||||
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.power = new MageInt(2);
|
||||
|
@ -98,11 +99,9 @@ class TunnelIgnusWatcher extends Watcher {
|
|||
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent.isLand() && game.getOpponents(this.controllerId).contains(permanent.getControllerId())) {
|
||||
int count = 1;
|
||||
if (counts.containsKey(permanent.getControllerId())) {
|
||||
count += counts.get(permanent.getControllerId());
|
||||
}
|
||||
counts.put(permanent.getControllerId(), count);
|
||||
|
||||
int count = counts.getOrDefault(permanent.getControllerId(), 0);
|
||||
counts.put(permanent.getControllerId(), count + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ package mage.cards.v;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
|
@ -52,13 +53,12 @@ import mage.players.Player;
|
|||
import mage.watchers.Watcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class VileRedeemer extends CardImpl {
|
||||
|
||||
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.power = new MageInt(3);
|
||||
this.toughness = new MageInt(3);
|
||||
|
@ -136,8 +136,7 @@ class VileRedeemerNonTokenCreaturesDiedWatcher extends Watcher {
|
|||
if (zEvent.isDiesEvent() && zEvent.getTarget() != null
|
||||
&& zEvent.getTarget().isCreature()
|
||||
&& !(zEvent.getTarget() instanceof PermanentToken)) {
|
||||
int count = amountOfCreaturesThatDied.containsKey(zEvent.getTarget().getControllerId())
|
||||
? amountOfCreaturesThatDied.get(zEvent.getTarget().getControllerId()) : 0;
|
||||
int count = getAmountOfNontokenCreatureDiedThisTurn(zEvent.getTargetId());
|
||||
amountOfCreaturesThatDied.put(zEvent.getTarget().getControllerId(), ++count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl {
|
|||
super(duration, Outcome.Benefit);
|
||||
this.amount = amount;
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue