forked from GitHub-Mirrors/foundry-sw5e
Have Powers consume Force and Tech Points
Add the ability for powers to automatically deduct force and tech points
This commit is contained in:
parent
ad50d1549f
commit
fa5dc07869
2 changed files with 53 additions and 12 deletions
|
@ -100,6 +100,19 @@ export default class AbilityUseDialog extends Dialog {
|
||||||
|
|
||||||
// Determine the levels which are feasible
|
// Determine the levels which are feasible
|
||||||
let lmax = 0;
|
let lmax = 0;
|
||||||
|
let points;
|
||||||
|
switch (itemData.school){
|
||||||
|
case "lgt":
|
||||||
|
case "uni":
|
||||||
|
case "drk": {
|
||||||
|
points = actorData.attributes.force.points.value + actorData.attributes.force.points.temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "tec": {
|
||||||
|
points = actorData.attributes.tech.points.value + actorData.attributes.tech.points.temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
const powerLevels = Array.fromRange(10).reduce((arr, i) => {
|
const powerLevels = Array.fromRange(10).reduce((arr, i) => {
|
||||||
if ( i < lvl ) return arr;
|
if ( i < lvl ) return arr;
|
||||||
const label = CONFIG.SW5E.powerLevels[i];
|
const label = CONFIG.SW5E.powerLevels[i];
|
||||||
|
@ -111,21 +124,11 @@ export default class AbilityUseDialog extends Dialog {
|
||||||
level: i,
|
level: i,
|
||||||
label: i > 0 ? game.i18n.format('SW5E.PowerLevelSlot', {level: label, n: slots}) : label,
|
label: i > 0 ? game.i18n.format('SW5E.PowerLevelSlot', {level: label, n: slots}) : label,
|
||||||
canCast: max > 0,
|
canCast: max > 0,
|
||||||
hasSlots: slots > 0
|
hasSlots: ((slots > 0) && (points > i))
|
||||||
});
|
});
|
||||||
return arr;
|
return arr;
|
||||||
}, []).filter(sl => sl.level <= lmax);
|
}, []).filter(sl => sl.level <= lmax);
|
||||||
|
|
||||||
// If this character has pact slots, present them as an option for casting the power.
|
|
||||||
const pact = actorData.powers.pact;
|
|
||||||
if (pact.level >= lvl) {
|
|
||||||
powerLevels.push({
|
|
||||||
level: 'pact',
|
|
||||||
label: `${game.i18n.format('SW5E.PowerLevelPact', {level: pact.level, n: pact.value})}`,
|
|
||||||
canCast: true,
|
|
||||||
hasSlots: pact.value > 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const canCast = powerLevels.some(l => l.hasSlots);
|
const canCast = powerLevels.some(l => l.hasSlots);
|
||||||
if ( !canCast ) data.errors.push(game.i18n.format("SW5E.PowerCastNoSlots", {
|
if ( !canCast ) data.errors.push(game.i18n.format("SW5E.PowerCastNoSlots", {
|
||||||
level: CONFIG.SW5E.powerLevels[lvl],
|
level: CONFIG.SW5E.powerLevels[lvl],
|
||||||
|
|
|
@ -431,11 +431,18 @@ export default class Item5e extends Item {
|
||||||
let consumeUsage = !!uses.per; // Consume limited uses
|
let consumeUsage = !!uses.per; // Consume limited uses
|
||||||
let consumeQuantity = uses.autoDestroy; // Consume quantity of the item in lieu of uses
|
let consumeQuantity = uses.autoDestroy; // Consume quantity of the item in lieu of uses
|
||||||
|
|
||||||
|
//set rollback values in case you pick a spell level you can't cast anymore
|
||||||
|
let forcePointValueRollback = actor.data.data.attributes.force.points.value;
|
||||||
|
let forcePointTempRollback = actor.data.data.attributes.force.points.temp;
|
||||||
|
let techPointValueRollback = actor.data.data.attributes.tech.points.value;
|
||||||
|
let techPointTempRollback = actor.data.data.attributes.tech.points.temp;
|
||||||
|
|
||||||
// Display a configuration dialog to customize the usage
|
// Display a configuration dialog to customize the usage
|
||||||
const needsConfiguration = createMeasuredTemplate || consumeRecharge || consumeResource || consumePowerSlot || consumeUsage;
|
const needsConfiguration = createMeasuredTemplate || consumeRecharge || consumeResource || consumePowerSlot || consumeUsage;
|
||||||
if (configureDialog && needsConfiguration) {
|
if (configureDialog && needsConfiguration) {
|
||||||
const configuration = await AbilityUseDialog.create(this);
|
const configuration = await AbilityUseDialog.create(this);
|
||||||
if (!configuration) return;
|
if (!configuration) return;
|
||||||
|
|
||||||
|
|
||||||
// Determine consumption preferences
|
// Determine consumption preferences
|
||||||
createMeasuredTemplate = Boolean(configuration.placeTemplate);
|
createMeasuredTemplate = Boolean(configuration.placeTemplate);
|
||||||
|
@ -448,6 +455,31 @@ export default class Item5e extends Item {
|
||||||
if ( requirePowerSlot ) {
|
if ( requirePowerSlot ) {
|
||||||
const slotLevel = configuration.level;
|
const slotLevel = configuration.level;
|
||||||
const powerLevel = parseInt(slotLevel);
|
const powerLevel = parseInt(slotLevel);
|
||||||
|
const fp = actor.data.data.attributes.force.points;
|
||||||
|
const tp = actor.data.data.attributes.tech.points;
|
||||||
|
const powerCost = powerLevel + 1;
|
||||||
|
switch (id.school){
|
||||||
|
case "lgt":
|
||||||
|
case "uni":
|
||||||
|
case "drk": {
|
||||||
|
if (fp.temp >= powerCost) {
|
||||||
|
actor.update({"data.attributes.force.points.temp": fp.temp - powerCost});
|
||||||
|
}else{
|
||||||
|
actor.update({"data.attributes.force.points.value": fp.value + fp.temp - powerCost});
|
||||||
|
actor.update({"data.attributes.force.points.temp": 0});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "tec": {
|
||||||
|
if (tp.temp >= powerCost) {
|
||||||
|
actor.update({"data.attributes.tech.points.temp": tp.temp - powerCost});
|
||||||
|
}else{
|
||||||
|
actor.update({"data.attributes.tech.points.value": tp.value + tp.temp - powerCost});
|
||||||
|
actor.update({"data.attributes.tech.points.temp": 0});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (powerLevel !== id.level) {
|
if (powerLevel !== id.level) {
|
||||||
const upcastData = mergeObject(this.data, {"data.level": powerLevel}, {inplace: false});
|
const upcastData = mergeObject(this.data, {"data.level": powerLevel}, {inplace: false});
|
||||||
item = this.constructor.createOwned(upcastData, actor); // Replace the item with an upcast version
|
item = this.constructor.createOwned(upcastData, actor); // Replace the item with an upcast version
|
||||||
|
@ -458,7 +490,13 @@ export default class Item5e extends Item {
|
||||||
|
|
||||||
// Determine whether the item can be used by testing for resource consumption
|
// Determine whether the item can be used by testing for resource consumption
|
||||||
const usage = item._getUsageUpdates({consumeRecharge, consumeResource, consumePowerSlot, consumeUsage, consumeQuantity});
|
const usage = item._getUsageUpdates({consumeRecharge, consumeResource, consumePowerSlot, consumeUsage, consumeQuantity});
|
||||||
if ( !usage ) return;
|
if ( !usage ) {
|
||||||
|
actor.update({"data.attributes.force.points.value": forcePointValueRollback});
|
||||||
|
actor.update({"data.attributes.force.points.temp": forcePointTempRollback});
|
||||||
|
actor.update({"data.attributes.tech.points.value": techPointValueRollback});
|
||||||
|
actor.update({"data.attributes.tech.points.temp": techPointTempRollback});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const {actorUpdates, itemUpdates, resourceUpdates} = usage;
|
const {actorUpdates, itemUpdates, resourceUpdates} = usage;
|
||||||
|
|
||||||
// Commit pending data updates
|
// Commit pending data updates
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue