Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(animations): animations will now miss if the attack misses #179

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ffg-star-wars-enhancements.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function register_hooks() {
we may want to monkeypatch a different function in the future. this location doesn't seem to have access
to the actual weapon in use. I'm not sure if we actually care yet, but worth considering.
*/
if (!this._evaluated) this.evaluate();
var data = attack_animation(this, ...args);
return wrapped(...data);
}
Expand Down
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- NEW FEATURE: Configurable Book of Boba Fett-style title cards can be played like the opening crawl
- IMPROVEMENT: Opening crawl timing can be configured in the settings
- FIX: Module settings popup windows titles corrected
- NEW FEATURE: Attack animations now take into account if the attack hit or not. Have fun watching blaster bolts go
everywhere but your target!

`2.0.5` - 2023-12-29

Expand Down
61 changes: 52 additions & 9 deletions scripts/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export function attack_animation_check() {

export function attack_animation(...args) {
// take our custom arg out of the array so we don't return it
let that = args[0];
const roll_data = args[0];
console.log(roll_data);
const hit = roll_data.ffg.success > 0;
console.log(hit);
args = args.splice(1);

if (!game.settings.get("ffg-star-wars-enhancements", "attack-animation-enable")) {
Expand Down Expand Up @@ -311,14 +314,14 @@ export function attack_animation(...args) {
actor_id = args[0]["speaker"]["actor"]["_id"];
}

if (that["data"] === null || jQuery.isEmptyObject(that["data"])) {
if (roll_data["data"] === null || jQuery.isEmptyObject(roll_data["data"])) {
// this was a roll from a skill
var flag_data = null;
var item_name = null;
} else {
// this was a roll from an item
let item_id = that["data"]["_id"];
var item_name = that["data"]["name"];
let item_id = roll_data["data"]["_id"];
var item_name = roll_data["data"]["name"];
let the_item = game.actors.get(actor_id).items.get(item_id);
if (the_item !== null && the_item !== undefined) {
var flag_data = the_item.getFlag("ffg-star-wars-enhancements", "attack-animation");
Expand Down Expand Up @@ -361,7 +364,7 @@ export function attack_animation(...args) {
// todo: based on dice results, we could have the animation miss
log("attack_animation", "Playing the attack animation: " + animation_file + " / " + sound_file);
// noinspection JSIgnoredPromiseFromCall
play_animation(animation_file, sound_file, skill, source, count);
play_animation(animation_file, sound_file, skill, source, count, hit);
return args;
} else {
// not a combat skill; ignore it
Expand All @@ -371,9 +374,12 @@ export function attack_animation(...args) {

const sleepNow = (delay) => new Promise((resolve) => setTimeout(resolve, delay));

async function play_animation(animation_file, sound_file, skill, source, count) {
async function play_animation(animation_file, sound_file, skill, source, count, hit) {
const tokens = source;
let min_miss_offset = 30;
let max_miss_offset = 50;
var arrayLength = game.user.targets.size;
let position;
for (var i = 0; i < arrayLength; i++) {
if (count !== null) {
var range = count.split("-");
Expand All @@ -394,9 +400,46 @@ async function play_animation(animation_file, sound_file, skill, source, count)
var num_shots = Math.floor(Math.random() * 6 + 1);
}
for (var x = lower_bound - 1; x < num_shots; x++) {
const center = Array.from(game.user.targets)[i].center;
// pick a random spot to draw the ray to (based on if the attack hit or not)
if (hit) {
min_miss_offset = 2;
max_miss_offset = 15;
} else {
min_miss_offset = 40;
max_miss_offset = 55;
}
let dir = Math.floor(Math.random() * 4);
switch (dir) {
case 0:
position = {
x: center["x"] - Math.floor(Math.random() * max_miss_offset) - min_miss_offset,
y: center["y"] - Math.floor(Math.random() * max_miss_offset) - min_miss_offset,
};
break;
case 1:
position = {
x: center["x"] - Math.floor(Math.random() * max_miss_offset) - min_miss_offset,
y: center["y"] + Math.floor(Math.random() * max_miss_offset) + min_miss_offset,
};
break;
case 2:
position = {
x: center["x"] + Math.floor(Math.random() * max_miss_offset) + min_miss_offset,
y: center["y"] - Math.floor(Math.random() * max_miss_offset) - min_miss_offset,
};
break;
case 3:
position = {
x: center["x"] + Math.floor(Math.random() * max_miss_offset) + min_miss_offset,
y: center["y"] + Math.floor(Math.random() * max_miss_offset) + min_miss_offset,
};
break;
}
// configure the animation
if (skill === "grenade") {
var animation_config = {
position: Array.from(game.user.targets)[i].center,
position: position,
file: animation_file,
anchor: {
x: 0.5,
Expand All @@ -405,7 +448,7 @@ async function play_animation(animation_file, sound_file, skill, source, count)
angle: -90,
};
} else if (skill.toLowerCase().includes("ranged") || skill.toLowerCase().includes("gunnery")) {
var ray = new Ray(tokens[0].center, Array.from(game.user.targets)[i].center);
var ray = new Ray(tokens[0].center, position);
var animation_config = {
position: tokens[0].center,
file: animation_file,
Expand All @@ -420,7 +463,7 @@ async function play_animation(animation_file, sound_file, skill, source, count)
},
};
} else {
var ray = new Ray(tokens[0].center, Array.from(game.user.targets)[i].center);
var ray = new Ray(tokens[0].center, position);
var animation_config = {
position: tokens[0].center,
file: animation_file,
Expand Down
Loading