Ranged attacks

This commit is contained in:
sladecraven 2022-08-17 22:51:52 +02:00
parent 68b8d42925
commit fabc5f2287
9 changed files with 150 additions and 21 deletions

View File

@ -556,7 +556,16 @@ export class CrucibleActor extends Actor {
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage() rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
rollData.noAdvantage = this.isNoAdvantage() rollData.noAdvantage = this.isNoAdvantage()
if ( rollData.defenderTokenId) { if ( rollData.defenderTokenId) {
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor let defenderToken = game.canvas.tokens.get(rollData.defenderTokenId)
let defender = defenderToken.actor
// Distance management
if ( this.token) {
const ray = new Ray(this.token.object.center, defenderToken.center)
rollData.tokensDistance = canvas.grid.measureDistances([{ray}], {gridSpaces:false})[0] / canvas.grid.grid.options.dimensions.distance
} else {
ui.notifications.info("No token connected to this actor, unable to compute distance.")
}
if (defender ) { if (defender ) {
rollData.forceAdvantage = defender.isAttackerAdvantage() rollData.forceAdvantage = defender.isAttackerAdvantage()
rollData.advantageFromTarget = true rollData.advantageFromTarget = true
@ -625,6 +634,10 @@ export class CrucibleActor extends Actor {
if ( !rollData.forceDisadvantage) { // This is an attack, check if disadvantaged if ( !rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
rollData.forceDisadvantage = this.isAttackDisadvantage() rollData.forceDisadvantage = this.isAttackDisadvantage()
} }
if (rollData.weapon.system.isranged && rollData.tokensDistance > CrucibleUtility.getWeaponMaxRange(rollData.weapon) ) {
ui.notifications.warn(`Your target is out of range of your weapon (max: ${CrucibleUtility.getWeaponMaxRange(rollData.weapon)} - current : ${rollData.tokensDistance})` )
return
}
this.startRoll(rollData) this.startRoll(rollData)
} else { } else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name) ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
@ -663,6 +676,23 @@ export class CrucibleActor extends Actor {
} }
} }
/* -------------------------------------------- */
rollDefenseRanged(attackRollData) {
let rollData = this.getCommonRollData()
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "rangeddefense"
rollData.attackRollData = duplicate(attackRollData)
rollData.sizeDice = CrucibleUtility.getSizeDice( this.system.biodata.size )
rollData.effectiveRange = CrucibleUtility.getWeaponRange(attackRollData.weapon)
rollData.tokensDistance = attackRollData.tokensDistance // QoL copy
rollData.distanceBonusDice = Math.max(0, Math.floor((rollData.tokensDistance - rollData.effectiveRange) + 0.5))
rollData.hasCover = "none"
rollData.situational = "none"
rollData.useshield = false
rollData.shield = this.getEquippedShield()
this.startRoll(rollData)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
rollShieldDie() { rollShieldDie() {
let shield = this.getEquippedShield() let shield = this.getEquippedShield()

View File

@ -70,6 +70,12 @@ export class CrucibleRollDialog extends Dialog {
html.find('#useshield').change((event) => { html.find('#useshield').change((event) => {
this.rollData.useshield = event.currentTarget.checked this.rollData.useshield = event.currentTarget.checked
}) })
html.find('#hasCover').change((event) => {
this.rollData.hasCover = event.currentTarget.value
})
html.find('#situational').change((event) => {
this.rollData.situational = event.currentTarget.value
})
} }
} }

View File

