Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.5 kB
33
Indexable
Never
const handleCrits = (roll) => roll === 1 ? -10 : (roll === 20 ? 10 : 0);
const options = ['all', 'skill-check', "religion", 'battle-prayer']

if (canvas.tokens.controlled == 0) {
  ui.notifications.warn("You must select a token.");
  return
}

if (game.user.targets.size == 0) {
  ui.notifications.warn("You must have a target.");
  return
}


////////////// To chat message data /////////////////

let toChat = (content) => {
    let chatData = {
        user: game.user.id,
        content,
        speaker: ChatMessage.getSpeaker(),
    }

    ChatMessage.create(chatData, {})
}

//////////// To chat message data //////////////////

game.user.targets.forEach(t => {

    token.actor.data.data.skills.itm.roll(event, options, (result) => {
        let roll = result._total;
        let crit = handleCrits(result.parts[0].rolls[0].result);
        let willDC = 10 + t.actor.data.data.saves.will.totalModifier

        if (roll + crit >= willDC + 10) {
            toChat(`<div><h3 style='border-bottom: 3px solid black'>Battle-Prayer</h3></div><div style="color:#131516;margin-top:4px;">
            💥 <b>Crit Success! 
             <br> <b>${t.name}:</b>  takes [[/r 2d6[lawful]]],[[/r 2d6[good]]], [[/r 2d6[chaotic]]], [[/r 2d6[evil]]] damage!                  
            <div style="border-bottom: 2px solid black;color:#131516;padding-bottom:4px;">
            <b style="color:#990000">
            </div>  `)
            addAlert(t, 2)
        } else if (roll + crit >= willDC) {
            toChat(`<div><h3 style='border-bottom: 3px solid black'>Battle-Prayer</h3></div><div style="color:#131516;margin-top:4px;">
            ✔️ <b>Success! 
             <br> <b>${t.name}:</b>  takes [[/r 1d6[lawful]]],[[/r 1d6[good]]], [[/r 1d6[chaotic]]], [[/r 1d6[evil]]] damage!                  
            <div style="border-bottom: 2px solid black;color:#131516;padding-bottom:4px;">
            <b style="color:#990000">
            </div>  `)
            addAlert(t, 1)
        } else if (roll + crit < willDC - 10) {

            toChat(`<div><h3 style='border-bottom: 3px solid black'>Battle-Prayer</h3></div><div style="color:#131516;margin-top:4px;">
            ❌ <b>Crit Fail! 
             <br> <b>${t.name}:</b> unaffected                
            <div style="border-bottom: 2px solid black;color:#131516;padding-bottom:4px;">
            <b style="color:#990000">
            </div>  `)

        } else if (roll + crit < willDC) {

            toChat(`<div><h3 style='border-bottom: 3px solid black'>Battle-Prayer</h3></div><div style="color:#131516;margin-top:4px;">
            ❌ <b>Fail! 
             <br> <b>${t.name}:</b>  unaffected                
            <div style="border-bottom: 2px solid black;color:#131516;padding-bottom:4px;">
            <b style="color:#990000">
            </div>  `)
        } else if (roll + crit >= willDC - 10) {
            toChat(`<div><h3 style='border-bottom: 3px solid black'>Battle-Prayer</h3></div><div style="color:#131516;margin-top:4px;">
            💥 <b>Crit failure! 
             The backlash of <br> <b>${t.name}:</b>'s will against your prayer prevents you from using Battle Prayer again for 10 minutes.              
            <div style="border-bottom: 2px solid black;color:#131516;padding-bottom:4px;">
            <b style="color:#990000">
            </div>  `)
            addAlert(t, 2)
})

})