Fix #49
This commit is contained in:
@@ -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 }])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user