Skip to content

Commit

Permalink
Bugfixes and added so that attack traits can be toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
WBHarry committed Aug 24, 2024
1 parent ad2ab09 commit b04b18a
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
env:
version: ${{steps.get_version.outputs.version-without-v}}
url: https://github.com/${{github.repository}}
manifest: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.json
manifest: https://github.com/${{github.repository}}/releases/latest/download/module.json
download: https://github.com/${{github.repository}}/releases/download/${{github.event.release.tag_name}}/module.zip

# Create a zip file with all files required by the module to add to the release
Expand Down
85 changes: 58 additions & 27 deletions BestiaryTracking.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@
},
"Errors": {
"UnsupportedType": "Not a supported NPC type!",
"UnsupportedCharacterType": "Player Character are not supported in the bestiary.",
"UnsupportedCharacterType": "Player Characters are not supported in the bestiary.",
"DataMissing": "Some data is missing. You'll have to reimport the creature. Sorry about that!"
},
"Info": {
"GMOnly": "This is a GM only function."
"GMOnly": "This is a GM only function.",
"AddedToBestiary": "[{creatures}] were added to the Bestiary",
"AlreadyExistsInBestiary": "[{creatures}] already exists in the Bestiary."
}
},
"Menus": {
Expand Down
4 changes: 3 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@
"DataMissing": "Certaines données sont manquantes. Vous devrez réimporter la créature. Désolé pour cela !"
},
"Info": {
"GMOnly": "Cette fonction est réservée au MJ."
"GMOnly": "Cette fonction est réservée au MJ.",
"AddedToBestiary": "Added [{creatures}] to Bestiary",
"AlreadyExistsInBestiary": "[{creatures}] already exists in the Bestiary."
}
},
"Menus": {
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "pf2e-bestiary-tracking",
"title": "PF2E Bestiary Tracking",
"description": "A module to track known information about enemies for players in a bestiary.",
"version": "0.8.9.5.1",
"version": "0.8.9.6",
"authors": [
{
"name": "HarryBoy"
Expand Down
18 changes: 10 additions & 8 deletions module/bestiary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { getCreatureSize, getCreaturesTypes, getExpandedCreatureTypes, getIWRString, getMultiplesString, slugify } from "../scripts/helpers.js";
import { getBaseActor, getCreatureSize, getCreaturesTypes, getExpandedCreatureTypes, getIWRString, getMultiplesString, slugify } from "../scripts/helpers.js";
import { socketEvent } from "../scripts/socket.js";
import { acTable, attackTable, attributeTable, damageTable, hpTable, savingThrowPerceptionTable, skillTable, spellAttackTable, spellDCTable } from "../scripts/statisticsData.js";
import { getCategoryFromIntervals, getCategoryLabel, getCategoryRange, getMixedCategoryLabel, getRollAverage, getWeaknessCategoryClass } from "../scripts/statisticsHelper.js";
Expand Down Expand Up @@ -405,8 +405,8 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
return acc;
}, { revealed: false, values: {} }),
traits: action.traits.map(trait => ({
label: trait.label,
description: trait.description,
...trait,
revealed: detailedInformation.attackTraits ? trait.revealed : true,
})),
value: `${action.totalModifier >= 0 ? '+' : '-'} ${action.totalModifier}`,
...attackParts,
Expand Down Expand Up @@ -1209,13 +1209,13 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
}

static async addMonster(item){
const monster = await PF2EBestiary.getMonsterData(item.token.document ? item.token.document.baseActor : item.token.baseActor);
if (!monster) return;
const monster = await PF2EBestiary.getMonsterData(getBaseActor(item));
if (!monster) return null;

const bestiary = await game.settings.get('pf2e-bestiary-tracking', 'bestiary-tracking');

// We do not currently refresh already present creatures in the Bestiary.
if(bestiary.monster[monster.uuid]) return;
if(bestiary.monster[monster.uuid]) return false;

bestiary.monster[monster.uuid] = monster;

Expand All @@ -1235,10 +1235,12 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
});

Hooks.callAll(socketEvent.UpdateBestiary, {});

return true;
}

