Real fix for 4125d1eb46, updated outdated comments.

This commit is contained in:
Oleg Agafonov 2021-07-31 09:36:38 +04:00
parent 0136b986e4
commit 6e0184a38d
7 changed files with 50 additions and 35 deletions

View file

@ -494,9 +494,7 @@ public interface Ability extends Controllable, Serializable {
boolean activateAlternateOrAdditionalCosts(MageObject sourceObject, boolean noMana, Player controller, Game game);
/**
* Returns the object that actually existed while a ability triggered or an
* ability was activated. If not set yet, the current object will be
* retrieved from the game.
* Return source object or LKI from battlefield
*
* @param game
* @return
@ -508,9 +506,9 @@ public interface Ability extends Controllable, Serializable {
int getSourceObjectZoneChangeCounter();
/**
* Returns the object that actually existed while a ability triggerd or an
* ability was activated only if it has not changed zone meanwhile. If not
* set yet, the current object will be retrieved from the game.
* Returns exists source object:
* - for not activated ability - returns exists object
* - for activated ability - returns exists object or LKI (if it triggers from non battlefield, e.g. sacrifice cost);
*
* @param game
* @return
@ -518,16 +516,19 @@ public interface Ability extends Controllable, Serializable {
MageObject getSourceObjectIfItStillExists(Game game);
/**
* Returns the permanent that actually existed while the ability triggerd or
* an ability was activated only if it has not changed zone meanwhile. If
* not set yet, the current permanent if one exists will be retrieved from
* the game and returned.
* See getSourceObjectIfItStillExists for details. Works with Permanent only.
*
* @param game
* @return
*/
Permanent getSourcePermanentIfItStillExists(Game game);
/**
* Returns source permanent info (actual or from LKI)
*
* @param game
* @return
*/
Permanent getSourcePermanentOrLKI(Game game);
String getTargetDescription(Targets targets, Game game);

View file

@ -22,7 +22,6 @@ import mage.game.command.Emblem;
import mage.game.command.Plane;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
import mage.players.Player;
@ -374,10 +373,7 @@ public abstract class AbilityImpl implements Ability {
// fused spell contains 3 abilities (fused, left, right)
// fused cost added to fused ability, so no need cost modification for other parts
boolean needCostModification = true;
if (CardUtil.isFusedPartAbility(this, game)) {
needCostModification = false;
}
boolean needCostModification = !CardUtil.isFusedPartAbility(this, game);
//20101001 - 601.2e
if (needCostModification && sourceObject != null) {
@ -603,7 +599,7 @@ public abstract class AbilityImpl implements Ability {
manaSymbol = "W";
}
if (manaSymbol == null) {
throw new UnsupportedOperationException("ManaFilter is not supported: " + this.toString());
throw new UnsupportedOperationException("ManaFilter is not supported: " + this);
}
for (int i = 0; i < amountMana; i++) {
manaString.append('{').append(manaSymbol).append('}');
@ -1094,7 +1090,7 @@ public abstract class AbilityImpl implements Ability {
}
MageObject object = game.getObject(this.sourceId);
if (object == null) { // e.g. sacrificed token
logger.warn("Could get no object: " + this.toString());
logger.warn("Could get no object: " + this);
}
return new StringBuilder(" activates: ")
.append(object != null ? this.formatRule(getModes().getText(), object.getLogName()) : getModes().getText())
@ -1243,6 +1239,7 @@ public abstract class AbilityImpl implements Ability {
public MageObject getSourceObjectIfItStillExists(Game game) {
if (getSourceObjectZoneChangeCounter() == 0
|| getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(getSourceId())) {
// exists or lki from battlefield
return game.getObject(getSourceId());
}
return null;
@ -1259,15 +1256,11 @@ public abstract class AbilityImpl implements Ability {
@Override
public Permanent getSourcePermanentOrLKI(Game game) {
Permanent permanent = game.getPermanentOrLKIBattlefield(getSourceId());
if (permanent instanceof PermanentToken) {
return permanent;
Permanent permanent = getSourcePermanentIfItStillExists(game);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD, getSourceObjectZoneChangeCounter());
}
if (getSourceObjectZoneChangeCounter() == 0
|| getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(getSourceId())) {
return game.getPermanent(getSourceId());
}
return (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD, getSourceObjectZoneChangeCounter());
return permanent;
}
@Override

View file

@ -71,6 +71,12 @@ public interface Game extends MageItem, Serializable {
GameOptions getOptions();
/**
* Return object or LKI from battlefield
*
* @param objectId
* @return
*/
MageObject getObject(UUID objectId);
MageObject getBaseObject(UUID objectId);