Ranged attacks
This commit is contained in:
parent
68b8d42925
commit
fabc5f2287
@ -556,7 +556,16 @@ export class CrucibleActor extends Actor {
|
||||
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
|
||||
rollData.noAdvantage = this.isNoAdvantage()
|
||||
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 ) {
|
||||
rollData.forceAdvantage = defender.isAttackerAdvantage()
|
||||
rollData.advantageFromTarget = true
|
||||
@ -625,6 +634,10 @@ export class CrucibleActor extends Actor {
|
||||
if ( !rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
|
||||
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)
|
||||
} else {
|
||||
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() {
|
||||
let shield = this.getEquippedShield()
|
||||
|
@ -70,6 +70,12 @@ export class CrucibleRollDialog extends Dialog {
|
||||
html.find('#useshield').change((event) => {
|
||||
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
|
||||
})
|
||||
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ const __color2RollTable = {
|
||||
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"
|
||||
}
|
||||
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 {
|
||||
@ -150,6 +151,20 @@ export class CrucibleUtility {
|
||||
}
|
||||
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) {
|
||||
@ -163,6 +178,10 @@ export class CrucibleUtility {
|
||||
return draw.results.length > 0 ? draw.results[0] : undefined
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getSizeDice(sizeValue) {
|
||||
return __size2Dice[sizeValue]
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getCritical(level, weapon) {
|
||||
@ -191,6 +210,15 @@ export class CrucibleUtility {
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -295,7 +323,7 @@ export class CrucibleUtility {
|
||||
if (game.user.isGM || (game.user.character && game.user.character.id == defender.id)) {
|
||||
rollData.defender = defender
|
||||
rollData.defenderWeapons = defender.getEquippedWeapons()
|
||||
rollData.isRollTarget = rollData.weapon?.system.isranged
|
||||
rollData.isRangedAttack = rollData.weapon?.system.isranged
|
||||
this.createChatWithRollMode(defender.name, {
|
||||
name: defender.name,
|
||||
alias: defender.name,
|
||||
@ -480,12 +508,26 @@ export class CrucibleUtility {
|
||||
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) {
|
||||
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
|
||||
// ability/save => 0
|
||||
// ability/save/size => 0
|
||||
let diceFormula
|
||||
let startFormula = "0d6cs>=5"
|
||||
if (rollData.ability) {
|
||||
@ -494,6 +536,10 @@ export class CrucibleUtility {
|
||||
if (rollData.save) {
|
||||
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
|
||||
|
||||
// skill => 2
|
||||
|
@ -199,7 +199,7 @@
|
||||
"styles": [
|
||||
"styles/simple.css"
|
||||
],
|
||||
"version": "10.0.3",
|
||||
"version": "10.0.4",
|
||||
"compatibility": {
|
||||
"minimum": "10",
|
||||
"verified": "10.278",
|
||||
@ -207,7 +207,7 @@
|
||||
},
|
||||
"title": "Crucible RPG",
|
||||
"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",
|
||||
"background": "images/ui/crucible_welcome_page.webp",
|
||||
"id": "fvtt-crucible-rpg"
|
||||
|
@ -36,6 +36,14 @@
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
{{#if sizeDice}}
|
||||
<li>Size/Range/Cover/Situational dices
|
||||
({{#each roll.terms.0.results as |die idx|}}
|
||||
{{die.result}}
|
||||
{{/each}})
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
{{#if ability}}
|
||||
<li>Ability : {{ability.label}} - {{ability.value}}d6
|
||||
({{#each roll.terms.0.results as |die idx|}}
|
||||
|
@ -18,17 +18,16 @@
|
||||
|
||||
<div>
|
||||
|
||||
{{#if isRollTarget}}
|
||||
{{#if isRangedAttack}}
|
||||
<div>{{defender.name}} is under Ranged attack. He must roll a Target Roll to defend himself.</div>
|
||||
{{else}}
|
||||
<div>{{defender.name}} is under Melee attack. He must roll a Defense Roll to defend himself.</div>
|
||||
{{/if}}
|
||||
|
||||
<ul>
|
||||
{{#if isRollTarget}}
|
||||
{{#if isRangedAttack}}
|
||||
<li>
|
||||
<button class="chat-card-button roll-defense-ranged" data-defense-weapon-id="{{weapon._id}}"
|
||||
data-roll-id="{{@root.rollId}}">Roll Target !</button>
|
||||
<button class="chat-card-button roll-defense-ranged" data-roll-id="{{@root.rollId}}">Roll Target !</button>
|
||||
</li>
|
||||
{{else}}
|
||||
<li>
|
||||
|
@ -36,7 +36,7 @@
|
||||
<label class="attribute-value checkbox"><input type="checkbox" name="system.loosehpround" {{checked data.loosehpround}}/></label>
|
||||
</li>
|
||||
{{#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"/>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
@ -56,7 +56,7 @@
|
||||
<label class="attribute-value checkbox"><input type="checkbox" name="system.isranged" {{checked data.isranged}}/></label>
|
||||
</li>
|
||||
{{#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"/>
|
||||
</li>
|
||||
<li class="flexrow"><label class="generic-label">Max range</label>
|
||||
|
@ -8,6 +8,46 @@
|
||||
|
||||
<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}}
|
||||
<div class="flexrow">
|
||||
<span class="roll-dialog-label">{{save.label}} : </span>
|
||||
|
Loading…
Reference in New Issue
Block a user