1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-05 09:12:29 -09:00

Fixed to do the check of existing abilities always by rule text. Added a new abilities.containsRule() method to check by rule, that's sometimes needed. To check always by rule text leaded to bugs during applying copy effects.

This commit is contained in:
LevelX2 2013-02-21 00:15:11 +01:00
parent 768cf365b9
commit 391c3db02e
5 changed files with 46 additions and 2 deletions

View file

@ -214,6 +214,14 @@ public interface Abilities<T extends Ability> extends List<T>, Serializable {
*/
boolean contains(T ability);
/**
* Searches an ability with the same rule text as the passed in ability.
*
* @param ability
* @return
*/
boolean containsRule(T ability);
/**
* Searches this set of abilities for the existence of each of the passed in
* set of abilities.

View file

@ -232,7 +232,26 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
@Override
public boolean contains(T ability) {
for (T test: this) {
if (ability.getId().equals(test.getId()) || ability.getRule().equals(test.getRule())) {
// Checking also by getRule() without other restrictions is a problem when a triggered ability will be copied to a permanent that had the same ability
// already before the copy. Because then it keeps the triggered ability twice and it triggers twice.
// e.g. 2 Biovisonary and one enchanted with Infinite Reflection
if (ability.getId().equals(test.getId())) {
return true;
}
if (ability.getOriginalId().equals(test.getId())) {
return true;
}
if (ability instanceof MageSingleton && ability.getRule().equals(test.getRule())) {
return true;
}
}
return false;
}
@Override
public boolean containsRule(T ability) {
for (T test: this) {
if (ability.getRule().equals(test.getRule())) {
return true;
}
}

View file

@ -379,4 +379,11 @@ public interface Ability extends Controllable, Serializable {
*/
void setRuleAtTheTop(boolean ruleAtTheTop);
/**
* Get the originalId of the ability
*
* @return originalId
*/
UUID getOriginalId();
}

View file

@ -580,6 +580,11 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
@Override
public void setRuleAtTheTop(boolean ruleAtTheTop) {
this.ruleAtTheTop = ruleAtTheTop;
}
}
@Override
public UUID getOriginalId() {
return this.originalId;
}
}

View file

@ -372,4 +372,9 @@ public class StackAbility implements StackObject, Ability {
public void setRuleAtTheTop(boolean ruleAtTheTop) {
this.ability.setRuleAtTheTop(ruleAtTheTop);
}
@Override
public UUID getOriginalId() {
return this.ability.getOriginalId();
}
}