Beached As - fixed performance issues with Wonder etc...
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
Beached As - fixed performance issues with Wonder etc...
by mtgrares » 02 Jul 2010, 16:05
How did you fix the problem? Feel free to copy and paste your code here. It seems like I coded Wonder eons ago. 

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Beached As - fixed performance issues with Wonder etc...
by Beached As » 06 Jul 2010, 12:04
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.
Old Code for Wonder:
- Code: Select all
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
- Code: Select all
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
- Beached As
- Programmer
- Posts: 110
- Joined: 23 Feb 2010, 07:48
- Has thanked: 0 time
- Been thanked: 0 time
Re: Beached As - fixed performance issues with Wonder etc...
by mtgrares » 08 Jul 2010, 14:26
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.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Beached As - fixed performance issues with Wonder etc...
by juzamjedi » 08 Jul 2010, 14:42
This is pretty awesome - I liked the incarnations, but previously they made the game way too slow for my liking. I will have to try them again in draft.
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 66 guests