Skip to content

Commit

Permalink
Merge pull request #46 from kandashi/0.1.29
Browse files Browse the repository at this point in the history
0.1.29
  • Loading branch information
kandashi authored Jan 19, 2021
2 parents 0191bc9 + 1c40b7c commit 5cfc1b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 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.28",
"version": "0.1.29",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9",
"packs": [
Expand Down
69 changes: 38 additions & 31 deletions src/aura.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Hooks.on("ready", () => {
newEffect.data.changes[changeIndex].value = `+ ${newValue}`
}
}
if(change.key === "macro.execute") newEffect.data.flags.ActiveAuras.isMacro = true
if (change.key === "macro.execute") newEffect.data.flags.ActiveAuras.isMacro = true
}
effectArray.push(newEffect)
}
Expand Down Expand Up @@ -259,15 +259,15 @@ Hooks.on("ready", () => {
for (let mapEffect of map) {
let MapKey = mapEffect[0]
let newEffectData = duplicate(mapEffect[1].effect.data)

newEffectData.disabled = false
let macro = newEffectData.flags.ActiveAuras.isMacro

newEffectData.flags.ActiveAuras = {
isAura: false,
applied: true,
isMacro: macro
}
newEffectData.flags.ActiveAuras = {
isAura: false,
applied: true,
isMacro: macro
}
map.set(MapKey, { add: mapEffect[1].add, token: mapEffect[1].token, effect: newEffectData })
}

Expand Down Expand Up @@ -374,43 +374,50 @@ Hooks.on("ready", () => {
}
let collision = canvas.walls.checkCollision(ray)
if (collision && game.settings.get("ActiveAuras", "wall-block") === true) return false
if(auraHeight === true) {
if(game.settings.get("ActiveAuras", "vertical-euclidean") === true) {
let heightChange = Math.abs(token1.data.elevation - token2.data.elevation)
if (auraHeight === true) {
if (game.settings.get("ActiveAuras", "vertical-euclidean") === true) {
let heightChange = Math.abs(token1.data.elevation - token2.data.elevation)
distance = distance > heightChange ? distance : heightChange
}
if(game.settings.get("ActiveAuras", "vertical-euclidean") === false) {
let a = distance;
let b = (token1.data.elevation - token2.data.elevation)
let c = (a*a) + (b*b)
distance = Math.sqrt(c)
if (game.settings.get("ActiveAuras", "vertical-euclidean") === false) {
let a = distance;
let b = (token1.data.elevation - token2.data.elevation)
let c = (a * a) + (b * b)
distance = Math.sqrt(c)
}
}
return distance
}

/**
*
* @param {Token} token - token to apply effect too
* @param {ActiveEffect} effectData - effect data to generate effect
*/
*
* @param {Token} token - token to apply effect too
* @param {ActiveEffect} effectData - effect data to generate effect
*/
async function CreateActiveEffect(token, effectData) {
if (token.actor.effects.entries.find(e => e.data.label === effectData.label)) return
if(effectData.flags.ActiveAuras?.isMacro){
for (let change of effectData.changes) {
if (change.key === "macro.execute") {
if (change.value.includes("@token")) {
let re = /(\s@token)/gms
let newValue = change.value.replaceAll(re, ` ${token.data._id}`)
const changeIndex = effectData.changes.findIndex(i => i.value === change.value && i.key === change.key)
effectData.changes[changeIndex].value = `${newValue}`
if (token.actor.effects.entries.find(e => e.data.label === effectData.label)) return;
if (effectData.flags.ActiveAuras?.isMacro) {
for (let change of effectData.changes) {
let newValue = change.value;
if (change.key === "macro.execute") {
if (typeof newValue === "string") {
newValue = [newValue]
}
newValue = newValue.map(val => {
if (typeof val === "string" && val.includes("@token")) {
let re = /([\s]*@token)/gms
return val.replaceAll(re, ` ${token.data._id}`)
}
return val;
});
if (typeof change.value === "string")
change.value = newValue[0];
else
change.value = newValue;
}
}
}
}

await token.actor.createEmbeddedEntity("ActiveEffect", effectData);

console.log(game.i18n.format("ACTIVEAURAS.ApplyLog", { effectDataLabel: effectData.label, tokenName: token.name }))
}

Expand Down

0 comments on commit 5cfc1b9

Please sign in to comment.