Beached As - fixed performance issues with Wonder etc...

How did you fix the problem? Feel free to copy and paste your code here. It seems like I coded Wonder eons ago. 

High Quality Resources for Collectible Card Games
https://www.slightlymagic.net/forum/
https://www.slightlymagic.net/forum/viewtopic.php?f=52&t=2821
Previously the code for the incarnations (e.g. Wonder) removed the keyword from all creatures effected by Wonder and then added the keyword back to them whenever the state effects are checked. The problem is however, that state effects are checked VERY often (you can confirm this by adding a message popup in any active state effect). The new code only adds and removes keywords from single creatures as they enter or leave the controller's play zone.mtgrares wrote:How did you fix the problem? Feel free to copy and paste your code here. It seems like I coded Wonder eons ago.
public static Command Wonder = new Command() {
private static final long serialVersionUID = 8346741995447241353L;
CardList old = new CardList();
public void execute() {
// reset creatures
removeFlying(old);
if(isInGrave(Constant.Player.Computer)) addFlying(Constant.Player.Computer);
if(isInGrave(Constant.Player.Human)) addFlying(Constant.Player.Human);
}// execute()
void addFlying(String player) {
PlayerZone play = AllZone.getZone(
Constant.Zone.Play, player);
CardList list = new CardList(play.getCards());
list = list.getType("Creature");
// add creatures to "old" or previous list of creatures
old.addAll(list.toArray());
addFlying(list);
}
boolean isInGrave(String player) {
PlayerZone grave = AllZone.getZone(
Constant.Zone.Graveyard, player);
CardList list = new CardList(grave.getCards());
PlayerZone play = AllZone.getZone(
Constant.Zone.Play, player);
CardList lands = new CardList(play.getCards());
lands = lands.getType("Island");
if(!list.containsName("Wonder") || lands.size() == 0) return false;
else return true;
}
void removeFlying(CardList list) {
for(int i = 0; i < list.size(); i++)
list.get(i).removeExtrinsicKeyword("Flying");
}
void addFlying(CardList list) {
for(int i = 0; i < list.size(); i++)
list.get(i).addExtrinsicKeyword("Flying");
}
}; // Wonder
public static Command Wonder = new Command() {
private static final long serialVersionUID = -846723300545847505L;
CardList old = new CardList();
CardList next = new CardList();
public void execute() {
if(Phase.GameBegins == 1) {
// reset creatures
removeFlying(old);
if(isInGrave(Constant.Player.Computer)) addFlying(Constant.Player.Computer);
if(isInGrave(Constant.Player.Human)) addFlying(Constant.Player.Human);
}
}// execute()
void addFlying(String player) {
next.clear();
PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
CardList playlist = new CardList(play.getCards());
playlist = playlist.getType("Creature");
for(int i = 0; i < playlist.size(); i++) {
if(!old.contains(playlist.get(i))) next.add(playlist.get(i));
}
// add creatures to "old" or previous list of creatures
addFlying(next);
}
boolean isInGrave(String player) {
PlayerZone grave = AllZone.getZone(
Constant.Zone.Graveyard, player);
CardList list = new CardList(grave.getCards());
PlayerZone play = AllZone.getZone(
Constant.Zone.Play, player);
CardList lands = new CardList(play.getCards());
lands = lands.getType("Island");
if(!list.containsName("Wonder") || lands.size() == 0) return false;
else return true;
}
void removeFlying(CardList list) {
CardList List_Copy = new CardList();
List_Copy.add(list);
for(int i = 0; i < List_Copy.size(); i++) {
Card c = List_Copy.get(i);
if(!isInGrave(c.getController()) && old.contains(c)) {
List_Copy.get(i).removeExtrinsicKeyword("Flying");
old.remove(c);
}
}
}
void addFlying(CardList list) {
int Count = list.size();
for(int i = 0; i < Count; i++) {
list.get(i).addExtrinsicKeyword("Flying");
old.add(list.get(i));
}
}
}; // Wonder
Yeah, that was my code. I didn't know how to do it any better. Thanks for the update, no one likes it when Forge slows to a crawl.