Skip to content

Commit

Permalink
Merge pull request #147 from Savantford/experimental
Browse files Browse the repository at this point in the history
3.1.1: Char Options Fixes & Health Changes
  • Loading branch information
Savantford committed Feb 20, 2024
2 parents f7f93d5 + df1c72e commit 1bff913
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 192 deletions.
1 change: 0 additions & 1 deletion assets/icons/targeted-grey.svg

This file was deleted.

File renamed without changes
2 changes: 2 additions & 0 deletions lang/en.json
Expand Up @@ -200,6 +200,8 @@
"Size": "Size # Area",
"Spread": "Spread from Central Point (BROKEN)",
"MeasuredUnit": "yard(s)",
"Targets": "Targets",
"Target": "Target",
"Dialog": {
"SelectTargets": "Please select one or more tokens to target.",
"Confirm": "Confirm Targets and Continue",
Expand Down
2 changes: 1 addition & 1 deletion module/chat/chat-html-templates.mjs
Expand Up @@ -9,7 +9,7 @@ export async function diceTotalHtml(roll) {
export function targetHeader(target, html, noItem) {
if ((target.id === undefined) || noItem) return (html ? html : '');

else return `<p class="owner-only chat-target">${i18n('WW.Target')}: ${target.name}</p><p class="non-owner-only chat-target">${i18n('WW.Target')}: ???</p><div class="chat-target-content">${html}</div>`;
else return `<p class="owner-only chat-target">${i18n('WW.Targeting.Target')}: ${target.name}</p><p class="non-owner-only chat-target">${i18n('WW.Targeting.Target')}: ???</p><div class="chat-target-content">${html}</div>`;
}

// Prepare html header for a target
Expand Down
4 changes: 2 additions & 2 deletions module/chat/chat-listeners.mjs
Expand Up @@ -138,7 +138,7 @@ function _onMessageButtonContext(element) {
game.combat?.combatants.forEach(c => {
const actor = c.actor;

if (actor.testUserPermission(user, "OBSERVER") && (!menuItems.find(o => o.uuid === actor.uuid))) menuItems.push({
if (actor && actor.testUserPermission(user, "OBSERVER") && (!menuItems.find(o => o.uuid === actor.uuid))) menuItems.push({
name: actor.name,
icon: iconToHTML(actor.img, actor.uuid),
group: 'combatants',
Expand All @@ -152,7 +152,7 @@ function _onMessageButtonContext(element) {
for (const id in game.actors.tokens) {
const actor = game.actors.tokens[id];

if (actor.testUserPermission(user, "OBSERVER") && (!menuItems.find(o => o.uuid === actor.uuid))) menuItems.push({
if (actor && actor.testUserPermission(user, "OBSERVER") && (!menuItems.find(o => o.uuid === actor.uuid))) menuItems.push({
name: actor.name,
icon: iconToHTML(actor.img, actor.uuid),
group: 'tokens',
Expand Down
22 changes: 8 additions & 14 deletions module/data/actors/common.mjs
Expand Up @@ -185,22 +185,16 @@ function makeDefense(type) {

function makeHealth(type) {

if (type == 'Character') { return new fields.SchemaField({
current: makeIntField(),
normal: makeIntField(),
starting: makeIntField(10),
novice: makeIntField(),
expert: makeIntField(),
master: makeIntField(),
lost: makeIntField(),
bonus: makeIntField()
})}

else if (type == 'NPC') return new fields.SchemaField({
if (type == 'Character') {
return new fields.SchemaField({
current: makeIntField(),
normal: makeIntField(),
lost: makeIntField()
})
} else if (type == 'NPC') return new fields.SchemaField({
current: makeIntField(),
normal: makeIntField(10),
lost: makeIntField(),
bonus: makeIntField()
lost: makeIntField()
})

else return {}
Expand Down
13 changes: 6 additions & 7 deletions module/dice/roll-attribute.mjs
Expand Up @@ -130,7 +130,7 @@ export default class RollAttribute extends FormApplication {
for (const t of this.targets) {

// Set boons text
const boonsNo = parseInt(boonsFinal) + t.boonsAgainst[against];
const boonsNo = parseInt(boonsFinal) + (t.boonsAgainst ? t.boonsAgainst[against] : 0);
if (boonsNo != 0) { boons = (boonsNo < 0 ? "" : "+") + boonsNo + "d6kh" } else { boons = ""; };

// Determine the rollFormula
Expand Down Expand Up @@ -429,7 +429,7 @@ export default class RollAttribute extends FormApplication {
let targetsDisplay = '';

context.targets.forEach(t => {
const boonsNo = t.boonsAgainst[against];
const boonsNo = t.boonsagainst ? t.boonsAgainst[against] : 0;

targetsDisplay += '<p>' + t.name;

Expand Down Expand Up @@ -539,12 +539,11 @@ export default class RollAttribute extends FormApplication {

// Add htmls to finalHtml
if (options.singleRoll) {
console.log('chegou no single')
if (anyHtml) finalHtml += buttonsHeader(anyHtml, 'Any', !this.item);
if (enemiesHtml) finalHtml += buttonsHeader(enemiesHtml, 'Enemies', !this.item);
if (alliesHtml) finalHtml += buttonsHeader(alliesHtml, 'Allies', !this.item);

} else {
console.log('chegou no multi')
finalHtml += '<div class="chat-buttons">';
if (anyHtml) finalHtml += anyHtml;
if (enemiesHtml) finalHtml += enemiesHtml;
Expand Down Expand Up @@ -578,9 +577,9 @@ export default class RollAttribute extends FormApplication {
targets.push({
id: t.id,
name: t.document.name,
attributes: t.document.actor.system.attributes,
defense: t.document.actor.system.stats.defense.total,
boonsAgainst: t.document.actor.system.boons.against
attributes: t.document.actor?.system.attributes,
defense: t.document.actor?.system.stats.defense.total,
boonsAgainst: t.document.actor?.system.boons.against
})
});

Expand Down
12 changes: 2 additions & 10 deletions module/documents/active-effect.mjs
Expand Up @@ -33,8 +33,6 @@ export default class WWActiveEffect extends ActiveEffect {
async _onUpdate(data, options, userId) {
super._onUpdate(data, options, userId);

// If benefits were changed
console.log('preparing effect data')
}

/* -------------------------------------------- */
Expand Down Expand Up @@ -203,11 +201,11 @@ export default class WWActiveEffect extends ActiveEffect {
*/

apply(actor, change) {

// Save label key and get real change key
const labelKey = change.key;
change.key = CONFIG.WW.EFFECT_CHANGE_KEYS[change.key];

// Determine the data type of the target field
const current = foundry.utils.getProperty(actor, change.key) ?? null;

Expand All @@ -221,12 +219,6 @@ export default class WWActiveEffect extends ActiveEffect {
// Alter Change Values to negative values if they are meant to be
if (labelKey.includes('banes') || (labelKey.includes('Reduce') && !labelKey.includes('health'))) change.value = -change.value;

// Fix modes automatically according to the label key
if (labelKey === 'speed.normal') {
change.mode = 5;
change.priority = 1;
}

// Cast the effect change value to the correct type
let delta;
try {
Expand Down
13 changes: 6 additions & 7 deletions module/documents/actor.mjs
Expand Up @@ -41,6 +41,9 @@ export default class WWActor extends Actor {
}
};

// Create bonus Health
this.system.stats.health.bonus = 0;

// Create objects
this.system.autoFail = {};
this.system.against = {};
Expand Down Expand Up @@ -154,9 +157,7 @@ export default class WWActor extends Actor {
if (changed.system?.stats?.level) {

for (const i of this.items) {

if (i.charOption) i.updateBenefitsOnActor();

}

}
Expand Down Expand Up @@ -322,8 +323,6 @@ export default class WWActor extends Actor {

/* Apply Affliction */
async applyAffliction(key) {

console.log(key)

// Get affliction
const effect = CONFIG.statusEffects.find(a => a.id === key);
Expand Down Expand Up @@ -388,14 +387,14 @@ export default class WWActor extends Actor {
_calculateHealth(system) {
const health = system.stats.health;
const level = system.stats.level;

// Health override effect exists
if (health.override) {
health.normal = health.override;
} else {

// If Character, calculate normal Health from Paths
if (this.type === 'Character') {
/*if (this.type === 'Character') {
function count(levels) { // Count how many of provided levels the Character has
let newValue = 0;
Expand All @@ -420,7 +419,7 @@ export default class WWActor extends Actor {
// Calculate normal Health
health.normal = health.starting + noviceBonus + expertBonus + masterBonus;
}
}*/

// Assign current health
health.current = health.normal + health.bonus - health.lost;
Expand Down
93 changes: 61 additions & 32 deletions module/documents/item.mjs
Expand Up @@ -243,37 +243,51 @@ export default class WWItem extends Item {

if (stats.naturalIncrease) changes.push({
key: 'defense.naturalIncrease',
value: stats.naturalIncrease
value: stats.naturalIncrease,
mode: 2,
priority: null
})

if (stats.armoredIncrease) changes.push({
key: 'defense.armoredIncrease',
value: stats.armoredIncrease
value: stats.armoredIncrease,
mode: 2,
priority: null
})

if (stats.healthIncrease) changes.push({
key: 'health.increase',
value: stats.healthIncrease
value: stats.healthIncrease,
mode: 2,
priority: null
})

if (stats.sizeNormal) changes.push({
key: 'size.normal',
value: stats.sizeNormal
value: stats.sizeNormal,
mode: 4,
priority: 1
})

if (stats.speedNormal) changes.push({
key: 'speed.normal',
value: stats.speedNormal
value: stats.speedNormal,
mode: 4,
priority: 1
})

if (stats.speedIncrease) changes.push({
key: 'speed.increase',
value: stats.speedIncrease
value: stats.speedIncrease,
mode: 2,
priority: null
})

if (stats.bonusDamage) changes.push({
key: 'bonusDamage.increase',
value: stats.bonusDamage
value: stats.bonusDamage,
mode: 2,
priority: null
})

// Create effect data object
Expand Down Expand Up @@ -354,26 +368,34 @@ export default class WWItem extends Item {

// Return if no actor exists
if (!this.actor) return;

const benefits = this.system.benefits;
const level = this.actor.system.stats.level;

// Get actor list entries granted by the character option
const aDetails = {
senses: this.actor.system.details.senses.filter(i => {
const filteredDetails = {
types: await this.actor.system.details.types.filter(i => {
return i.grantedBy === this._id;
}),
languages: this.actor.system.details.languages.filter(i => {
senses: await this.actor.system.details.senses.filter(i => {
return i.grantedBy === this._id;
}),
immune: this.actor.system.details.immune.filter(i => {
languages: await this.actor.system.details.languages.filter(i => {
return i.grantedBy === this._id;
}),
traditions: this.actor.system.details.traditions.filter(i => {
immune: await this.actor.system.details.immune.filter(i => {
return i.grantedBy === this._id;
}),
traditions: await this.actor.system.details.traditions.filter(i => {
return i.grantedBy === this._id;
})
}


// Shortcuts
const benefits = this.system.benefits;
const level = this.actor.system.stats.level;

// Create newDetails to store data
const newDetails = {};

// Loop through each benefit
for (const b in benefits) {

const benefit = benefits[b];
Expand All @@ -382,35 +404,42 @@ export default class WWItem extends Item {
// If level does not meet the requirement, ignore it
if (level >= benefit.levelReq) {

if (benefit.senses) await benefit.senses.forEach(e => this._addEntry(aDetails, e, 'senses'));
if (benefit.types) this._addEntries(newDetails, filteredDetails, benefit, 'types');

if (benefit.senses) this._addEntries(newDetails, filteredDetails, benefit, 'senses');

if (benefit.languages) this._addEntries(newDetails, filteredDetails, benefit, 'languages');

if (benefit.languages) await benefit.languages.forEach(e => this._addEntry(aDetails, e, 'languages'));
if (benefit.immune) this._addEntries(newDetails, filteredDetails, benefit, 'immune');

if (benefit.immune) await benefit.immune.forEach(e => this._addEntry(aDetails, e, 'immune'));

if (benefit.traditions) await benefit.traditions.forEach(e => this._addEntry(aDetails, e, 'traditions'));
if (benefit.traditions) this._addEntries(newDetails, filteredDetails, benefit, 'traditions');

}

}

}
// Update actor with new details object
await this.actor.update({['system.details']: {...this.actor.system.details, ...newDetails} });

async _addEntry(actorDetails, entry, arrName) {
}

// If entry with the same name is not found, add it to the actor's entries list
if (!actorDetails[arrName].find(ae => ae.name === entry.name )) {
_addEntries(newDetails, filteredDetails, benefit, arrName) {
const arr = [...benefit[arrName]];

// Store the char option id on grantedBy
entry.grantedBy = this._id;
// For each entry
arr.forEach(entry => {

// Create new array
const arr = [...this.actor.system.details[arrName], entry];
if (!filteredDetails[arrName].find(ae => ae.name === entry.name )) {

// Store the char option id on grantedBy
entry.grantedBy = this._id;

}

// Update actor with new array
await this.actor.update({['system.details.' + arrName]: arr});
});

}
// Add entries to newDetails object
newDetails[arrName] = newDetails[arrName] ? newDetails[arrName].concat(arr) : arr;

}

Expand Down
5 changes: 0 additions & 5 deletions module/sheets/actor-sheet.mjs
Expand Up @@ -367,11 +367,6 @@ export default class WWActorSheet extends ActorSheet {

// Input resize
resizeInput(html);

// Edit Health button
html.find('.health-edit').click(ev => {
new healthDetails(this.actor).render(true)
});

// Rest button dialog + function
html.find('.rest-button').click(this._onRest.bind(this));
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packs/armor/CURRENT
@@ -1 +1 @@
MANIFEST-000502
MANIFEST-000504
6 changes: 3 additions & 3 deletions packs/armor/LOG
@@ -1,3 +1,3 @@
2024/02/19-15:51:57.421 694 Recovering log #500
2024/02/19-15:51:57.426 694 Delete type=0 #500
2024/02/19-15:51:57.426 694 Delete type=3 #498
2024/02/20-15:20:16.604 2784 Recovering log #503
2024/02/20-15:20:16.608 2784 Delete type=0 #503
2024/02/20-15:20:16.608 2784 Delete type=3 #502

0 comments on commit 1bff913

Please sign in to comment.