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

@ -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();
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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) {

View file

@ -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;
}

View file

@ -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())) {

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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

View file

@ -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()) {

View file

@ -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;

View file

@ -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()) {