remove redundant null checks, remove some static fields

This commit is contained in:
Ingmar Goudt 2018-09-26 21:55:58 +02:00
parent 05dcfeaaa1
commit a0e54fbb7b
21 changed files with 84 additions and 104 deletions

View file

@ -33,8 +33,8 @@ public final class Config {
static { static {
Properties p = new Properties(); Properties p = new Properties();
try { try(FileInputStream fis =new FileInputStream(new File("config/config.properties"))) {
p.load(new FileInputStream(new File("config/config.properties"))); p.load(fis);
} catch (IOException ex) { } catch (IOException ex) {
logger.fatal("Config error ", ex); logger.fatal("Config error ", ex);
} }

View file

@ -55,7 +55,7 @@ public final class BlowflyInfestation extends CardImpl {
class BlowflyInfestationCondition implements Condition { class BlowflyInfestationCondition implements Condition {
private static Permanent permanent; private Permanent permanent;
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {

View file

@ -158,7 +158,7 @@ class IceCauldronCastFromExileEffect extends AsThoughEffectImpl {
class IceCauldronNoteManaEffect extends OneShotEffect { class IceCauldronNoteManaEffect extends OneShotEffect {
private static String manaUsedString; private String manaUsedString;
public IceCauldronNoteManaEffect() { public IceCauldronNoteManaEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
@ -167,6 +167,7 @@ class IceCauldronNoteManaEffect extends OneShotEffect {
public IceCauldronNoteManaEffect(final IceCauldronNoteManaEffect effect) { public IceCauldronNoteManaEffect(final IceCauldronNoteManaEffect effect) {
super(effect); super(effect);
manaUsedString = effect.manaUsedString;
} }
@Override @Override
@ -190,8 +191,8 @@ class IceCauldronNoteManaEffect extends OneShotEffect {
class IceCauldronAddManaEffect extends ManaEffect { class IceCauldronAddManaEffect extends ManaEffect {
private static Mana storedMana; private Mana storedMana;
private static MageObjectReference exiledCardMor; private MageObjectReference exiledCardMor;
IceCauldronAddManaEffect() { IceCauldronAddManaEffect() {
super(); super();
@ -200,6 +201,8 @@ class IceCauldronAddManaEffect extends ManaEffect {
IceCauldronAddManaEffect(IceCauldronAddManaEffect effect) { IceCauldronAddManaEffect(IceCauldronAddManaEffect effect) {
super(effect); super(effect);
storedMana = effect.storedMana.copy();
exiledCardMor = effect.exiledCardMor;
} }
@Override @Override

View file

@ -60,7 +60,7 @@ public final class JeweledAmulet extends CardImpl {
class JeweledAmuletAddCounterEffect extends OneShotEffect { class JeweledAmuletAddCounterEffect extends OneShotEffect {
private static String manaUsedString; private String manaUsedString;
public JeweledAmuletAddCounterEffect() { public JeweledAmuletAddCounterEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
@ -69,6 +69,7 @@ class JeweledAmuletAddCounterEffect extends OneShotEffect {
public JeweledAmuletAddCounterEffect(final JeweledAmuletAddCounterEffect effect) { public JeweledAmuletAddCounterEffect(final JeweledAmuletAddCounterEffect effect) {
super(effect); super(effect);
manaUsedString = effect.manaUsedString;
} }
@Override @Override
@ -93,7 +94,7 @@ class JeweledAmuletAddCounterEffect extends OneShotEffect {
class JeweledAmuletAddManaEffect extends ManaEffect { class JeweledAmuletAddManaEffect extends ManaEffect {
private static Mana storedMana; private Mana storedMana;
JeweledAmuletAddManaEffect() { JeweledAmuletAddManaEffect() {
super(); super();
@ -102,6 +103,7 @@ class JeweledAmuletAddManaEffect extends ManaEffect {
JeweledAmuletAddManaEffect(JeweledAmuletAddManaEffect effect) { JeweledAmuletAddManaEffect(JeweledAmuletAddManaEffect effect) {
super(effect); super(effect);
storedMana = effect.storedMana;
} }
@Override @Override

View file

@ -68,7 +68,7 @@ class MagesContestEffect extends OneShotEffect {
Player winner = you; Player winner = you;
Player currentPlayer = spellController; Player currentPlayer = spellController;
do { do {
if (currentPlayer != null && currentPlayer.canRespond()) { if (currentPlayer.canRespond()) {
int newBid = 0; int newBid = 0;
if (!currentPlayer.isHuman()) { if (!currentPlayer.isHuman()) {
// make AI evaluate value of the spell to decide on bidding, should be reworked // make AI evaluate value of the spell to decide on bidding, should be reworked

View file

@ -52,8 +52,8 @@ public final class ProtectiveSphere extends CardImpl {
class ProtectiveSphereEffect extends PreventionEffectImpl { class ProtectiveSphereEffect extends PreventionEffectImpl {
private final TargetSource target; private final TargetSource target;
private static Mana manaUsed; private Mana manaUsed;
private static List<ObjectColor> colorsOfChosenSource = new ArrayList<>(); private List<ObjectColor> colorsOfChosenSource = new ArrayList<>();
public ProtectiveSphereEffect() { public ProtectiveSphereEffect() {
super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false); super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false);
@ -64,6 +64,8 @@ class ProtectiveSphereEffect extends PreventionEffectImpl {
public ProtectiveSphereEffect(final ProtectiveSphereEffect effect) { public ProtectiveSphereEffect(final ProtectiveSphereEffect effect) {
super(effect); super(effect);
this.target = effect.target.copy(); this.target = effect.target.copy();
manaUsed = effect.manaUsed.copy();
colorsOfChosenSource = effect.colorsOfChosenSource;
} }
@Override @Override

View file

@ -75,7 +75,7 @@ class ScribNibblersEffect extends OneShotEffect {
if (targetPlayer != null && targetPlayer.getLibrary().hasCards()) { if (targetPlayer != null && targetPlayer.getLibrary().hasCards()) {
Card card = targetPlayer.getLibrary().getFromTop(game); Card card = targetPlayer.getLibrary().getFromTop(game);
card.moveToExile(id, "Scrib Nibblers Exile", source.getSourceId(), game); card.moveToExile(id, "Scrib Nibblers Exile", source.getSourceId(), game);
if (card != null && card.isLand()) { if (card.isLand()) {
you.gainLife(1, game, source); you.gainLife(1, game, source);
return true; return true;
} }

View file

@ -98,7 +98,7 @@ class WordOfCommandEffect extends OneShotEffect {
// You control that player until Word of Command finishes resolving // You control that player until Word of Command finishes resolving
controller.controlPlayersTurn(game, targetPlayer.getId()); controller.controlPlayersTurn(game, targetPlayer.getId());
while (controller != null && controller.canRespond()) { while (controller.canRespond()) {
if (controller.chooseUse(Outcome.Benefit, "Resolve " + sourceObject.getLogName() + " now" + (card != null ? " and play " + card.getLogName() : "") + '?', source, game)) { if (controller.chooseUse(Outcome.Benefit, "Resolve " + sourceObject.getLogName() + " now" + (card != null ? " and play " + card.getLogName() : "") + '?', source, game)) {
// this is used to give the controller a little space to utilize his player controlling effect (look at face down creatures, hand, etc.) // this is used to give the controller a little space to utilize his player controlling effect (look at face down creatures, hand, etc.)
break; break;

View file

@ -10,7 +10,6 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl { public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl {
@ -37,15 +36,12 @@ public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl {
} else { } else {
sb.append(" Activate this ability only "); sb.append(" Activate this ability only ");
} }
if (condition.toString() != null) { if (!condition.toString().startsWith("during")
if (!condition.toString().startsWith("during") && !condition.toString().startsWith("before")) {
&& !condition.toString().startsWith("before")) { sb.append("if ");
sb.append("if ");
}
sb.append(condition.toString()).append('.');
} else {
sb.append(" [Condition toString() == null] ");
} }
sb.append(condition.toString()).append('.');
return sb.toString(); return sb.toString();
} }

View file

@ -62,41 +62,40 @@ public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl {
if (((ZoneChangeEvent) event).isDiesEvent()) { if (((ZoneChangeEvent) event).isDiesEvent()) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event; ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
boolean triggered = false; boolean triggered = false;
if (zEvent != null) { if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) { triggered = true;
triggered = true; } else {
} else { // If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.)
// If both (attachment and attached went to graveyard at the same time, the attachemnets can be already removed from the attached object.) // So check here with the LKI of the enchantment
// So check here with the LKI of the enchantment Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); if (attachment != null
if (attachment != null && zEvent.getTargetId() != null && attachment.getAttachedTo() != null
&& zEvent.getTargetId() != null && attachment.getAttachedTo() != null && zEvent.getTargetId().equals(attachment.getAttachedTo())) {
&& zEvent.getTargetId().equals(attachment.getAttachedTo())) { Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo()); if (attachedTo != null
if (attachedTo != null && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent
&& attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent triggered = true;
triggered = true;
}
} }
} }
if (triggered) { }
for (Effect effect : getEffects()) { if (triggered) {
if (zEvent.getTarget() != null) { for (Effect effect : getEffects()) {
effect.setValue("attachedTo", zEvent.getTarget()); if (zEvent.getTarget() != null) {
if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) { effect.setValue("attachedTo", zEvent.getTarget());
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId()); if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) {
if (attachment != null && attachment.getAttachedTo() != null) { Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter()); if (attachment != null && attachment.getAttachedTo() != null) {
if (attachedTo != null) { Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId())); if (attachedTo != null) {
} effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
} }
} }
} }
} }
return true;
} }
return true;
} }
} }
return false; return false;
} }

View file

@ -76,7 +76,7 @@ public class RollPlanarDieEffect extends OneShotEffect {
for (int i = 0; i < chaosEffects.size(); i++) { for (int i = 0; i < chaosEffects.size(); i++) {
Effect effect = chaosEffects.get(i); Effect effect = chaosEffects.get(i);
Target target = null; Target target = null;
if (chaosTargets != null && chaosTargets.size() > i) { if (chaosTargets.size() > i) {
target = chaosTargets.get(i); target = chaosTargets.get(i);
} }
boolean done = false; boolean done = false;

View file

@ -88,10 +88,8 @@ class DrawCardsActivePlayerEffect extends OneShotEffect {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Academy at Tolaria West")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Academy at Tolaria West")) { return false;
return false;
}
} }
Player player = game.getPlayer(game.getActivePlayerId()); Player player = game.getPlayer(game.getActivePlayerId());
if (player != null) { if (player != null) {

View file

@ -81,10 +81,8 @@ class AstralArenaAttackRestrictionEffect extends RestrictionEffect {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) { return false;
return false;
}
} }
return true; return true;
@ -118,10 +116,8 @@ class AstralArenaBlockRestrictionEffect extends RestrictionEffect {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) { return false;
return false;
}
} }
return true; return true;
} }

View file

@ -101,10 +101,8 @@ class EdgeOfMalacolEffect extends ContinuousRuleModifyingEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Edge of Malacol")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Edge of Malacol")) { return false;
return false;
}
} }
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && filter.match(permanent, game) && Objects.equals(permanent.getControllerId(), game.getActivePlayerId())) { if (permanent != null && filter.match(permanent, game) && Objects.equals(permanent.getControllerId(), game.getActivePlayerId())) {

View file

@ -79,7 +79,7 @@ class FeedingGroundsEffect extends CostModificationEffectImpl {
new ColorPredicate(ObjectColor.GREEN))); new ColorPredicate(ObjectColor.GREEN)));
} }
private static final String rule = "Red spells cost {1} less to cast. Green spells cost {1} less to cast."; private static final String rule = "Red spells cost {1} less to cast. Green spells cost {1} less to cast.";
private int amount = 1; private int amount = 1;
public FeedingGroundsEffect() { public FeedingGroundsEffect() {
@ -133,19 +133,17 @@ class FeedingGroundsEffect extends CostModificationEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Feeding Grounds")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Feeding Grounds")) { return false;
return false;
}
} }
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId()); Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) { if (spell != null) {
return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game); return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else { } else {
// used at least for flashback ability because Flashback ability doesn't use stack // used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId()); Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game); return sourceCard != null && filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
} }
} }
return false; return false;

View file

@ -95,10 +95,8 @@ class HedronFieldsOfAgadeemRestrictionEffect extends RestrictionEffect {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Hedron Fields of Agadeem")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Hedron Fields of Agadeem")) { return false;
return false;
}
} }
return filter.match(permanent, source.getSourceId(), source.getControllerId(), game); return filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
} }

View file

@ -87,10 +87,8 @@ class TheEonFogSkipUntapStepEffect extends ContinuousRuleModifyingEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - The Eon Fog")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - The Eon Fog")) { return false;
return false;
}
} }
return event.getType() == GameEvent.EventType.UNTAP_STEP; return event.getType() == GameEvent.EventType.UNTAP_STEP;
} }

View file

@ -86,10 +86,8 @@ class TheGreatForestCombatDamageRuleEffect extends ContinuousEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - The Great Forest")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - The Great Forest")) { return false;
return false;
}
} }
// Change the rule // Change the rule

View file

@ -101,10 +101,8 @@ class TrailOfTheMageRingsReboundEffect extends ContinuousEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Trail of the Mage-Rings")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Trail of the Mage-Rings")) { return false;
return false;
}
} }
for (UUID playerId : game.getPlayers().keySet()) { for (UUID playerId : game.getPlayers().keySet()) {

View file

@ -114,19 +114,17 @@ class TurriIslandEffect extends CostModificationEffectImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Turri Island")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Turri Island")) { return false;
return false;
}
} }
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId()); Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) { if (spell != null) {
return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game); return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else { } else {
// used at least for flashback ability because Flashback ability doesn't use stack // used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId()); Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game); return sourceCard != null && filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
} }
} }
return false; return false;

View file

@ -96,10 +96,8 @@ class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl {
if (cPlane == null) { if (cPlane == null) {
return false; return false;
} }
if (cPlane != null) { if (!cPlane.getName().equalsIgnoreCase("Plane - Undercity Reaches")) {
if (!cPlane.getName().equalsIgnoreCase("Plane - Undercity Reaches")) { return false;
return false;
}
} }
if (((DamagedPlayerEvent) event).isCombatDamage()) { if (((DamagedPlayerEvent) event).isCombatDamage()) {