mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 09:48:02 +00:00
Merge pull request #8528 from kevlahnota/master3
update ConsoleCommandInterpreter
This commit is contained in:
@@ -6,11 +6,9 @@ import com.badlogic.gdx.utils.Array;
|
|||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.adventure.character.PlayerSprite;
|
import forge.adventure.character.PlayerSprite;
|
||||||
import forge.adventure.data.BiomeData;
|
import forge.adventure.data.*;
|
||||||
import forge.adventure.data.EnemyData;
|
|
||||||
import forge.adventure.data.PointOfInterestData;
|
|
||||||
import forge.adventure.data.WorldData;
|
|
||||||
import forge.adventure.pointofintrest.PointOfInterest;
|
import forge.adventure.pointofintrest.PointOfInterest;
|
||||||
|
import forge.adventure.scene.InventoryScene;
|
||||||
import forge.adventure.util.AdventureEventController;
|
import forge.adventure.util.AdventureEventController;
|
||||||
import forge.adventure.util.Current;
|
import forge.adventure.util.Current;
|
||||||
import forge.adventure.util.Paths;
|
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());
|
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);
|
String[] parameters = Arrays.copyOfRange(words, i, words.length);
|
||||||
for (int j = 0; j < parameters.length; j++)
|
// this removes apostrophe...
|
||||||
parameters[j] = parameters[j].replaceAll("[\"']", "");
|
/*for (int j = 0; j < parameters.length; j++)
|
||||||
|
parameters[j] = parameters[j].replaceAll("[\"']", "");*/
|
||||||
return currentCommand.function.apply(parameters);
|
return currentCommand.function.apply(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
WorldStage.getInstance().player.playEffect(Paths.EFFECT_TELEPORT, 10);
|
WorldStage.getInstance().player.playEffect(Paths.EFFECT_TELEPORT, 10);
|
||||||
return "teleport to (" + s[0] + "," + s[1] + ")";
|
return "teleport to (" + s[0] + "," + s[1] + ")";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "Exception occured, Invalid input";
|
return "Exception occurred, Invalid input";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
registerCommand(new String[]{"teleport", "to", "poi"}, s -> {
|
registerCommand(new String[]{"teleport", "to", "poi"}, s -> {
|
||||||
@@ -170,13 +169,12 @@ public class ConsoleCommandInterpreter {
|
|||||||
return "Added " + amount + " gold";
|
return "Added " + amount + " gold";
|
||||||
});
|
});
|
||||||
registerCommand(new String[]{"give", "quest"}, s -> {
|
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;
|
int ID;
|
||||||
try{
|
try {
|
||||||
ID =Integer.parseInt(s[0]);
|
ID = Integer.parseInt(s[0]);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e){
|
return "Can not convert " + s[0] + " to number";
|
||||||
return "Can not convert " +s[0]+" to number";
|
|
||||||
}
|
}
|
||||||
Current.player().addQuest(ID, false);
|
Current.player().addQuest(ID, false);
|
||||||
return "Quest generated";
|
return "Quest generated";
|
||||||
@@ -216,13 +214,13 @@ public class ConsoleCommandInterpreter {
|
|||||||
if (s.length < 1) return "Command needs 1 parameter: Card name.";
|
if (s.length < 1) return "Command needs 1 parameter: Card name.";
|
||||||
PaperCard card = StaticData.instance().fetchCard(s[0]);
|
PaperCard card = StaticData.instance().fetchCard(s[0]);
|
||||||
if (card == null) return "Cannot find card: " + s[0];
|
if (card == null) return "Cannot find card: " + s[0];
|
||||||
if(s.length >= 2) {
|
if (s.length >= 2) {
|
||||||
try {
|
try {
|
||||||
int amount = Integer.parseInt(s[1]);
|
int amount = Integer.parseInt(s[1]);
|
||||||
Current.player().addCard(card, amount);
|
Current.player().addCard(card, amount);
|
||||||
return String.format("Added %d cards: %s", amount, card.getName());
|
return String.format("Added %d cards: %s", amount, card.getName());
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
catch(NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
Current.player().addCard(card);
|
Current.player().addCard(card);
|
||||||
return "Added card: " + card.getName();
|
return "Added card: " + card.getName();
|
||||||
@@ -231,13 +229,13 @@ public class ConsoleCommandInterpreter {
|
|||||||
if (s.length < 1) return "Command needs 1 parameter: Card name.";
|
if (s.length < 1) return "Command needs 1 parameter: Card name.";
|
||||||
PaperCard card = StaticData.instance().fetchCard(s[0]);
|
PaperCard card = StaticData.instance().fetchCard(s[0]);
|
||||||
if (card == null) return "Cannot find card: " + s[0];
|
if (card == null) return "Cannot find card: " + s[0];
|
||||||
if(s.length >= 2) {
|
if (s.length >= 2) {
|
||||||
try {
|
try {
|
||||||
int amount = Integer.parseInt(s[1]);
|
int amount = Integer.parseInt(s[1]);
|
||||||
Current.player().addCard(card.getNoSellVersion(), amount);
|
Current.player().addCard(card.getNoSellVersion(), amount);
|
||||||
return String.format("Added %d cards: %s", amount, card.getName());
|
return String.format("Added %d cards: %s", amount, card.getName());
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
catch(NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
Current.player().addCard(card.getNoSellVersion());
|
Current.player().addCard(card.getNoSellVersion());
|
||||||
return "Added card: " + card.getName();
|
return "Added card: " + card.getName();
|
||||||
@@ -247,19 +245,20 @@ public class ConsoleCommandInterpreter {
|
|||||||
CardEdition edition = StaticData.instance().getCardEdition(s[0]);
|
CardEdition edition = StaticData.instance().getCardEdition(s[0]);
|
||||||
if (edition == null) return "Cannot find edition: " + s[0];
|
if (edition == null) return "Cannot find edition: " + s[0];
|
||||||
CardEdition.EditionEntry cis = edition.getCardFromCollectorNumber(s[1]);
|
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());
|
PaperCard card = StaticData.instance().fetchCard(cis.name(), edition.getCode(), cis.collectorNumber());
|
||||||
if(card == null) {
|
if (card == null) {
|
||||||
//Found in the set, not supported.
|
//Found in the set, not supported.
|
||||||
return String.format("Failed to fetch (%s, %s, %s) - Not currently supported.", cis.name(), edition.getCode(), cis.collectorNumber());
|
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 {
|
try {
|
||||||
int amount = Integer.parseInt(s[2]);
|
int amount = Integer.parseInt(s[2]);
|
||||||
Current.player().addCard(card, amount);
|
Current.player().addCard(card, amount);
|
||||||
return String.format("Added %d cards: %s", amount, card.getName());
|
return String.format("Added %d cards: %s", amount, card.getName());
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
catch(NumberFormatException ignored) {}
|
|
||||||
}
|
}
|
||||||
Current.player().addCard(card);
|
Current.player().addCard(card);
|
||||||
return "Added card: " + card.getName();
|
return "Added card: " + card.getName();
|
||||||
@@ -269,7 +268,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
CardEdition edition = StaticData.instance().getCardEdition(s[0]);
|
CardEdition edition = StaticData.instance().getCardEdition(s[0]);
|
||||||
if (edition == null) return "Cannot find edition: " + 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());
|
PaperCard card = StaticData.instance().fetchCard(entry.name(), edition.getCode(), entry.collectorNumber());
|
||||||
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
@@ -294,10 +293,11 @@ public class ConsoleCommandInterpreter {
|
|||||||
if (s.length >= 2) {
|
if (s.length >= 2) {
|
||||||
try {
|
try {
|
||||||
amount = Integer.parseInt(s[1]);
|
amount = Integer.parseInt(s[1]);
|
||||||
} catch (NumberFormatException ignored) {}
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Current.player().addBooster(AdventureEventController.instance().generateBooster(edition.getCode()));
|
Current.player().addBooster(AdventureEventController.instance().generateBooster(edition.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
});
|
});
|
||||||
registerCommand(new String[]{"clearnosell"}, s -> {
|
registerCommand(new String[]{"clearnosell"}, s -> {
|
||||||
CardPool cards = Current.player().getCards();
|
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);
|
cards.remove(c);
|
||||||
}
|
}
|
||||||
return "Removed all no sell flagged cards.";
|
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());
|
Deck D = E.generateDeck(Current.player().isFantasyMode(), Current.player().isUsingCustomDeck() || Current.player().isHardorInsaneDifficulty());
|
||||||
DeckProxy DP = new DeckProxy(D, "Constructed", GameType.Constructed, null);
|
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()
|
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.";
|
return "Enemy color Identity dumped to stdout.";
|
||||||
});
|
});
|
||||||
registerCommand(new String[]{"heal", "amount"}, s -> {
|
registerCommand(new String[]{"heal", "amount"}, s -> {
|
||||||
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
||||||
int N = 0;
|
int N;
|
||||||
try {
|
try {
|
||||||
N = Integer.parseInt(s[0]);
|
N = Integer.parseInt(s[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -397,7 +397,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
});
|
});
|
||||||
registerCommand(new String[]{"heal", "percent"}, s -> {
|
registerCommand(new String[]{"heal", "percent"}, s -> {
|
||||||
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
||||||
float value = 0;
|
float value;
|
||||||
try {
|
try {
|
||||||
value = Float.parseFloat(s[0]);
|
value = Float.parseFloat(s[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -424,7 +424,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
Current.player().addShards(value);
|
Current.player().addShards(value);
|
||||||
return "Player now has " + Current.player().getShards() + " shards";
|
return "Player now has " + Current.player().getShards() + " shards";
|
||||||
});
|
});
|
||||||
registerCommand(new String[]{"debug","map"}, s -> {
|
registerCommand(new String[]{"debug", "map"}, s -> {
|
||||||
GameHUD.getInstance().setDebug(true);
|
GameHUD.getInstance().setDebug(true);
|
||||||
return "Debug map ON";
|
return "Debug map ON";
|
||||||
});
|
});
|
||||||
@@ -437,7 +437,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
if (!MapStage.getInstance().isInMap()) {
|
if (!MapStage.getInstance().isInMap()) {
|
||||||
WorldStage ws = WorldStage.getInstance();
|
WorldStage ws = WorldStage.getInstance();
|
||||||
int enemiesCount = ws.enemies.size();
|
int enemiesCount = ws.enemies.size();
|
||||||
for(int i = 0; i < enemiesCount; i++) {
|
for (int i = 0; i < enemiesCount; i++) {
|
||||||
ws.removeNearestEnemy();
|
ws.removeNearestEnemy();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -448,7 +448,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
|
|
||||||
registerCommand(new String[]{"hide"}, s -> {
|
registerCommand(new String[]{"hide"}, s -> {
|
||||||
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
||||||
float value = 0;
|
float value;
|
||||||
try {
|
try {
|
||||||
value = Float.parseFloat(s[0]);
|
value = Float.parseFloat(s[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -460,7 +460,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
|
|
||||||
registerCommand(new String[]{"fly"}, s -> {
|
registerCommand(new String[]{"fly"}, s -> {
|
||||||
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
||||||
float value = 0;
|
float value;
|
||||||
try {
|
try {
|
||||||
value = Float.parseFloat(s[0]);
|
value = Float.parseFloat(s[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -471,7 +471,7 @@ public class ConsoleCommandInterpreter {
|
|||||||
});
|
});
|
||||||
registerCommand(new String[]{"sprint"}, s -> {
|
registerCommand(new String[]{"sprint"}, s -> {
|
||||||
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
if (s.length < 1) return "Command needs 1 parameter: Amount";
|
||||||
float value = 0;
|
float value;
|
||||||
try {
|
try {
|
||||||
value = Float.parseFloat(s[0]);
|
value = Float.parseFloat(s[0]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -497,5 +497,18 @@ public class ConsoleCommandInterpreter {
|
|||||||
MapStage.getInstance().deleteObject(id);
|
MapStage.getInstance().deleteObject(id);
|
||||||
return "Removed enemy " + s[0];
|
return "Removed enemy " + s[0];
|
||||||
});
|
});
|
||||||
|
// this is for test purposes unless you want to crack your items
|
||||||
|
registerCommand(new String[]{"crack"}, s -> {
|
||||||
|
ItemData itemData = Current.player().getRandomEquippedItem();
|
||||||
|
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); //Unequipped the itemData
|
||||||
|
InventoryScene.instance().clearItemDescription();
|
||||||
|
message = itemData.name + " " + Forge.getLocalizer().getMessage("lblCracked");
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user