static async getMonsterData(item){
if(!item || item.type !== 'npc') return null;
if(!item || item.hasPlayerOwner || item.type !== 'npc') return null;

const dataObject = item.toObject(false);
dataObject.uuid = item.uuid;
Expand Down Expand Up @@ -1393,7 +1395,7 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
const data = TextEditor.getDragEventData(event);
const baseItem = await fromUuid(data.uuid);

if(baseItem?.type === 'character'){
if(baseItem?.type === 'character' || baseItem.hasPlayerOwner){
ui.notifications.error(game.i18n.localize("PF2EBestiary.Bestiary.Errors.UnsupportedCharacterType"));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion module/bestiaryAppearanceMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(A
useTokenArt: data.useTokenArt,
contrastRevealedState: data.contrastRevealedState,
optionalFields: data.optionalFields,
detailedInformation: { ...data.detailedInformation, attackTraits: false }
detailedInformation: { ...data.detailedInformation }
};
this.render();
}
Expand Down
45 changes: 33 additions & 12 deletions pf2e-bestiary-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { registerGameSettings } from "./scripts/setup.js";
import { handleSocketEvent, socketEvent } from "./scripts/socket.js";
import * as macros from "./scripts/macros.js";
import { handleDataMigration } from "./scripts/migrationHandler.js";
import { getBaseActor } from "./scripts/helpers.js";

Hooks.once('init', () => {
registerGameSettings();
Expand Down Expand Up @@ -56,14 +57,27 @@ Hooks.once("setup", () => {
});

Hooks.on("combatStart", async (encounter) => {
if(game.user.isGM){
if (game.user.isGM) {
const added = [];
const exists = [];
const automaticCombatSetting = await game.settings.get('pf2e-bestiary-tracking', 'automatic-combat-registration');
if(automaticCombatSetting === 1){
for(var combatant of encounter.combatants){
await PF2EBestiary.addMonster(combatant.actor);
}

if (automaticCombatSetting === 1) {
for (var combatant of encounter.combatants.filter(combatant => combatant?.actor?.type === 'npc')) {
const successful = await PF2EBestiary.addMonster(combatant.actor);
if (successful && combatant?.actor?.name) {
added.push(combatant.actor.name);
}
else if (successful === false && combatant?.actor?.name){
exists.push(combatant.actor.name);
}
}

exists?.length && ui.notifications.info(game.i18n.format('PF2EBestiary.Bestiary.Info.AlreadyExistsInBestiary', { creatures: exists.join(', ') }));
added?.length && ui.notifications.info(game.i18n.format('PF2EBestiary.Bestiary.Info.AddedToBestiary', { creatures: added.join(', ') }));
}
}

});

Hooks.on("updateCombatant", async (combatant, changes) => {
Expand Down Expand Up @@ -94,14 +108,14 @@ Hooks.on("xdy-pf2e-workbench.tokenCreateMystification", token => {
});

Hooks.on("preCreateToken", async token => {
if(!game.user.isGM) return;
if(!game.user.isGM || token.actor.type !== 'npc' || token.hasPlayerOwner) return;

if(game.settings.get('pf2e-bestiary-tracking', 'hide-token-names')){
const bestiary = game.settings.get('pf2e-bestiary-tracking', 'bestiary-tracking');
const monster = bestiary.monster[token.baseActor.uuid];
if(monster){
if(monster.name.custom && monster.name.revealed) {
await token.updateSource({ name: monster.name.custom });
if(monster.name.revealed) {
await token.updateSource({ name: monster.name.custom ? monster.name.custom : monster.name.value });
return;
}
}
Expand Down Expand Up @@ -134,14 +148,16 @@ Hooks.on("createChatMessage", async (message) => {
const { automaticReveal } = game.settings.get('pf2e-bestiary-tracking', 'chat-message-handling');
if(automaticReveal){
const bestiary = game.settings.get('pf2e-bestiary-tracking', 'bestiary-tracking');
const { automaticReveal } = game.settings.get('pf2e-bestiary-tracking', 'chat-message-handling');

if(message.flags.pf2e.origin){
// Attacks | Actions | Spells
const actorUuid = message.flags.pf2e.origin.actor;
const actor = await fromUuid(message.flags.pf2e.origin.actor);
if(actor.type !== 'npc' || actor.hasPlayerOwner) return;

const actorUuid = getBaseActor(actor).uuid;
const monster = bestiary.monster[actorUuid];
const item = await fromUuid(message.flags.pf2e.origin.uuid);

const item = await fromUuid(message.flags.pf2e.origin.uuid);
if(monster && item){
if(message.flags.pf2e.modifierName && automaticReveal.attacks){
const monsterItem = monster.system.actions[item.id];
Expand All @@ -162,7 +178,12 @@ Hooks.on("createChatMessage", async (message) => {
}
else {
// Skills | Saving Throws
const monster = bestiary.monster[`Actor.${message.flags.pf2e.context.actor}`];
const actor = await fromUuid(`Actor.${message.flags.pf2e.context.actor}`);
if(actor.type !== 'npc' || actor.hasPlayerOwner) return;

const actorUuid = getBaseActor(actor).uuid;
const monster = bestiary.monster[actorUuid];

if(monster){
if(message.flags.pf2e.context.type === 'skill-check' && automaticReveal.skills)
{
Expand Down
Loading

0 comments on commit b04b18a

Please sign in to comment.