Skip to content

Commit

Permalink
Merge pull request #45 from kandashi/0.1.28
Browse files Browse the repository at this point in the history
height check and macro fix
  • Loading branch information
kandashi authored Jan 18, 2021
2 parents 756d6a5 + ad5270e commit 0191bc9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ The "Apply while inactive" option allows for effects to propagate to other token

![Active Aura Test](https://github.com/kandashi/Active-Auras/blob/main/Images/ActiveAuras%20test2.gif)

## DAE Macro Executes
- Using `@token` as a macro argument will now refer to the token the aura is applied to, you can use this in any DAE auras as normal


## Compatability
- Works with DAE as far as I know
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"ACTIVEAURAS.measurmentoptions_name":"Measurement system",
"ACTIVEAURAS.measurmentoptions_hint":"Use system defined movement measurement system rather than straight line (euclidean), default on",
"ACTIVEAURAS.measurementHeight_name":"Height measurement system",
"ACTIVEAURAS.measurementHeight_hint":"System for measuring heights in regards to auras. True is simple comparison of heights, false is eucleadian distance (experimental)",
"ACTIVEAURAS.tabname": "Auras",

"ACTIVEAURAS.walltoptions_name": "Walls Block Auras",
Expand All @@ -15,6 +17,7 @@
"ACTIVEAURAS.FORM_TargetsAllies":"Allies",
"ACTIVEAURAS.FORM_TargetsAll":"All",
"ACTIVEAURAS.FORM_Radius": "Aura radius",
"ACTIVEAURAS.FORM_Height": "Check Token Height",

"ACTIVEAURAS.ApplyLog":"Active Auras: applied {effectDataLabel} to {tokenName}",
"ACTIVEAURAS.RemoveLog":"Active Auras: removed {effectDataLabel} to {tokenName}"
Expand Down
3 changes: 3 additions & 0 deletions lang/es.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"ACTIVEAURAS.measurmentoptions_name":"Sistema de medida",
"ACTIVEAURAS.measurmentoptions_hint":"Usar el sistema de medida de movimiento definido por el sistema, en lugar de una línea recta (euclídeo), por defecto activado",
"ACTIVEAURAS.measurementHeight_name":"Sistema de medida de altura",
"ACTIVEAURAS.measurementHeight_hint":"Sistema para medir alturas con respecto a auras. Verdadero es una comparación simple, falso es distancia euclídea (experimental)",
"ACTIVEAURAS.tabname": "Auras",

"ACTIVEAURAS.walltoptions_name": "Paredes bloquean auras",
Expand All @@ -15,6 +17,7 @@
"ACTIVEAURAS.FORM_TargetsAllies":"Aliados",
"ACTIVEAURAS.FORM_TargetsAll":"Todos",
"ACTIVEAURAS.FORM_Radius": "Radio del aura",
"ACTIVEAURAS.FORM_Height": "Comprobar altura del token",

"ACTIVEAURAS.ApplyLog":"Active Auras: {effectDataLabel} aplicado a {tokenName}",
"ACTIVEAURAS.RemoveLog":"Active Auras: {effectDataLabel} quitado de {tokenName}"
Expand Down
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.27",
"version": "0.1.28",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9",
"packs": [
Expand Down
77 changes: 56 additions & 21 deletions src/aura.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Hooks.on('init', () => {
default: false,
type: Boolean,
});
game.settings.register("ActiveAuras", "vertical-euclidean", {
name: game.i18n.format("ACTIVEAURAS.measurementHeight_name"),
hint: game.i18n.format("ACTIVEAURAS.measurementHeight_hint"),
scope: "world",
config: true,
default: true,
type: Boolean,
});
});


