{"size": 1412, "ext": "js", "max_stars_repo_path": "src/module/rules/actions/actor/character/calculate-bab.js", "max_stars_repo_name": "msbranin/foundryvtt-starfinder", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/module/rules/actions/actor/character/calculate-bab.js", "max_issues_repo_name": "msbranin/foundryvtt-starfinder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/module/rules/actions/actor/character/calculate-bab.js", "max_forks_repo_name": "msbranin/foundryvtt-starfinder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 37.1578947368, "max_line_length": 104, "alphanum_fraction": 0.5701133144}
import { SFRPGEffectType, SFRPGModifierType, SFRPGModifierTypes } from "../../../../modifiers/types.js";

export default function (engine) {
    engine.closures.add("calculateBaseAttackBonus", (fact, context) => {
        const data = fact.data;
        const classes = fact.classes;
        
        data.attributes.baseAttackBonus = mergeObject(data.attributes.baseAttackBonus, {
            value: 0,
            rolledMods: [],
            tooltip: []
        }, {overwrite: false});

        /** Clear out default values. */
        data.attributes.baseAttackBonus.value = 0;
        data.attributes.baseAttackBonus.rolledMods = [];

        for (const cls of classes) {
            let mod = 0;
            switch (cls.data.bab) {
                case "slow": mod += Math.floor(cls.data.levels * 0.5); break;
                case "moderate": mod += Math.floor(cls.data.levels * 0.75); break;
                case "full": mod += cls.data.levels; break;
            }

            data.attributes.baseAttackBonus.tooltip.push(game.i18n.format("SFRPG.BABTooltip", {
                class: cls.name,
                bonus: mod.signedString()
            }));

            data.attributes.baseAttackBonus.value += mod;
        }

        data.attributes.bab = data.attributes.baseAttackBonus.value;
        
        return fact;
    }, { required: ["stackModifiers"], closureParameters: ["stackModifiers"] });
}