Skip to content
Permalink
Browse files
Cheat engine: added support of @ref command (replace @ref by commands…
… from another group)
  • Loading branch information
JayDi85 committed Feb 26, 2020
1 parent f50bc8f commit 67cf4bc5351246d8c50918d7739b8080f03d5820
Showing with 32 additions and 0 deletions.
  1. +32 −0 Mage.Server/src/main/java/mage/server/util/SystemUtil.java
@@ -46,6 +46,16 @@ private SystemUtil() {
private static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SystemUtil.class);

// replace ref group command like @group by real commands from that group
// example:
// [my group]
// command 1
// @another group
// [another group]
// command 2
// command 3
private static final String COMMAND_REF_PREFIX = "@";

// transform special group names from init.txt to special commands in choose dialog:
// [@mana add] -> MANA ADD
private static final String COMMAND_MANA_ADD = "@mana add"; // TODO: not implemented
@@ -451,6 +461,28 @@ public static void addCardsForTesting(Game game, String fileSource, Player feedb
return;
}

// insert group refs as extra commands (only user defined groups allowed, no special)
Map<String, CommandGroup> otherGroupRefs = new HashMap<>();
for (CommandGroup group : groups) {
if (group != runGroup) {
otherGroupRefs.putIfAbsent(COMMAND_REF_PREFIX + group.name, group);
}
}
for (int i = runGroup.commands.size() - 1; i >= 0; i--) {
String line = runGroup.commands.get(i);
// replace ref by real commands from another group
if (line.startsWith(COMMAND_REF_PREFIX)) {
CommandGroup other = otherGroupRefs.getOrDefault(line, null);
if (other != null && !other.isSpecialCommand) {
logger.info("Replace ref group " + line + " by " + other.commands.size() + " commands");
runGroup.commands.remove(i);
runGroup.commands.addAll(i, other.commands);
} else {
logger.error("Can't find ref group: " + line);
}
}
}

// 4. run commands
for (String line : runGroup.commands) {

1 comment on commit 67cf4bc

@JayDi85

This comment has been minimized.

Copy link
Member Author

@JayDi85 JayDi85 commented on 67cf4bc Feb 26, 2020

Useful feature. Now you can re-use custom commands by one ref line.

As example:

[test cast]
@init
hand:Human:Act of Treason:1

[test bolt]
@init
@bears
hand:Human:Lightning Bolt:1

[init]
battlefield:Human:Forest:5
battlefield:Human:Plains:5
battlefield:Human:Mountain:5
battlefield:Human:Swamp:5
battlefield:Human:Island:5

[bears]
battlefield:Human:Grizzly Bears:2
battlefield:Computer:Grizzly Bears:2
Please sign in to comment.