Started fixing action target selection

This commit is contained in:
ThaumRystra
2024-06-12 15:43:56 +02:00
parent 4921a34dfe
commit a5292cf0f2
17 changed files with 162 additions and 15 deletions

View File

@@ -35,7 +35,7 @@ const ActionSchema = new SimpleSchema({
},
targetIds: {
type: Array,
defaultValue: [],
optional: true,
},
'targetIds.$': {
type: String,

View File

@@ -40,14 +40,28 @@ export default async function applyAction(action: EngineAction, userInput: Input
action._isSimulation = simulate;
action.taskCount = 0;
let task = options?.task;
console.log('task', task, action.targetIds)
if (!task) {
const prop = await getSingleProperty(action.creatureId, action.rootPropId);
if (!prop) throw new Meteor.Error('Not found', 'Root action property could not be found');
// If the target ids weren't already set, get them from the user
console.log(action.targetIds, prop);
if (!action.targetIds && (
prop.target === 'singleTarget' ||
prop.target === 'multipleTargets'
)) {
console.log('getting targetIds');
action.targetIds = await (userInput.targetIds(prop.targets));
console.log('got targetIds', action.targetIds);
}
task = {
prop,
targetIds: action.targetIds || [],
}
}
await applyTask(action, task, userInput);
return action;
}

View File

@@ -63,6 +63,7 @@ export default async function spendResources(
!quantity ||
!isFinite(quantity)
) continue;
await applyTask(action, {
prop,
targetIds,

View File

@@ -1,6 +1,10 @@
import Task from '/imports/api/engine/action/tasks/Task';
type InputProvider = {
/**
* Get the ids of the creatures being targeted
*/
targetIds(target: 'singleTarget' | 'multipleTargets', currentTargetIds?: string[]): Promise<string[]>;
/**
* Show the user the next property or task to apply and wait for input to continue
*/

View File

@@ -8,6 +8,9 @@ export default function getReplayChoicesInputProvider(actionId: string, decision
const decisionStack = [...decisions].reverse();
const dRoller = getDeterministicDiceRoller(actionId);
const replaySavedInput: InputProvider = {
targetIds() {
return Promise.resolve(decisionStack.pop());
},
nextStep() {
return Promise.resolve();
},

View File

@@ -1,6 +1,9 @@
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
const inputProviderForTests: InputProvider = {
async targetIds(target, currentTargetIds = []) {
return currentTargetIds;
},
/**
* For testing, randomness is hard to deal with
* rollDice function returns the average roll for every dice rolled

View File

@@ -47,7 +47,7 @@ export default async function applyItemAsAmmoTask(task: ItemAsAmmoTask, action:
type: 'item',
}],
// Log the item name as a heading if it has child properties to apply
...itemChildren.length && {
...itemChildren.length && !task.params.skipChildren && {
contents: [{
name: getPropertyTitle(item) || 'Ammo',
inline: false,