Added short and long rest and Temp points

Updated Force and Tech Points on Short and Long Rests along with Temporary points.

Also added class powercasting to migration
This commit is contained in:
supervj 2021-02-09 02:14:10 -05:00
parent 932c96ba4a
commit b5ecde7f0c
5 changed files with 105 additions and 24 deletions

View file

@ -588,10 +588,23 @@
"SW5E.LongRestGritty": "Long Rest (7 days)",
"SW5E.LongRestEpic": "Long Rest (1 hour)",
"SW5E.LongRestOvernight": "Long Rest (New Day)",
"SW5E.LongRestResult": "{name} takes a long rest and recovers {health} Hit Points and {dice} Hit Dice.",
"SW5E.LongRestResultHitDice": "{name} takes a long rest and recovers {dice} Hit Dice.",
"SW5E.LongRestResultHitPoints": "{name} takes a long rest and recovers {health} Hit Points.",
"SW5E.LongRestResultShort": "{name} takes a long rest.",
"SW5E.LongRestResult": "{name} takes a long rest.",
"SW5E.LongRestResultFP": "{name} takes a long rest and recovers {force} Force Points.",
"SW5E.LongRestResultFPHD": "{name} takes a long rest and recovers {force} Force Points and {dice} Hit Dice.",
"SW5E.LongRestResultFPTP": "{name} takes a long rest and recovers {force} Force Points and {tech} Tech Points.",
"SW5E.LongRestResultFPTPHD": "{name} takes a long rest and recovers {force} Force Points, {tech} Tech Points and {dice} Hit Dice.",
"SW5E.LongRestResultHD": "{name} takes a long rest and recovers {dice} Hit Dice.",
"SW5E.LongRestResultHP": "{name} takes a long rest and recovers {health} Hit Points.",
"SW5E.LongRestResultHPFP": "{name} takes a long rest and recovers {health} Hit Points and {force} Force Points.",
"SW5E.LongRestResultHPHD": "{name} takes a long rest and recovers {health} Hit Points and {dice} Hit Dice.",
"SW5E.LongRestResultHPTP": "{name} takes a long rest and recovers {health} Hit Points and {tech} Tech Points.",
"SW5E.LongRestResultHPFPHD": "{name} takes a long rest and recovers {health} Hit Points, {force} Force Points, and {dice} Hit Dice.",
"SW5E.LongRestResultHPFPTP": "{name} takes a long rest and recovers {health} Hit Points, {force} Force Points and {tech} Tech Points.",
"SW5E.LongRestResultHPTPHD": "{name} takes a long rest and recovers {health} Hit Points, {tech} Tech Points, and {dice} Hit Dice.",
"SW5E.LongRestResultHPFPTPHD": "{name} takes a long rest and recovers {health} Hit Points, {force} Force Points, {tech} Tech Points and {dice} Hit Dice.",
"SW5E.LongRestResultTP": "{name} takes a long rest and recovers {tech} Tech Points.",
"SW5E.LongRestResultTPHD": "{name} takes a long rest and recovers {tech} Tech Points and {dice} Hit Dice.",
"SW5E.Max": "Max",
"SW5E.Modifier": "Modifier",
"SW5E.Name": "Character Name",
@ -699,6 +712,8 @@
"SW5E.ShortRestHint": "Take a short rest? On a short rest you may spend remaining Hit Dice and recover primary or secondary resources.",
"SW5E.ShortRestNoHD": "No Hit Dice remaining",
"SW5E.ShortRestResult": "{name} takes a short rest spending {dice} Hit Dice to recover {health} Hit Points.",
"SW5E.ShortRestResultWithTech": "{name} takes a short rest spending {dice} Hit Dice to recover {health} Hit Points and {tech} Tech Points.",
"SW5E.ShortRestResultOnlyTech": "{name} takes a short rest to recover {tech} Tech Points.",
"SW5E.ShortRestResultShort": "{name} takes a short rest.",
"SW5E.ShortRestSelect": "Select Dice to Roll",
"SW5E.Size": "Size",

View file