Expand All @@ -38,6 +46,7 @@ Hooks.on("ready", () => {
const FormTargetsAll = game.i18n.format("ACTIVEAURAS.FORM_TargetsAll");
const FormRadius = game.i18n.format("ACTIVEAURAS.FORM_Radius");
const AuraTab = game.i18n.format("ACTIVEAURAS.tabname");
const FormCheckHeight = game.i18n.format("ACTIVEAURAS.FORM_Height");

const tab = `<a class="item" data-tab="ActiveAuras">
<i class="fas fa-broadcast-tower"></i> ${AuraTab}
Expand All @@ -57,6 +66,11 @@ Hooks.on("ready", () => {
<label>${FormHidden}?</label>
<input name="flags.${MODULE_NAME}.hidden" type="checkbox" ${flags[MODULE_NAME].hidden ? 'checked' : ''} </input>
</div>
<div class="form-group">
<label>${FormCheckHeight}</label>
<input name="flags.${MODULE_NAME}.height" type="checkbox" ${flags[MODULE_NAME].height ? 'checked' : ''} </input>
</select>
</div>
<div class="form-group">
<label>${FormTargetsName}:</label>
<select name="flags.${MODULE_NAME}.aura" data-dtype="String" value=${flags[MODULE_NAME]?.aura}>
Expand All @@ -71,6 +85,7 @@ Hooks.on("ready", () => {
<input id="radius" name="flags.${MODULE_NAME}.radius" type="number" min="0" value="${flags[MODULE_NAME].radius}"></input>
</select>
</div>
</div>`;
html.find(".tabs .item").last().after(tab);
html.find(".tab").last().after(contents);
Expand Down Expand Up @@ -104,7 +119,7 @@ Hooks.on("ready", () => {
* On token movement run MainAura
*/
Hooks.on("updateToken", (scene, token, update, flags, id) => {
if (("y" in update || "x" in update))
if (("y" in update || "x" in update || "elevation" in update))
MainAura(token,)
if ((update?.actorData?.effects) || ("hidden" in update)) {
setTimeout(() => {
Expand Down Expand Up @@ -189,6 +204,7 @@ Hooks.on("ready", () => {
newEffect.data.changes[changeIndex].value = `+ ${newValue}`
}
}
if(change.key === "macro.execute") newEffect.data.flags.ActiveAuras.isMacro = true
}
effectArray.push(newEffect)
}
Expand Down Expand Up @@ -243,24 +259,15 @@ Hooks.on("ready", () => {
for (let mapEffect of map) {
let MapKey = mapEffect[0]
let newEffectData = duplicate(mapEffect[1].effect.data)
newEffectData.flags.ActiveAuras = {
isAura: false,
applied: true
}

newEffectData.disabled = false
/*
for (let change of newEffectData.changes) {
if (typeof change.value === "string" && change.key !== "macro.execute") {
if (change.value.includes("@")) {
let dataPath = change.value.substring(2)
let newValue = getProperty(mapEffect[1].effect.parent.getRollData(), dataPath)
const changeIndex = newEffectData.changes.findIndex(i => i.value === change.value && i.key === change.key)
newEffectData.changes[changeIndex].value = `+ ${newValue}`
}
}
}
*/
let macro = newEffectData.flags.ActiveAuras.isMacro

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 @@ -309,7 +316,9 @@ Hooks.on("ready", () => {
let MapKey = auraEffect.data.label + "-" + canvasToken.id;
MapObject = map.get(MapKey);
let auraToken;
let auraRadius = auraEffect.data.flags?.ActiveAuras?.radius
let auraRadius = auraEffect.data.flags?.ActiveAuras?.radius;
let auraHeight = auraEffect.data.flags?.ActiveAuras?.height

//{data: testEffect.data, parentActorLink :testEffect.parent.data.token.actorLink, parentActorId : testEffect.parent._id, tokenId: testToken.id}
if (auraEffect.parentActorLink) {
let auraTokenArray = game.actors.get(auraEffect.parentActorId).getActiveTokens()
Expand All @@ -328,7 +337,7 @@ Hooks.on("ready", () => {
if (auraTargets === "Allies" && (auraToken.data.disposition !== canvasToken.data.disposition)) continue;
if (auraTargets === "Enemy" && (auraToken.data.disposition === canvasToken.data.disposition)) continue;

let distance = RayDistance(canvasToken, auraToken)
let distance = RayDistance(canvasToken, auraToken, auraHeight)
if ((distance !== false) && (distance <= auraRadius) && !effectDisabled) {
if (MapObject) {
MapObject.add = true
Expand All @@ -353,7 +362,7 @@ Hooks.on("ready", () => {
* @param {Token} token1 - test token
* @param {Token} token2 - aura token
*/
function RayDistance(token1, token2) {
function RayDistance(token1, token2, auraHeight) {
const ray = new Ray(token1.center, token2.center)
const segments = [{ ray }]
let distance;
Expand All @@ -365,6 +374,18 @@ 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)
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)
}
}
return distance
}

Expand All @@ -375,7 +396,21 @@ Hooks.on("ready", () => {
*/
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}`
}
}
}
}

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 0191bc9

Please sign in to comment.