Add weapons attacks

This commit is contained in:
2023-04-14 17:01:29 +02:00
parent 606271e725
commit 32b5868646
10 changed files with 218 additions and 137 deletions

View File

@ -87,26 +87,16 @@ export class DarkStarsUtility {
static async chatListeners(html) {
html.on("click", '.view-item-from-chat', event => {
game.system.crucible.creator.openItemView(event)
game.system.darkstars.creator.openItemView(event)
})
html.on("click", '.roll-defense-melee', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = DarkStarsUtility.getRollData(rollId)
rollData.defenseWeaponId = $(event.currentTarget).data("defense-weapon-id")
let actor = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (actor && (game.user.isGM || actor.isOwner)) {
actor.rollDefenseMelee(rollData)
}
html.on("click", '.chat-reroll', event => {
let messageId = this.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let rollData = message.getFlag("world", "darkstars-roll-data")
rollData.reroll = true
rollData.roll = undefined
this.rollDarkStars(rollData)
})
html.on("click", '.roll-defense-ranged', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = DarkStarsUtility.getRollData(rollId)
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (defender && (game.user.isGM || defender.isOwner)) {
defender.rollDefenseRanged(rollData)
}
})
}
/* -------------------------------------------- */
@ -249,6 +239,31 @@ export class DarkStarsUtility {
}
}
/* -------------------------------------------- */
static getAimingMalus(location) {
if (location == "arm" || location == "head") {
return -50
}
if (location == "torso" || location == "leg") {
return -30
}
if (location == "hand" ) {
return -70
}
return 0
}
/* -------------------------------------------- */
static getAimingLocation(roll) {
if (roll == 1) return "head"
if (roll >=2 && roll <=4 ) return "chest"
if (roll >=5 && roll <=6 ) return "abdomen"
if (roll == 7 ) return "leftarm"
if (roll == 8 ) return "rightarm"
if (roll == 9 ) return "rightleg"
if (roll == 10 ) return "leftleg"
return "abdomen"
}
/* -------------------------------------------- */
static async rollDarkStars(rollData) {
@ -256,12 +271,21 @@ export class DarkStarsUtility {
// ability/save/size => 0
rollData.percentValue = 0
if ( rollData.mode == "skill") {
if ( rollData.skill ) {
rollData.percentValue = rollData.skill.total
}
rollData.percentValue += rollData.bonusMalus
rollData.diceFormula = "1d100"
if (rollData.isAboveEffectiveRange) {
rollData.percentValue -= 30
rollData.percentValue = Math.max(0, rollData.percentValue)
}
if (rollData.mode == "weapon") {
rollData.locationMalus = this.getAimingMalus(rollData.weaponAiming)
rollData.percentValue += rollData.locationMalus
}
// Performs roll
console.log("Roll formula", rollData.diceFormula)
let myRoll = rollData.roll
@ -276,13 +300,23 @@ export class DarkStarsUtility {
rollData.isSuccess = rollData.diceResult == 1 || rollData.diceResult <= rollData.percentValue
rollData.isFailure = rollData.diceResult == 100 || rollData.diceResult > rollData.percentValue
rollData.degrees = Math.floor(rollData.percentValue/10) - Math.floor(rollData.diceResult/10)
if (rollData.reroll) {
actor.modifyRerolls(-1)
rollData.rerolls = 0 // DIsable rerolls
}
if (rollData.weaponAiming == "none" ) {
let rollLoc = new Roll("1d10").roll({async: false})
rollData.weaponAiming = this.getAimingLocation(rollLoc.total)
}
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-dark-stars/templates/chat/chat-generic-result.hbs`, rollData)
})
console.log("Rolldata result", rollData)
msg.setFlag("world", "roll-data", rollData)
msg.setFlag("world", "darkstars-roll-data", rollData)
}
/* -------------------------------------------- */
@ -384,7 +418,9 @@ export class DarkStarsUtility {
let rollData = {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
bonusMalus : 0
bonusMalus : 0,
isAboveEffectiveRange: false,
weaponAiming: "none"
}
DarkStarsUtility.updateWithTarget(rollData)
return rollData