Skip to content

Commit

Permalink
Merge pull request #25 from dodgepong/dodgepong-FXPass
Browse files Browse the repository at this point in the history
Add center point calculation methods to the API
  • Loading branch information
Z3nner authored Jan 6, 2024
2 parents 92ddd65 + cc295bf commit 6b7c117
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 284 deletions.
126 changes: 61 additions & 65 deletions packs/weaponfx.db

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions packs_source/weaponfx.db/Apocalypse Rail.Ui60K7EYoOV23KNM.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

let sequence = new Sequence()
.sound()
Expand Down
23 changes: 5 additions & 18 deletions packs_source/weaponfx.db/Displacer.IrU7oILyUlyEecJs.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

//Calculate the point at the center of a group of targets
const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const pTarget = findCenterOfTargetGroup(targetTokens);
const pTarget = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

let sequence = new Sequence()

Expand All @@ -22,7 +9,7 @@ let sequence = new Sequence()
.file("modules/lancer-weapon-fx/soundfx/DisplacerFire.ogg")
.startTime(900)
.fadeInAudio(300)

.effect()
.file("jb2a.dancing_light.purplegreen")
.tint("#2d0a3d")
Expand All @@ -32,7 +19,7 @@ let sequence = new Sequence()
.atLocation(sourceToken)
.moveTowards(pTarget)
.waitUntilFinished();

sequence.effect()
.file("jb2a.fumes.steam.white")
.fadeIn(1500)
Expand All @@ -41,7 +28,7 @@ let sequence = new Sequence()
.spriteAnchor({ x: 0.2, y: 1.2 })
.scaleToObject()
.opacity(0.7);

sequence.sound()
.file("modules/lancer-weapon-fx/soundfx/DisplacerHit2.ogg")
.volume(game.modules.get("lancer-weapon-fx").api.getEffectVolume(0.8));
Expand All @@ -56,7 +43,7 @@ let sequence = new Sequence()


for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

if (!targetsMissed.has(target.id)) {

Expand Down
18 changes: 3 additions & 15 deletions packs_source/weaponfx.db/Flamethrower.uOyi8zHzCseXGQSR.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

let sequence = new Sequence()
.effect()
Expand All @@ -24,9 +12,9 @@ let sequence = new Sequence()
.file("modules/lancer-weapon-fx/soundfx/flamethrower_fire.ogg")
.volume(game.modules.get("lancer-weapon-fx").api.getEffectVolume(0.5))
.waitUntilFinished(-3000)

for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

if (!targetsMissed.has(target.id)) {
sequence.effect()
Expand Down
14 changes: 1 addition & 13 deletions packs_source/weaponfx.db/Missile.4M655uuaKwHfZJfZ.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];


let sequence = new Sequence()
Expand Down
17 changes: 2 additions & 15 deletions packs_source/weaponfx.db/MissileAirBurst.1ntDWMtnxAA1uZMH.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

//Calculate the point at the center of a group of targets
const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const pTarget = findCenterOfTargetGroup(targetTokens);
const pTarget = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

// Calculate the point 70% of the distance between sourceToken and pTarget
const pBlast = {
Expand Down Expand Up @@ -49,7 +36,7 @@ let sequence = new Sequence()
.volume(game.modules.get("lancer-weapon-fx").api.getEffectVolume(0.5))

for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

sequence.effect()
.file("jb2a.bullet.02.orange")
Expand Down
14 changes: 1 addition & 13 deletions packs_source/weaponfx.db/MissileAoE.HOn4Xub4x5q0AmPw.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];


let sequence = new Sequence()
Expand Down
75 changes: 3 additions & 72 deletions packs_source/weaponfx.db/MissilePinaka.nigj4bbJZOVrFf0u.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,11 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const euclideanDistance = (point1, point2) => {
// Calculate the Euclidean distance between two points.
const dx = point1.x - point2.x;
const dy = point1.y - point2.y;
return Math.sqrt(dx * dx + dy * dy);
};

const assignToClusters = (points, centroids) => {
const clusters = new Array(centroids.length).fill(null).map(() => []);

for (const point of points) {
const distances = centroids.map(centroid => euclideanDistance(point, centroid));
const clusterIndex = distances.indexOf(Math.min(...distances));
clusters[clusterIndex].push(point);
}

return clusters;
};

const calculateCentroids = (cluster) => {
// Calculate the centroid (mean) of a cluster of points.
if (cluster.length === 0) {
return null;
}

const sumX = cluster.reduce((sum, point) => sum + point.x, 0);
const sumY = cluster.reduce((sum, point) => sum + point.y, 0);

return { x: sumX / cluster.length, y: sumY / cluster.length };
};

const lloydsAlgorithm = (points, numCentroids) => {
if (numCentroids <= 0) {
return [];
}

// Initialize random centroids to start the algorithm.
const centroids = [];
for (let i = 0; i < numCentroids; i++) {
centroids.push(points[Math.floor(Math.random() * points.length)]);
}

let previousCentroids;
while (
!previousCentroids ||
!centroids.every((centroid, i) =>
centroid.x === previousCentroids[i].x && centroid.y === previousCentroids[i].y
)
) {
previousCentroids = centroids.map(centroid => ({ ...centroid }));

// Assign points to clusters based on the current centroids.
const clusters = assignToClusters(points, centroids);

// Calculate new centroids based on the current cluster assignments.
centroids.forEach((_, i) => {
centroids[i] = calculateCentroids(clusters[i]);
});
}

return centroids;
};

// extract target positions into x/y pairs
const targetPoints = targetTokens.map(token => {
return {x: token.center.x, y: token.center.y};
});

// Split all targets into 2 groups and find the center points (centroids) of each group
// Pinaka wants 2 missiles, so get 2 centroids
const centroids = lloydsAlgorithm(targetPoints, 2);
// Pinaka wants 2 missiles, so get 2 groups
const targetPoints = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 2);

