Started fixing action target selection
This commit is contained in:
@@ -35,7 +35,7 @@ const ActionSchema = new SimpleSchema({
|
||||
},
|
||||
targetIds: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
optional: true,
|
||||
},
|
||||
'targetIds.$': {
|
||||
type: String,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ export default async function spendResources(
|
||||
!quantity ||
|
||||
!isFinite(quantity)
|
||||
) continue;
|
||||
|
||||
await applyTask(action, {
|
||||
prop,
|
||||
targetIds,
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user