module/actor.js
/**
     * Roll a Weapon Attack
     * @param {string} weaponId     The weapon id (e.g. "m1", "r1")
     * @param {Object} options      Options which configure how ability tests are rolled
     */
Roll a Weapon Attack
@param {string} weaponId     The weapon id
@param {Object} options      Options which configure how ability tests are rolled
Roll a Weapon Attack @param { string } weaponId The weapon id @param { Object } options Options which configure how ability tests are rolled
async rollWeaponAttack(weaponId, options = {}) {
        const weapon = this.data.data.items.weapons[weaponId];
        const speaker = {alias: this.name, _id: this._id};
        const formula = `1d20 + ${weapon.toHit}`
        let roll = new Roll(formula, {'critical': 20});
        roll.roll();
        const rollHTML = this._formatRoll(roll, formula);
        let crit = "";
        if (Number(roll.dice[0].results[0]) === 20) {
            const critTableFilter = `Crit Table ${this.data.data.attributes.critical.table}`;
            const pack = game.packs.get('mcc.criticalhits');
            await pack.getIndex(); 
            let entry = pack.index.find(entity => entity.name.startsWith(critTableFilter));
            const table = await pack.getEntity(entry._id);
            const roll = new Roll(`${this.data.data.attributes.critical.die} + ${this.data.data.abilities.lck.mod}`);
            const critResult = await table.draw({'roll': roll, 'displayChat': false});
            crit = ` <br><br><span style="color:red; font-weight: bolder">Critical Hit!</span> ${critResult.results[0].text}</span>`;
        }
        let fumble = "";
        let fumbleDie;
        try {
            fumbleDie = this.data.data.items.armor.a0.fumbleDie;
        } catch (e) {
            fumbleDie = "1d4";
        }
        if (Number(roll.dice[0].results[0]) === 1) {
            const pack = game.packs.get('mcc.fumbles');
            await pack.getIndex(); 
            let entry = pack.index.find(entity => entity.name.startsWith("Fumble"));
            const table = await pack.getEntity(entry._id);
            const roll = new Roll(`${fumbleDie} - ${this.data.data.abilities.lck.mod}`);
            const fumbleResult = await table.draw({'roll': roll, 'displayChat': false});
            fumble = ` <br><br><span style="color:red; font-weight: bolder">Fumble!</span> ${fumbleResult.results[0].text}</span>`;
        }
        const messageData = {
            user: game.user._id,
            speaker: speaker,
            type: CONST.CHAT_MESSAGE_TYPES.EMOTE,
            content: `Attacks with their ${game.i18n.localize(weapon.name)} and hits AC ${rollHTML} for [[${weapon.damage}]] points of damage!${crit}${fumble}`,
            sound: CONFIG.sounds.dice
        };
        CONFIG.ChatMessage.entityClass.create(messageData);
    }
async rollWeaponAttack ( weaponId , options = { } ) { const weapon = this . data . data . items . weapons [ weaponId ] ; const speaker = { alias : this . name , _id : this . _id } ; const formula = ` ${ weapon . toHit } ` let roll = new Roll ( formula , { 'critical' : 20 } ) ; roll . roll ( ) ; const rollHTML = this . _formatRoll ( roll , formula ) ; let crit = "" ; if ( Number ( roll . dice [ 0 ] . results [ 0 ] ) === 20 ) { const critTableFilter = ` ${ this . data . data . attributes . critical . table } ` ; const pack = game . packs . get ( 'mcc.criticalhits' ) ; await pack . getIndex ( ) ; let entry = pack . index . find ( entity => entity . name . startsWith ( critTableFilter ) ) ; const table = await pack . getEntity ( entry . _id ) ; const roll = new Roll ( ` ${ this . data . data . attributes . critical . die } ${ this . data . data . abilities . lck . mod } ` ) ; const critResult = await table . draw ( { 'roll' : roll , 'displayChat' : false } ) ; crit = ` ${ critResult . results [ 0 ] . text } ` ; } let fumble = "" ; let fumbleDie ; try { fumbleDie = this . data . data . items . armor . a0 . fumbleDie ; } catch ( e ) { fumbleDie = "1d4" ; } if ( Number ( roll . dice [ 0 ] . results [ 0 ] ) === 1 ) { const pack = game . packs . get ( 'mcc.fumbles' ) ; await pack . getIndex ( ) ; let entry = pack . index . find ( entity => entity . name . startsWith ( "Fumble" ) ) ; const table = await pack . getEntity ( entry . _id ) ; const roll = new Roll ( ` ${ fumbleDie } ${ this . data . data . abilities . lck . mod } ` ) ; const fumbleResult = await table . draw ( { 'roll' : roll , 'displayChat' : false } ) ; fumble = ` ${ fumbleResult . results [ 0 ] . text } ` ; } const messageData = { user : game . user . _id , speaker : speaker , type : CONST . CHAT_MESSAGE_TYPES . EMOTE , content : ` ${ game . i18n . localize ( weapon . name ) } ${ rollHTML } ${ weapon . damage } ${ crit } ${ fumble } ` , sound : CONFIG . sounds . dice } ; CONFIG . ChatMessage . entityClass . create ( messageData ) ; }
Roll a Weapon Attack
 @param {string} weaponId     The weapon id (e.g.
Roll a Weapon Attack @param { string } weaponId The weapon id ( e . g .
/* Roll the Attack */ /** Handle Critical Hits **/ //Load the compendium index /** Handle Fumbles **/ //Load the compendium index /* Emote attack results */