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

Add combat event hooks #222

Merged
merged 6 commits into from
Feb 28, 2025
Merged

Add combat event hooks #222

merged 6 commits into from
Feb 28, 2025

Conversation

Azurelol
Copy link
Collaborator

@Azurelol Azurelol commented Feb 16, 2025

Add a variety of combat event hooks that can be used by modules (and the system) . These can all be found in FUHooks.

  • ATTACK_EVENT
  • DAMAGE_EVENT
  • COMBAT_EVENT
  • GAIN_EVENT
  • LOSS_EVENT
  • CRISIS_EVENT
  • DEFEAT_EVENT
  • STATUS_EVENT

Examples

    Hooks.on('projectfu.events.damage', async event => {
        Azurecompendia.log(`Playing sound effect for damage event: ${event.type} on token: ${event.token.name}`);
        switch (event.type) {
            case "physical":
                playSoundEffect('physical');
                break;
            default:
                break;
        }
    });

    Hooks.on('projectfu.events.gain', async event => {
        Azurecompendia.log(`Playing sound effect for gain event: ${event.resource} on token: ${event.token.name}`);
    });

    Hooks.on('projectfu.events.loss', async event => {
        Azurecompendia.log(`Playing sound effect for loss event: ${event.resource} on token: ${event.token.name}`);
    });

    Hooks.on('projectfu.events.crisis', async event => {
        Azurecompendia.log(`Playing sound effect for crisis event on token: ${event.token.name}`);
    });

    Hooks.on('projectfu.events.combat', async event => {        
        switch (event.type) {
            case 'FU.StartOfCombat':
            case 'FU.EndOfCombat':
                Azurecompendia.log(`Playing sound effect for combat event: ${event.type}`);
                break;

            case 'FU.StartOfTurn':
                Azurecompendia.log(`Playing sound effect for combat event ${event.type} on token ${event.token.name}`);
                break;
            case 'FU.EndOfTurn':
                Azurecompendia.log(`Playing sound effect for combat event ${event.type} on token ${event.token.name}`);
                break;
            default:
                break;
        }
    });

@Azurelol Azurelol changed the base branch from main to dev February 16, 2025 13:03
@Azurelol Azurelol marked this pull request as ready for review February 16, 2025 14:41
@Azurelol Azurelol changed the title Add event hooks Add combat event hooks Feb 16, 2025
@Azurelol Azurelol force-pushed the add/event_hooks branch 2 times, most recently from 47cf701 to ff757f8 Compare February 17, 2025 17:33
@Azurelol Azurelol changed the base branch from dev to add/damage_model_bonus February 17, 2025 18:42
if (!this.#check.additionalData[TRAITS]) {
this.#check.additionalData[TRAITS] = [];
}
traits.forEach((t) => this.#check.additionalData[TRAITS].push(t));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a concat method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah looks like an alternative is
this.#check.additionalData[TRAITS].push(...traits);

@KSops
Copy link
Collaborator

KSops commented Feb 17, 2025

As a general comment, I'm not sure the JSDoc typedefs are working, but that could also be my VSCode acting up.

@Azurelol
Copy link
Collaborator Author

As a general comment, I'm not sure the JSDoc typedefs are working, but that could also be my VSCode acting up.

Oh I definitely had issues referencing types in VScode; hence my switch to Webstorm.

Base automatically changed from add/damage_model_bonus to dev February 19, 2025 21:00
@Azurelol Azurelol force-pushed the add/event_hooks branch 7 times, most recently from 044a507 to d11b7b9 Compare February 26, 2025 17:14
*/
function attack(inspector, actor, item) {
const traits = inspector.getTraits();
const targets = inspector.getTargets();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getTraits and getTargets can return null. In these cases it looks like there might be exceptions thrown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A while ago they would, but now they return empty arrays if nothing instead. I updated the comments.

Copy link
Collaborator

@KSops KSops Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTargets returns an empty array, but getTraits still returns null doesnt it?

getTraits() {
  return this.#check.additionalData[TRAITS] ?? null;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it.

@Azurelol Azurelol requested a review from KSops February 28, 2025 15:57
@Azurelol Azurelol merged commit 3098e9b into dev Feb 28, 2025
@Azurelol Azurelol deleted the add/event_hooks branch February 28, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants