Enhance styling

This commit is contained in:
2022-03-07 16:00:53 +01:00
parent b97d626fc7
commit 041568f34e
19 changed files with 213 additions and 153 deletions

View File

@ -297,13 +297,13 @@ export class PegasusActor extends Actor {
/* ------------------------------------------- */
async buildContainerTree() {
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [] )
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [])
for (let equip1 of equipments) {
if ( equip1.data.iscontainer) {
if (equip1.data.iscontainer) {
equip1.data.contents = []
equip1.data.contentsEnc = 0
for (let equip2 of equipments) {
if ( equip1._id != equip2._id && equip2.data.containerid == equip1._id ) {
if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) {
equip1.data.contents.push(equip2)
equip1.data.contentsEnc += equip2.data.weight
}
@ -311,27 +311,35 @@ export class PegasusActor extends Actor {
}
}
// Compute whole enc
let enc = 0
for( let item of equipments) {
for (let item of equipments) {
if (item.data.equipped) {
if ( item.data.iscontainer) {
if (item.data.iscontainer) {
enc += item.data.contentsEnc
} else {
enc += item.data.weight
}
}
}
for (let item of this.data.items) { // Process items/shields/armors
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.data.data.equipped) {
enc += item.data.data.weight
}
}
// Store local values
this.encCurrent = enc
this.containersTree = equipments.filter( item => item.data.containerid == "") // Returns the root of equipements without container
this.containersTree = equipments.filter(item => item.data.containerid == "") // Returns the root of equipements without container
// Manages slow effect
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity() )
this.encHindrance = Math.floor(this.encCurrent / this.getEncumbranceCapacity() )
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
this.encHindrance = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
//console.log("Capacity", overCapacity, this.encCurrent / this.getEncumbranceCapacity() )
let effect = this.data.items.find(item => item.type == "effect" && item.data.data.slow)
if (overCapacity >= 4 ) {
if ( !effect) {
if (overCapacity >= 4) {
if (!effect) {
effect = await PegasusUtility.getEffectFromCompendium("Slowed")
effect.data.slow = true
this.createEmbeddedDocuments('Item', [effect])
@ -344,14 +352,27 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
modifyMomentum( incDec) {
modifyMomentum(incDec) {
let momentum = duplicate(this.data.data.momentum)
momentum.value += incDec
if ( momentum.value >= 0 && momentum.value <= momentum.max ){
this.update( { 'data.momentum': momentum})
if (momentum.value >= 0 ) {
this.update({ 'data.momentum': momentum })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM'))
}
if (incDec > 0) {
chatData.content = `<div>${this.name} has gained a Momentum</div`
} else {
chatData.content = `<div>${this.name} has used a Momentum</div`
}
ChatMessage.create(chatData)
}else {
ui.notifications.warn("Momentum cannot go below 0")
}
}
/* -------------------------------------------- */
getActiveEffects(matching = it => true) {
let array = Array.from(this.getEmbeddedCollection("ActiveEffect").values());
@ -372,25 +393,25 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
async addObjectToContainer( itemId, containerId ) {
let container = this.data.items.find( item => item.id == containerId && item.data.data.iscontainer)
let object = this.data.items.find( item => item.id == itemId )
async addObjectToContainer(itemId, containerId) {
let container = this.data.items.find(item => item.id == containerId && item.data.data.iscontainer)
let object = this.data.items.find(item => item.id == itemId)
console.log("Found", container, object)
if ( container ) {
if ( object.data.data.iscontainer) {
if (container) {
if (object.data.data.iscontainer) {
ui.notifications.warn("Only 1 level of container allowed")
return
}
let alreadyInside = this.data.items.filter( item => item.data.data.containerid && item.data.data.containerid == containerId);
if ( alreadyInside.length >= container.data.data.containercapacity ) {
let alreadyInside = this.data.items.filter(item => item.data.data.containerid && item.data.data.containerid == containerId);
if (alreadyInside.length >= container.data.data.containercapacity) {
ui.notifications.warn("Container is already full !")
return
} else {
await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':containerId }] )
} else {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': containerId }])
}
} else if ( object && object.data.data.containerid) { // remove from container
} else if (object && object.data.data.containerid) { // remove from container
console.log("Removeing: ", object)
await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':"" }]);
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': "" }]);
}
}
@ -414,7 +435,7 @@ export class PegasusActor extends Actor {
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(objectID, dropID)
}
/* -------------------------------------------- */
@ -438,7 +459,7 @@ export class PegasusActor extends Actor {
getSubActors() {
let subActors = [];
for (let id of this.data.data.subactors) {
subActors.push( duplicate(game.actors.get(id)) )
subActors.push(duplicate(game.actors.get(id)))
}
return subActors;
}
@ -531,7 +552,7 @@ export class PegasusActor extends Actor {
effects.push(effect)
}
if (effects.length > 0) {
this.createEmbeddedDocuments('Item', effects )
this.createEmbeddedDocuments('Item', effects)
}
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.activated': true }])
}
@ -735,7 +756,7 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
async computeNRGHealth() {
if (this.isToken) return
if (this.isOwner || game.user.isGM) {
let updates = {}
let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value) + this.data.data.secondary.health.bonus + this.data.data.statistics.phy.mod;
@ -974,8 +995,8 @@ export class PegasusActor extends Actor {
if (this.data.data.combat.hindrancedice > 0) {
effectsList.push({ label: "Health/Delirium Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.hindrancedice })
}
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity() )
if (overCapacity > 0 ) {
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
effectsList.push({ label: "Encumbrance Hindrance", type: "hindrance", applied: false, value: overCapacity })
}
let effects = this.data.items.filter(item => item.type == 'effect')
@ -1083,14 +1104,14 @@ export class PegasusActor extends Actor {
}
/* -------------------------------------------- */
powerDmgRoll( itemId) {
powerDmgRoll(itemId) {
let power = this.data.items.get(itemId)
if (power ) {
if (power) {
power = duplicate(power)
this.rollPool( power.data.dmgstatistic )
this.rollPool(power.data.dmgstatistic)
}
}
/* -------------------------------------------- */
rollPool(statKey, useShield = false) {
let stat = this.getStat(statKey)