This commit is contained in:
2022-09-27 14:16:11 +02:00
parent 5346debdbb
commit 0386f5e272
5 changed files with 26 additions and 7 deletions

View File

@@ -2171,7 +2171,27 @@ export class PegasusActor extends Actor {
activateVehicleModule(itemId) {
let mod = this.items.get(itemId)
if (mod) {
this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }])
if ( mod.system.nrg && mod.system.nrg > 0) {
let pc = duplicate( this.system.statistics.pc)
if ( !mod.system.activated ) { // Previous state was non activated -> activated now
if ( mod.system.nrg > pc.curnrg) {
ChatMessage.create( { content: `The Vehicle ${this.name} does not have enough Energy to Activate this module at this time.`})
return
}
this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }])
pc.actnrg += Number(mod.system.nrg)
pc.maxnrg -= Number(mod.system.nrg)
pc.curnrg -= Number(mod.system.nrg)
this.update({'system.statistics.pc': pc})
} else { // Now deactivated
pc.actnrg -= Number(mod.system.nrg)
pc.maxnrg += Number(mod.system.nrg)
this.update({'system.statistics.pc': pc})
this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }])
}
} else {
this.updateEmbeddedDocuments('Item', [{ _id: mod.id, 'system.activated': !mod.system.activated }])
}
}
}