From bbe53331587384faef9c834680aeee0cc5e7862e Mon Sep 17 00:00:00 2001 From: SpectralFlame <4493131+cyip92@users.noreply.github.com> Date: Sat, 17 Jun 2023 02:40:49 -0500 Subject: [PATCH] Add functionality for immediately starting ECs (fixes #3319) --- src/components/modals/StudyStringModal.vue | 6 ++--- .../StudyStringPreview.vue | 2 +- .../tt-shop/TimeStudySaveLoadButton.vue | 4 ++-- src/core/automator/automator-commands.js | 22 ++++++++++++++----- src/core/automator/compiler.js | 3 ++- src/core/time-studies/time-study-tree.js | 8 +++++-- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/components/modals/StudyStringModal.vue b/src/components/modals/StudyStringModal.vue index ebebc5578..fd104507b 100644 --- a/src/components/modals/StudyStringModal.vue +++ b/src/components/modals/StudyStringModal.vue @@ -163,8 +163,8 @@ export default { } else if (this.isImporting) { if (this.respecAndLoad && Player.canEternity) { player.respec = true; - const studies = new TimeStudyTree(this.truncatedInput).purchasedStudies; - animateAndEternity(() => TimeStudyTree.commitToGameState(studies, false)); + const tree = new TimeStudyTree(this.truncatedInput); + animateAndEternity(() => TimeStudyTree.commitToGameState(tree.purchasedStudies, false, tree.startEC)); return; } this.importTree(); @@ -182,7 +182,7 @@ export default { this.emitClose(); // We need to use a combined tree for committing to the game state, or else it won't buy studies in the imported // tree are only reachable if the current tree is already bought - TimeStudyTree.commitToGameState(this.combinedTreeObject.purchasedStudies, false); + TimeStudyTree.commitToGameState(this.combinedTreeObject.purchasedStudies, false, this.combinedTreeObject.startEC); }, savePreset() { if (this.inputIsValid) { diff --git a/src/components/modals/time-study-modal-preview/StudyStringPreview.vue b/src/components/modals/time-study-modal-preview/StudyStringPreview.vue index be326cab5..292494a5d 100644 --- a/src/components/modals/time-study-modal-preview/StudyStringPreview.vue +++ b/src/components/modals/time-study-modal-preview/StudyStringPreview.vue @@ -157,7 +157,7 @@ export default { display: flex; overflow-y: auto; width: 20rem; - height: 55rem; + height: 44.5rem; position: relative; justify-content: center; border: var(--color-text) solid var(--var-border-width, 0.3rem); diff --git a/src/components/tabs/time-studies/tt-shop/TimeStudySaveLoadButton.vue b/src/components/tabs/time-studies/tt-shop/TimeStudySaveLoadButton.vue index c5e7c7afd..05303f07c 100644 --- a/src/components/tabs/time-studies/tt-shop/TimeStudySaveLoadButton.vue +++ b/src/components/tabs/time-studies/tt-shop/TimeStudySaveLoadButton.vue @@ -59,7 +59,7 @@ export default { const combinedTree = new TimeStudyTree(); combinedTree.attemptBuyArray(TimeStudyTree.currentStudies, false); combinedTree.attemptBuyArray(combinedTree.parseStudyImport(this.preset.studies), true); - TimeStudyTree.commitToGameState(combinedTree.purchasedStudies, false); + TimeStudyTree.commitToGameState(combinedTree.purchasedStudies, false, combinedTree.startEC); const presetName = this.name ? `Study preset "${this.name}"` : "Study preset"; GameUI.notify.eternity(`${presetName} loaded from slot ${this.saveslot}`); @@ -72,7 +72,7 @@ export default { player.respec = true; const newTree = new TimeStudyTree(); newTree.attemptBuyArray(newTree.parseStudyImport(this.preset.studies)); - animateAndEternity(() => TimeStudyTree.commitToGameState(newTree.purchasedStudies, false)); + animateAndEternity(() => TimeStudyTree.commitToGameState(newTree.purchasedStudies, false, newTree.startEC)); } }, deletePreset() { diff --git a/src/core/automator/automator-commands.js b/src/core/automator/automator-commands.js index d9e92df03..14561f880 100644 --- a/src/core/automator/automator-commands.js +++ b/src/core/automator/automator-commands.js @@ -640,14 +640,26 @@ export const AutomatorCommands = [ } return AUTOMATOR_COMMAND_STATUS.NEXT_TICK_SAME_INSTRUCTION; } - if (!studies.ec || TimeStudy.eternityChallenge(studies.ec).isBought) { + const hasEC = TimeStudy.eternityChallenge(studies.ec).isBought; + if (!studies.ec || (hasEC && !studies.startEC)) { AutomatorData.logCommandEvent(`Purchased all specified Time Studies`, ctx.startLine); return AUTOMATOR_COMMAND_STATUS.NEXT_INSTRUCTION; } const unlockedEC = TimeStudy.eternityChallenge(studies.ec).purchase(true); - if (unlockedEC) { - AutomatorData.logCommandEvent(`Purchased all specified Time Studies and unlocked Eternity Challenge - ${studies.ec}`, ctx.startLine); + if (hasEC || unlockedEC) { + if (studies.startEC) { + EternityChallenge(studies.ec).start(true); + if (EternityChallenge(studies.ec).isRunning) { + AutomatorData.logCommandEvent(`Purchased all specified Time Studies, then unlocked and started running + Eternity Challenge ${studies.ec}`, ctx.startLine); + } else { + AutomatorData.logCommandEvent(`Purchased all specified Time Studies and unlocked Eternity Challenge + ${studies.ec}, but failed to start it`, ctx.startLine); + } + } else { + AutomatorData.logCommandEvent(`Purchased all specified Time Studies and unlocked Eternity Challenge + ${studies.ec}`, ctx.startLine); + } return AUTOMATOR_COMMAND_STATUS.NEXT_INSTRUCTION; } return AUTOMATOR_COMMAND_STATUS.NEXT_TICK_SAME_INSTRUCTION; @@ -726,7 +738,7 @@ export const AutomatorCommands = [ return () => { const imported = new TimeStudyTree(player.timestudy.presets[presetIndex - 1].studies); const beforeCount = GameCache.currentStudyTree.value.purchasedStudies.length; - TimeStudyTree.commitToGameState(imported.purchasedStudies); + TimeStudyTree.commitToGameState(imported.purchasedStudies, true, imported.startEC); const afterCount = GameCache.currentStudyTree.value.purchasedStudies.length; // Check if there are still any unbought studies from the preset after attempting to commit it all; // if there are then we keep trying on this line until there aren't, unless we are given nowait diff --git a/src/core/automator/compiler.js b/src/core/automator/compiler.js index 5d829f927..bc25c8c9e 100644 --- a/src/core/automator/compiler.js +++ b/src/core/automator/compiler.js @@ -208,7 +208,8 @@ class Validator extends BaseVisitor { tree = new TimeStudyTree(value); varInfo.value = { normal: tree.selectedStudies.map(ts => ts.id), - ec: tree.ec + ec: tree.ec, + startEC: tree.startEC, }; break; case AUTOMATOR_VAR_TYPES.DURATION: diff --git a/src/core/time-studies/time-study-tree.js b/src/core/time-studies/time-study-tree.js index 7f10cb718..05bccb874 100644 --- a/src/core/time-studies/time-study-tree.js +++ b/src/core/time-studies/time-study-tree.js @@ -22,6 +22,7 @@ * accessible or purchasable in the given order * @member {TimeStudyState[]} purchasedStudies Array of studies which were actually purchased, using the given amount * of available theorems + * @member {Boolean} startEC Whether or not to start an EC within purchasedStudies when committing to game state */ export class TimeStudyTree { // The first parameter will either be an import string or an array of studies (possibly with an EC at the end) @@ -30,6 +31,7 @@ export class TimeStudyTree { this.invalidStudies = []; this.purchasedStudies = []; this.selectedStudies = []; + this.startEC = false; switch (typeof studies) { case "string": // Input parameter is an unparsed study import string @@ -59,7 +61,7 @@ export class TimeStudyTree { } let test = input.replaceAll(/ +/gu, ""); TimeStudyTree.sets.forEach((_, x) => test = test.replaceAll(new RegExp(`${x},?`, "gu"), "")); - return /^,?((\d{2,3}(-\d{2,3})?)\b,?)*(\|\d{0,2})?$/iu.test(test); + return /^,?((\d{2,3}(-\d{2,3})?)\b,?)*(\|\d{1,2}!?)?$/iu.test(test); } // Getter for all the studies in the current game state @@ -74,10 +76,11 @@ export class TimeStudyTree { // THIS METHOD HAS LASTING CONSEQUENCES ON THE GAME STATE. STUDIES WILL ACTUALLY BE PURCHASED IF POSSIBLE. // This method attempts to take the parameter array and purchase all the studies specified, using the current game // state to determine if they are affordable. Input array may be either an id array or a TimeStudyState array - static commitToGameState(studyArray, auto = true) { + static commitToGameState(studyArray, auto = true, startEC = false) { for (const item of studyArray) { const study = typeof item === "number" ? TimeStudy(item) : item; if (study && !study.isBought) study.purchase(auto); + if (startEC && study instanceof ECTimeStudyState) EternityChallenge(study.id).start(auto); } GameCache.currentStudyTree.invalidate(); } @@ -143,6 +146,7 @@ export class TimeStudyTree { // If the string has an EC indicated in it, append that to the end of the study array const ecString = input.split("|")[1]; + this.startEC = input.endsWith("!"); if (!ecString) { // Study strings without an ending "|##" are still valid, but will result in ecString being undefined return output;