MSUTeam / MSU

Modding Standards and Utilities for Battle Brothers
21 stars 4 forks source link

[REQUEST] New onOtherSkillAdded() Event for skills #390

Open Darxo opened 1 month ago

Darxo commented 1 month ago

Is your feature request related to a problem? Please describe. A skill currently can't react to another skill being added directly. For example:

Instead those changes currently have to either be done in the code of the respective effects or in something like the onUpdate loop.

Describe the solution you'd like Add a new onOtherSkillAdded(_skill) function to skill_container.nut

q.onOtherSkillAdded <- function( _skill )
{
    this.callSkillsFunction("onOtherSkillAdded", [
        _skill
    ], false);
}

Add a new onOtherSkillAdded(_skill) function to skill.nut

q.onOtherSkillAdded <- function( _skill )
{
}

Use hookTree on skill.nut in order to call onOtherSkillAdded when onAdded is called. HookTree is needed because the base function onAdded is generally overriden by skills.

::MSU.HooksMod.hookTree("scripts/skills/skill", function(q) {
    q.onAdded = @(__original) function()
    {
        __original();
        this.getContainer().onOtherSkillAdded(this);
    }
});

Additional context This Event is especially useful when designing perks or traits which buff certain existing combat effects. As perks and traits are only added outside of battle and combat effects are only added inside of battle, it is as simple as doing something like this

q.onOtherSkillAdded = @(__original) function( _skill )
{
    if (_skill.getID() == "effects.riposte")
    {
        _skill.m.HitCHance += 15;
    }
}
LordMidas commented 1 month ago

I've many times run into situations where I would've liked the existence of such a function - this is definitely a useful feature. There are two points to discuss about how to approach this problem: