Vehicles enhancements

This commit is contained in:
2022-09-25 09:26:12 +02:00
parent 7a9ed39d02
commit 7a1171b774
12 changed files with 422 additions and 225 deletions

View File

@ -7,7 +7,7 @@ const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entre
const statThreatLevel = ["agi", "str", "phy", "com", "def", "per"]
const __subkey2title = {
"melee-dmg": "Melee Damage", "melee-atk": "Melee Attack", "ranged-atk": "Ranged Attack",
"ranged-dmg": "Ranged Damage", "dmg-res": "Damare Resistance"
"ranged-dmg": "Ranged Damage", "defence": "Defence", "dmg-res": "Damare Resistance"
}
const __statBuild = [
{ modules: ["vehiclehull"], field: "hr", itemfield: "hr" },
@ -20,11 +20,42 @@ const __statBuild = [
{ 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 __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 }
const __num2speed = ["fullstop", "crawling", "slow", "average", "fast", "extfast"]
const __isVehicle = { vehiclehull: 1, powercoremodule: 1, mobilitymodule: 1, combatmodule: 1, propulsionmodule: 1, vehiclemodule: 1, vehicleweaponmodule: 1, effect: 1}
const __isVehicle = { vehiclehull: 1, powercoremodule: 1, mobilitymodule: 1, combatmodule: 1, propulsionmodule: 1, vehiclemodule: 1, vehicleweaponmodule: 1, effect: 1 }
const __bonusEffect = {
name: "Crawling MAN Bonus", type: "effect", img: "systems/fvtt-pegasus-rpg/images/icons/icon_effect.webp",
system: {
type: "physical",
genre: "positive",
effectlevel: 3,
reducedicevalue: false,
stataffected: "man",
specaffected: [],
statdice: false,
bonusdice: true,
weapondamage: false,
hindrance: false,
resistedby: "notapplicable",
recoveryroll: false,
recoveryrollstat: "",
recoveryrollspec: [],
effectstatlevel: false,
effectstat: "",
oneuse: false,
ignorehealthpenalty: false,
isthispossible: "",
mentaldisruption: false,
physicaldisruption: false,
mentalimmunity: false,
physicalimmunity: false,
nobonusdice: false,
noperksallowed: false,
description: "",
otherdice: false
}
}
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
@ -338,7 +369,7 @@ export class PegasusActor extends Actor {
nrg.activated += item.system.costspent
nrg.value -= item.system.costspent
nrg.max -= item.system.costspent
await this.update({ 'data.nrg': nrg })
await this.update({ 'system.nrg': nrg })
let effects = []
for (let effect of item.system.effectsgained) {
@ -354,7 +385,7 @@ export class PegasusActor extends Actor {
} else {
nrg.activated -= item.system.costspent
nrg.max += item.system.costspent
await this.update({ 'data.nrg': nrg })
await this.update({ 'system.nrg': nrg })
let toRem = []
for (let item of this.items) {
@ -443,7 +474,7 @@ export class PegasusActor extends Actor {
tl += equip.system.threatlevel
}
if (tl != this.system.biodata.threatlevel) {
this.update({ 'data.biodata.threatlevel': tl })
this.update({ 'system.biodata.threatlevel': tl })
}
}
@ -512,7 +543,7 @@ export class PegasusActor extends Actor {
let combat = duplicate(this.system.combat)
combat.stunlevel += incDec
if (combat.stunlevel >= 0) {
this.update({ 'data.combat': combat })
this.update({ 'system.combat': combat })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
@ -534,7 +565,7 @@ export class PegasusActor extends Actor {
if (incDec > 0 && stunAbove > 0) {
let delirium = duplicate(this.system.secondary.delirium)
delirium.value -= incDec
this.update({ 'data.secondary.delirium': delirium })
this.update({ 'system.secondary.delirium': delirium })
}
}
@ -542,7 +573,7 @@ export class PegasusActor extends Actor {
modifyMomentum(incDec) {
let momentum = duplicate(this.system.momentum)
momentum.value += incDec
this.update({ 'data.momentum': momentum })
this.update({ 'system.momentum': momentum })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
@ -592,11 +623,11 @@ export class PegasusActor extends Actor {
ui.notifications.warn("Container is already full !")
return
} else {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': containerId }])
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'system.containerid': containerId }])
}
} else if (object && object.system.containerid) { // remove from container
console.log("Removeing: ", object)
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': "" }]);
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'system.containerid': "" }]);
}
}
/* -------------------------------------------- */
@ -629,7 +660,8 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
async preprocessItem(event, item, onDrop = false) {
if ( item.type != "effect" && __isVehicle[item.type]) {
console.log("Pre-process", item)
if (item.type != "effect" && __isVehicle[item.type]) {
ui.notifications.warn("You can't drop Vehicles item over a character sheet.")
return
}
@ -656,11 +688,11 @@ export class PegasusActor extends Actor {
if (item.type == 'race') {
this.applyRace(item.system)
this.applyRace(item)
} else if (item.type == 'role') {
this.applyRole(item.system)
this.applyRole(item)
} else if (item.type == 'ability') {
this.applyAbility(item.system, [], true)
this.applyAbility(item, [], true)
if (!onDrop) {
await this.createEmbeddedDocuments('Item', [item])
}
@ -720,7 +752,7 @@ export class PegasusActor extends Actor {
async addSubActor(subActorId) {
let subActors = duplicate(this.system.subactors);
subActors.push(subActorId);
await this.update({ 'data.subactors': subActors });
await this.update({ 'system.subactors': subActors });
}
/* -------------------------------------------- */
async delSubActor(subActorId) {
@ -730,7 +762,7 @@ export class PegasusActor extends Actor {
newArray.push(id);
}
}
await this.update({ 'data.subactors': newArray });
await this.update({ 'system.subactors': newArray });
}
/* -------------------------------------------- */
@ -780,7 +812,7 @@ export class PegasusActor extends Actor {
if (powers.length > 0) {
this.createEmbeddedDocuments('Item', powers)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': true }])
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'system.powersactivated': true }])
}
}
@ -795,7 +827,7 @@ export class PegasusActor extends Actor {
if (toRem.length > 0) {
this.deleteEmbeddedDocuments('Item', toRem)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': false }])
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'system.powersactivated': false }])
}
/* -------------------------------------------- */
@ -810,7 +842,7 @@ export class PegasusActor extends Actor {
if (effects.length > 0) {
this.createEmbeddedDocuments('Item', effects)
}
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.activated': true }])
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'system.activated': true }])
}
}
@ -825,7 +857,7 @@ export class PegasusActor extends Actor {
if (toRem.length > 0) {
this.deleteEmbeddedDocuments('Item', toRem)
}
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.activated': false }])
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'system.activated': false }])
}
/* -------------------------------------------- */
@ -900,7 +932,7 @@ export class PegasusActor extends Actor {
let item = this.items.get(itemId)
if (item && value) {
value = Number(value) || 0
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.costspent': value }])
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'system.costspent': value }])
}
}
@ -910,7 +942,7 @@ export class PegasusActor extends Actor {
for (let perk of this.items) {
if (perk.type == "perk") {
this.cleanPerkEffects(perk.id)
this.updateEmbeddedDocuments('Item', [{ _id: perk.id, 'data.status': "ready", 'data.used1': false, 'data.used2': false, 'data.used3': false }])
this.updateEmbeddedDocuments('Item', [{ _id: perk.id, 'system.status': "ready", 'system.used1': false, 'system.used2': false, 'system.used3': false }])
ChatMessage.create({ content: `Perk ${perk.name} has been deactivated due to Severe Trauma state !` })
}
}
@ -923,7 +955,7 @@ export class PegasusActor extends Actor {
let nrg = duplicate(this.system.nrg)
nrg.value += value
if (nrg.value >= 0 && nrg.value <= nrg.max) {
this.update({ 'data.nrg': nrg })
this.update({ 'system.nrg': nrg })
}
} else {
let pc = duplicate(this.system.statistics.pc)
@ -1068,7 +1100,7 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
getTraumaState() {
this.traumaState = "none"
if ( this.type == "character") {
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) {
@ -1175,64 +1207,64 @@ export class PegasusActor extends Actor {
let updates = {}
let phyDiceValue = PegasusUtility.getDiceValue(this.system.statistics.phy.value) + this.system.secondary.health.bonus + this.system.statistics.phy.mod;
if (phyDiceValue != this.system.secondary.health.max) {
updates['data.secondary.health.max'] = phyDiceValue
updates['system.secondary.health.max'] = phyDiceValue
}
if (this.computeValue) {
updates['data.secondary.health.value'] = phyDiceValue
updates['system.secondary.health.value'] = phyDiceValue
}
let mndDiceValue = PegasusUtility.getDiceValue(this.system.statistics.mnd.value) + this.system.secondary.delirium.bonus + this.system.statistics.mnd.mod;
if (mndDiceValue != this.system.secondary.delirium.max) {
updates['data.secondary.delirium.max'] = mndDiceValue
updates['system.secondary.delirium.max'] = mndDiceValue
}
if (this.computeValue) {
updates['data.secondary.delirium.value'] = mndDiceValue
updates['system.secondary.delirium.value'] = mndDiceValue
}
let stlDiceValue = PegasusUtility.getDiceValue(this.system.statistics.stl.value) + this.system.secondary.stealthhealth.bonus + this.system.statistics.stl.mod;
if (stlDiceValue != this.system.secondary.stealthhealth.max) {
updates['data.secondary.stealthhealth.max'] = stlDiceValue
updates['system.secondary.stealthhealth.max'] = stlDiceValue
}
if (this.computeValue) {
updates['data.secondary.stealthhealth.value'] = stlDiceValue
updates['system.secondary.stealthhealth.value'] = stlDiceValue
}
let socDiceValue = PegasusUtility.getDiceValue(this.system.statistics.soc.value) + this.system.secondary.socialhealth.bonus + this.system.statistics.soc.mod;
if (socDiceValue != this.system.secondary.socialhealth.max) {
updates['data.secondary.socialhealth.max'] = socDiceValue
updates['system.secondary.socialhealth.max'] = socDiceValue
}
if (this.computeValue) {
updates['data.secondary.socialhealth.value'] = socDiceValue
updates['system.secondary.socialhealth.value'] = socDiceValue
}
let nrgValue = PegasusUtility.getDiceValue(this.system.statistics.foc.value) + this.system.nrg.mod + this.system.statistics.foc.mod
if (nrgValue != this.system.nrg.absolutemax) {
updates['data.nrg.absolutemax'] = nrgValue
updates['system.nrg.absolutemax'] = nrgValue
}
if (this.computeValue) {
updates['data.nrg.max'] = nrgValue
updates['data.nrg.value'] = nrgValue
updates['system.nrg.max'] = nrgValue
updates['system.nrg.value'] = nrgValue
}
let stunth = PegasusUtility.getDiceValue(this.system.statistics.phy.value) + PegasusUtility.getDiceValue(this.system.statistics.mnd.value) + PegasusUtility.getDiceValue(this.system.statistics.foc.value)
+ this.system.statistics.mnd.mod + this.system.statistics.phy.mod + this.system.statistics.foc.mod
if (stunth != this.system.combat.stunthreshold) {
updates['data.combat.stunthreshold'] = stunth
updates['system.combat.stunthreshold'] = stunth
}
let momentum = this.system.statistics.foc.value + this.system.statistics.foc.mod
if (momentum != this.system.momentum.max) {
updates['data.momentum.value'] = 0
updates['data.momentum.max'] = momentum
updates['system.momentum.value'] = 0
updates['system.momentum.max'] = momentum
}
let mrLevel = (this.system.statistics.agi.value + this.system.statistics.str.value) - this.system.statistics.phy.value
mrLevel = (mrLevel < 1) ? 1 : mrLevel;
if (mrLevel != this.system.mr.value) {
updates['data.mr.value'] = mrLevel
updates['system.mr.value'] = mrLevel
}
let moralitythreshold = - (Number(PegasusUtility.getDiceValue(this.system.statistics.foc.value)) + Number(this.system.statistics.foc.mod))
if (moralitythreshold != this.system.biodata.moralitythreshold) {
updates['data.biodata.moralitythreshold'] = moralitythreshold
updates['system.biodata.moralitythreshold'] = moralitythreshold
}
if (!this.isToken) {
if (this.warnMorality != this.system.biodata.morality && this.system.biodata.morality < 0) {
@ -1246,11 +1278,11 @@ export class PegasusActor extends Actor {
let race = this.getRace()
if (race && race.name && (race.name != this.system.biodata.racename)) {
updates['data.biodata.racename'] = race.name
updates['system.biodata.racename'] = race.name
}
let role = this.getRole()
if (role && role.name && (role.name != this.system.biodata.rolename)) {
updates['data.biodata.rolename'] = role.name
updates['system.biodata.rolename'] = role.name
}
if (Object.entries(updates).length > 0) {
await this.update(updates)
@ -1312,7 +1344,7 @@ export class PegasusActor extends Actor {
if (objetQ) {
let newQ = objetQ.system.quantity + incDec
if (newQ >= 0) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]) // pdates one EmbeddedEntity
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]) // pdates one EmbeddedEntity
}
}
}
@ -1322,7 +1354,7 @@ export class PegasusActor extends Actor {
if (objetQ) {
let newQ = objetQ.system.ammocurrent + incDec;
if (newQ >= 0 && newQ <= objetQ.system.ammomax) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.ammocurrent': newQ }]); // pdates one EmbeddedEntity
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.ammocurrent': newQ }]); // pdates one EmbeddedEntity
}
}
}
@ -1388,11 +1420,12 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
async applyRace(race) {
let updates = { 'data.biodata.racename': race.name }
let updates = { 'system.biodata.racename': race.name }
let newItems = []
await this.deleteAllItemsByType('race')
newItems.push(race);
console.log("DROPPED RACE", race)
for (let ability of race.system.abilities) {
newItems.push(ability)
this.applyAbility(ability, updates)
@ -1420,7 +1453,7 @@ export class PegasusActor extends Actor {
async applyRole(role) {
console.log("ROLE", role)
let updates = { 'data.biodata.rolename': role.name }
let updates = { 'system.biodata.rolename': role.name }
let newItems = []
await this.deleteAllItemsByType('role')
newItems.push(role)
@ -1441,24 +1474,46 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
addHindrancesList(effectsList) {
if (this.system.combat.stunlevel > 0) {
effectsList.push({ label: "Stun Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: this.system.combat.stunlevel })
if (this.type == "character") {
if (this.system.combat.stunlevel > 0) {
effectsList.push({ label: "Stun Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 2 })
}
if (this.system.combat.hindrancedice > 0) {
effectsList.push({ label: "Wounds Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: this.system.combat.hindrancedice })
}
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
effectsList.push({ label: "Encumbrance Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: overCapacity })
}
if (this.system.biodata.morality <= 0) {
effectsList.push({ label: "Morality Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 3 })
}
let effects = this.items.filter(item => item.type == 'effect')
for (let effect of effects) {
effect = duplicate(effect)
if (effect.system.hindrance) {
effectsList.push({ label: effect.name, type: "effect", foreign: true, actorId: this.id, applied: false, effect: effect, value: effect.system.effectlevel })
}
}
}
if (this.system.combat.hindrancedice > 0) {
effectsList.push({ label: "Wounds Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: this.system.combat.hindrancedice })
}
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
effectsList.push({ label: "Encumbrance Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: overCapacity })
}
if (this.system.biodata.morality <= 0) {
effectsList.push({ label: "Morality Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 3 })
}
let effects = this.items.filter(item => item.type == 'effect')
for (let effect of effects) {
effect = duplicate(effect)
if (effect.system.hindrance) {
effectsList.push({ label: effect.name, type: "effect", foreign: true, actorId: this.id, applied: false, effect: effect, value: effect.system.effectlevel })
if (this.type == "vehicle") {
if (this.system.stun.value > 0) {
effectsList.push({ label: "Stun Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 2 })
}
if (this.isVehicleCrawling()) {
effectsList.push({ label: "Crawling Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 3 })
}
if (this.isVehicleSlow()) {
effectsList.push({ label: "Slow Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 1 })
}
if (this.isVehicleAverage()) {
effectsList.push({ label: "Average Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 1 })
}
if (this.isVehicleFast()) {
effectsList.push({ label: "Fast Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 3 })
}
if (this.isVehicleExFast()) {
effectsList.push({ label: "Ext. Fast Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 5 })
}
}
}
@ -1466,7 +1521,6 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
/* ROLL SECTION
/* -------------------------------------------- */
pushEffect(rollData, effect) {
if (this.getTraumaState() == "none" && !this.checkNoBonusDice()) {
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.system.effectlevel })
@ -1546,15 +1600,15 @@ export class PegasusActor extends Actor {
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 } )
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, subKey = "", vehicle = undefined ) {
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
@ -1574,27 +1628,35 @@ export class PegasusActor extends Actor {
if (statKey) {
rollData.statKey = statKey
rollData.stat = this.getStat(statKey)
rollData.statDicesLevel = rollData.stat.value || rollData.stat.level
rollData.statDicesLevel = rollData.stat.value || rollData.stat.level
rollData.statMod = rollData.stat.mod
if ( vehicle) {
if (vehicle) {
rollData.vehicle = duplicate(vehicle)
if (subKey == "melee-dmg") {
rollData.statVehicle = vehicle.system.statistics.mr
rollData.statDicesLevel += vehicle.system.statistics.mr.currentlevel
if (vehicle.isVehicleFullStop()) {
ui.notifications.warn("MR not added to Melee Damage due to Full Stop.")
} else {
rollData.statVehicle = vehicle.system.statistics.mr
}
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
}
if (vehicle.isVehicleFullStop()) {
ui.notifications.warn("MAN not added to Defense due to Full Stop.")
} else {
rollData.statVehicle = vehicle.system.statistics.man
}
}
//this.addVehiculeHindrances(rollData.effectsList, vehicle)
//this.addVehicleBonus(rollData, vehicle)
}
rollData.specList = this.getRelevantSpec(statKey)
rollData.selectedSpec = "0"
if (statKey.toLowerCase() == "mr") {
@ -1602,21 +1664,13 @@ export class PegasusActor extends Actor {
} else {
rollData.img = `systems/fvtt-pegasus-rpg/images/icons/${rollData.stat.abbrev}.webp`
}
let diceKey = PegasusUtility.getDiceFromLevel(rollData.statDicesLevel)
let diceList = diceKey.split(" ")
let mod = rollData.stat.mod
for (let myDice of diceList) {
myDice = myDice.trim()
let newDice = {
name: "stat", key: myDice, level: PegasusUtility.getLevelFromDice(myDice), mod: mod,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
rollData.dicePool.push(newDice)
mod = 0 // Only first dice has modifier
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("stat", rollData.statDicesLevel, rollData.stat.mod))
if (rollData.statVehicle) {
rollData.dicePool = rollData.dicePool.concat(PegasusUtility.buildDicePool("statvehicle", rollData.statVehicle.currentlevel, 0))
}
}
this.addEffects(rollData, isInit, isPower, subKey == "power-dmg" )
this.addEffects(rollData, isInit, isPower, subKey == "power-dmg")
this.addArmorsShields(rollData, statKey, useShield)
this.addWeapons(rollData, statKey, useShield)
this.addEquipments(rollData, statKey)
@ -1672,7 +1726,7 @@ export class PegasusActor extends Actor {
if (subKey) {
def = __subkey2title[subKey]
}
rollData.title = `Roll : ${def} `
rollData.title = `Roll : ${def} `
rollData.img = "icons/dice/d12black.svg"
this.startRoll(rollData)
} else {
@ -1822,13 +1876,32 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
addTopSpeedBonus( topspeed, bonus) {
addTopSpeedBonus(topspeed, bonus) {
let num = __speed2Num[topspeed] + Number(bonus)
num = Math.max(0, num)
num = Math.min(num, __num2speed.length-1)
num = Math.min(num, __num2speed.length - 1)
return __num2speed[num]
}
/* -------------------------------------------- */
manageVehicleSpeedBonus(speed, name, stat, level) {
if (this.system.statistics.ad.currentspeed == speed) {
if (!this.items.find(effect => effect.system.isspeed == speed)) {
let effect = duplicate(__bonusEffect)
effect.name = name
effect.system.stataffected = stat
effect.system.effectlevel = level
effect.system.isspeed = speed
this.createEmbeddedDocuments("Item", [effect])
}
} else {
let effect = this.items.find(effect => effect.system.isspeed == speed)
if (effect) {
this.deleteEmbeddedDocuments("Item", [effect.id])
}
}
}
/* -------------------------------------------- */
async computeVehicleStats() {
@ -1844,41 +1917,41 @@ export class PegasusActor extends Actor {
sum = list.reduce((value, item2) => value + Number(item2.system[statDef.itemfield]), 0)
}
//console.log("Processing", statDef.field, this.system.statistics[statDef.field].level, list, sum)
if (statDef.subfield){
if (statDef.subfield) {
if (sum != Number(this.system.statistics[statDef.field][statDef.subfield])) {
//console.log("Update", statDef.field, statDef.subfield, sum, this.system.statistics[statDef.field][statDef.subfield])
this.update({ [`system.statistics.${statDef.field}.${statDef.subfield}`]: sum } )
this.update({ [`system.statistics.${statDef.field}.${statDef.subfield}`]: sum })
}
} 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 } )
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 } )
this.update({ [`system.statistics.${statDef.field}.${statDef.additionnal2}`]: sum })
}
}
}
}
}
}
// Top speed management
let mobility = this.items.find( item => item.type == "mobilitymodule")
let mobility = this.items.find(item => item.type == "mobilitymodule")
let arcs = duplicate(this.system.arcs)
if (mobility) {
let propulsion = this.items.find( item => item.type == "propulsionmodule")
let propulsion = this.items.find(item => item.type == "propulsionmodule")
let bonus = (propulsion) ? propulsion.system.topspeed : 0
arcs.frontarc.topspeed = this.addTopSpeedBonus(mobility.system.ts_f, bonus)
arcs.rightarc.topspeed = mobility.system.ts_s
arcs.leftarc.topspeed = mobility.system.ts_s
arcs.toparc.topspeed = mobility.system.ts_s
arcs.bottomarc.topspeed = mobility.system.ts_s
arcs.reararc.topspeed = mobility.system.ts_r
} else {
arcs.reararc.topspeed = mobility.system.ts_r
} else {
arcs.frontarc.topspeed = "fullstop"
arcs.rightarc.topspeed = "fullstop"
arcs.leftarc.topspeed = "fullstop"
@ -1886,43 +1959,49 @@ export class PegasusActor extends Actor {
arcs.bottomarc.topspeed = "fullstop"
arcs.reararc.topspeed = "fullstop"
}
for (let key in this.system.arcs) {
for (let key in this.system.arcs) {
if (this.system.arcs[key].topspeed != arcs[key].topspeed) {
this.update( { 'system.arcs': arcs})
this.update({ 'system.arcs': arcs })
}
}
// VMS management
let hull = this.items.find( item => item.type == "vehiclehull")
let hull = this.items.find(item => item.type == "vehiclehull")
let modules = duplicate(this.system.modules)
if (hull ) {
if (hull) {
modules.totalvms = Number(hull.system.vms)
} else {
modules.totalvms = 0
}
}
let spaceList = this.items.filter(item => item.type == "vehiclemodule") || []
spaceList = spaceList.concat(this.items.filter(item => item.type == "vehicleweaponmodule") || [])
let space = 0
if (spaceList && spaceList.length> 0) {
space = spaceList.reduce((value, item2) => value + Number(item2.system.space), 0)
if (spaceList && spaceList.length > 0) {
space = spaceList.reduce((value, item2) => value + Number(item2.system.space), 0)
}
modules.usedvms = space
if ( modules.totalvms != this.system.modules.totalvms || modules.usedvms != this.system.modules.usedvms) {
this.update( {'system.modules': modules})
if (modules.totalvms != this.system.modules.totalvms || modules.usedvms != this.system.modules.usedvms) {
this.update({ 'system.modules': modules })
}
if (modules.usedvms > modules.totalvms ) {
if (modules.usedvms > modules.totalvms) {
ui.notifications.warn("Warning! No more space available in cargo !!")
}
}
// Speed effect management
this.manageVehicleSpeedBonus("crawling", "Crawling MAN Bonus", "man", 3)
this.manageVehicleSpeedBonus("slow", "Slow MAN Bonus", "man", 1)
this.manageVehicleSpeedBonus("average", "Avoid attack Bonus", "all", 1)
this.manageVehicleSpeedBonus("fast", "Avoid attack Bonus", "all", 3)
this.manageVehicleSpeedBonus("extfast", "Avoid attack Bonus", "all", 5)
}
/* -------------------------------------------- */
getTotalCost( ) {
getTotalCost() {
let sumCost = 0
for( let item of this.items) {
if ( __isVehicle[item.type]) {
for (let item of this.items) {
if (__isVehicle[item.type]) {
if (item.system.cost) {
sumCost += Number(item.system.cost)
}
@ -1930,33 +2009,33 @@ export class PegasusActor extends Actor {
}
return sumCost
}
/* -------------------------------------------- */
async preprocessItemVehicle(event, item, onDrop = false) {
if ( item.type != "effect" && !__isVehicle[item.type]) {
if (item.type != "effect" && !__isVehicle[item.type]) {
ui.notifications.warn("You can't drop Character items over a vehicle sheet.")
return
}
//console.log(">>>>> item", item.type, __isVehicleUnique[item.type])
if ( __isVehicleUnique[item.type] ) {
if (__isVehicleUnique[item.type]) {
let toDelList = []
for (let toDel of this.items) {
if ( toDel.type == item.type) {
toDelList.push( toDel.id )
if (toDel.type == item.type) {
toDelList.push(toDel.id)
}
}
//console.log("TODEL : ", toDelList)
if ( toDelList.length > 0 ) {
if (toDelList.length > 0) {
await this.deleteEmbeddedDocuments('Item', toDelList)
}
}
// 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.`})
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
}
}
@ -1964,44 +2043,101 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
getCrewList() {
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 })
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 } )
addCrew(actorId) {
let crewList = duplicate(this.system.crew.filter(actorDef => actorDef.id != actorId) || [])
crewList.push({ id: actorId })
this.update({ 'system.crew': crewList })
}
/* -------------------------------------------- */
delCrew(actorId) {
let crewList = duplicate( this.system.crew.filter( actorDef => actorDef.id != actorId ) || [] )
this.update( { 'system.crew': crewList } )
let crewList = duplicate(this.system.crew.filter(actorDef => actorDef.id != actorId) || [])
this.update({ 'system.crew': crewList })
}
/* -------------------------------------------- */
rollPoolFromVehicle(statKey, useShield = false, subKey = "none") {
isVehicleFullStop() {
return this.system.statistics.ad.currentspeed == "fullstop"
}
isVehicleCrawling() {
return this.system.statistics.ad.currentspeed == "crawling"
}
isVehicleSlow() {
return this.system.statistics.ad.currentspeed == "slow"
}
isVehicleAverage() {
return this.system.statistics.ad.currentspeed == "average"
}
isVehicleFast() {
return this.system.statistics.ad.currentspeed == "fast"
}
isVehicleExFast() {
return this.system.statistics.ad.currentspeed == "extfast"
}
/* -------------------------------------------- */
isValidActor() {
// 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
let actor
for (let actorDef of this.system.crew) {
let actorTest = game.actors.get(actorDef.id)
if (actorTest.testUserPermission(game.user, "OWNER")) {
return actorTest
}
}
if (!actor) {
ui.notifications.warn("You do no own any actors in the crew of this vehicle.")
return
}
}
/* -------------------------------------------- */
rollPoolFromVehicle(statKey, useShield = false, subKey = "none") {
let actor = this.isValidActor()
if (actor) {
actor.rollPool(statKey, useShield, subKey, this)
}
}
/* -------------------------------------------- */
addVehicleShields(rollData) {
let shields = this.items.filter( shield => shield.type == "vehiclemodule" && shield.system.activated && shield.system.shielddicevalue > 0) || []
for (let shield of shields) {
rollData.vehicleShieldList.push({ label: `${shield.name} (${shield.system.arccoverage})`, type: "vehicleshield", applied: false, value: shield.system.shielddicevalue })
}
}
/* -------------------------------------------- */
rollVehicleDamageResistance() {
let actor = this.isValidActor()
if (actor) {
let stat = this.getStat("hr")
let rollData = this.getCommonRollData("hr")
rollData.mode = "stat"
rollData.title = `Stat ${stat.label}`;
this.addVehicleShields(rollData)
this.startRoll(rollData)
}
}
/* -------------------------------------------- */
activateVehicleModule(itemId) {
let mod = this.items.get(itemId)
if (mod) {
this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }])
}
actor.rollPool( statKey, useShield, subKey, this )
}
}