@ -10,6 +10,7 @@ const __color2RollTable = {
blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die", blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die",
white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice" white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice"
} }
const __size2Dice = [ { nb: 0, dice: "d0" }, { nb: 5, dice: "d8" }, { nb: 3, dice: "d8" }, { nb: 2, dice: "d8" }, { nb: 1, dice: "d8" }, { nb: 1, dice: "d6" }, { nb: 1, noAddFirst: true, dice: "d6" }]
/* -------------------------------------------- */ /* -------------------------------------------- */
export class CrucibleUtility { export class CrucibleUtility {
@ -56,7 +57,7 @@ export class CrucibleUtility {
if (typeof text !== 'string') return text if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1) return text.charAt(0).toUpperCase() + text.slice(1)
} }
/*-------------------------------------------- */ /*-------------------------------------------- */
static getSkills() { static getSkills() {
return duplicate(this.skills) return duplicate(this.skills)
@ -150,6 +151,20 @@ export class CrucibleUtility {
} }
return false return false
} }
static getWeaponRange(weapon) {
if (weapon && weapon.system.isranged) {
let rangeValue = weapon.system.range.replace(/[^0-9]/g, '')
return Number(rangeValue)
}
return false
}
static getWeaponMaxRange(weapon) {
if (weapon && weapon.system.isranged) {
let rangeValue = weapon.system.maxrange.replace(/[^0-9]/g, '')
return Number(rangeValue)
}
return false
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async getRollTableFromDiceColor(diceColor, displayChat = true) { static async getRollTableFromDiceColor(diceColor, displayChat = true) {
@ -163,6 +178,10 @@ export class CrucibleUtility {
return draw.results.length > 0 ? draw.results[0] : undefined return draw.results.length > 0 ? draw.results[0] : undefined
} }
} }
/* -------------------------------------------- */
static getSizeDice(sizeValue) {
return __size2Dice[sizeValue]
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async getCritical(level, weapon) { static async getCritical(level, weapon) {
@ -191,6 +210,15 @@ export class CrucibleUtility {
actor.rollDefenseMelee(rollData) actor.rollDefenseMelee(rollData)
} }
}) })
html.on("click", '.roll-defense-ranged', event => {
let rollId = $(event.currentTarget).data("roll-id")
let rollData = CrucibleUtility.getRollData(rollId)
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (defender && (game.user.isGM || defender.isOwner)) {
defender.rollDefenseRanged(rollData)
}
})
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -290,12 +318,12 @@ export class CrucibleUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async displayDefenseMessage(rollData) { static async displayDefenseMessage(rollData) {
if (rollData.mode == "weapon" && rollData.defenderTokenId) { if (rollData.mode == "weapon" && rollData.defenderTokenId) {
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (game.user.isGM || (game.user.character && game.user.character.id == defender.id)) { if (game.user.isGM || (game.user.character && game.user.character.id == defender.id)) {
rollData.defender = defender rollData.defender = defender
rollData.defenderWeapons = defender.getEquippedWeapons() rollData.defenderWeapons = defender.getEquippedWeapons()
rollData.isRollTarget = rollData.weapon?.system.isranged rollData.isRangedAttack = rollData.weapon?.system.isranged
this.createChatWithRollMode(defender.name, { this.createChatWithRollMode(defender.name, {
name: defender.name, name: defender.name,
alias: defender.name, alias: defender.name,
@ -373,7 +401,7 @@ export class CrucibleUtility {
} }
if (result.critical_1 || result.critical_2) { if (result.critical_1 || result.critical_2) {
let isDeadly = CrucibleUtility.isWeaponDeadly(rollData.attackRollData.weapon) let isDeadly = CrucibleUtility.isWeaponDeadly(rollData.attackRollData.weapon)
result.critical = await this.getCritical((result.critical_1) ? "I" : "II", rollData.attackRollData.weapon ) result.critical = await this.getCritical((result.critical_1) ? "I" : "II", rollData.attackRollData.weapon)
result.criticalText = result.critical.text result.criticalText = result.critical.text
} }
this.createChatWithRollMode(rollData.alias, { this.createChatWithRollMode(rollData.alias, {
@ -480,12 +508,26 @@ export class CrucibleUtility {
skill.system.skilldice = __skillLevel2Dice[skill.system.level] skill.system.skilldice = __skillLevel2Dice[skill.system.level]
} }
/* -------------------------------------------- */
static getDiceFromCover(cover) {
if (cover == "cover50") return 1
return 0
}
/* -------------------------------------------- */
static getDiceFromSituational(cover) {
if (cover == "prone") return 1
if (cover == "dodge") return 1
if (cover == "moving") return 1
if (cover == "engaged") return 1
return 0
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollCrucible(rollData) { static async rollCrucible(rollData) {
let actor = game.actors.get(rollData.actorId) let actor = game.actors.get(rollData.actorId)
// ability/save => 0 // ability/save/size => 0
let diceFormula let diceFormula
let startFormula = "0d6cs>=5" let startFormula = "0d6cs>=5"
if (rollData.ability) { if (rollData.ability) {
@ -494,6 +536,10 @@ export class CrucibleUtility {
if (rollData.save) { if (rollData.save) {
startFormula = String(rollData.save.value) + "d6cs>=5" startFormula = String(rollData.save.value) + "d6cs>=5"
} }
if (rollData.sizeDice) {
let nb = rollData.sizeDice.nb + rollData.distanceBonusDice + this.getDiceFromCover(rollData.hasCover) + this.getDiceFromSituational(rollData.situational)
startFormula = String(nb) + String(rollData.sizeDice.dice) + "cs>=5"
}
diceFormula = startFormula diceFormula = startFormula
// skill => 2 // skill => 2
@ -582,16 +628,16 @@ export class CrucibleUtility {
rollData.roll = myRoll rollData.roll = myRoll
rollData.nbSuccess = myRoll.total rollData.nbSuccess = myRoll.total
if ( rollData.rollAdvantage == "none" && rollData.forceRollAdvantage) { if (rollData.rollAdvantage == "none" && rollData.forceRollAdvantage) {
rollData.rollAdvantage = "roll-advantage" rollData.rollAdvantage = "roll-advantage"
} }
if ( rollData.rollAdvantage == "none" && rollData.forceRollDisadvantage) { if (rollData.rollAdvantage == "none" && rollData.forceRollDisadvantage) {
rollData.rollAdvantage = "roll-disadvantage" rollData.rollAdvantage = "roll-disadvantage"
} }
if (rollData.rollAdvantage != "none" ) { if (rollData.rollAdvantage != "none") {
rollData.rollOrder = 1 rollData.rollOrder = 1
rollData.rollType = (rollData.rollAdvantage == "roll-advantage") ? "Advantage": "Disadvantage" rollData.rollType = (rollData.rollAdvantage == "roll-advantage") ? "Advantage" : "Disadvantage"
this.createChatWithRollMode(rollData.alias, { this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData) content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
}) })
@ -599,7 +645,7 @@ export class CrucibleUtility {
rollData.rollOrder = 2 rollData.rollOrder = 2
let myRoll2 = new Roll(diceFormula).roll({ async: false }) let myRoll2 = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll2, game.settings.get("core", "rollMode")) await this.showDiceSoNice(myRoll2, game.settings.get("core", "rollMode"))
rollData.roll = myRoll2 // Tmp switch to display the proper results rollData.roll = myRoll2 // Tmp switch to display the proper results
rollData.nbSuccess = myRoll2.total rollData.nbSuccess = myRoll2.total
this.createChatWithRollMode(rollData.alias, { this.createChatWithRollMode(rollData.alias, {

View File

@ -199,7 +199,7 @@
"styles": [ "styles": [
"styles/simple.css" "styles/simple.css"
], ],
"version": "10.0.3", "version": "10.0.4",
"compatibility": { "compatibility": {
"minimum": "10", "minimum": "10",
"verified": "10.278", "verified": "10.278",
@ -207,7 +207,7 @@
}, },
"title": "Crucible RPG", "title": "Crucible RPG",
"manifest": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/raw/master/system.json", "manifest": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/raw/master/system.json",
"download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v10.0.3.zip", "download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v10.0.4.zip",
"url": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg", "url": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg",
"background": "images/ui/crucible_welcome_page.webp", "background": "images/ui/crucible_welcome_page.webp",
"id": "fvtt-crucible-rpg" "id": "fvtt-crucible-rpg"

View File

@ -36,6 +36,14 @@
</li> </li>
{{/if}} {{/if}}
{{#if sizeDice}}
<li>Size/Range/Cover/Situational dices
({{#each roll.terms.0.results as |die idx|}}
{{die.result}}&nbsp;
{{/each}})
</li>
{{/if}}
{{#if ability}} {{#if ability}}
<li>Ability : {{ability.label}} - {{ability.value}}d6 <li>Ability : {{ability.label}} - {{ability.value}}d6
({{#each roll.terms.0.results as |die idx|}} ({{#each roll.terms.0.results as |die idx|}}

View File

@ -18,17 +18,16 @@
<div> <div>
{{#if isRollTarget}} {{#if isRangedAttack}}
<div>{{defender.name}} is under Ranged attack. He must roll a Target Roll to defend himself.</div> <div>{{defender.name}} is under Ranged attack. He must roll a Target Roll to defend himself.</div>
{{else}} {{else}}
<div>{{defender.name}} is under Melee attack. He must roll a Defense Roll to defend himself.</div> <div>{{defender.name}} is under Melee attack. He must roll a Defense Roll to defend himself.</div>
{{/if}} {{/if}}
<ul> <ul>
{{#if isRollTarget}} {{#if isRangedAttack}}
<li> <li>
<button class="chat-card-button roll-defense-ranged" data-defense-weapon-id="{{weapon._id}}" <button class="chat-card-button roll-defense-ranged" data-roll-id="{{@root.rollId}}">Roll Target !</button>
data-roll-id="{{@root.rollId}}">Roll Target !</button>
</li> </li>
{{else}} {{else}}
<li> <li>

View File

@ -36,7 +36,7 @@
<label class="attribute-value checkbox"><input type="checkbox" name="system.loosehpround" {{checked data.loosehpround}}/></label> <label class="attribute-value checkbox"><input type="checkbox" name="system.loosehpround" {{checked data.loosehpround}}/></label>
</li> </li>
{{#if data.loosehpround}} {{#if data.loosehpround}}
<li class="flexrow"><label class="generic-label">Quantity</label> <li class="flexrow"><label class="generic-label">Number of HP : </label>
<input type="text" class="input-numeric-short padd-right" name="system.loohproundvalue" value="{{data.loohproundvalue}}" data-dtype="Number"/> <input type="text" class="input-numeric-short padd-right" name="system.loohproundvalue" value="{{data.loohproundvalue}}" data-dtype="Number"/>
</li> </li>
{{/if}} {{/if}}

View File

@ -56,7 +56,7 @@
<label class="attribute-value checkbox"><input type="checkbox" name="system.isranged" {{checked data.isranged}}/></label> <label class="attribute-value checkbox"><input type="checkbox" name="system.isranged" {{checked data.isranged}}/></label>
</li> </li>
{{#if data.isranged}} {{#if data.isranged}}
<li class="flexrow"><label class="generic-label">Range</label> <li class="flexrow"><label class="generic-label">Effective Range</label>
<input type="text" class="right" name="system.range" value="{{data.range}}" data-dtype="String"/> <input type="text" class="right" name="system.range" value="{{data.range}}" data-dtype="String"/>
</li> </li>
<li class="flexrow"><label class="generic-label">Max range</label> <li class="flexrow"><label class="generic-label">Max range</label>

View File

@ -7,6 +7,46 @@
</header> </header>
<div class="flexcol"> <div class="flexcol">
{{#if sizeDice}}
<div class="flexrow">
<span class="roll-dialog-label">Size basic dices : </span>
<span class="roll-dialog-label">{{sizeDice.nb}}{{sizeDice.dice}}</span>
</div>
<div class="flexrow">
<span class="roll-dialog-label">Distance bonus dice(s) : </span>
<span class="roll-dialog-label">{{distanceBonusDice}}</span>
</div>
{{/if}}
{{#if hasCover}}
<div class="flexrow">
<span class="roll-dialog-label">Cover : </span>
<select class="status-small-label color-class-common" type="text" id="hasCover" value="{{hasCover}}" data-dtype="String" >
{{#select hasCover}}
<option value="none">None</option>
<option value="cover50">Cover at 50% (+1 dice)</option>
{{/select}}
</select>
</div>
{{/if}}
{{#if situational}}
<div class="flexrow">
<span class="roll-dialog-label">Situational : </span>
<select class="status-small-label color-class-common" type="text" id="situational" value="{{situational}}" data-dtype="String" >
{{#select situational}}
<option value="none">None</option>
<option value="dodge">Dodge (+1 dice)</option>
<option value="prone">Prone (+1 dice)</option>
<option value="moving">Moving (+1 dice)</option>
<option value="Engaged">Engaged (+1 dice)</option>
{{/select}}
</select>
</div>
{{/if}}
{{#if save}} {{#if save}}
<div class="flexrow"> <div class="flexrow">