Skip to content

Commit

Permalink
vehicle fixes, alignemnts/type fixes, wall fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kandashi committed Feb 23, 2021
1 parent ab066bb commit 260382d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
68 changes: 49 additions & 19 deletions src/aura.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Hooks.on("ready", () => {
</div>
<div class="form-group">
<label>${FormRadius}</label>
<input id="radius" name="flags.${MODULE_NAME}.radius" type="number" min="0" value="${flags[MODULE_NAME]?.radius}" placeholder="${FormRadiusPrompt}"></input>
<input id="radius" name="flags.${MODULE_NAME}.radius" type="number" min="0" step="any" value="${flags[MODULE_NAME]?.radius}" placeholder="${FormRadiusPrompt}"></input>
</div>
<div class="form-group">
<label>${FormSaveEnable}</label>
Expand All @@ -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`)
}
});

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -444,7 +450,7 @@ Hooks.on("ready", () => {
}



/**
* Test individual token against aura array
* @param {Map} map - empty map to populate
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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))
Expand Down

0 comments on commit 260382d

Please sign in to comment.