From 8af4fb1d5a3bbb9dd85de0584a03451a2aa03fea Mon Sep 17 00:00:00 2001 From: borisflagell Date: Mon, 23 May 2022 20:03:13 +0200 Subject: [PATCH] UI: Fix #3366 Sleeve UI would sometime display the stat in TaskSelector while working out. fixes #3366 Sleeve.gymStatType will now be constrainded to the following values by Sleeve.workoutAtGym() : "none" , "str", "def", "dex", "agi". (could previously be anything inputted by player through API) Sleeve.updateGainTaskRate() and TaskSelector.tasks's initializer block will now use a switch, expecting one of those value, instead of reevaluating the string. (fixing commit issue) --- src/PersonObjects/Sleeve/Sleeve.ts | 53 ++++++++++++-------- src/PersonObjects/Sleeve/ui/TaskSelector.tsx | 16 +++++- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts index 9b49e6e22..f33646932 100644 --- a/src/PersonObjects/Sleeve/Sleeve.ts +++ b/src/PersonObjects/Sleeve/Sleeve.ts @@ -854,17 +854,22 @@ export class Sleeve extends Person { // Set stat gain rate const baseGymExp = 1; const totalExpMultiplier = p.hashManager.getTrainingMult() * expMult; - const sanitizedStat: string = this.gymStatType.toLowerCase(); - if (sanitizedStat.includes("str")) { - this.gainRatesForTask.str = baseGymExp * totalExpMultiplier * this.strength_exp_mult; - } else if (sanitizedStat.includes("def")) { - this.gainRatesForTask.def = baseGymExp * totalExpMultiplier * this.defense_exp_mult; - } else if (sanitizedStat.includes("dex")) { - this.gainRatesForTask.dex = baseGymExp * totalExpMultiplier * this.dexterity_exp_mult; - } else if (sanitizedStat.includes("agi")) { - this.gainRatesForTask.agi = baseGymExp * totalExpMultiplier * this.agility_exp_mult; + switch (this.gymStatType) { + case "none": // Note : due to the way Sleeve.workOutAtGym() is currently designed, this should never happend. + break; + case "str": + this.gainRatesForTask.str = baseGymExp * totalExpMultiplier * this.strength_exp_mult; + break; + case "def": + this.gainRatesForTask.def = baseGymExp * totalExpMultiplier * this.defense_exp_mult; + break; + case "dex": + this.gainRatesForTask.dex = baseGymExp * totalExpMultiplier * this.dexterity_exp_mult; + break; + case "agi": + this.gainRatesForTask.agi = baseGymExp * totalExpMultiplier * this.agility_exp_mult; + break; } - return; } @@ -1058,19 +1063,27 @@ export class Sleeve extends Person { // Set experience/money gains based on class const sanitizedStat: string = stat.toLowerCase(); - // Set cost - this.gainRatesForTask.money = -1 * (CONSTANTS.ClassGymBaseCost * costMult); - - // Validate "stat" argument - if ( - !sanitizedStat.includes("str") && - !sanitizedStat.includes("def") && - !sanitizedStat.includes("dex") && - !sanitizedStat.includes("agi") - ) { + // set stat to a default value. + stat = "none"; + if (sanitizedStat.includes("str")) { + stat = "str"; + } + if (sanitizedStat.includes("def")) { + stat = "def"; + } + if (sanitizedStat.includes("dex")) { + stat = "dex"; + } + if (sanitizedStat.includes("agi")) { + stat = "agi"; + } + // if stat is still equals its default value, then validation has failed. + if (stat === "none") { return false; } + // Set cost + this.gainRatesForTask.money = -1 * (CONSTANTS.ClassGymBaseCost * costMult); this.gymStatType = stat; this.currentTask = SleeveTaskType.Gym; diff --git a/src/PersonObjects/Sleeve/ui/TaskSelector.tsx b/src/PersonObjects/Sleeve/ui/TaskSelector.tsx index 0de75b9b0..dad1a96f1 100644 --- a/src/PersonObjects/Sleeve/ui/TaskSelector.tsx +++ b/src/PersonObjects/Sleeve/ui/TaskSelector.tsx @@ -270,8 +270,20 @@ function getABC(sleeve: Sleeve): [string, string, string] { return ["Commit Crime", sleeve.crimeType, "------"]; case SleeveTaskType.Class: return ["Take University Course", sleeve.className, sleeve.currentTaskLocation]; - case SleeveTaskType.Gym: - return ["Workout at Gym", sleeve.gymStatType, sleeve.currentTaskLocation]; + case SleeveTaskType.Gym: { + switch (sleeve.gymStatType) { + case "none": + return ["Idle", "------", "------"]; + case "str": + return ["Workout at Gym", "Train Strength", sleeve.currentTaskLocation]; + case "def": + return ["Workout at Gym", "Train Defense", sleeve.currentTaskLocation]; + case "dex": + return ["Workout at Gym", "Train Dexterity", sleeve.currentTaskLocation]; + case "agi": + return ["Workout at Gym", "Train Agility", sleeve.currentTaskLocation]; + } + } case SleeveTaskType.Bladeburner: return ["Perform Bladeburner Actions", sleeve.bbAction, sleeve.bbContract]; case SleeveTaskType.Recovery: