diff --git a/db/redux/game/manualTasks.js b/db/redux/game/manualTasks.js index ce6e240..7f54d3f 100644 --- a/db/redux/game/manualTasks.js +++ b/db/redux/game/manualTasks.js @@ -3178,10 +3178,9 @@ blobs.push({ id: 'doomba', type: 'task', game: 'doomba', - singleUse: false, + singleUse: true, used: false, - eeType: 'lifesupport', - eeHealth: 0.2, + lifesupportHealth: 0.20, // fixes 20% status: 'initial', calibrationCount: 1, calibrationTime: 870, diff --git a/src/rules/boxes/fuseboxes.js b/src/rules/boxes/fuseboxes.js index d0dbbbf..842fd71 100644 --- a/src/rules/boxes/fuseboxes.js +++ b/src/rules/boxes/fuseboxes.js @@ -2,7 +2,7 @@ import store, { watch } from '../../store/store'; import { CHANNELS, fireEvent } from '../../dmx'; import { logger } from '../../logger'; import { isNumber, isEqual } from 'lodash'; -import { chooseRandom, saveBlob } from '../helpers'; +import { chooseRandom, getPriorityTasks, saveBlob } from '../helpers'; // Fire DMX signals based on dmxFuse configuration watch(['data', 'box'], (boxes, previousBoxes, state) => { @@ -45,8 +45,14 @@ watch(['data', 'box'], (boxes, previousBoxes, state) => { function breakTask() { const allTasks = Object.values(store.getState().data.task); - const tasks = allTasks.filter(task => task.lifesupportHealth && task.status === 'fixed'); - const task = chooseRandom(tasks)[0]; + const tasks = allTasks.filter((task) => { + const isLifeSupportTask = Number.isFinite(task.lifesupportHealth); + const isBreakable = ['fixed', 'initial'].includes(task.status); + const isNotUsed = !task.singleUse || !task.used; + return isLifeSupportTask && isBreakable && isNotUsed; + }); + const priorityTasks = getPriorityTasks(tasks); + const task = chooseRandom(priorityTasks)[0]; if (!task) { logger.warn(`Cound not find life support task to break`); return; diff --git a/src/rules/helpers.js b/src/rules/helpers.js index 0605e36..8423bd6 100644 --- a/src/rules/helpers.js +++ b/src/rules/helpers.js @@ -158,3 +158,11 @@ export function* rng(seed = 1) { } } +/** + * Return the tasks with the highest priority + * @param {array} tasks + */ +export function getPriorityTasks(tasks) { + const maxPriority = tasks.reduce((max, task) => Math.max(max, task.priority ? task.priority : 0), -Infinity); + return tasks.filter(task => (task.priority ? task.priority : 0) === maxPriority); +} diff --git a/src/rules/ship/eeHealth.js b/src/rules/ship/eeHealth.js index 1f02cc3..4429db3 100644 --- a/src/rules/ship/eeHealth.js +++ b/src/rules/ship/eeHealth.js @@ -1,4 +1,4 @@ -import { clamp, interval, chooseRandom } from '../helpers'; +import { clamp, interval, chooseRandom, getPriorityTasks } from '../helpers'; import { breakTask } from '../breakTask'; import store, { watch } from '../../store/store'; import { getEmptyEpsilonClient } from '../../integrations/emptyepsilon/client'; @@ -59,11 +59,6 @@ function computeHealth(brokenTasks) { return brokenTasks.reduce((health, task) => health - task.eeHealth, 1); } -function getPriorityTasks(tasks) { - const maxPriority = tasks.reduce((max, task) => Math.max(max, task.priority ? task.priority : 0), -1000000); - return tasks.filter(task => (task.priority ? task.priority : 0) === maxPriority); -} - function breakTasks(type, targetHealth) { const tasks = getEETasks(type); const brokenTasks = tasks.filter(isBroken);