diff --git a/D35E.js b/D35E.js index d89c0456..3bf61733 100644 --- a/D35E.js +++ b/D35E.js @@ -99,11 +99,11 @@ Hooks.once("init", async function() { D35ELayer.registerLayer(); + // Patch Core Functions + PatchCore(); // Preload Handlebars Templates await preloadHandlebarsTemplates(); applyConfigModifications(); - // Patch Core Functions - PatchCore(); // Register sheet application classes Actors.unregisterSheet("core", ActorSheet); @@ -205,10 +205,20 @@ Hooks.once("ready", async function() { TopPortraitBar.render(game.actors.get(key)) } + let updateRequestArray = [] + const interval = setInterval(function() { - game.actors.entities.filter(obj => obj.hasPerm(game.user, "OWNER") && obj.data.data.companionUuid).forEach(a => { + if (updateRequestArray.length === 0) { + game.actors.entities.filter(obj => obj.hasPerm(game.user, "OWNER") && obj.data.data.companionUuid && obj.canAskForRequest).forEach(a => { + updateRequestArray.push(a); + }); + } + }, 1000); + + const actionRequestInterval = setInterval(function() { + let a = updateRequestArray.shift(); + if (a) a.getQueuedActions(); - }); }, 500); if (!game.user.isGM) { diff --git a/changelogs/changelog.0.92.5.md b/changelogs/changelog.0.92.5.md new file mode 100644 index 00000000..3361b722 --- /dev/null +++ b/changelogs/changelog.0.92.5.md @@ -0,0 +1,6 @@ +### All changes +- Limited amount of calls system does to Companion +- Added feedback for manual Companion sync +- Fixed web addresses in tokens used for shapechange causing errors +- Fixed PV/libWrapper error +- [491](https://github.com/Rughalt/D35E/issues/491) - Bonus attacks from Rapid Shot and Haste are added at the top of the list. diff --git a/lang/en.json b/lang/en.json index c1587cbe..e06911c4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1429,6 +1429,9 @@ "D35E.NoBuffDisplay": "No Buff Icons on Actor Token", "D35E.NoBuffDisplayH": "Do not display buff icons on token for this actor for people other then OWNER and GM", + "D35E.NotificationSyncSuccessfull": "Manual sync to LotD Players Companion for {0} was successful!", + "D35E.NotificationSyncError": "Manual sync to LotD Players Companion for {0} encountered an error! Check Companion setup for both World and Character!", + "SETTINGS.D35EShowPartyHudN": "Party HUD type", "SETTINGS.D35EShowPartyHudL": "How to display party HUD", "SETTINGS.D35ECustomSkinN": "Use Custom Skin", diff --git a/module/actor/entity.js b/module/actor/entity.js index 52ef6a6f..c439ce9a 100644 --- a/module/actor/entity.js +++ b/module/actor/entity.js @@ -12,7 +12,8 @@ import {D35E} from "../config.js"; */ export class ActorPF extends Actor { /* -------------------------------------------- */ - API_URI = 'https://companion.legaciesofthedragon.com/'; + //API_URI = 'https://companion.legaciesofthedragon.com/'; + API_URI = 'http://localhost:5000'; static chatListeners(html) { html.on('click', 'button[data-action]', this._onChatCardButtonAction.bind(this)); @@ -5991,6 +5992,7 @@ export class ActorPF extends Actor { return; function isActionRollable(_action) { + if (_action.indexOf("://")) return false; return /^(.*?[0-9]d[0-9]+.*?)$/.test(_action) || _action.indexOf("max") !== -1 || _action.indexOf("min") !== -1 @@ -6816,11 +6818,12 @@ export class ActorPF extends Actor { }, {}); } - async syncToCompendium() { + async syncToCompendium(manual = false) { if (!this.data.data.companionUuid) return; let apiKey = game.settings.get("D35E", "apiKeyWorld") if (this.data.data.companionUsePersonalKey) apiKey = game.settings.get("D35E", "apiKeyPersonal") if (!apiKey) return; + let that = this; $.ajax({ url: `${this.API_URI}/api/character/${this.data.data.companionUuid}`, type: 'PUT', @@ -6830,23 +6833,38 @@ export class ActorPF extends Actor { contentType: 'application/json; charset=utf-8', data: JSON.stringify(this.data), success: function(data) { - //play with data + if (manual) { + ui.notifications.info(game.i18n.localize("D35E.NotificationSyncSuccessfull").format(that.data.name)); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + console.log(textStatus) + if (manual) { + ui.notifications.error(game.i18n.localize("D35E.NotificationSyncError").format(that.data.name)); + } } }); } - async getQueuedActions() { - if (!this.data.data.companionUuid) return; - let that = this; - let apiKey = game.settings.get("D35E", "apiKeyWorld") - if (this.data.data.companionUsePersonalKey) apiKey = game.settings.get("D35E", "apiKeyPersonal") + get canAskForRequest() { + if (!this.data.data.companionUuid) return false; let userWithCharacterIsActive = game.users.players.some(u => u.active && u.data.character === this.id) let isMyCharacter = game.users.current.data.character === this.id; // It is not ours character and user that has this character is active - so better direct commands to his/her account - if (!isMyCharacter && userWithCharacterIsActive) return; + if (!isMyCharacter && userWithCharacterIsActive) return false; + return true; + } + + async getQueuedActions() { + if (!this.canAskForRequest) return; + + let that = this; + let apiKey = game.settings.get("D35E", "apiKeyWorld") if (!apiKey) return; + + if (this.data.data.companionUsePersonalKey) apiKey = game.settings.get("D35E", "apiKeyPersonal") $.ajax({ url: `${this.API_URI}/api/character/actions/${this.data.data.companionUuid}`, type: 'GET', diff --git a/module/actor/sheets/base.js b/module/actor/sheets/base.js index 173a8efe..824921a1 100644 --- a/module/actor/sheets/base.js +++ b/module/actor/sheets/base.js @@ -767,7 +767,7 @@ export class ActorSheetPF extends ActorSheet { { $(`.sync-to-companion`).unbind( "mouseup" ); $(`.sync-to-companion`).mouseup(ev => { - this.actor.syncToCompendium() + this.actor.syncToCompendium(true) }); $(`.backup-to-companion`).unbind( "mouseup" ); $(`.backup-to-companion`).mouseup(async ev => { diff --git a/module/item/entity.js b/module/item/entity.js index 7edf900a..07a40081 100644 --- a/module/item/entity.js +++ b/module/item/entity.js @@ -1427,7 +1427,7 @@ export class ItemPF extends Item { } if ((fullAttack || actor.data.data.attributes.bab.total < 6) && rapidShot) { - allAttacks.push({ + allAttacks.unshift({ bonus: 0, label: `Rapid Shot` }) @@ -1462,7 +1462,7 @@ export class ItemPF extends Item { let isHasted = (this.actor?.items || []).filter(o => o.type === "buff" && o.data.data.active && (o.name === "Haste" || o.data.data.changeFlags.hasted)).length > 0; if ((fullAttack || actor.data.data.attributes.bab.total < 6) && isHasted && (getProperty(this.data, "data.attackType") === "weapon" || getProperty(this.data, "data.attackType") === "natural")) { - allAttacks.push({ + allAttacks.unshift({ bonus: 0, label: `Haste` }) diff --git a/system.json b/system.json index 879e9701..feace054 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "D35E", "title": "3.5e SRD", "description": "Implementation of 3.5 edition System Reference Document for Foundry VTT. Aiming to provide 100% SRD coverage.", - "version": "0.92.4", + "version": "0.92.5", "author": "Rughalt", "templateVersion": 2, "scripts": [],