let sequence = new Sequence();

for (const targetPoint of centroids) {
for (const targetPoint of targetPoints) {
sequence.sound()
.file("modules/lancer-weapon-fx/soundfx/Missile_Launch.ogg")
.volume(game.modules.get("lancer-weapon-fx").api.getEffectVolume(0.5));
Expand Down
16 changes: 2 additions & 14 deletions packs_source/weaponfx.db/Mortar.sSGstellhxzWUTXd.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const centerMass = findCenterOfTargetGroup(targetTokens);
const centerMass = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

const repeatImpactAnimationForEachTarget = function (sequence, targetTokens) {
targetTokens.forEach(t => {
Expand Down Expand Up @@ -58,7 +46,7 @@ let sequence = new Sequence();
sequence.sound()
.file("modules/lancer-weapon-fx/soundfx/Mortar_Impact.ogg")
.volume(game.modules.get("lancer-weapon-fx").api.getEffectVolume(0.5));

sequence = repeatImpactAnimationForEachTarget(sequence, targetTokens);

sequence.play();
17 changes: 2 additions & 15 deletions packs_source/weaponfx.db/Nexus.RmFiCRMoSOku7G5g.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

//Calculate the point at the center of a group of targets
const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const pTarget = findCenterOfTargetGroup(targetTokens);
const pTarget = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

// Calculate the point 70% of the distance between sourceToken and pTarget
const pBlast = {
Expand Down Expand Up @@ -50,7 +37,7 @@ let sequence = new Sequence()
.waitUntilFinished(-2200);

for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

sequence.effect()
.file("jb2a.impact.004.blue")
Expand Down
18 changes: 3 additions & 15 deletions packs_source/weaponfx.db/Plasma Thrower.e5XwWrHsiRKrgh7S.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

let sequence = new Sequence()

Expand All @@ -28,9 +16,9 @@ let sequence = new Sequence()
.playbackRate(1.6)
.rotateTowards(target)
.waitUntilFinished(-3500);

for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

if (!targetsMissed.has(target.id)) {
sequence.effect()
Expand Down
18 changes: 3 additions & 15 deletions packs_source/weaponfx.db/Slag Cannon.OAs6mALoTynun3lM.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
const {targetsMissed, targetTokens, sourceToken} = game.modules.get("lancer-weapon-fx").api.getMacroVariables(typeof messageId === "undefined" ? null : messageId, actor);

const findCenterOfTargetGroup = function (targetTokens) {
let total_x = 0;
let total_y = 0;
const numTargets = targetTokens.length;
targetTokens.forEach(t => {
let center = t.getCenter(t.position.x, t.position.y);
total_x = total_x + center.x;
total_y = total_y + center.y;
});
return {x: (total_x / numTargets), y: (total_y / numTargets)};
};

const target = findCenterOfTargetGroup(targetTokens);
const target = game.modules.get("lancer-weapon-fx").api.getTargetLocationsFromTokenGroup(targetTokens, 1)[0];

let sequence = new Sequence()

Expand All @@ -27,9 +15,9 @@ let sequence = new Sequence()
.stretchTo(target)
.playbackRate(1.5)
.waitUntilFinished(-3500);

for (let i=0; i < targetTokens.length; i++) {
let target = targetTokens[i];
let target = targetTokens[i];

if (!targetsMissed.has(target.id)) {
sequence.effect()
Expand Down
Loading

0 comments on commit 6b7c117

Please sign in to comment.