Refactor: fixed wrong usage of getSourceObjectIfItStillExists (fixed error "cannot be cast to Permanent");

This commit is contained in:
Oleg Agafonov 2023-03-26 13:10:00 +04:00
parent bfba179bdf
commit b632d89caa
24 changed files with 26 additions and 26 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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