Skip to content

Commit

Permalink
fix: small fix on the chat processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Jan 24, 2025
1 parent d0ad191 commit 2ad12cb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
46 changes: 33 additions & 13 deletions megamek/src/megamek/client/bot/ChatProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Adjust fall shame.
if (command.toLowerCase().startsWith(ChatCommands.CAUTION.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid Syntax. Should be 'princessName : caution : <+/->'.";
msg = "Invalid Syntax. " + ChatCommands.CAUTION.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand All @@ -307,7 +307,11 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
String adjustment = arguments[0];
int currentFallShame = princess.getBehaviorSettings().getFallShameIndex();
int newFallShame = currentFallShame;
newFallShame += princess.calculateAdjustment(adjustment);
if (StringUtil.isNumeric(adjustment)) {
newFallShame = princess.calculateAdjustment(adjustment);
} else {
newFallShame += princess.calculateAdjustment(adjustment);
}
princess.getBehaviorSettings().setFallShameIndex(newFallShame);
msg = "Piloting Caution changed from " + currentFallShame + " to " +
princess.getBehaviorSettings().getFallShameIndex();
Expand All @@ -317,7 +321,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Adjust self preservation.
if (command.toLowerCase().startsWith(ChatCommands.AVOID.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid Syntax. Should be 'princessName : avoid : <+/->'.";
msg = "Invalid Syntax. " + ChatCommands.AVOID.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand All @@ -326,7 +330,11 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
String adjustment = arguments[0];
int currentSelfPreservation = princess.getBehaviorSettings().getSelfPreservationIndex();
int newSelfPreservation = currentSelfPreservation;
newSelfPreservation += princess.calculateAdjustment(adjustment);
if (StringUtil.isNumeric(adjustment)) {
newSelfPreservation = princess.calculateAdjustment(adjustment);
} else {
newSelfPreservation += princess.calculateAdjustment(adjustment);
}
princess.getBehaviorSettings().setSelfPreservationIndex(newSelfPreservation);
msg = "Self Preservation changed from " + currentSelfPreservation + " to " +
princess.getBehaviorSettings().getSelfPreservationIndex();
Expand All @@ -336,7 +344,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Adjust aggression.
if (command.toLowerCase().startsWith(ChatCommands.AGGRESSION.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid Syntax. Should be 'princessName : aggression : <+/->'.";
msg = "Invalid Syntax. " + ChatCommands.AGGRESSION.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand All @@ -345,7 +353,11 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
String adjustment = arguments[0];
int currentAggression = princess.getBehaviorSettings().getHyperAggressionIndex();
int newAggression = currentAggression;
newAggression += princess.calculateAdjustment(adjustment);
if (StringUtil.isNumeric(adjustment)) {
newAggression = princess.calculateAdjustment(adjustment);
} else {
newAggression += princess.calculateAdjustment(adjustment);
}
princess.getBehaviorSettings().setHyperAggressionIndex(newAggression);
msg = "Aggression changed from " + currentAggression + " to " +
princess.getBehaviorSettings().getHyperAggressionIndex();
Expand All @@ -356,7 +368,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Adjust herd mentality.
if (command.toLowerCase().startsWith(ChatCommands.HERDING.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid Syntax. Should be 'princessName : herding : <+/->'.";
msg = "Invalid Syntax. " + ChatCommands.HERDING.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand All @@ -365,7 +377,11 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
String adjustment = arguments[0];
int currentHerding = princess.getBehaviorSettings().getHerdMentalityIndex();
int newHerding = currentHerding;
newHerding += princess.calculateAdjustment(adjustment);
if (StringUtil.isNumeric(adjustment)) {
newHerding = princess.calculateAdjustment(adjustment);
} else {
newHerding += princess.calculateAdjustment(adjustment);
}
princess.getBehaviorSettings().setHerdMentalityIndex(newHerding);
msg = "Herding changed from " + currentHerding + " to " +
princess.getBehaviorSettings().getHerdMentalityIndex();
Expand All @@ -375,7 +391,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Adjust bravery.
if (command.toLowerCase().startsWith(ChatCommands.BRAVERY.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid Syntax. Should be 'princessName : brave : <+/->'.";
msg = "Invalid Syntax. " + ChatCommands.BRAVERY.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand All @@ -384,7 +400,11 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
String adjustment = arguments[0];
int currentBravery = princess.getBehaviorSettings().getBraveryIndex();
int newBravery = currentBravery;
newBravery += princess.calculateAdjustment(adjustment);
if (StringUtil.isNumeric(adjustment)) {
newBravery = princess.calculateAdjustment(adjustment);
} else {
newBravery += princess.calculateAdjustment(adjustment);
}
princess.getBehaviorSettings().setBraveryIndex(newBravery);
msg = "Bravery changed from " + currentBravery + " to " +
princess.getBehaviorSettings().getBraveryIndex();
Expand All @@ -394,7 +414,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Specify a "strategic" building target.
if (command.toLowerCase().startsWith(ChatCommands.TARGET.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid syntax. Should be 'princessName : target : hexNumber'.";
msg = "Invalid Syntax. " + ChatCommands.TARGET.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand Down Expand Up @@ -426,7 +446,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess
// Specify a priority unit target.
if (command.toLowerCase().startsWith(ChatCommands.PRIORITIZE.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid syntax. Should be 'princessName : priority : unitId'.";
msg = "Invalid Syntax. " + ChatCommands.PRIORITIZE.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand Down Expand Up @@ -454,7 +474,7 @@ void additionalPrincessCommands(GamePlayerChatEvent chatEvent, Princess princess

if (command.toLowerCase().startsWith(ChatCommands.BLOOD_FEUD.getAbbreviation())) {
if (arguments == null || arguments.length == 0) {
msg = "Invalid syntax. Should be 'princessName : bf : playerId'.";
msg = "Invalid Syntax. " + ChatCommands.BLOOD_FEUD.getSyntax();
logger.warn(msg + "\n" + chatEvent.getMessage());
princess.sendChat(msg);
return;
Expand Down
32 changes: 16 additions & 16 deletions megamek/src/megamek/client/bot/princess/ChatCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@
* @since 10/24/2014 9:57 AM
*/
public enum ChatCommands {
FLEE("fl", "princessName: flee", "Causes princess-controlled units to start fleeing the board, regardless of " +
FLEE("fl", "princessName: fl", "Flee - Causes princess-controlled units to start fleeing the board, regardless of " +
"damage level or Forced Withdrawal setting."),
VERBOSE("ve", "princessName: verbose : <error/warning/info/debug>", "Sets princess's verbosity level."),
BEHAVIOR("be", "princessName: behavior : behaviorName", "Change's princess's behavior to the named behavior."),
CAUTION("ca", "princessName: caution : <+/->", "Modifies princess's Piloting Caution setting. Each '+' increases " +
VERBOSE("ve", "princessName: ve: <error/warning/info/debug>", "Sets princess's verbosity level."),
BEHAVIOR("be", "princessName: be: behaviorName", "Behavior - Change's princess's behavior to the named behavior."),
CAUTION("ca", "princessName: ca: +/-", "Caution - Modifies princess's Piloting Caution setting. Each '+' increases " +
"it by 1 and each '-' decreases it by one."),
AVOID("av", "princessName: avoid : <+/->", "Modifies princess's Self Preservation setting. Each '+' increases it " +
AVOID("av", "princessName: av: +/-", "Avoid - Modifies princess's Self Preservation setting. Each '+' increases it " +
"by 1 and each '-' decreases it by one."),
AGGRESSION("ag", "princessName: aggression : <+/->", "Modifies princess's Aggression setting. Each '+' increases " +
AGGRESSION("ag", "princessName: ag : +/-", "Aggression - Modifies princess's Aggression setting. Each '+' increases " +
"it by 1 and each '-' decreases it by one."),
HERDING("he", "princessName: herd : <+/->", "Modifies princess's Herding setting. Each '+' increases it by 1 and " +
HERDING("he", "princessName: he: +/-", "Herd - Modifies princess's Herding setting. Each '+' increases it by 1 and " +
"each '-' decreases it by one."),
BRAVERY("br", "princessName: brave : <+/->", "Modifies princess's Bravery setting. Each '+' increases it by 1 " +
BRAVERY("br", "princessName: br: +/-", "Brave - Modifies princess's Bravery setting. Each '+' increases it by 1 " +
"and each '-' decreases it by one."),
TARGET("ta", "princessName: target : hexNumber", "Adds the specified hex to princess's list of Strategic Targets."),
PRIORITIZE("pr", "princessName: prioritize : unitId", "Adds the specified unit to princess's Priority Targets " +
TARGET("ta", "princessName: ta: hexNumber", "Target Hex - Adds the specified hex to princess's list of Strategic Targets."),
PRIORITIZE("pr", "princessName: pr: unitId", "Priority Target - Adds the specified unit to princess's Priority Targets " +
"list."),
SHOW_BEHAVIOR("sh", "princessName: showBehavior", "Princess will state the name of her current behavior."),
LIST__COMMANDS("li", "princessName: listCommands", "Displays this list of commands."),
IGNORE_TARGET("ig", "princessName: ignoreTarget: unitId", "Will not fire on the entity with this ID."),
SHOW_DISHONORED("di", "princessName: dishonored", "Show the players on the dishonored enemies list."),
CLEAR_IGNORED_TARGETS("cl", "princessName: clearIgnoredTargets", "Clears the list of ignored targets."),
BLOOD_FEUD("bf", "princessName: bloodFeud: playerId", "Adds player to the dishonored enemies list.");
SHOW_BEHAVIOR("sh", "princessName: sh", "Show Behavior - Princess will state the name of her current behavior."),
LIST__COMMANDS("li", "princessName: li", "List Commands - Displays this list of commands."),
IGNORE_TARGET("ig", "princessName: ig: unitId", "Ignore Target - Will not fire on the entity with this ID."),
SHOW_DISHONORED("di", "princessName: di", "Show Dishonored - Show the players on the dishonored enemies list."),
CLEAR_IGNORED_TARGETS("cl", "princessName: cl", "Clear Ignored Target - Clears the list of ignored targets."),
BLOOD_FEUD("bf", "princessName: bf: playerId", "Blood Feud - Adds player to the dishonored enemies list.");
private final String abbreviation;
private final String syntax;
private final String description;
Expand Down
4 changes: 4 additions & 0 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,10 @@ public int calculateAdjustment(final String ticks) {
if (StringUtility.isNullOrBlank(ticks)) {
return 0;
}
if (StringUtil.isNumeric(ticks)) {
return Integer.parseInt(ticks);
}

for (final char tick : ticks.toCharArray()) {
if (PLUS == tick) {
adjustment++;
Expand Down

0 comments on commit 2ad12cb

Please sign in to comment.