#Staff of Power Implementation

1 messages · Page 1 of 1 (latest)

fluid juniper
#
  • @shrewd osprey
tropic basalt
#

thanks!

fluid juniper
#

unfortunately, i can only thread from a single message, feel free to repost any context needed

tropic basalt
#

thanks.

tropic basalt
#

ok. i've managed to loop over all the targets within the 30 foot range and get their center coords. But how would I find the distance from the caster to the targets? this is what I have, but distance is coming back as undefined: ```js
for (i; i < targets.length; i++) {
let tokenCenter = targets[i]?.object.center;
let ray = new Ray(myCenter, tokenCenter);
let distance = canvas.grid.measureDistance([{ ray }], { gridSpaces: true })[
i
];
console.log("distance: ", distance);
console.log(targets[i].data.name, tokenCenter, ray.distance);
}

#

gridsize = (await canvas.grid.size) / 2;

#

ok. this is what I have so far. it sorta works, but the distances aren't quite coming out exact: ```js
console.log("args: ", args);
const lastArg = args[args.length - 1];
const actorD = game.actors.get(lastArg.actor._id);
const me = canvas.tokens.get(token.id);
const targets = lastArg.targets;
// console.log(actorD)
// console.log("me: ", me)
console.log("targets: ", targets);
let gridsize = await canvas.grid.size;
console.log("gridsize: ", gridsize);

const myCenter = me.center;
console.log("myCenter: ", myCenter);

// Define the staff of power
// let itemD = await fromUuid(lastArg.itemUuid);
let staffPower = actorD.items.getName("Staff of Power");
let chargesLeft = staffPower.data.flags.magicitems.uses;
// console.log("staffPower: ", staffPower)
// console.log("chargesLeft: ", chargesLeft)

// let randomNumber = Math.random();
// console.log(randomNumber);
// if (randomNumber >= 0.5) {
// ui.notifications.error("You take all the damage and die")
let i = 0;
for (i; i < targets.length; i++) {
let tokenCenter = targets[i]?.object.center;
let ray = new Ray(myCenter, tokenCenter);
// let distance = canvas.grid.measureDistance([{ ray }], { gridSpaces: true });
console.log(targets[i].data.name, tokenCenter, Math.floor(ray.distance / gridsize) * 5);
}

// determine distance from actorD
// apply damage based on distance (10ft or less = 8 * charges, 20feet or less = 6 * charges, 30ft or less = 4 * charges)
// apply damage to actorD (16 * charges)
// } else {
// ui.notifications.info("You have been transported to a different plane!")
// // delete actorD token
// // get all targets in range
// // determine distance from actorD
// // apply damage based on distance (10ft or less = 8 * charges, 20feet or less = 6 * charges, 30ft or less = 4 * charges)
// }

shrewd osprey
#

you could just get the tokens near by with midi and store them

#

MidiQOL.findNearby(null,me,30,null);

#

or you can grab everybody within the template

#

MidiQOL.selectTargetsForTemplate

tropic basalt
#

how would I set up a ternary to set the damage multiplier? I've got it so I can grab the targets within 30 and compute their distance from the caster. Now I just want to say if within 10 feet or less, damage multiplier is 8, else if within 11-20 feet, it's 6, else if within 21-30 it's 4x damage.

shrewd osprey
#

You got a couple of options... You could group them together into different arrays then deal damage to that array. else you can loop them and deal damage to each one

#

reduce would probably be your best option for the multi grouping

#

although you could probably loop it all through that then push out the results of the damage

shrewd osprey
#
let targets = MidiQOL.findNearby(null,me,30,null);
targets.reduce((list, target) => {
let distance = MidiQOL.getDistance(me, target, true);
let multiplier = distance <= 30 ? 4 : distance <= 20 ? 6 : distance <= 10 ? 8 : false;
if(multiplier) {
// could deal damage here with applyToken Damage
list.push(`//push out any details you want`);
}
return list;
}, []);
tropic basalt
#

question: where do you find the midi functions like findNearby and getDistance, and their syntax? I have looked and looked, but I can't really find a simple explanation of how the damageOnlyWorkflow works, for example.

shrewd osprey
#

Just type in MidiQOL in the console