Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
0.92.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Rughalt committed May 6, 2021
1 parent 012b341 commit e0fd7b7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
18 changes: 14 additions & 4 deletions D35E.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions changelogs/changelog.0.92.5.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 27 additions & 9 deletions module/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion module/actor/sheets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions module/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
})
Expand Down Expand Up @@ -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`
})
Expand Down
2 changes: 1 addition & 1 deletion system.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down

0 comments on commit e0fd7b7

Please sign in to comment.