Fix #124 containers

This commit is contained in:
sladecraven 2022-11-11 08:47:48 +01:00
parent 3c893e9be5
commit e9ac959a81
2 changed files with 24 additions and 17 deletions

View File

@ -363,12 +363,17 @@ export class PegasusActorSheet extends ActorSheet {
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
const item = fromUuidSync(dragData.uuid)
let itemFull
if (item == undefined) {
item = this.actor.items.get( dragData.uuid )
itemFull = this.actor.items.get( dragData.uuid )
} else {
if (item && item.system) {
itemFull = item
} else {
itemFull = await PegasusUtility.searchItem( item )
}
}
console.log("Dropped", item)
let itemFull = await PegasusUtility.searchItem( item )
console.log("Dropped", item, itemFull)
let ret = await this.actor.preprocessItem( event, itemFull, true )
if ( ret ) {
super._onDropItem(event, dragData)

View File

@ -742,11 +742,11 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
async addObjectToContainer(itemId, containerId) {
async addObjectToContainer(object, containerId) {
let container = this.items.find(item => item.id == containerId && item.system.iscontainer)
let object = this.items.find(item => item.id == itemId)
console.log("Adding container: ", container, object)
if (container) {
if (object.system.iscontainer) {
if (object.system?.iscontainer) {
ui.notifications.warn("Only 1 level of container allowed")
return
}
@ -755,13 +755,13 @@ export class PegasusActor extends Actor {
ui.notifications.warn("Container is already full !")
return
} else {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'system.containerid': containerId }])
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, 'system.containerid': "" }]);
this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'system.containerid':"" }])
}
}
/* -------------------------------------------- */
checkVirtue(virtue) {
let vices = this.getVices()
@ -793,6 +793,9 @@ export class PegasusActor extends Actor {
async preprocessItem(event, item, onDrop = false) {
console.log("Pre-process", item)
if (!item) {
return
}
if (item.type != "effect" && __isVehicle[item.type]) {
ui.notifications.warn("You can't drop Vehicles item over a character sheet.")
return
@ -852,8 +855,7 @@ export class PegasusActor extends Actor {
ChatMessage.create({ content: `Power ${item.name} puchased : ${item.system.purchasedtext}` })
}
let dropID = $(event.target).parents(".item").attr("data-item-id") // Only relevant if container drop
let objectID = item.id || item._id
this.addObjectToContainer(objectID, dropID)
this.addObjectToContainer(item, dropID)
return true
}
@ -1349,21 +1351,21 @@ export class PegasusActor extends Actor {
if (this.isOwner || game.user.isGM) {
let updates = {}
let phyDiceValue = PegasusUtility.getDiceValue(this.system.statistics.phy.value) + this.system.secondary.health.bonus + this.system.statistics.phy.mod + PegasusUtility.getDiceValue(this.system.phy.bonuseffect);
let phyDiceValue = PegasusUtility.getDiceValue(this.system.statistics.phy.value) + this.system.secondary.health.bonus + this.system.statistics.phy.mod + PegasusUtility.getDiceValue(this.system.statistics.phy.bonuseffect);
if (phyDiceValue != this.system.secondary.health.max) {
updates['system.secondary.health.max'] = phyDiceValue
}
if (this.computeValue) {
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 + PegasusUtility.getDiceValue(this.system.mnd.bonuseffect);
let mndDiceValue = PegasusUtility.getDiceValue(this.system.statistics.mnd.value) + this.system.secondary.delirium.bonus + this.system.statistics.mnd.mod + PegasusUtility.getDiceValue(this.system.statistics.mnd.bonuseffect);
if (mndDiceValue != this.system.secondary.delirium.max) {
updates['system.secondary.delirium.max'] = mndDiceValue
}
if (this.computeValue) {
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 + PegasusUtility.getDiceValue(this.system.stl.bonuseffect);
let stlDiceValue = PegasusUtility.getDiceValue(this.system.statistics.stl.value) + this.system.secondary.stealthhealth.bonus + this.system.statistics.stl.mod + PegasusUtility.getDiceValue(this.system.statistics.stl.bonuseffect);
if (stlDiceValue != this.system.secondary.stealthhealth.max) {
updates['system.secondary.stealthhealth.max'] = stlDiceValue
}
@ -1371,7 +1373,7 @@ export class PegasusActor extends Actor {
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 + PegasusUtility.getDiceValue(this.system.soc.bonuseffect);
let socDiceValue = PegasusUtility.getDiceValue(this.system.statistics.soc.value) + this.system.secondary.socialhealth.bonus + this.system.statistics.soc.mod + PegasusUtility.getDiceValue(this.system.statistics.soc.bonuseffect);
if (socDiceValue != this.system.secondary.socialhealth.max) {
updates['system.secondary.socialhealth.max'] = socDiceValue
}
@ -1379,7 +1381,7 @@ export class PegasusActor extends Actor {
updates['system.secondary.socialhealth.value'] = socDiceValue
}
let nrgValue = PegasusUtility.getDiceValue(this.system.statistics.foc.value) + this.system.nrg.mod + this.system.statistics.foc.mod + PegasusUtility.getDiceValue(this.system.foc.bonuseffect)
let nrgValue = PegasusUtility.getDiceValue(this.system.statistics.foc.value) + this.system.nrg.mod + this.system.statistics.foc.mod + PegasusUtility.getDiceValue(this.system.statistics.foc.bonuseffect)
if (nrgValue != this.system.nrg.absolutemax) {
updates['system.nrg.absolutemax'] = nrgValue
}