diff --git a/src/004-base/basePitFight.js b/src/004-base/basePitFight.js index e24727bd98aafd9e2c26516a6db8d1d008c332a9..9172994ff6e5907ca879997367f38ed7fa51e3ff 100644 --- a/src/004-base/basePitFight.js +++ b/src/004-base/basePitFight.js @@ -100,12 +100,34 @@ App.Facilities.Pit.Fights.BaseFight = class BaseFight { * default implementation should suffice for child classes with a fixed number of actors; may be overridden for fights with variable actor count. * @returns {boolean} - return false if sufficient qualified actors could not be found (cancel the fight) */ - castActors() { + castActors(toFight = {firstFighter: -1, secondFighter: -1}) { const prereqs = this.actorPrerequisites(); this.actors = [...this.forcedActors()]; - + switch (this.actors.length) { + // add both custom fighters if they're not invalid + case 0: + if (toFight.firstFighter >= 0) { + this.actors.push(toFight.firstFighter); + } + if (toFight.secondFighter >= 0) { + this.actors.push(toFight.secondFighter); + } + break; + // add either fighter, defaulting to first + case 1: + if (toFight.firstFighter >= 0) { + this.actors.push(toFight.firstFighter); + } else if (toFight.secondFighter >= 0) { + this.actors.push(toFight.secondFighter); + } + break; + } + // if not fully chosen, select until we have 2 actors for (let i = 0; i < prereqs.length; ++i) { + if (this.actors.length >= 2) { + continue; + } if (this.allowTrainees) { if (this._selectActor(prereqs[i], ...App.Entity.facilities.pit.job("trainee").employeesIDs())) { continue; @@ -115,7 +137,6 @@ App.Facilities.Pit.Fights.BaseFight = class BaseFight { return false; } } - return true; // all actors cast } diff --git a/src/events/scheduled/pitFight.js b/src/events/scheduled/pitFight.js index 36bebbc909cf58a4c1aa3b944e4e0719da0e053f..518173fa4859dcf1dfa7786451896eaa8962e8a9 100644 --- a/src/events/scheduled/pitFight.js +++ b/src/events/scheduled/pitFight.js @@ -18,7 +18,10 @@ App.Events.SEPitFight = class SEPitFight extends App.Events.BaseEvent { let completedFights = 0; let totalSuccess = 0; let lethalFights = 0; - + let toFight = { + firstFighter: -1, + secondFighter: -1 + }; const fighterMap = new App.Facilities.Pit.Fights.FighterMap(); const interactionSpan = document.createElement("span"); @@ -29,10 +32,35 @@ App.Events.SEPitFight = class SEPitFight extends App.Events.BaseEvent { const f = new DocumentFragment(); App.Events.addParagraph(f, [`Select a fight. You have ${maxFights - completedFights} left.`]); - + const slaveIDs = [...App.Entity.facilities.pit.job("fighter").employeesIDs()]; + if (slaveIDs.length - 2 > 0) { // subtract 2 to account for just bodyguard / only 1 possible fight + SlaveSort.IDs(slaveIDs); + const options = new App.UI.OptionsGroup().customRefresh(() => { refreshInteractionSpan(selectFight()); }); + const firstoption = options.addOption(`First Fighter`, "firstFighter", toFight); + const secondoption = options.addOption(`Second Fighter`, "secondFighter", toFight); + let firstArray = []; + let secondArray = []; + for (const id of slaveIDs) { + if (id === V.BodyguardID) { // skip bodyguard as option + continue; + } + const slave = getSlave(id); + // only add if not the other fighter + firstoption.addValue(SlaveFullName(slave), id).addCallback((id) => id === toFight.secondFighter ? toFight.secondFighter = -1 : undefined); + secondoption.addValue(SlaveFullName(slave), id).addCallback((id) => id === toFight.firstFighter ? toFight.firstFighter = -1 : undefined); + if (id !== toFight.firstFighter) { + secondArray.push(id); + } + if (id !== toFight.secondFighter) { + firstArray.push(id); + } + } + firstoption.customButton("Random", () => toFight.firstFighter = firstArray[(Math.floor(Math.random() * firstArray.length))], ""); + secondoption.customButton("Random", () => toFight.secondFighter = secondArray[(Math.floor(Math.random() * secondArray.length))], ""); + f.append(options.render()); + } const availableFights = App.Facilities.Pit.getFights() - .filter(f => f.fightPrerequisites().every(p => p()) && f.castActors()); - + .filter(f => f.fightPrerequisites().every(p => p()) && f.castActors(toFight)); const choices = []; for (const fight of availableFights) { App.UI.DOM.appendNewElement("div", f, fight.fightDescription()); @@ -67,7 +95,7 @@ App.Events.SEPitFight = class SEPitFight extends App.Events.BaseEvent { if (availableFights.length === 0) { App.UI.DOM.appendNewElement("div", f, "No fights available"); } - App.UI.DOM.appendNewElement("div", f, App.UI.DOM.link("Select different fighters", () => refreshInteractionSpan(selectFight()))); + // App.UI.DOM.appendNewElement("div", f, App.UI.DOM.link("Select different fighters", () => refreshInteractionSpan(selectFight()))); App.UI.DOM.appendNewElement("div", f, App.UI.DOM.link("Head back to the penthouse and cancel all the remaining fights", () => refreshInteractionSpan(finishEvent()))); App.Events.addResponses(f, choices); @@ -120,6 +148,11 @@ App.Events.SEPitFight = class SEPitFight extends App.Events.BaseEvent { } if (completedFights < maxFights) { + // reset fighter choices for next round + toFight = { + firstFighter: -1, + secondFighter: -1 + }; f.append(selectFight()); } else { f.append(finishEvent());