diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index da4b737..ecfd8a8 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -15,10 +15,10 @@ const __statBuild = [ //{ modules: ["vehiclehull"], field: "pc", itemfield: "vms", subfield: "avgnrg" }, //{ modules: ["powercoremodule"], field: "pc", itemfield: "nrg", subfield: "avgnrg" }, { modules: ["vehiclehull", "mobilitymodule"], itemfield: "man", field: "man" }, - { modules: ["powercoremodule"], field: "pc", itemfield: "pc", }, - { modules: ["mobilitymodule"], field: "mr", itemfield: "mr", }, - { modules: ["propulsionmodule"], field: "ad", itemfield: "ad", }, - { modules: ["combatmodule"], field: "fc", itemfield: "fc", }, + { modules: ["powercoremodule"], field: "pc", itemfield: "pc", additionnal1: "curnrg", additionnal2: "maxnrg" }, + { modules: ["mobilitymodule"], field: "mr", itemfield: "mr" }, + { modules: ["propulsionmodule"], field: "ad", itemfield: "ad" }, + { modules: ["combatmodule"], field: "fc", itemfield: "fc" }, ] const __isVehicleUnique = { vehiclehull:1, powercoremodule:1, mobilitymodule: 1, propulsionmodule: 1, combatmodule: 1} const __speed2Num = { fullstop: 0, crawling: 1, slow: 2, average: 3, fast: 4, extfast: 5 } @@ -746,12 +746,12 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ getStat(statKey) { let stat - if (statKey == 'mr') { + if (this.type == "character" && statKey == 'mr') { stat = duplicate(this.system.mr); } else { stat = duplicate(this.system.statistics[statKey]); } - stat.dice = PegasusUtility.getDiceFromLevel(stat.value); + stat.dice = PegasusUtility.getDiceFromLevel(stat.value || stat.level); return stat; } @@ -928,7 +928,7 @@ export class PegasusActor extends Actor { } else { let pc = duplicate(this.system.statistics.pc) pc.curnrg += value - if (pc.curnrg >= 0) { + if (pc.curnrg >= 0 && pc.curnrg <= pc.maxnrg) { this.update({ 'system.statistics.pc': pc }) } } @@ -1068,13 +1068,15 @@ export class PegasusActor extends Actor { /* -------------------------------------------- */ getTraumaState() { this.traumaState = "none" - let negDelirium = -Math.floor((this.system.secondary.delirium.max + 1) / 2) - if (this.type == "character") { - if (this.system.secondary.delirium.value <= 0 && this.system.secondary.delirium.value >= negDelirium) { - this.traumaState = "trauma" - } - if (this.system.secondary.delirium.value < negDelirium) { - this.traumaState = "severetrauma" + if ( this.type == "character") { + let negDelirium = -Math.floor((this.system.secondary.delirium.max + 1) / 2) + if (this.type == "character") { + if (this.system.secondary.delirium.value <= 0 && this.system.secondary.delirium.value >= negDelirium) { + this.traumaState = "trauma" + } + if (this.system.secondary.delirium.value < negDelirium) { + this.traumaState = "severetrauma" + } } } return this.traumaState @@ -1540,9 +1542,19 @@ export class PegasusActor extends Actor { } } } + addVehicleWeapons(rollData, vehicle) { + if (vehicle) { + let modules = vehicle.items.filter(vehicle => vehicle.type == "vehicleweaponmodule") + if (modules && modules.length > 0) { + for( let module of modules) { + rollData.vehicleWeapons.push({ label: `Weapon ${module.name}`, type: "item", applied: false, weapon: module, value: module.system.damagedicevalue } ) + } + } + } + } /* -------------------------------------------- */ - getCommonRollData(statKey = undefined, useShield = false, isInit = false, isPower = false, isPowerDmg = false) { + getCommonRollData(statKey = undefined, useShield = false, isInit = false, isPower = false, subKey = "", vehicle = undefined ) { let rollData = PegasusUtility.getBasicRollData(isInit) rollData.alias = this.name rollData.actorImg = this.img @@ -1555,11 +1567,34 @@ export class PegasusActor extends Actor { rollData.noBonusDice = this.checkNoBonusDice() rollData.dicePool = [] + if (subKey == "melee-dmg" || subKey == "ranged-dmg" || subKey == "power-dmg") { + rollData.isDamage = true + } + if (statKey) { rollData.statKey = statKey rollData.stat = this.getStat(statKey) - rollData.statDicesLevel = rollData.stat.value + rollData.statDicesLevel = rollData.stat.value || rollData.stat.level rollData.statMod = rollData.stat.mod + if ( vehicle) { + rollData.vehicle = duplicate(vehicle) + if (subKey == "melee-dmg") { + rollData.statVehicle = vehicle.system.statistics.mr + rollData.statDicesLevel += vehicle.system.statistics.mr.currentlevel + this.addVehicleWeapons(rollData, vehicle) + } + if (subKey == "ranged-atk") { + rollData.statVehicle = vehicle.system.statistics.fc + rollData.statDicesLevel += vehicle.system.statistics.fc.currentlevel + } + if (subKey == "ranged-dmg") { + this.addVehicleWeapons(rollData, vehicle) + } + if (subKey == "defense") { + rollData.statVehicle = vehicle.system.statistics.man + rollData.statDicesLevel += vehicle.system.statistics.man.currentlevel + } + } rollData.specList = this.getRelevantSpec(statKey) rollData.selectedSpec = "0" if (statKey.toLowerCase() == "mr") { @@ -1567,7 +1602,7 @@ export class PegasusActor extends Actor { } else { rollData.img = `systems/fvtt-pegasus-rpg/images/icons/${rollData.stat.abbrev}.webp` } - let diceKey = PegasusUtility.getDiceFromLevel(rollData.stat.value) + let diceKey = PegasusUtility.getDiceFromLevel(rollData.statDicesLevel) let diceList = diceKey.split(" ") let mod = rollData.stat.mod for (let myDice of diceList) { @@ -1581,7 +1616,7 @@ export class PegasusActor extends Actor { } } - this.addEffects(rollData, isInit, isPower, isPowerDmg) + this.addEffects(rollData, isInit, isPower, subKey == "power-dmg" ) this.addArmorsShields(rollData, statKey, useShield) this.addWeapons(rollData, statKey, useShield) this.addEquipments(rollData, statKey) @@ -1627,10 +1662,10 @@ export class PegasusActor extends Actor { } /* -------------------------------------------- */ - rollPool(statKey, useShield = false, subKey = "none") { + rollPool(statKey, useShield = false, subKey = "none", vehicle = undefined) { let stat = this.getStat(statKey) if (stat) { - let rollData = this.getCommonRollData(statKey, useShield, false, false, subKey == "power-dmg") + let rollData = this.getCommonRollData(statKey, useShield, false, false, subKey, vehicle) rollData.mode = "stat" rollData.subKey = subKey let def = stat.label @@ -1639,9 +1674,6 @@ export class PegasusActor extends Actor { } rollData.title = `Roll : ${def} ` rollData.img = "icons/dice/d12black.svg" - if (subKey == "melee-dmg" || subKey == "ranged-dmg" || subKey == "power-dmg") { - rollData.isDamage = true - } this.startRoll(rollData) } else { ui.notifications.warn("Statistic not found !"); @@ -1747,7 +1779,7 @@ export class PegasusActor extends Actor { if (power) { power = duplicate(power) - let rollData = this.getCommonRollData(power.system.statistic, false, false, true, false) + let rollData = this.getCommonRollData(power.system.statistic, false, false, true) rollData.mode = "power" rollData.power = power @@ -1820,6 +1852,16 @@ export class PegasusActor extends Actor { } else { if (sum != Number(this.system.statistics[statDef.field].level)) { this.update({ [`system.statistics.${statDef.field}.level`]: sum, [`system.statistics.${statDef.field}.currentlevel`]: sum }) + if (statDef.additionnal1) { + if (sum != Number(this.system.statistics[statDef.field][statDef.additionnal1])) { + this.update({ [`system.statistics.${statDef.field}.${statDef.additionnal1}`]: sum } ) + } + } + if (statDef.additionnal2) { + if (sum != Number(this.system.statistics[statDef.field][statDef.additionnal2])) { + this.update({ [`system.statistics.${statDef.field}.${statDef.additionnal2}`]: sum } ) + } + } } } } @@ -1912,6 +1954,7 @@ export class PegasusActor extends Actor { } // Check size if (item.type == "vehiclemodule" || item.type == "vehicleweaponmodule") { + item.system.space = item.system.space || 0 if ( this.system.modules.usedvms + Number(item.system.space) > this.system.modules.totalvms ) { ChatMessage.create( { content: `No more room available to host module ${item.name}. Module is not added to the vehicle.`}) return false @@ -1920,4 +1963,40 @@ export class PegasusActor extends Actor { return true } + /* -------------------------------------------- */ + getCrewList() { + let crew = [] + for (let actorDef of this.system.crew) { + let actor = game.actors.get(actorDef.id) + if (actor ) { + crew.push( {name: actor.name, img: actor.img, id: actor.id }) + } + } + return crew + } + + /* -------------------------------------------- */ + addCrew(actorId) { + let crewList = duplicate( this.system.crew.filter( actorDef => actorDef.id != actorId ) || [] ) + crewList.push( {id: actorId}) + this.update( { 'system.crew': crewList } ) + } + + /* -------------------------------------------- */ + rollPoolFromVehicle(statKey, useShield = false, subKey = "none") { + // Find relevant actor + let actor + for( let actorDef of this.system.crew) { + let actorTest = game.actors.get( actorDef.id) + if (actorTest.testUserPermission( game.user, "OWNER")) { + actor = actorTest + break + } + } + if (!actor) { + ui.notifications.warn("You do no own any actors in the crew of this vehicle.") + return + } + actor.rollPool( statKey, useShield, subKey, this ) + } } diff --git a/modules/pegasus-roll-dialog.js b/modules/pegasus-roll-dialog.js index e695ca3..4abb038 100644 --- a/modules/pegasus-roll-dialog.js +++ b/modules/pegasus-roll-dialog.js @@ -118,6 +118,21 @@ export class PegasusRollDialog extends Dialog { PegasusUtility.updateDamageDicePool(this.rollData) } + /* -------------------------------------------- */ + manageVehicleWeapon( weaponIdx, toggled) { + let weapon = this.rollData.vehicleWeapons[weaponIdx] + if (weapon) { + this.rollData.weapon = duplicate(weapon) + if (toggled) { + this.rollData.weaponName = weapon.weapon.name + } else { + this.rollData.weaponName = undefined + } + weapon.applied = toggled + } + PegasusUtility.updateDamageDicePool(this.rollData) + } + /* -------------------------------------------- */ manageEquip(equipIdx, toggled) { let equip = this.rollData.equipmentsList[equipIdx] @@ -216,6 +231,12 @@ export class PegasusRollDialog extends Dialog { let equipIdx = $(event.currentTarget).data("equip-idx") this.manageEquip(equipIdx, toggled) }) + html.find('.vehicle-weapon-clicked').change((event) => { + let toggled = event.currentTarget.checked + let weaponIdx = $(event.currentTarget).data("vehicle-weapon-idx") + this.manageVehicleWeapon(weaponIdx, toggled) + this.refreshDialog() + }) html.find('.pool-add-dice').click(async (event) => { let diceKey = $(event.currentTarget).data("dice-key") diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 3049e2e..a52d233 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -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: '', 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 diff --git a/modules/pegasus-vehicle-sheet.js b/modules/pegasus-vehicle-sheet.js index 1b9125b..47bc3f2 100644 --- a/modules/pegasus-vehicle-sheet.js +++ b/modules/pegasus-vehicle-sheet.js @@ -41,6 +41,8 @@ export class PegasusVehicleSheet extends ActorSheet { limited: this.object.limited, optionsDiceList: PegasusUtility.getOptionsDiceList(), vmsAvailable: objectData.system.modules.totalvms - objectData.system.modules.vmsused, + avgNRG: objectData.system.statistics.pc.maxnrg - objectData.system.statistics.pc.curnrg, + crewList: this.actor.getCrewList(), totalCost: this.actor.getTotalCost(), optionsLevel: PegasusUtility.getOptionsLevel(), subActors: duplicate(this.actor.getSubActors()), @@ -195,23 +197,24 @@ export class PegasusVehicleSheet extends ActorSheet { html.find('.generic-pool-roll').click((event) => { this.openGenericRoll() } ); + html.find('.attack-melee').click((event) => { - this.actor.rollPool( 'com', false, "melee-atk"); - }); - html.find('.attack-ranged').click((event) => { - this.actor.rollPool( 'agi', false, "ranged-atk"); - }); - html.find('.defense-roll').click((event) => { - this.actor.rollPool( 'def', true); + this.actor.rollPoolFromVehicle( 'com', false, "melee-atk") }); html.find('.damage-melee').click((event) => { - this.actor.rollPool( 'str', false, "melee-dmg"); + this.actor.rollPoolFromVehicle( 'str', false, "melee-dmg") + }); + html.find('.attack-ranged').click((event) => { + this.actor.rollPoolFromVehicle( 'agi', false, "ranged-atk") }); html.find('.damage-ranged').click((event) => { - this.actor.rollPool( 'per', false, "ranged-dmg"); + this.actor.rollPoolFromVehicle( 'per', false, "ranged-dmg"); + }); + html.find('.defense-roll').click((event) => { + this.actor.rollPoolFromVehicle( 'def', true, "defense"); }); html.find('.damage-resistance').click((event) => { - this.actor.rollPool( 'phy', false, "dmg-res"); + this.actor.rollVehicleDamageResistance( ); }); html.find('.roll-stat').click((event) => { @@ -269,7 +272,14 @@ export class PegasusVehicleSheet extends ActorSheet { const fieldName = $(ev.currentTarget).data("field-name"); let value = Number(ev.currentTarget.value); this.actor.update( { [`${fieldName}`]: value } ); - }); + }) + + html.find('.member-view').click((event) => { + const li = $(event.currentTarget).parents(".item") + let actorId = li.data("actor-id") + const actor = game.actors.get( actorId ) + actor.sheet.render(true) + }) } /* -------------------------------------------- */ @@ -294,6 +304,17 @@ export class PegasusVehicleSheet extends ActorSheet { } } + /* -------------------------------------------- */ + async _onDropActor(event, dragData) { + const actor = fromUuidSync(dragData.uuid) + if (actor) { + this.actor.addCrew(actor.id) + }else { + ui.notifications.warn("This actor is not found and can't be added to the Vehicle's crew.") + } + super._onDropActor(event) + } + /* -------------------------------------------- */ /** @override */ _updateObject(event, formData) { diff --git a/system.json b/system.json index 7d7f196..7d343c1 100644 --- a/system.json +++ b/system.json @@ -1,6 +1,5 @@ { "description": "Pegasus RPG system for FoundryVTT", - "download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.0.8.zip", "esmodules": [ "modules/pegasus-main.js" ], @@ -24,7 +23,7 @@ "manifest": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/raw/branch/master/system.json", "compatibility": { "minimum": "10", - "verified": "10.284", + "verified": "10.285", "maximum": "10" }, "id": "fvtt-pegasus-rpg", @@ -254,6 +253,7 @@ ], "title": "Pegasus RPG", "url": "https://www.uberwald.me/data/files/fvtt-pegasus-rpg", - "version": "10.0.9", + "version": "10.0.11", + "download": "https://www.uberwald.me/gitea/uberwald/fvtt-pegasus-rpg/archive/fvtt-pegasus-rpg-v10.0.11.zip", "background": "systems/fvtt-pegasus-rpg/images/ui/pegasus_welcome_page.webp" } \ No newline at end of file diff --git a/template.json b/template.json index 6f06067..fe28d8d 100644 --- a/template.json +++ b/template.json @@ -200,7 +200,7 @@ "description": "" }, "vehicle": { - "subactors": [], + "crew": [], "statistics": { "fc": { "label": "FC", diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index 7374b56..5e78337 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -25,7 +25,7 @@