From 8313414f78295d0ac206d9ab03396af4ab23fe9e Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 25 Aug 2025 06:49:59 +0800 Subject: [PATCH 1/3] update ConsoleCommandInterpreter --- .../stage/ConsoleCommandInterpreter.java | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java index 324e5888405..ecf7044913e 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java +++ b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java @@ -6,11 +6,9 @@ import com.badlogic.gdx.utils.Array; import forge.Forge; import forge.StaticData; import forge.adventure.character.PlayerSprite; -import forge.adventure.data.BiomeData; -import forge.adventure.data.EnemyData; -import forge.adventure.data.PointOfInterestData; -import forge.adventure.data.WorldData; +import forge.adventure.data.*; import forge.adventure.pointofintrest.PointOfInterest; +import forge.adventure.scene.InventoryScene; import forge.adventure.util.AdventureEventController; import forge.adventure.util.Current; import forge.adventure.util.Paths; @@ -91,8 +89,9 @@ public class ConsoleCommandInterpreter { return "Command not found. Available commands:\n" + String.join(" ", Arrays.copyOfRange(words, 0, i)) + "\n" + String.join("\n", currentCommand.children.keySet()); } String[] parameters = Arrays.copyOfRange(words, i, words.length); - for (int j = 0; j < parameters.length; j++) - parameters[j] = parameters[j].replaceAll("[\"']", ""); + // this removes apostrophy... + /*for (int j = 0; j < parameters.length; j++) + parameters[j] = parameters[j].replaceAll("[\"']", "");*/ return currentCommand.function.apply(parameters); } @@ -170,13 +169,12 @@ public class ConsoleCommandInterpreter { return "Added " + amount + " gold"; }); registerCommand(new String[]{"give", "quest"}, s -> { - if (s.length<1) return "Command needs 1 parameter: QuestID"; + if (s.length < 1) return "Command needs 1 parameter: QuestID"; int ID; - try{ - ID =Integer.parseInt(s[0]); - } - catch (Exception e){ - return "Can not convert " +s[0]+" to number"; + try { + ID = Integer.parseInt(s[0]); + } catch (Exception e) { + return "Can not convert " + s[0] + " to number"; } Current.player().addQuest(ID, false); return "Quest generated"; @@ -216,13 +214,13 @@ public class ConsoleCommandInterpreter { if (s.length < 1) return "Command needs 1 parameter: Card name."; PaperCard card = StaticData.instance().fetchCard(s[0]); if (card == null) return "Cannot find card: " + s[0]; - if(s.length >= 2) { + if (s.length >= 2) { try { int amount = Integer.parseInt(s[1]); Current.player().addCard(card, amount); return String.format("Added %d cards: %s", amount, card.getName()); + } catch (NumberFormatException ignored) { } - catch(NumberFormatException ignored) {} } Current.player().addCard(card); return "Added card: " + card.getName(); @@ -231,13 +229,13 @@ public class ConsoleCommandInterpreter { if (s.length < 1) return "Command needs 1 parameter: Card name."; PaperCard card = StaticData.instance().fetchCard(s[0]); if (card == null) return "Cannot find card: " + s[0]; - if(s.length >= 2) { + if (s.length >= 2) { try { int amount = Integer.parseInt(s[1]); Current.player().addCard(card.getNoSellVersion(), amount); return String.format("Added %d cards: %s", amount, card.getName()); + } catch (NumberFormatException ignored) { } - catch(NumberFormatException ignored) {} } Current.player().addCard(card.getNoSellVersion()); return "Added card: " + card.getName(); @@ -247,19 +245,20 @@ public class ConsoleCommandInterpreter { CardEdition edition = StaticData.instance().getCardEdition(s[0]); if (edition == null) return "Cannot find edition: " + s[0]; CardEdition.EditionEntry cis = edition.getCardFromCollectorNumber(s[1]); - if (cis == null) return String.format("Set '%s' does not have a card with collector number '%s'.", edition.getName(), s[1]); + if (cis == null) + return String.format("Set '%s' does not have a card with collector number '%s'.", edition.getName(), s[1]); PaperCard card = StaticData.instance().fetchCard(cis.name(), edition.getCode(), cis.collectorNumber()); - if(card == null) { + if (card == null) { //Found in the set, not supported. return String.format("Failed to fetch (%s, %s, %s) - Not currently supported.", cis.name(), edition.getCode(), cis.collectorNumber()); } - if(s.length >= 3) { + if (s.length >= 3) { try { int amount = Integer.parseInt(s[2]); Current.player().addCard(card, amount); return String.format("Added %d cards: %s", amount, card.getName()); + } catch (NumberFormatException ignored) { } - catch(NumberFormatException ignored) {} } Current.player().addCard(card); return "Added card: " + card.getName(); @@ -269,7 +268,7 @@ public class ConsoleCommandInterpreter { CardEdition edition = StaticData.instance().getCardEdition(s[0]); if (edition == null) return "Cannot find edition: " + s[0]; - for(CardEdition.EditionEntry entry : edition.getObtainableCards()) { + for (CardEdition.EditionEntry entry : edition.getObtainableCards()) { PaperCard card = StaticData.instance().fetchCard(entry.name(), edition.getCode(), entry.collectorNumber()); if (card != null) { @@ -294,10 +293,11 @@ public class ConsoleCommandInterpreter { if (s.length >= 2) { try { amount = Integer.parseInt(s[1]); - } catch (NumberFormatException ignored) {} + } catch (NumberFormatException ignored) { + } } - for(int i=0; i { CardPool cards = Current.player().getCards(); - for(PaperCard c : cards.getFilteredPool(c -> c.getMarkedFlags().noSellValue).toFlatList()) { + for (PaperCard c : cards.getFilteredPool(c -> c.getMarkedFlags().noSellValue).toFlatList()) { cards.remove(c); } return "Removed all no sell flagged cards."; @@ -379,13 +379,13 @@ public class ConsoleCommandInterpreter { Deck D = E.generateDeck(Current.player().isFantasyMode(), Current.player().isUsingCustomDeck() || Current.player().isHardorInsaneDifficulty()); DeckProxy DP = new DeckProxy(D, "Constructed", GameType.Constructed, null); System.out.printf("%s Colors: %s | Deck Colors: %s (%s)%s\n", E.name, E.colors, DP.getColorIdentity().toEnumSet().toString(), DP.getName() - , E.boss ? " - BOSS" : ""); + , E.boss ? " - BOSS" : ""); } return "Enemy color Identity dumped to stdout."; }); registerCommand(new String[]{"heal", "amount"}, s -> { if (s.length < 1) return "Command needs 1 parameter: Amount"; - int N = 0; + int N; try { N = Integer.parseInt(s[0]); } catch (Exception e) { @@ -397,7 +397,7 @@ public class ConsoleCommandInterpreter { }); registerCommand(new String[]{"heal", "percent"}, s -> { if (s.length < 1) return "Command needs 1 parameter: Amount"; - float value = 0; + float value; try { value = Float.parseFloat(s[0]); } catch (Exception e) { @@ -424,7 +424,7 @@ public class ConsoleCommandInterpreter { Current.player().addShards(value); return "Player now has " + Current.player().getShards() + " shards"; }); - registerCommand(new String[]{"debug","map"}, s -> { + registerCommand(new String[]{"debug", "map"}, s -> { GameHUD.getInstance().setDebug(true); return "Debug map ON"; }); @@ -437,7 +437,7 @@ public class ConsoleCommandInterpreter { if (!MapStage.getInstance().isInMap()) { WorldStage ws = WorldStage.getInstance(); int enemiesCount = ws.enemies.size(); - for(int i = 0; i < enemiesCount; i++) { + for (int i = 0; i < enemiesCount; i++) { ws.removeNearestEnemy(); } } else { @@ -448,7 +448,7 @@ public class ConsoleCommandInterpreter { registerCommand(new String[]{"hide"}, s -> { if (s.length < 1) return "Command needs 1 parameter: Amount"; - float value = 0; + float value; try { value = Float.parseFloat(s[0]); } catch (Exception e) { @@ -460,7 +460,7 @@ public class ConsoleCommandInterpreter { registerCommand(new String[]{"fly"}, s -> { if (s.length < 1) return "Command needs 1 parameter: Amount"; - float value = 0; + float value; try { value = Float.parseFloat(s[0]); } catch (Exception e) { @@ -471,7 +471,7 @@ public class ConsoleCommandInterpreter { }); registerCommand(new String[]{"sprint"}, s -> { if (s.length < 1) return "Command needs 1 parameter: Amount"; - float value = 0; + float value; try { value = Float.parseFloat(s[0]); } catch (Exception e) { @@ -497,5 +497,17 @@ public class ConsoleCommandInterpreter { MapStage.getInstance().deleteObject(id); return "Removed enemy " + s[0]; }); + // this is for test purpposes + registerCommand(new String[]{"crack"}, s -> { + ItemData itemData = Current.player().getRandomEquippedItem(); + String message = "Ok, no equipped items to crack... :)"; + if (itemData != null) { + itemData.isCracked = true; + Current.player().equip(itemData); //unequip... + InventoryScene.instance().clearItemDescription(); + message = itemData.name + " " + Forge.getLocalizer().getMessage("lblCracked"); + } + return message; + }); } } From 977f2c75b97361c086402b3357c1e3865a196a1e Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 25 Aug 2025 06:53:28 +0800 Subject: [PATCH 2/3] update comment --- .../src/forge/adventure/stage/ConsoleCommandInterpreter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java index ecf7044913e..5b48adb7593 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java +++ b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java @@ -497,10 +497,11 @@ public class ConsoleCommandInterpreter { MapStage.getInstance().deleteObject(id); return "Removed enemy " + s[0]; }); - // this is for test purpposes + // this is for test purposes unless you want to crack your items registerCommand(new String[]{"crack"}, s -> { ItemData itemData = Current.player().getRandomEquippedItem(); - String message = "Ok, no equipped items to crack... :)"; + String value = Current.player().isHardorInsaneDifficulty() ? "items" : "armor"; + String message = "Ok, no equipped " + value + " to crack... :)"; if (itemData != null) { itemData.isCracked = true; Current.player().equip(itemData); //unequip... From ad0a690764953742e56110b9240edf402e8b5188 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Mon, 25 Aug 2025 06:56:27 +0800 Subject: [PATCH 3/3] minor typo --- .../forge/adventure/stage/ConsoleCommandInterpreter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java index 5b48adb7593..e19f72e1ffe 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java +++ b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java @@ -89,7 +89,7 @@ public class ConsoleCommandInterpreter { return "Command not found. Available commands:\n" + String.join(" ", Arrays.copyOfRange(words, 0, i)) + "\n" + String.join("\n", currentCommand.children.keySet()); } String[] parameters = Arrays.copyOfRange(words, i, words.length); - // this removes apostrophy... + // this removes apostrophe... /*for (int j = 0; j < parameters.length; j++) parameters[j] = parameters[j].replaceAll("[\"']", "");*/ return currentCommand.function.apply(parameters); @@ -132,7 +132,7 @@ public class ConsoleCommandInterpreter { WorldStage.getInstance().player.playEffect(Paths.EFFECT_TELEPORT, 10); return "teleport to (" + s[0] + "," + s[1] + ")"; } catch (Exception e) { - return "Exception occured, Invalid input"; + return "Exception occurred, Invalid input"; } }); registerCommand(new String[]{"teleport", "to", "poi"}, s -> { @@ -504,7 +504,7 @@ public class ConsoleCommandInterpreter { String message = "Ok, no equipped " + value + " to crack... :)"; if (itemData != null) { itemData.isCracked = true; - Current.player().equip(itemData); //unequip... + Current.player().equip(itemData); //Unequipped the itemData InventoryScene.instance().clearItemDescription(); message = itemData.name + " " + Forge.getLocalizer().getMessage("lblCracked"); }