Actor/Crew rolls

This commit is contained in:
2022-09-21 16:54:34 +02:00
parent 343ac6ab9d
commit 8345ee0ebb
11 changed files with 268 additions and 310 deletions

View File

@ -7,7 +7,7 @@ import { PegasusRollDialog } from "./pegasus-roll-dialog.js";
/* -------------------------------------------- */
const __level2Dice = ["d0", "d4", "d6", "d8", "d10", "d12"]
const __name2DiceValue = { "0": 0, "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10": 10, "d12": 12 }
const __dice2Level = {"d0": 0, "d4": 1, "d6": 2, "d8": 3, "d10": 4, "d12": 5}
const __dice2Level = { "d0": 0, "d4": 1, "d6": 2, "d8": 3, "d10": 4, "d12": 5 }
/* -------------------------------------------- */
export class PegasusUtility {
@ -61,8 +61,8 @@ export class PegasusUtility {
/* -------------------------------------------- */
static initGenericRoll() {
let rollData = PegasusUtility.getBasicRollData()
rollData.alias = "Dice Pool Roll",
rollData.mode = "generic"
rollData.alias = "Dice Pool Roll",
rollData.mode = "generic"
rollData.title = `Dice Pool Roll`
rollData.img = "icons/dice/d12black.svg"
rollData.isGeneric = true
@ -85,14 +85,14 @@ export class PegasusUtility {
event.preventDefault()
let rollData = PegasusUtility.initGenericRoll()
rollData.isChatRoll = true
let rollDialog = await PegasusRollDialog.create( undefined, rollData)
rollDialog.render( true )
let rollDialog = await PegasusRollDialog.create(undefined, rollData)
rollDialog.render(true)
})
}
})
}
}
/* -------------------------------------------- */
static pushInitiativeOptions(html, options) {
options.push({ name: "Apply -10", condition: true, icon: '<i class="fas fa-plus"></i>', callback: target => { PegasusCombat.decInitBy10(target.data('combatant-id'), -10); } })
@ -114,7 +114,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for (let myDice of diceList) {
let newDice = {
name: "effect-bonus-dice", key: myDice, level: effect.effect.system.effectlevel, effect: effect.effect.name,
name: "effect-bonus-dice", key: myDice, level: PegasusUtility.getLevelFromDice(myDice), effect: effect.effect.name,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -128,12 +128,12 @@ export class PegasusUtility {
static updateHindranceBonusDice(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "effect-hindrance")
for (let hindrance of rollData.effectsList) {
if (hindrance && hindrance.applied && (hindrance.type == "hindrance" || (hindrance.type == "effect" && hindrance.effect?.system?.hindrance) ) ) {
let diceKey = PegasusUtility.getDiceFromLevel( (hindrance.value) ? hindrance.value : hindrance.effect.system.effectlevel)
if (hindrance && hindrance.applied && (hindrance.type == "hindrance" || (hindrance.type == "effect" && hindrance.effect?.system?.hindrance))) {
let diceKey = PegasusUtility.getDiceFromLevel((hindrance.value) ? hindrance.value : hindrance.effect.system.effectlevel)
let diceList = diceKey.split(" ")
for (let myDice of diceList) {
let newDice = {
name: "effect-hindrance", key: myDice, level: hindrance.value, effect: hindrance.name,
name: "effect-hindrance", key: myDice, level: PegasusUtility.getLevelFromDice(myDice), effect: hindrance.name,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -152,7 +152,7 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for (let myDice of diceList) {
let newDice = {
name: "armor-shield", key: myDice, level: armor.value,
name: "armor-shield", key: myDice, level: PegasusUtility.getLevelFromDice(myDice),
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -173,7 +173,21 @@ export class PegasusUtility {
let diceList = diceKey.split(" ")
for (let myDice of diceList) {
let newDice = {
name: "damage", key: myDice, level: weapon.value,
name: "damage", key: myDice, level: PegasusUtility.getLevelFromDice(myDice),
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
}
}
}
for (let weapon of rollData.vehicleWeapons) {
if (weapon.applied) {
let diceKey = PegasusUtility.getDiceFromLevel(weapon.value)
let diceList = diceKey.split(" ")
for (let myDice of diceList) {
let newDice = {
name: "damage", key: myDice, level: PegasusUtility.getLevelFromDice(myDice),
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
newDicePool.push(newDice)
@ -181,11 +195,11 @@ export class PegasusUtility {
}
}
rollData.dicePool = newDicePool
}
}
}
/* -------------------------------------------- */
static updateStatDicePool( rollData) {
static updateStatDicePool(rollData) {
let newDicePool = rollData.dicePool.filter(dice => dice.name != "stat")
let statDice = rollData.dicePool.find(dice => dice.name == "stat")
if (statDice.level > 0) {
@ -410,7 +424,7 @@ export class PegasusUtility {
}
/* -------------------------------------------- */
static targetToken( user, token, flag) {
static targetToken(user, token, flag) {
if (flag) {
token.actor.checkIfPossible()
}
@ -463,7 +477,7 @@ export class PegasusUtility {
static async getEffectFromCompendium(effectName) {
effectName = effectName.toLowerCase()
let effect = game.items.contents.find(item => item.type == 'effect' && item.name.toLowerCase() == effectName)
if (!effect ) {
if (!effect) {
let effects = await this.loadCompendium('fvtt-pegasus-rpg.effects', item => item.name.toLowerCase() == effectName)
let objs = effects.map(i => i.toObject())
effect = objs[0]
@ -636,7 +650,7 @@ export class PegasusUtility {
}
/* -------------------------------------------- */
static removeForeignEffect( effectData) {
static removeForeignEffect(effectData) {
if (game.user.isGM) {
console.log("Remote removal of effects", effectData)
let actor = game.canvas.tokens.get(effectData.defenderTokenId).actor
@ -714,7 +728,7 @@ export class PegasusUtility {
if (effect.foreign) {
if (game.user.isGM) {
this.removeForeignEffect(effect)
} else {
} else {
game.socket.emit("system.fvtt-pegasus-rpg", { msg: "msg_gm_remove_effect", data: effect })
}
} else {
@ -767,7 +781,6 @@ export class PegasusUtility {
/* -------------------------------------------- */
static async rollPegasus(rollData) {
let actor = game.actors.get(rollData.actorId)
let diceFormulaTab = []
@ -815,6 +828,8 @@ export class PegasusUtility {
// And save the roll
this.saveRollData(rollData)
actor.lastRoll = rollData
console.log("Rolldata performed ", rollData, diceFormula)
}
/* -------------------------------------------- */
@ -968,10 +983,11 @@ export class PegasusUtility {
effectsList: [],
armorsList: [],
weaponsList: [],
vehicleWeapons: [],
equipmentsList: [],
optionsDiceList: PegasusUtility.getOptionsDiceList()
}
if ( !isInit) { // For init, do not display target hindrances
if (!isInit) { // For init, do not display target hindrances
PegasusUtility.updateWithTarget(rollData)
}
return rollData
@ -981,7 +997,7 @@ export class PegasusUtility {
static updateWithTarget(rollData) {
let target = PegasusUtility.getTarget()
if (target) {
console.log("TARGET ", target)
console.log("TARGET ", target)
let defenderActor = target.actor
rollData.defenderTokenId = target.id
//rollData.attackerId = this.id