@ -1086,7 +1086,7 @@ export default class Actor5e extends Actor {
/* -------------------------------------------- */
/**
* Cause this Actor to take a Short Rest
* Cause this Actor to take a Short Rest and regain all Tech Points
* During a Short Rest resources and limited item uses may be recovered
* @param {boolean} dialog Present a dialog window which allows for rolling hit dice as part of the Short Rest
* @param {boolean} chat Summarize the results of the rest workflow as a chat message
@ -1119,10 +1119,16 @@ export default class Actor5e extends Actor {
}
}
// Note the change in HP and HD which occurred
// Note the change in HP and HD and TP which occurred
const dhd = this.data.data.attributes.hd - hd0;
const dhp = this.data.data.attributes.hp.value - hp0;
const dtp = this.data.data.attributes.tech.points.max - this.data.data.attributes.tech.points.value;
// Automatically Retore Tech Points
this.update({"data.attributes.tech.points.value": this.data.data.attributes.tech.points.max});
// Recover character resources
const updateData = {};
for ( let [k, r] of Object.entries(this.data.data.resources) ) {
@ -1155,14 +1161,24 @@ export default class Actor5e extends Actor {
// Summarize the health effects
let srMessage = "SW5E.ShortRestResultShort";
if ((dhd !== 0) && (dhp !== 0)) srMessage = "SW5E.ShortRestResult";
if ((dhd !== 0) && (dhp !== 0)){
if (dtp !== 0){
srMessage = "SW5E.ShortRestResultWithTech";
}else{
srMessage = "SW5E.ShortRestResult";
}
}else{
if (dtp !== 0){
srMessage = "SW5E.ShortRestResultOnlyTech";
}
}
// Create a chat message
ChatMessage.create({
user: game.user._id,
speaker: {actor: this, alias: this.name},
flavor: restFlavor,
content: game.i18n.format(srMessage, {name: this.name, dice: -dhd, health: dhp})
content: game.i18n.format(srMessage, {name: this.name, dice: -dhd, health: dhp, tech: dtp})
});
}
@ -1170,6 +1186,7 @@ export default class Actor5e extends Actor {
return {
dhd: dhd,
dhp: dhp,
dtp: dtp,
updateData: updateData,
updateItems: updateItems,
newDay: newDay
@ -1179,7 +1196,7 @@ export default class Actor5e extends Actor {
/* -------------------------------------------- */
/**
* Take a long rest, recovering HP, HD, resources, and power slots
* Take a long rest, recovering HP, HD, resources, Force and Power points and power slots
* @param {boolean} dialog Present a confirmation dialog window whether or not to take a long rest
* @param {boolean} chat Summarize the results of the rest workflow as a chat message
* @param {boolean} newDay Whether the long rest carries over to a new day
@ -1197,12 +1214,20 @@ export default class Actor5e extends Actor {
}
}
// Recover hit points to full, and eliminate any existing temporary HP
// Recover hit, tech, and force points to full, and eliminate any existing temporary HP, TP, and FP
const dhp = data.attributes.hp.max - data.attributes.hp.value;
const dtp = data.attributes.tech.points.max - data.attributes.tech.points.value;
const dfp = data.attributes.force.points.max - data.attributes.force.points.value;
const updateData = {
"data.attributes.hp.value": data.attributes.hp.max,
"data.attributes.hp.temp": 0,
"data.attributes.hp.tempmax": 0
"data.attributes.hp.tempmax": 0,
"data.attributes.tech.points.value": data.attributes.tech.points.max,
"data.attributes.tech.points.temp": 0,
"data.attributes.tech.points.tempmax": 0,
"data.attributes.force.points.value": data.attributes.force.points.max,
"data.attributes.force.points.temp": 0,
"data.attributes.force.points.tempmax": 0
};
// Recover character resources
@ -1263,15 +1288,16 @@ export default class Actor5e extends Actor {
// Determine the chat message to display
if ( chat ) {
let lrMessage = "SW5E.LongRestResultShort";
if((dhp !== 0) && (dhd !== 0)) lrMessage = "SW5E.LongRestResult";
else if ((dhp !== 0) && (dhd === 0)) lrMessage = "SW5E.LongRestResultHitPoints";
else if ((dhp === 0) && (dhd !== 0)) lrMessage = "SW5E.LongRestResultHitDice";
let lrMessage = "SW5E.LongRestResult";
if (dhp !== 0) lrMessage += "HP";
if (dfp !== 0) lrMessage += "FP";
if (dtp !== 0) lrMessage += "TP";
if (dhd !== 0) lrMessage += "HD";
ChatMessage.create({
user: game.user._id,
speaker: {actor: this, alias: this.name},
flavor: restFlavor,
content: game.i18n.format(lrMessage, {name: this.name, health: dhp, dice: dhd})
content: game.i18n.format(lrMessage, {name: this.name, health: dhp, tech: dtp, force: dfp, dice: dhd})
});
}
@ -1279,6 +1305,8 @@ export default class Actor5e extends Actor {
return {
dhd: dhd,
dhp: dhp,
dtp: dtp,
dfp: dfp,
updateData: updateData,
updateItems: updateItems,
newDay: newDay

View file

@ -192,6 +192,7 @@ function cleanActorData(actorData) {
*/
export const migrateItemData = function(item) {
const updateData = {};
_migrateItemClassPowerCasting(item, updateData)
_migrateItemAttunement(item, updateData);
return updateData;
};
@ -272,6 +273,8 @@ function _migrateActorPowers(actorData, updateData) {
updateData["data.attributes.force.points.value"] = 0;
updateData["data.attributes.force.points.min"] = 0;
updateData["data.attributes.force.points.max"] = 0;
updateData["data.attributes.force.points.temp"] = 0;
updateData["data.attributes.force.points.tempmax"] = 0;
updateData["data.attributes.force.level"] = 0;
updateData["data.attributes.tech.known.value"] = 0;
updateData["data.attributes.tech.known.min"] = 0;
@ -279,6 +282,8 @@ function _migrateActorPowers(actorData, updateData) {
updateData["data.attributes.tech.points.value"] = 0;
updateData["data.attributes.tech.points.min"] = 0;
updateData["data.attributes.tech.points.max"] = 0;
updateData["data.attributes.tech.points.temp"] = 0;
updateData["data.attributes.tech.points.tempmax"] = 0;
updateData["data.attributes.tech.level"] = 0;
}
// If new Bonus Power DC data is not present, create it
@ -333,6 +338,35 @@ function _migrateActorSenses(actor, updateData) {
return updateData;
}
/* -------------------------------------------- */
/**
* @private
*/
function _migrateItemClassPowerCasting(item, updateData) {
if (item.type === "class"){
switch (item.name){
case "Consular":
updateData["data.powercasting"] = "consular";
break;
case "Engineer":
updateData["data.powercasting"] = "engineer";
break;
case "Guardian":
updateData["data.powercasting"] = "guardian";
break;
case "Scout":
updateData["data.powercasting"] = "scout";
break;
case "Sentinel":
updateData["data.powercasting"] = "sentinel";
break;
}
}
return updateData;
}
/* -------------------------------------------- */
/**

12
sw5e.js
View file

@ -195,16 +195,16 @@ Hooks.once("ready", function() {
// Determine whether a system migration is required and feasible
if ( !game.user.isGM ) return;
const currentVersion = game.settings.get("sw5e", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = "1.2.1";
const NEEDS_MIGRATION_VERSION = "R1-A1";
const COMPATIBLE_MIGRATION_VERSION = 0.80;
const needsMigration = currentVersion && isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion);
if ( !needsMigration ) return;
//if ( !needsMigration ) return;
// Perform the migration
if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) {
const warning = `Your SW5e system data is from too old a Foundry version and cannot be reliably migrated to the latest version. The process will be attempted, but errors may occur.`;
ui.notifications.error(warning, {permanent: true});
}
//if ( currentVersion && isNewerVersion(COMPATIBLE_MIGRATION_VERSION, currentVersion) ) {
// const warning = `Your SW5e system data is from too old a Foundry version and cannot be reliably migrated to the latest version. The process will be attempted, but errors may occur.`;
// ui.notifications.error(warning, {permanent: true});
//}
migrations.migrateWorld();
});

View file

@ -103,7 +103,9 @@
"points": {
"value": 0,
"min": 0,
"max": 0
"max": 0,
"temp": 0,
"tempmax": 0
},
"level": 0
},
@ -116,7 +118,9 @@
"points": {
"value": 0,
"min": 0,
"max": 0
"max": 0,
"temp": 0,
"tempmax": 0
},
"level": 0
}