Stage 5
This commit is contained in:
@ -61,6 +61,8 @@ export class PegasusActor extends Actor {
|
||||
|
||||
if (this.type == 'character') {
|
||||
this.computeNRGHealth();
|
||||
this.data.data.encCapacity = this.getEncumbranceCapacity()
|
||||
this.buildContainerTree()
|
||||
}
|
||||
|
||||
super.prepareDerivedData();
|
||||
@ -71,6 +73,12 @@ export class PegasusActor extends Actor {
|
||||
|
||||
super._preUpdate(changed, options, user);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getEncumbranceCapacity() {
|
||||
return this.data.data.statistics.str.value * 25
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getActivePerks() {
|
||||
let perks = this.data.items.filter(item => item.type == 'perk' && item.data.data.active);
|
||||
@ -287,6 +295,63 @@ export class PegasusActor extends Actor {
|
||||
return duplicate(this.data.items.filter(item => item.type == "equipment") || [])
|
||||
}
|
||||
|
||||
/* ------------------------------------------- */
|
||||
async buildContainerTree() {
|
||||
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [] )
|
||||
for (let equip1 of equipments) {
|
||||
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 ) {
|
||||
equip1.data.contents.push(equip2)
|
||||
equip1.data.contentsEnc += equip2.data.weight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let enc = 0
|
||||
for( let item of equipments) {
|
||||
if (item.data.equipped) {
|
||||
if ( item.data.iscontainer) {
|
||||
enc += item.data.contentsEnc
|
||||
} else {
|
||||
enc += item.data.weight
|
||||
}
|
||||
}
|
||||
}
|
||||
this.encCurrent = enc
|
||||
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() )
|
||||
|
||||
//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) {
|
||||
effect = await PegasusUtility.getEffectFromCompendium("Slowed")
|
||||
effect.data.slow = true
|
||||
this.createEmbeddedDocuments('Item', [effect])
|
||||
}
|
||||
} else {
|
||||
if (effect) {
|
||||
this.deleteEmbeddedDocuments('Item', [effect.id])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getActiveEffects(matching = it => true) {
|
||||
let array = Array.from(this.getEmbeddedCollection("ActiveEffect").values());
|
||||
@ -306,20 +371,50 @@ export class PegasusActor extends Actor {
|
||||
return this.data.data.attributes[attrKey];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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) {
|
||||
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 ) {
|
||||
ui.notifications.warn("Container is already full !")
|
||||
return
|
||||
} else {
|
||||
await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':containerId }] )
|
||||
}
|
||||
} else if ( object && object.data.data.containerid) { // remove from container
|
||||
console.log("Removeing: ", object)
|
||||
await this.updateEmbeddedDocuments( "Item", [{ _id: object.id, 'data.containerid':"" }]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async preprocessItem(event, item, onDrop = false) {
|
||||
console.log("Pre-process !!!", item)
|
||||
if (item.data.type == 'race') {
|
||||
this.applyRace(item.data)
|
||||
} else if (item.data.type == 'ability') {
|
||||
this.applyAbility(item.data, [], true)
|
||||
if (!onDrop) {
|
||||
await this.createEmbeddedDocuments('Item', [item.data])
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (!onDrop) {
|
||||
await this.createEmbeddedDocuments('Item', [item.data])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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 )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -343,7 +438,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;
|
||||
}
|
||||
@ -879,6 +974,10 @@ 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 ) {
|
||||
effectsList.push({ label: "Encumbrance Hindrance", type: "hindrance", applied: false, value: overCapacity })
|
||||
}
|
||||
let effects = this.data.items.filter(item => item.type == 'effect')
|
||||
for (let effect of effects) {
|
||||
effect = duplicate(effect)
|
||||
@ -962,6 +1061,7 @@ export class PegasusActor extends Actor {
|
||||
rollData.statMod = rollData.stat.mod
|
||||
rollData.specList = this.getRelevantSpec(statKey)
|
||||
rollData.selectedSpec = "0"
|
||||
rollData.img = `systems/fvtt-pegasus-rpg/images/icons/${rollData.stat.abbrev}.webp`
|
||||
}
|
||||
|
||||
this.addEffects(rollData)
|
||||
@ -1044,6 +1144,7 @@ export class PegasusActor extends Actor {
|
||||
rollData.specList = [spec]
|
||||
rollData.selectedSpec = spec._id
|
||||
rollData.specName = spec.name
|
||||
rollData.img = spec.img
|
||||
rollData.specDicesLevel = spec.data.level
|
||||
this.startRoll(rollData)
|
||||
} else {
|
||||
@ -1083,6 +1184,7 @@ export class PegasusActor extends Actor {
|
||||
rollData.armor = armor
|
||||
rollData.title = `Armor : ${armor.name}`
|
||||
rollData.isResistance = true;
|
||||
rollData.img = armor.img
|
||||
rollData.otherDicesLevel = armor.data.resistance
|
||||
|
||||
this.startRoll(rollData);
|
||||
@ -1102,6 +1204,8 @@ export class PegasusActor extends Actor {
|
||||
rollData.mode = "power"
|
||||
rollData.power = power
|
||||
rollData.title = `Power : ${power.name}`
|
||||
rollData.img = power.img
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Power not found !", powerId);
|
||||
|
Reference in New Issue
Block a user