From 260382d44717d1b2a0b17f754240a9d0c3d90470 Mon Sep 17 00:00:00 2001 From: kandashi Date: Tue, 23 Feb 2021 22:59:25 +0000 Subject: [PATCH] vehicle fixes, alignemnts/type fixes, wall fixes --- module.json | 2 +- src/aura.js | 68 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/module.json b/module.json index d8c61ea..5b61878 100644 --- a/module.json +++ b/module.json @@ -3,7 +3,7 @@ "title": "Active-Auras", "description": "Active-Auras", "author": "Kandashi", - "version": "0.1.45", + "version": "0.1.46", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", "packs": [ diff --git a/src/aura.js b/src/aura.js index f511bdb..b29169e 100644 --- a/src/aura.js +++ b/src/aura.js @@ -126,7 +126,7 @@ Hooks.on("ready", () => {
- +
@@ -153,16 +153,21 @@ Hooks.on("ready", () => { */ Hooks.on("createToken", (_scene, token) => { let actor = game.actors.get(token.actorId) - if (actor.effects?.entries) { - for (let effect of actor.effects?.entries) { - if (effect.getFlag('ActiveAuras', 'isAura')) { - setTimeout(() => { - if (debug) console.log("createToken, collate auras true false") - CollateAuras(canvas, true, false, "createToken") - }, 20) - break; + try { + if (actor.effects?.entries) { + for (let effect of actor.effects?.entries) { + if (effect.getFlag('ActiveAuras', 'isAura')) { + setTimeout(() => { + if (debug) console.log("createToken, collate auras true false") + CollateAuras(canvas, true, false, "createToken") + }, 20) + break; + } } } + } catch (error) { + if (error.message === "Cannot read property 'effects' of null") + console.error(token, `This token has a no actor linked to it, please cleanup this token`) } }); @@ -303,6 +308,7 @@ Hooks.on("ready", () => { function IsAuraToken(token, canvas) { let MapKey = canvas.scene._id; MapObject = AuraMap.get(MapKey); + if (!MapObject.effects) return; for (let effect of MapObject.effects) { if (effect.tokenId === token._id) return true; @@ -444,7 +450,7 @@ Hooks.on("ready", () => { } - + /** * Test individual token against aura array * @param {Map} map - empty map to populate @@ -456,18 +462,41 @@ Hooks.on("ready", () => { if (GetAllFlags(canvasToken, 'multilevel-tokens')) return; } if (canvasToken.actor === null) return; + let tokenType; switch (canvasToken.actor.data.type) { - case "npc": - tokenType = canvasToken.actor?.data.data.details.type.toLowerCase(); + case "npc": { + try { + tokenType = canvasToken.actor?.data.data.details.type.toLowerCase(); + } catch (error) { + console.error([`ActiveAuras the token has an unreadable type`, canvasToken]) + } + } break; - case "character": - tokenType = canvasToken.actor?.data.data.details.race.toLowerCase() + case "character": { + try { + tokenType = canvasToken.actor?.data.data.details.race.toLowerCase() + } catch (error) { + console.error([`ActiveAuras the token has an unreadable type`, canvasToken]) + } + } break; + case "vehicle": return; + } + tokenType = tokenType.split(" "); + let humanoidRaces = ["human", "orc", "elf", "tiefling", "gnome", "aaracokra", "dragonborn", "dwarf", "halfling", "leonin", "satyr", "genasi", "goliath", "aasimar", "bugbear", "firbolg", "goblin", "lizardfolk", "tabxi", "triton", "yuan-ti", "tortle", "changling", "kalashtar", "shifter", "warforged", "gith", "centaur", "loxodon", "minotaur", "simic hybrid", "vedalken", "verdan", "locathah", "grung"] + for (x of tokenType) { + if (humanoidRaces.includes(x)) { + tokenType = "humanoid" + continue; + } } - let humanoidRaces = ["human", "orc", "half orc", "elf", "half elf", "tiefling", "gnome", "aaracokra", "dragonborn", "dwarf", "halfing", "leonin", "satyr", "genasi", "goliath", "aasimar", "bugbear", "firbolg", "goblin", "lizardfolk", "tabxi", "triton", "yuan-ti", "tortle", "changling", "kalashtar", "shifter", "warforged", "gith", "centaur", "loxodon", "minotaur", "simic hybrid", "vedalken", "verdan", "locathah", "grung"] - if (humanoidRaces.includes(tokenType)) tokenType = "humanoid" - let tokenAlignment = canvasToken.actor?.data.data.details.alignment.toLowerCase(); + let tokenAlignment; + try { + tokenAlignment = canvasToken.actor?.data.data.details.alignment.toLowerCase(); + } catch (error) { + console.error([`ActiveAuras the token has an unreadable alignment`, canvasToken]) + } let MapKey = canvasToken.scene._id; MapObject = AuraMap.get(MapKey) let checkEffects = MapObject.effects; @@ -528,6 +557,7 @@ Hooks.on("ready", () => { } + function getDistance(t1, t2, wallblocking = false, auraHeight) { //Log("get distance callsed"); var x, x1, y, y1, d, r, segments = [], rdistance, distance; @@ -552,7 +582,7 @@ Hooks.on("ready", () => { // console.log(segments); if (segments.length === 0) { //Log(`${t2.data.name} full blocked by walls`); - return -1; + return false; } rdistance = canvas.grid.measureDistances(segments, { gridSpaces: true }); distance = rdistance[0]; @@ -579,7 +609,7 @@ Hooks.on("ready", () => { } if (segments.length === 0) { //Log(`${t2.data.name} full blocked by walls`); - return -1; + return false; } rdistance = [] segments.forEach(i => rdistance.push(i.ray.distance / gs * canvas.dimensions.distance))