const version = 'v1.0'; const chatimage = "https://raw.githubusercontent.com/brunocalado/mestre-digital/master/Foundry%20VTT/Macros/Savage%20Worlds/icons/clock.webp"; /* Deviation p99 SWADE If a blast template misses, it deviates 1d6″ for thrown weapons (such as grenades) and 2d6″ for fired projectiles. Multiply by 2 if the attack was made at Medium Range, 3 if Long, and 4 for Extreme. Next roll a d12 and read it like a clock facing to determine the direction the missile deviates. A weapon can never deviate more than half the distance to the original target (that keeps it from going behind the thrower). source: https://raw.githubusercontent.com/brunocalado/mestre-digital/master/Foundry%20VTT/Macros/Savage%20Worlds/Deviation.js icon: icons/weapons/artillery/cannon-engraved-gold.webp */ getRequirements(); function getRequirements() { let template = `

Weapon Type

Projectile

Range

Short
`; new Dialog({ title: "Deviation", content: template, buttons: { ok: { label: "Go!", callback: async (html) => { rollForIt(html); }, } }, }).render(true); } function rollForIt(html) { const weapontype=html.find('input[name="weapontype"]:checked').val(); const range=html.find('input[name="range"]:checked').val(); let deviation; if (weapontype=='thrown') { deviation = diceRoll('1d6', range); } else { deviation = diceRoll('2d6', range); } } function diceRoll(die, range) { const rangeMultiplier = rangeCheck(range); let direction = new Roll('1d12').roll(); let roll = new Roll(die).roll(); let message = `

Deviation

`; message += `

Move the blast ${roll.total*rangeMultiplier}" to ${direction.total} O'Clock.

`; if (directionCheck(direction.total)) { message += `

A weapon can never deviate more than half the distance to the original target (that keeps it from going behind the thrower).

`; } message += `

`; let tempChatData = { type: CHAT_MESSAGE_TYPES.ROLL, roll: roll, rollMode: game.settings.get("core", "rollMode"), content: message }; ChatMessage.create(tempChatData); return roll.total; } function rangeCheck(range) { if (range=='short') { return 1; } else if (range=='medium') { return 2; } else if (range=='long') { return 3; } else if (range=='extreme') { return 4; } } function directionCheck(direction) { console.log(direction); if (direction==4 || direction==5 || direction==6 || direction==7 || direction==8) { return true } else { return false } }