Ability refactor: removed deprecated code

This commit is contained in:
Oleg Agafonov 2020-05-28 23:24:30 +04:00
parent d63a3e88ce
commit c656bea31c
14 changed files with 17 additions and 28 deletions

View file

@ -112,7 +112,7 @@ class ExcavatorEffect extends ContinuousEffectImpl implements SourceEffect {
if (permanent != null) {
for(Ability ability : abilities)
{
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
}
}
}

View file

@ -66,7 +66,7 @@ class MartyrdomGainAbilityTargetEffect extends ContinuousEffectImpl {
if (permanent != null) {
ActivatedAbilityImpl ability = new MartyrdomActivatedAbility(source.getControllerId());
ability.setMayActivate(TargetController.ANY);
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;

View file

@ -78,7 +78,7 @@ class ShieldsOfVelisVelGainEffect extends ContinuousEffectImpl {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext();) {
Permanent permanent = it.next().getPermanent(game);
if (permanent != null) {
permanent.addAbility(ChangelingAbility.getInstance(), source.getSourceId(), game, false);
permanent.addAbility(ChangelingAbility.getInstance(), source.getSourceId(), game);
} else {
it.remove();
}

View file

@ -111,7 +111,7 @@ class TestamentOfFaithBecomesCreatureSourceEffect extends ContinuousEffectImpl i
if (sublayer == SubLayer.NA) {
if (!token.getAbilities().isEmpty()) {
for (Ability ability: token.getAbilities()) {
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
}
}
}

View file

@ -115,11 +115,11 @@ public class CopyEffect extends ContinuousEffectImpl {
permanent.removeAllAbilities(source.getSourceId(), game);
if (copyFromObject instanceof Permanent) {
for (Ability ability : ((Permanent) copyFromObject).getAbilities(game)) {
permanent.addAbility(ability, getSourceId(), game, false); // no new Id so consumed replacement effects are known while new continuousEffects.apply happen.
permanent.addAbility(ability, getSourceId(), game);
}
} else {
for (Ability ability : copyFromObject.getAbilities()) {
permanent.addAbility(ability, getSourceId(), game, false); // no new Id so consumed replacement effects are known while new continuousEffects.apply happen.
permanent.addAbility(ability, getSourceId(), game);
}
}

View file

@ -87,7 +87,7 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost
Permanent permanent = it.next().getPermanentOrLKIBattlefield(game); //LKI is neccessary for "dies triggered abilities" to work given to permanets (e.g. Showstopper)
if (permanent != null) {
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
} else {
it.remove(); // no longer on the battlefield, remove reference to object
if (affectedObjectList.isEmpty()) {
@ -99,7 +99,7 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl {
setRuntimeData(source, game);
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) {
perm.addAbility(ability, source.getSourceId(), game, false);
perm.addAbility(ability, source.getSourceId(), game);
}
}
// still as long as the prev. permanent is known to the LKI (e.g. Mikaeus, the Unhallowed) so gained dies triggered ability will trigger
@ -109,7 +109,7 @@ public class GainAbilityAllEffect extends ContinuousEffectImpl {
Permanent perm = (Permanent) mageObject;
if (!(excludeSource && perm.getId().equals(source.getSourceId())) && selectedByRuntimeData(perm, source, game)) {
if (filter.match(perm, source.getSourceId(), source.getControllerId(), game)) {
perm.addAbility(ability, source.getSourceId(), game, false);
perm.addAbility(ability, source.getSourceId(), game);
}
}
}

View file

@ -88,7 +88,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
}
}
if (permanent != null) {
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
}
return true;
}

View file

@ -87,7 +87,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl {
Permanent perm = it.next().getPermanentOrLKIBattlefield(game); //LKI is neccessary for "dies triggered abilities" to work given to permanets (e.g. Showstopper)
if (perm != null) {
for (Ability abilityToAdd : ability) {
perm.addAbility(abilityToAdd, source.getSourceId(), game, false);
perm.addAbility(abilityToAdd, source.getSourceId(), game);
}
} else {
it.remove();
@ -100,7 +100,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
for (Ability abilityToAdd : ability) {
perm.addAbility(abilityToAdd, source.getSourceId(), game, false);
perm.addAbility(abilityToAdd, source.getSourceId(), game);
}
}
}
@ -112,7 +112,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl {
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
if (filter.match(perm, source.getSourceId(), source.getControllerId(), game)) {
for (Ability abilityToAdd : ability) {
perm.addAbility(abilityToAdd, source.getSourceId(), game, false);
perm.addAbility(abilityToAdd, source.getSourceId(), game);
}
}
}

View file

@ -43,7 +43,7 @@ public class GainAbilityPairedEffect extends ContinuousEffectImpl {
Permanent paired = permanent.getPairedCard().getPermanent(game);
if (paired != null && paired.getPairedCard() != null && paired.getPairedCard().equals(new MageObjectReference(permanent, game))) {
permanent.addAbility(ability, source.getSourceId(), game);
paired.addAbility(ability, source.getSourceId(), game, false);
paired.addAbility(ability, source.getSourceId(), game);
return true;
} else {

View file

@ -103,7 +103,7 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl implements Sou
permanent = game.getPermanent(source.getSourceId());
}
if (permanent != null) {
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
return true;
}
}

View file

@ -112,7 +112,7 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
for (UUID permanentId : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanentOrLKIBattlefield(permanentId);
if (permanent != null) {
permanent.addAbility(ability, source.getSourceId(), game, false);
permanent.addAbility(ability, source.getSourceId(), game);
affectedTargets++;
}
}

View file

@ -63,7 +63,7 @@ public class TransformAbility extends SimpleStaticAbility {
permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : sourceCard.getAbilities()) {
permanent.addAbility(ability, source == null ? null : source.getSourceId(), game, false);
permanent.addAbility(ability, source == null ? null : source.getSourceId(), game);
}
permanent.getPower().modifyBaseValue(sourceCard.getPower().getValue());
permanent.getToughness().modifyBaseValue(sourceCard.getToughness().getValue());

View file

@ -156,9 +156,6 @@ public interface Permanent extends Card, Controllable {
void addAbility(Ability ability, UUID sourceId, Game game);
@Deprecated // use addAbility(Ability ability, UUID sourceId, Game game) instead
void addAbility(Ability ability, UUID sourceId, Game game, boolean createNewId);
void removeAllAbilities(UUID sourceId, Game game);
void removeAbility(Ability abilityToRemove, UUID sourceId, Game game);

View file

@ -361,14 +361,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public void addAbility(Ability ability, UUID sourceId, Game game) {
addAbility(ability, sourceId, game, false);
}
@Override
public void addAbility(Ability ability, UUID sourceId, Game game, boolean createNewId) {
// singleton abilities -- only one instance
// other abilities -- any amount of instances
// TODO: no needs in createNewId, so move code to addAbility(Ability ability, UUID sourceId, Game game)
if (!abilities.containsKey(ability.getId())) {
Ability copyAbility = ability.copy();
copyAbility.newId(); // needed so that source can get an ability multiple times (e.g. Raging Ravine)
@ -383,7 +377,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public void removeAllAbilities(UUID sourceId, Game game) {
// can't use getAbilities() here -- cause it's can be auto-generated list potentially
// TODO: what about triggered abilities? See addAbility above -- triggers adds to GameState
abilities.clear();
}
@ -402,7 +395,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
});
// can't use getAbilities() here -- cause it's can be auto-generated list potentially
// TODO: what about triggered abilities? See addAbility above -- triggers adds to GameState
toRemove.forEach(r -> abilities.remove(r));
}