mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Refactor: fixed wrong usage of getSourceObjectIfItStillExists (fixed error "cannot be cast to Permanent");
This commit is contained in:
parent
bfba179bdf
commit
b632d89caa
24 changed files with 26 additions and 26 deletions
|
@ -81,7 +81,7 @@ class BishopOfBindingExileEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
// If this leaves the battlefield before its triggered ability resolves,
|
||||
// the target creature won't be exiled.
|
||||
if (permanent != null) {
|
||||
|
|
|
@ -122,7 +122,7 @@ class GainControlSourceEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -76,7 +76,7 @@ class ColfenorsUrnEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (controller != null && permanent != null) {
|
||||
UUID exileId = CardUtil.getCardExileZoneId(game, source);
|
||||
ExileZone exile = game.getExile().getExileZone(exileId);
|
||||
|
|
|
@ -77,7 +77,7 @@ class CrovaxTheCursedEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
int creatures = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game);
|
||||
if (creatures > 0 && controller.chooseUse(outcome, "Sacrifice a creature?", source, game)) {
|
||||
if (new SacrificeControllerEffect(StaticFilters.FILTER_PERMANENT_CREATURES, 1, "").apply(game, source)) {
|
||||
|
|
|
@ -67,7 +67,7 @@ class EntrailsFeasterEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null && source.getSourceId() != null) {
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
|
||||
target.setNotTarget(true);
|
||||
if (target.canChoose(controller.getId(), source, game) && controller.chooseUse(outcome, "Exile a creature card from a graveyard?", source, game)) {
|
||||
|
|
|
@ -73,7 +73,7 @@ class FlameKinWarScourEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
if (permanent.sacrifice(source, game)) {
|
||||
Effect effect = new DamageTargetEffect(4).setText("{this} deals 4 damage to it");
|
||||
|
|
|
@ -80,7 +80,7 @@ class FruitcakeElementalEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null && permanent != null) {
|
||||
ContinuousEffect effect = new FruitcakeElementalControlSourceEffect();
|
||||
|
|
|
@ -72,7 +72,7 @@ class GoToJailExileEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
|
||||
// If GO TO JAIL leaves the battlefield before its triggered ability resolves,
|
||||
|
@ -134,7 +134,7 @@ class GoToJailUpkeepEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
|
||||
|
||||
if (sourceObject instanceof Permanent && permanent != null) {
|
||||
|
|
|
@ -60,7 +60,7 @@ class GoblinCadetsChangeControlEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -57,7 +57,7 @@ class GravePerilEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
if (permanent.sacrifice(source, game)) {
|
||||
Effect effect = new DestroyTargetEffect();
|
||||
|
|
|
@ -71,7 +71,7 @@ class HumbleDefectorEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
controller.drawCards(2, source, game);
|
||||
}
|
||||
Permanent humbleDefector = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent humbleDefector = source.getSourcePermanentIfItStillExists(game);
|
||||
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (targetOpponent != null && humbleDefector != null) {
|
||||
ContinuousEffect effect = new HumbleDefectorControlSourceEffect();
|
||||
|
|
|
@ -68,7 +68,7 @@ class HungryHungryHeiferEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
if (sourceObject != null && controller != null) {
|
||||
if (controller.chooseUse(outcome, "Remove a counter from a permanent you control?", source, game)) {
|
||||
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
|
||||
|
|
|
@ -75,7 +75,7 @@ class JarJarBinksEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent jarJar = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent jarJar = source.getSourcePermanentIfItStillExists(game);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null && jarJar != null && opponent != null) {
|
||||
|
|
|
@ -76,7 +76,7 @@ class JinxedChokerChangeControllerEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -78,7 +78,7 @@ class JinxedRingEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -81,7 +81,7 @@ class MagmasaurEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
if (sourceObject != null && controller != null) {
|
||||
if (controller.chooseUse(outcome, "Remove a +1/+1 counter from " + sourceObject.getLogName() + '?', source, game)) {
|
||||
sourceObject.removeCounters(CounterType.P1P1.getName(), 1, source, game);
|
||||
|
|
|
@ -85,7 +85,7 @@ class MeasureOfWickednessControlSourceEffect extends ContinuousEffectImpl {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player targetOpponent = game.getPlayer(source.getFirstTarget());
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null && targetOpponent != null) {
|
||||
permanent.changeControllerId(targetOpponent.getId(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -71,7 +71,7 @@ class MissDemeanorEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
String activePlayerName = game.getPlayer(game.getActivePlayerId()).getName();
|
||||
if (sourceObject != null) {
|
||||
if (controller.chooseUse(outcome, "Compliment " + activePlayerName + " on their game play?", source, game)) {
|
||||
|
|
|
@ -66,7 +66,7 @@ class PrimordialOozeEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
if (controller != null && sourceObject != null) {
|
||||
int counter = sourceObject.getCounters(game).getCount(CounterType.P1P1);
|
||||
Cost cost = new ManaCostsImpl<>("{" + counter + '}');
|
||||
|
|
|
@ -70,7 +70,7 @@ class SleeperAgentChangeControlEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -73,7 +73,7 @@ class WitchEngineEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent != null) {
|
||||
return permanent.changeControllerId(source.getFirstTarget(), game, source);
|
||||
} else {
|
||||
|
|
|
@ -76,7 +76,7 @@ class YawgmothDemonEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
if (!artifactSacrificed) {
|
||||
Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent sourceObject = source.getSourcePermanentIfItStillExists(game);
|
||||
if (sourceObject != null) {
|
||||
sourceObject.tap(source, game);
|
||||
controller.damage(2, source.getSourceId(), source, game);
|
||||
|
|
|
@ -66,7 +66,7 @@ class LicidEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent licid = source.getSourcePermanentIfItStillExists(game);
|
||||
if (licid != null) {
|
||||
UUID messageId = UUID.randomUUID();
|
||||
LicidContinuousEffect effect = new LicidContinuousEffect(messageId);
|
||||
|
@ -103,7 +103,7 @@ class LicidContinuousEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent licid = source.getSourcePermanentIfItStillExists(game);
|
||||
if (licid != null) {
|
||||
switch (layer) {
|
||||
case TypeChangingEffects_4:
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MustBeBlockedByTargetSourceEffect extends RequirementEffect {
|
|||
if (permanent.getId().equals(this.getTargetPointer().getFirst(game, source))) {
|
||||
Permanent blocker = game.getPermanent(this.getTargetPointer().getFirst(game, source));
|
||||
if (blocker != null && blocker.canBlock(source.getSourceId(), game)) {
|
||||
Permanent attacker = (Permanent) source.getSourceObjectIfItStillExists(game);
|
||||
Permanent attacker = source.getSourcePermanentIfItStillExists(game);
|
||||
if (attacker != null) {
|
||||
BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
|
||||
if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) {
|
||||
|
|
Loading…
Reference in a new issue