Skip to content

Commit

Permalink
Add fusebox task priority (#67)
Browse files Browse the repository at this point in the history
* Fix the Doomba task so that it can be broken

* Move getPriorityTasks under helpers

* Fix fusebox breakTask()

Allow breaking of tasks with 'initial' status. Don't break single use
tasks that have already been used. Consider task priority when
breaking fusebox tasks.
  • Loading branch information
nicou authored Jul 3, 2024
1 parent bf8bc7c commit cb7bbed
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 2 additions & 3 deletions db/redux/game/manualTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions src/rules/boxes/fuseboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/rules/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 1 addition & 6 deletions src/rules/ship/eeHealth.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cb7bbed

Please sign in to comment.