mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
remove redundant null checks, remove some static fields
This commit is contained in:
parent
05dcfeaaa1
commit
a0e54fbb7b
21 changed files with 84 additions and 104 deletions
|
@ -33,8 +33,8 @@ public final class Config {
|
|||
|
||||
static {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
p.load(new FileInputStream(new File("config/config.properties")));
|
||||
try(FileInputStream fis =new FileInputStream(new File("config/config.properties"))) {
|
||||
p.load(fis);
|
||||
} catch (IOException ex) {
|
||||
logger.fatal("Config error ", ex);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public final class BlowflyInfestation extends CardImpl {
|
|||
|
||||
class BlowflyInfestationCondition implements Condition {
|
||||
|
||||
private static Permanent permanent;
|
||||
private Permanent permanent;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
|
|
|
@ -158,7 +158,7 @@ class IceCauldronCastFromExileEffect extends AsThoughEffectImpl {
|
|||
|
||||
class IceCauldronNoteManaEffect extends OneShotEffect {
|
||||
|
||||
private static String manaUsedString;
|
||||
private String manaUsedString;
|
||||
|
||||
public IceCauldronNoteManaEffect() {
|
||||
super(Outcome.Benefit);
|
||||
|
@ -167,6 +167,7 @@ class IceCauldronNoteManaEffect extends OneShotEffect {
|
|||
|
||||
public IceCauldronNoteManaEffect(final IceCauldronNoteManaEffect effect) {
|
||||
super(effect);
|
||||
manaUsedString = effect.manaUsedString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -190,8 +191,8 @@ class IceCauldronNoteManaEffect extends OneShotEffect {
|
|||
|
||||
class IceCauldronAddManaEffect extends ManaEffect {
|
||||
|
||||
private static Mana storedMana;
|
||||
private static MageObjectReference exiledCardMor;
|
||||
private Mana storedMana;
|
||||
private MageObjectReference exiledCardMor;
|
||||
|
||||
IceCauldronAddManaEffect() {
|
||||
super();
|
||||
|
@ -200,6 +201,8 @@ class IceCauldronAddManaEffect extends ManaEffect {
|
|||
|
||||
IceCauldronAddManaEffect(IceCauldronAddManaEffect effect) {
|
||||
super(effect);
|
||||
storedMana = effect.storedMana.copy();
|
||||
exiledCardMor = effect.exiledCardMor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,7 +60,7 @@ public final class JeweledAmulet extends CardImpl {
|
|||
|
||||
class JeweledAmuletAddCounterEffect extends OneShotEffect {
|
||||
|
||||
private static String manaUsedString;
|
||||
private String manaUsedString;
|
||||
|
||||
public JeweledAmuletAddCounterEffect() {
|
||||
super(Outcome.Benefit);
|
||||
|
@ -69,6 +69,7 @@ class JeweledAmuletAddCounterEffect extends OneShotEffect {
|
|||
|
||||
public JeweledAmuletAddCounterEffect(final JeweledAmuletAddCounterEffect effect) {
|
||||
super(effect);
|
||||
manaUsedString = effect.manaUsedString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +94,7 @@ class JeweledAmuletAddCounterEffect extends OneShotEffect {
|
|||
|
||||
class JeweledAmuletAddManaEffect extends ManaEffect {
|
||||
|
||||
private static Mana storedMana;
|
||||
private Mana storedMana;
|
||||
|
||||
JeweledAmuletAddManaEffect() {
|
||||
super();
|
||||
|
@ -102,6 +103,7 @@ class JeweledAmuletAddManaEffect extends ManaEffect {
|
|||
|
||||
JeweledAmuletAddManaEffect(JeweledAmuletAddManaEffect effect) {
|
||||
super(effect);
|
||||
storedMana = effect.storedMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,7 +68,7 @@ class MagesContestEffect extends OneShotEffect {
|
|||
Player winner = you;
|
||||
Player currentPlayer = spellController;
|
||||
do {
|
||||
if (currentPlayer != null && currentPlayer.canRespond()) {
|
||||
if (currentPlayer.canRespond()) {
|
||||
int newBid = 0;
|
||||
if (!currentPlayer.isHuman()) {
|
||||
// make AI evaluate value of the spell to decide on bidding, should be reworked
|
||||
|
|
|
@ -52,8 +52,8 @@ public final class ProtectiveSphere extends CardImpl {
|
|||
class ProtectiveSphereEffect extends PreventionEffectImpl {
|
||||
|
||||
private final TargetSource target;
|
||||
private static Mana manaUsed;
|
||||
private static List<ObjectColor> colorsOfChosenSource = new ArrayList<>();
|
||||
private Mana manaUsed;
|
||||
private List<ObjectColor> colorsOfChosenSource = new ArrayList<>();
|
||||
|
||||
public ProtectiveSphereEffect() {
|
||||
super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false);
|
||||
|
@ -64,6 +64,8 @@ class ProtectiveSphereEffect extends PreventionEffectImpl {
|
|||
public ProtectiveSphereEffect(final ProtectiveSphereEffect effect) {
|
||||
super(effect);
|
||||
this.target = effect.target.copy();
|
||||
manaUsed = effect.manaUsed.copy();
|
||||
colorsOfChosenSource = effect.colorsOfChosenSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,7 +75,7 @@ class ScribNibblersEffect extends OneShotEffect {
|
|||
if (targetPlayer != null && targetPlayer.getLibrary().hasCards()) {
|
||||
Card card = targetPlayer.getLibrary().getFromTop(game);
|
||||
card.moveToExile(id, "Scrib Nibblers Exile", source.getSourceId(), game);
|
||||
if (card != null && card.isLand()) {
|
||||
if (card.isLand()) {
|
||||
you.gainLife(1, game, source);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ class WordOfCommandEffect extends OneShotEffect {
|
|||
|
||||
// You control that player until Word of Command finishes resolving
|
||||
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)) {
|
||||
// this is used to give the controller a little space to utilize his player controlling effect (look at face down creatures, hand, etc.)
|
||||
break;
|
||||
|
|
|
@ -10,7 +10,6 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl {
|
||||
|
@ -37,15 +36,12 @@ public class ActivateIfConditionActivatedAbility extends ActivatedAbilityImpl {
|
|||
} else {
|
||||
sb.append(" Activate this ability only ");
|
||||
}
|
||||
if (condition.toString() != null) {
|
||||
if (!condition.toString().startsWith("during")
|
||||
&& !condition.toString().startsWith("before")) {
|
||||
sb.append("if ");
|
||||
}
|
||||
sb.append(condition.toString()).append('.');
|
||||
} else {
|
||||
sb.append(" [Condition toString() == null] ");
|
||||
if (!condition.toString().startsWith("during")
|
||||
&& !condition.toString().startsWith("before")) {
|
||||
sb.append("if ");
|
||||
}
|
||||
sb.append(condition.toString()).append('.');
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,41 +62,40 @@ public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
|||
if (((ZoneChangeEvent) event).isDiesEvent()) {
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
boolean triggered = false;
|
||||
if (zEvent != null) {
|
||||
if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
|
||||
triggered = true;
|
||||
} else {
|
||||
// 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
|
||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||
if (attachment != null
|
||||
&& zEvent.getTargetId() != null && attachment.getAttachedTo() != null
|
||||
&& zEvent.getTargetId().equals(attachment.getAttachedTo())) {
|
||||
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
|
||||
if (attachedTo != null
|
||||
&& attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent
|
||||
triggered = true;
|
||||
if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
|
||||
triggered = true;
|
||||
} else {
|
||||
// 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
|
||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||
if (attachment != null
|
||||
&& zEvent.getTargetId() != null && attachment.getAttachedTo() != null
|
||||
&& zEvent.getTargetId().equals(attachment.getAttachedTo())) {
|
||||
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
|
||||
if (attachedTo != null
|
||||
&& attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game)) { // zoneChangeCounter is stored in Permanent
|
||||
triggered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (triggered) {
|
||||
for (Effect effect : getEffects()) {
|
||||
if (zEvent.getTarget() != null) {
|
||||
effect.setValue("attachedTo", zEvent.getTarget());
|
||||
if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) {
|
||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||
if (attachment != null && attachment.getAttachedTo() != null) {
|
||||
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
|
||||
if (attachedTo != null) {
|
||||
effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (triggered) {
|
||||
for (Effect effect : getEffects()) {
|
||||
if (zEvent.getTarget() != null) {
|
||||
effect.setValue("attachedTo", zEvent.getTarget());
|
||||
if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) {
|
||||
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
|
||||
if (attachment != null && attachment.getAttachedTo() != null) {
|
||||
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
|
||||
if (attachedTo != null) {
|
||||
effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class RollPlanarDieEffect extends OneShotEffect {
|
|||
for (int i = 0; i < chaosEffects.size(); i++) {
|
||||
Effect effect = chaosEffects.get(i);
|
||||
Target target = null;
|
||||
if (chaosTargets != null && chaosTargets.size() > i) {
|
||||
if (chaosTargets.size() > i) {
|
||||
target = chaosTargets.get(i);
|
||||
}
|
||||
boolean done = false;
|
||||
|
|
|
@ -88,10 +88,8 @@ class DrawCardsActivePlayerEffect extends OneShotEffect {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Academy at Tolaria West")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Academy at Tolaria West")) {
|
||||
return false;
|
||||
}
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
if (player != null) {
|
||||
|
|
|
@ -81,10 +81,8 @@ class AstralArenaAttackRestrictionEffect extends RestrictionEffect {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -118,10 +116,8 @@ class AstralArenaBlockRestrictionEffect extends RestrictionEffect {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Astral Arena")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -101,10 +101,8 @@ class EdgeOfMalacolEffect extends ContinuousRuleModifyingEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Edge of Malacol")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Edge of Malacol")) {
|
||||
return false;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null && filter.match(permanent, game) && Objects.equals(permanent.getControllerId(), game.getActivePlayerId())) {
|
||||
|
|
|
@ -79,7 +79,7 @@ class FeedingGroundsEffect extends CostModificationEffectImpl {
|
|||
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;
|
||||
|
||||
public FeedingGroundsEffect() {
|
||||
|
@ -133,19 +133,17 @@ class FeedingGroundsEffect extends CostModificationEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Feeding Grounds")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Feeding Grounds")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
|
||||
if (spell != null) {
|
||||
return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
|
||||
return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
|
||||
} else {
|
||||
// used at least for flashback ability because Flashback ability doesn't use stack
|
||||
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;
|
||||
|
|
|
@ -95,10 +95,8 @@ class HedronFieldsOfAgadeemRestrictionEffect extends RestrictionEffect {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Hedron Fields of Agadeem")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Hedron Fields of Agadeem")) {
|
||||
return false;
|
||||
}
|
||||
return filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
|
||||
}
|
||||
|
|
|
@ -87,10 +87,8 @@ class TheEonFogSkipUntapStepEffect extends ContinuousRuleModifyingEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - The Eon Fog")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - The Eon Fog")) {
|
||||
return false;
|
||||
}
|
||||
return event.getType() == GameEvent.EventType.UNTAP_STEP;
|
||||
}
|
||||
|
|
|
@ -86,10 +86,8 @@ class TheGreatForestCombatDamageRuleEffect extends ContinuousEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - The Great Forest")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - The Great Forest")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Change the rule
|
||||
|
|
|
@ -101,10 +101,8 @@ class TrailOfTheMageRingsReboundEffect extends ContinuousEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Trail of the Mage-Rings")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Trail of the Mage-Rings")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (UUID playerId : game.getPlayers().keySet()) {
|
||||
|
|
|
@ -114,19 +114,17 @@ class TurriIslandEffect extends CostModificationEffectImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Turri Island")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Turri Island")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
|
||||
if (spell != null) {
|
||||
return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
|
||||
return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
|
||||
} else {
|
||||
// used at least for flashback ability because Flashback ability doesn't use stack
|
||||
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;
|
||||
|
|
|
@ -96,10 +96,8 @@ class UndercityReachesTriggeredAbility extends TriggeredAbilityImpl {
|
|||
if (cPlane == null) {
|
||||
return false;
|
||||
}
|
||||
if (cPlane != null) {
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Undercity Reaches")) {
|
||||
return false;
|
||||
}
|
||||
if (!cPlane.getName().equalsIgnoreCase("Plane - Undercity Reaches")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((DamagedPlayerEvent) event).isCombatDamage()) {
|
||||
|
|
Loading…
Reference in a new issue