From 67cf4bc5351246d8c50918d7739b8080f03d5820 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 27 Feb 2020 03:07:28 +0400 Subject: [PATCH] Cheat engine: added support of @ref command (replace @ref by commands from another group) --- .../java/mage/server/util/SystemUtil.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java index 9f754901c3..0bf9c0ac77 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -46,6 +46,16 @@ public final class 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 final class SystemUtil { return; } + // insert group refs as extra commands (only user defined groups allowed, no special) + Map 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) {