mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
remove redundant null checks before instanceof
This commit is contained in:
parent
d3aea0270c
commit
f04d7c9b03
72 changed files with 184 additions and 186 deletions
|
|
@ -31,7 +31,7 @@ public class DealsDamageToOneOrMoreCreaturesTriggeredAbility extends DealsDamage
|
|||
|| game.getTurn().getStepType() == PhaseStep.FIRST_COMBAT_DAMAGE) {
|
||||
String stepHash = (String) game.getState().getValue("damageStep" + getOriginalId());
|
||||
String newStepHash = game.getStep().getType().toString() + game.getTurnNum();
|
||||
if (stepHash == null || !newStepHash.equals(stepHash)) {
|
||||
if (!newStepHash.equals(stepHash)) {
|
||||
// this ability did not trigger during this damage step
|
||||
game.getState().setValue("damageStep" + getOriginalId(), game.getStep().getType().toString() + game.getTurnNum());
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fireshoes
|
||||
*/
|
||||
public class SpellCounteredControllerTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
}
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(final SpellCounteredControllerTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellCounteredControllerTriggeredAbility copy() {
|
||||
return new SpellCounteredControllerTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == EventType.COUNTERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
StackObject stackObjectThatCountered = game.getStack().getStackObject(event.getSourceId());
|
||||
if (stackObjectThatCountered == null) {
|
||||
stackObjectThatCountered = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
|
||||
}
|
||||
if (stackObjectThatCountered != null && stackObjectThatCountered.isControlledBy(getControllerId())) {
|
||||
StackObject counteredStackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
|
||||
return counteredStackObject != null && (counteredStackObject instanceof Spell);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a spell or ability you control counters a spell, " + super.getRule();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fireshoes
|
||||
*/
|
||||
public class SpellCounteredControllerTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
}
|
||||
|
||||
public SpellCounteredControllerTriggeredAbility(final SpellCounteredControllerTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellCounteredControllerTriggeredAbility copy() {
|
||||
return new SpellCounteredControllerTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == EventType.COUNTERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
StackObject stackObjectThatCountered = game.getStack().getStackObject(event.getSourceId());
|
||||
if (stackObjectThatCountered == null) {
|
||||
stackObjectThatCountered = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
|
||||
}
|
||||
if (stackObjectThatCountered != null && stackObjectThatCountered.isControlledBy(getControllerId())) {
|
||||
StackObject counteredStackObject = (StackObject) game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
|
||||
return (counteredStackObject instanceof Spell);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a spell or ability you control counters a spell, " + super.getRule();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,40 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.other.OwnerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author emerald000
|
||||
*/
|
||||
public class MeldCondition implements Condition {
|
||||
|
||||
private final String meldWithName;
|
||||
|
||||
public MeldCondition(String meldWithName) {
|
||||
this.meldWithName = meldWithName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
|
||||
if (sourceMageObject != null && sourceMageObject instanceof Permanent) {
|
||||
Permanent sourcePermanent = (Permanent) sourceMageObject;
|
||||
if (sourcePermanent.isControlledBy(source.getControllerId())
|
||||
&& sourcePermanent.isOwnedBy(source.getControllerId())) {
|
||||
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
|
||||
filter.add(new NamePredicate(this.meldWithName));
|
||||
filter.add(new OwnerIdPredicate(source.getControllerId()));
|
||||
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.other.OwnerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author emerald000
|
||||
*/
|
||||
public class MeldCondition implements Condition {
|
||||
|
||||
private final String meldWithName;
|
||||
|
||||
public MeldCondition(String meldWithName) {
|
||||
this.meldWithName = meldWithName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
|
||||
if (sourceMageObject instanceof Permanent) {
|
||||
Permanent sourcePermanent = (Permanent) sourceMageObject;
|
||||
if (sourcePermanent.isControlledBy(source.getControllerId())
|
||||
&& sourcePermanent.isOwnedBy(source.getControllerId())) {
|
||||
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
|
||||
filter.add(new NamePredicate(this.meldWithName));
|
||||
filter.add(new OwnerIdPredicate(source.getControllerId()));
|
||||
return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class SunburstCount implements DynamicValue {
|
|||
int count = 0;
|
||||
if (!game.getStack().isEmpty()) {
|
||||
StackObject spell = game.getStack().getFirst();
|
||||
if (spell != null && spell instanceof Spell && ((Spell) spell).getSourceId().equals(source.getSourceId())) {
|
||||
if (spell instanceof Spell && ((Spell) spell).getSourceId().equals(source.getSourceId())) {
|
||||
Mana mana = ((Spell) spell).getSpellAbility().getManaCostsToPay().getPayment();
|
||||
if (mana.getBlack() > 0) {
|
||||
count++;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getSourceId().equals(this.getSourceId())) {
|
||||
MageObject spellObject = game.getObject(sourceId);
|
||||
if (spellObject != null && (spellObject instanceof Spell)) {
|
||||
if ((spellObject instanceof Spell)) {
|
||||
Spell spell = (Spell) spellObject;
|
||||
if (spell.getSpellAbility() != null) {
|
||||
for (Effect effect : getEffects()) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
|
|||
if (spell != null) {
|
||||
StackObject newStackObject = spell.createCopyOnStack(game, source, useController ? spell.getControllerId() : source.getControllerId(), true);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null && newStackObject != null && newStackObject instanceof Spell) {
|
||||
if (player != null && newStackObject instanceof Spell) {
|
||||
String activateMessage = ((Spell) newStackObject).getActivatedMessage(game);
|
||||
if (activateMessage.startsWith(" casts ")) {
|
||||
activateMessage = activateMessage.substring(6);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ReturnToBattlefieldUnderOwnerControlAttachedEffect extends OneShotE
|
|||
return false;
|
||||
}
|
||||
Object object = getValue("attachedTo");
|
||||
if (object != null && object instanceof Permanent) {
|
||||
if (object instanceof Permanent) {
|
||||
Card card = game.getCard(((Permanent) object).getId());
|
||||
if (card != null) {
|
||||
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null)) {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class ReturnToBattlefieldUnderOwnerControlTargetEffect extends OneShotEff
|
|||
}
|
||||
else {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && card instanceof MeldCard) {
|
||||
if (card instanceof MeldCard) {
|
||||
MeldCard meldCard = (MeldCard) card;
|
||||
Card topCard = meldCard.getTopHalfCard();
|
||||
Card bottomCard = meldCard.getBottomHalfCard();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class ReturnToBattlefieldUnderYourControlAttachedEffect extends OneShotEf
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Object object = getValue("attachedTo");
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null && object != null && object instanceof Permanent) {
|
||||
if (controller != null && object instanceof Permanent) {
|
||||
Card card = game.getCard(((Permanent) object).getId());
|
||||
// Move the card only, if it is still in the next zone after the battlefield
|
||||
if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class ReturnToBattlefieldUnderYourControlTargetEffect extends OneShotEffe
|
|||
}
|
||||
else {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && card instanceof MeldCard) {
|
||||
if (card instanceof MeldCard) {
|
||||
MeldCard meldCard = (MeldCard) card;
|
||||
Card topCard = meldCard.getTopHalfCard();
|
||||
Card bottomCard = meldCard.getBottomHalfCard();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class ReturnToHandAttachedEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Object object = getValue("attachedTo");
|
||||
if (object != null && object instanceof Permanent) {
|
||||
if (object instanceof Permanent) {
|
||||
Card card = game.getCard(((Permanent)object).getId());
|
||||
if (card != null) {
|
||||
if (card.moveToZone(Zone.HAND, source.getSourceId(), game, false)) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class TransformSourceEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject sourceObject = source.getSourceObjectIfItStillExists(game); // Transform only if it's the same object as the effect was put on the stack
|
||||
if (sourceObject != null && sourceObject instanceof Permanent) {
|
||||
if (sourceObject instanceof Permanent) {
|
||||
Permanent sourcePermanent = (Permanent) sourceObject;
|
||||
if (sourcePermanent.canTransform(source, game)) {
|
||||
// check not to transform twice the same side
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class UntapAllThatAttackedEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName());
|
||||
if (watcher != null && watcher instanceof AttackedThisTurnWatcher) {
|
||||
if (watcher instanceof AttackedThisTurnWatcher) {
|
||||
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
|
||||
for (MageObjectReference mor : attackedThisTurn) {
|
||||
Permanent permanent = mor.getPermanent(game);
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class AftermathExileAsResolvesFromGraveyard extends ReplacementEffectImpl {
|
|||
// wants to do that in the future.
|
||||
UUID sourceId = source.getSourceId();
|
||||
Card sourceCard = game.getCard(source.getSourceId());
|
||||
if (sourceCard != null && sourceCard instanceof SplitCardHalf) {
|
||||
if (sourceCard instanceof SplitCardHalf) {
|
||||
sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
|
||||
sourceId = sourceCard.getId();
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ class AftermathExileAsResolvesFromGraveyard extends ReplacementEffectImpl {
|
|||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
UUID sourceId = source.getSourceId();
|
||||
Card sourceCard = game.getCard(source.getSourceId());
|
||||
if (sourceCard != null && sourceCard instanceof SplitCardHalf) {
|
||||
if (sourceCard instanceof SplitCardHalf) {
|
||||
sourceCard = ((SplitCardHalf) sourceCard).getParentCard();
|
||||
sourceId = sourceCard.getId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ class ConspireEffect extends OneShotEffect {
|
|||
Card card = game.getCard(conspiredSpell.getSourceId());
|
||||
if (card != null) {
|
||||
StackObject newStackObject = conspiredSpell.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
if (newStackObject != null && newStackObject instanceof Spell && !game.isSimulation()) {
|
||||
if (newStackObject instanceof Spell && !game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + ((Spell) newStackObject).getActivatedMessage(game));
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class HauntAbility extends TriggeredAbilityImpl {
|
|||
if (card != null) {
|
||||
String key = new StringBuilder("Haunting_").append(getSourceId().toString()).append('_').append(card.getZoneChangeCounter(game)).toString();
|
||||
Object object = game.getState().getValue(key);
|
||||
if (object != null && object instanceof FixedTarget) {
|
||||
if (object instanceof FixedTarget) {
|
||||
FixedTarget target = (FixedTarget) object;
|
||||
if (target.getTarget() != null && target.getTarget().equals(event.getTargetId())) {
|
||||
usedFromExile = true;
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ class ReplicateCopyEffect extends OneShotEffect {
|
|||
// create the copies
|
||||
for (int i = 0; i < replicateCount; i++) {
|
||||
StackObject newStackObject = spell.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
if (newStackObject != null && newStackObject instanceof Spell && !game.isSimulation()) {
|
||||
if (newStackObject instanceof Spell && !game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + ((Spell) newStackObject).getActivatedMessage(game));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ public class Plane implements CommandObject {
|
|||
Class<?> c = Class.forName(planeName);
|
||||
Constructor<?> cons = c.getConstructor();
|
||||
Object plane = cons.newInstance();
|
||||
if (plane != null && plane instanceof mage.game.command.Plane) {
|
||||
if (plane instanceof Plane) {
|
||||
return (Plane) plane;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class IllusionTokenTriggeredAbility extends TriggeredAbilityImpl {
|
|||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
MageObject eventSourceObject = game.getObject(event.getSourceId());
|
||||
if (eventSourceObject != null && event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
|
||||
if (event.getTargetId().equals(this.getSourceId()) && eventSourceObject instanceof Spell) {
|
||||
getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId()));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public abstract class TargetImpl implements Target {
|
|||
@Override
|
||||
public boolean isRequired(UUID sourceId, Game game) {
|
||||
MageObject object = game.getObject(sourceId);
|
||||
if (!requiredExplicitlySet && object != null && object instanceof Ability) {
|
||||
if (!requiredExplicitlySet && object instanceof Ability) {
|
||||
return isRequired((Ability) object);
|
||||
} else {
|
||||
return isRequired();
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class TargetSource extends TargetObject {
|
|||
public void addTarget(UUID id, Ability source, Game game) {
|
||||
if (targets.size() < maxNumberOfTargets) {
|
||||
MageObject object = game.getObject(id);
|
||||
if (object != null && object instanceof StackObject) {
|
||||
if (object instanceof StackObject) {
|
||||
addTarget(((StackObject) object).getSourceId(), source, game, notTarget);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
|
|||
lastActivePlayer = game.getActivePlayerId();
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null && lastActivePlayer != null && playerId.equals(lastActivePlayer)) {
|
||||
if (playerId != null && playerId.equals(lastActivePlayer)) {
|
||||
amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
|
||||
amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue