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

@@ -511,6 +511,13 @@ export class DarkStarsActor extends Actor {
return this.items.find(cond => cond.type == "condition" && cond.system.targetadvantage)
}
/* -------------------------------------------- */
modifyRerolls( value) {
let rerolls = duplicate(this.system.various.rerolls)
rerolls.value += value
this.update({ 'system.various.rerolls': rerolls })
}
/* -------------------------------------------- */
getCommonRollData(abilityKey = undefined) {
let noAction = this.isNoAction()
@@ -526,6 +533,8 @@ export class DarkStarsActor extends Actor {
rollData.img = this.img
rollData.armors = this.getArmors()
rollData.conditions = this.getConditions()
rollData.rerolls = this.system.various.rerolls.value
if (rollData.defenderTokenId) {
let defenderToken = game.canvas.tokens.get(rollData.defenderTokenId)
let defender = defenderToken.actor
@@ -597,20 +606,12 @@ export class DarkStarsActor extends Actor {
let skill = this.items.find(item => item.name.toLowerCase() == weapon.system.skill.toLowerCase())
if (skill) {
skill = duplicate(skill)
DarkStarsUtility.updateSkill(skill)
let abilityKey = skill.system.ability
let rollData = this.getCommonRollData(abilityKey)
this.updateSkill(skill)
let rollData = this.getCommonRollData()
rollData.mode = "weapon"
rollData.skill = skill
rollData.weapon = weapon
rollData.img = weapon.img
if (!rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
rollData.forceDisadvantage = this.isAttackDisadvantage()
}
/*if (rollData.weapon.system.isranged && rollData.tokensDistance > DarkStarsUtility.getWeaponMaxRange(rollData.weapon) ) {
ui.notifications.warn(`Your target is out of range of your weapon (max: ${DarkStarsUtility.getWeaponMaxRange(rollData.weapon)} - current : ${rollData.tokensDistance})` )
return
}*/
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)

View File

@@ -132,21 +132,9 @@ export class DarkStarsItemSheet extends ItemSheet {
this.deleteSubitem(ev);
});
// Update Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
let itemType = li.data("item-type");
});
html.find('.view-subitem').click(ev => {
this.viewSubitem(ev);
});
html.find('.view-spec').click(ev => {
this.manageSpec();
});
}

View File

@@ -5,7 +5,7 @@ export class DarkStarsRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData) {
let options = { classes: ["DarkStarsDialog"], width: 320, height: 'fit-content', 'z-index': 99999 };
let options = { classes: ["DarkStarsDialog"], width: 420, height: 'fit-content', 'z-index': 99999 };
let html = await renderTemplate('systems/fvtt-dark-stars/templates/apps/roll-dialog-generic.hbs', rollData);
return new DarkStarsRollDialog(actor, rollData, html, options);
@@ -61,6 +61,14 @@ export class DarkStarsRollDialog extends Dialog {
html.find('#bonusMalus').change((event) => {
this.rollData.bonusMalus = Number(event.currentTarget.value)
})
html.find('#above-effective-range').change((event) => {
this.rollData.isAboveEffectiveRange = event.currentTarget.checked
})
html.find('#weapon-aiming').change((event) => {
this.rollData.weaponAiming = String(event.currentTarget.value)
})
}
}

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