forked from GitHub-Mirrors/foundry-sw5e
Split Force and Tech Power Limits
Split force and tech power limits. Didn't test, may be broken. Needs separate tab for force vs tech. Still need to tally number of powers known
This commit is contained in:
parent
fa5dc07869
commit
fb73cdfc08
5 changed files with 154 additions and 77 deletions
|
@ -431,12 +431,12 @@ export default class Item5e extends Item {
|
|||
let consumeUsage = !!uses.per; // Consume limited 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
|
||||
/*//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
|
||||
const needsConfiguration = createMeasuredTemplate || consumeRecharge || consumeResource || consumePowerSlot || consumeUsage;
|
||||
if (configureDialog && needsConfiguration) {
|
||||
|
@ -455,31 +455,7 @@ export default class Item5e extends Item {
|
|||
if ( requirePowerSlot ) {
|
||||
const slotLevel = configuration.level;
|
||||
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) {
|
||||
const upcastData = mergeObject(this.data, {"data.level": powerLevel}, {inplace: false});
|
||||
item = this.constructor.createOwned(upcastData, actor); // Replace the item with an upcast version
|
||||
|
@ -490,13 +466,8 @@ export default class Item5e extends Item {
|
|||
|
||||
// Determine whether the item can be used by testing for resource consumption
|
||||
const usage = item._getUsageUpdates({consumeRecharge, consumeResource, consumePowerSlot, consumeUsage, consumeQuantity});
|
||||
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;
|
||||
}
|
||||
if ( !usage ) return;
|
||||
|
||||
const {actorUpdates, itemUpdates, resourceUpdates} = usage;
|
||||
|
||||
// Commit pending data updates
|
||||
|
@ -558,14 +529,47 @@ export default class Item5e extends Item {
|
|||
// Consume Power Slots
|
||||
if ( consumePowerSlot ) {
|
||||
const level = this.actor?.data.data.powers[consumePowerSlot];
|
||||
const powers = Number(level?.value ?? 0);
|
||||
if ( powers === 0 ) {
|
||||
const label = game.i18n.localize(`SW5E.PowerLevel${id.level}`);
|
||||
ui.notifications.warn(game.i18n.format("SW5E.PowerCastNoSlots", {name: this.name, level: label}));
|
||||
return false;
|
||||
const fp = this.actor.data.data.attributes.force.points;
|
||||
const tp = this.actor.data.data.attributes.tech.points;
|
||||
const powerCost = level + 1;
|
||||
switch (id.school){
|
||||
case "lgt":
|
||||
case "uni":
|
||||
case "drk": {
|
||||
const powers = Number(level?.fvalue ?? 0);
|
||||
if ( powers === 0 ) {
|
||||
const label = game.i18n.localize(`SW5E.PowerLevel${id.level}`);
|
||||
ui.notifications.warn(game.i18n.format("SW5E.PowerCastNoSlots", {name: this.name, level: label}));
|
||||
return false;
|
||||
}
|
||||
actorUpdates[`data.powers.${consumePowerSlot}.fvalue`] = Math.max(powers - 1, 0);
|
||||
if (fp.temp >= powerCost) {
|
||||
actorUpdates["data.attributes.force.points.temp"] = fp.temp - powerCost;
|
||||
}else{
|
||||
actorUpdates["data.attributes.force.points.value"] = fp.value + fp.temp - powerCost;
|
||||
actorUpdates["data.attributes.force.points.temp"] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "tec": {
|
||||
const powers = Number(level?.tvalue ?? 0);
|
||||
if ( powers === 0 ) {
|
||||
const label = game.i18n.localize(`SW5E.PowerLevel${id.level}`);
|
||||
ui.notifications.warn(game.i18n.format("SW5E.PowerCastNoSlots", {name: this.name, level: label}));
|
||||
return false;
|
||||
}
|
||||
actorUpdates[`data.powers.${consumePowerSlot}.tvalue`] = Math.max(powers - 1, 0);
|
||||
if (tp.temp >= powerCost) {
|
||||
actorUpdates["data.attributes.force.points.temp"] = tp.temp - powerCost;
|
||||
}else{
|
||||
actorUpdates["data.attributes.force.points.value"] = tp.value + tp.temp - powerCost;
|
||||
actorUpdates["data.attributes.force.points.temp"] = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
actorUpdates[`data.powers.${consumePowerSlot}.value`] = Math.max(powers - 1, 0);
|
||||
}
|
||||
|
||||
|
||||
// Consume Limited Usage
|
||||
if ( consumeUsage ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue