mirror of
https://github.com/IvarK/AntimatterDimensionsSourceCode.git
synced 2024-11-23 12:42:34 +00:00
Add functionality for immediately starting ECs (fixes #3319)
This commit is contained in:
parent
3a2ca20e7c
commit
bbe5333158
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user