Stage 5
This commit is contained in:
@@ -16,7 +16,7 @@ export class PegasusActorSheet extends ActorSheet {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["fvtt-pegasus-rpg", "sheet", "actor"],
|
||||
template: "systems/fvtt-pegasus-rpg/templates/actor-sheet.html",
|
||||
width: 640,
|
||||
width: 920,
|
||||
height: 720,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
|
||||
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
||||
@@ -58,6 +58,10 @@ export class PegasusActorSheet extends ActorSheet {
|
||||
role: duplicate(this.actor.getRole()),
|
||||
effects: duplicate(this.actor.getEffects()),
|
||||
moneys: duplicate(this.actor.getMoneys()),
|
||||
encCapacity: this.actor.getEncumbranceCapacity(),
|
||||
containersTree: this.actor.containersTree,
|
||||
encCurrent: this.actor.encCurrent,
|
||||
encHindrance: this.actor.encHindrance,
|
||||
options: this.options,
|
||||
owner: this.document.isOwner,
|
||||
editScore: this.options.editScore,
|
||||
@@ -180,6 +184,13 @@ export class PegasusActorSheet extends ActorSheet {
|
||||
this.actor.incDecQuantity( li.data("item-id"), +1 );
|
||||
} );
|
||||
|
||||
html.find('.momentum-minus').click(event => {
|
||||
this.actor.modifyMomentum( -1 )
|
||||
} )
|
||||
html.find('.momentum-plus').click(event => {
|
||||
this.actor.modifyMomentum( 1 )
|
||||
} )
|
||||
|
||||
html.find('.unarmed-attack').click((event) => {
|
||||
this.actor.rollUnarmedAttack();
|
||||
});
|
||||
@@ -298,7 +309,11 @@ export class PegasusActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDropItem(event, dragData) {
|
||||
console.log(">>>>>> DROPPED!!!!")
|
||||
let item = await PegasusUtility.searchItem( dragData)
|
||||
if (item == undefined) {
|
||||
item = this.actor.items.get( dragData.data._id )
|
||||
}
|
||||
this.actor.preprocessItem( event, item, true )
|
||||
super._onDropItem(event, dragData)
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -48,7 +48,7 @@ Hooks.once("init", async function () {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.socket.on("system.fvtt-pegasus-rpg", data => {
|
||||
PegasusUtility.onSocketMesssage(data);
|
||||
PegasusUtility.onSocketMesssage(data)
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
@@ -38,6 +38,9 @@ export class PegasusUtility {
|
||||
Handlebars.registerHelper('upper', function (text) {
|
||||
return text.toUpperCase();
|
||||
});
|
||||
Handlebars.registerHelper('lower', function (text) {
|
||||
return text.toLowerCase()
|
||||
});
|
||||
Handlebars.registerHelper('upperFirst', function (text) {
|
||||
if (typeof text !== 'string') return text
|
||||
return text.charAt(0).toUpperCase() + text.slice(1)
|
||||
@@ -65,6 +68,18 @@ export class PegasusUtility {
|
||||
this.specs = specs.map(i => i.toObject());
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async addItemDropToActor(actor, item) {
|
||||
actor.preprocessItem("none", item, false)
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
|
||||
content: `<div>The item ${item.name} has been dropped on the actor ${actor.name}</div`
|
||||
}
|
||||
ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async dropItemOnToken(canvas, data) {
|
||||
if (data.type != "Item") {
|
||||
@@ -79,8 +94,11 @@ export class PegasusUtility {
|
||||
if (x >= token.x && x <= (token.x + token.width)
|
||||
&& y >= token.y && y <= (token.y + token.height)) {
|
||||
let item = await this.searchItem(data)
|
||||
token.actor.preprocessItem("none", item, false)
|
||||
console.log("Dropped !!!", item, token)
|
||||
if (game.user.isGM || token.actor.isOwner) {
|
||||
this.addItemDropToActor(token.actor, item)
|
||||
} else {
|
||||
game.socket.emit("system.fvtt-pegasus-rpg", { name: "msg_gm_item_drop", data: { actorId: token.actor.id, itemId: item.id, isPack: item.pack } })
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -188,7 +206,9 @@ export class PegasusUtility {
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-options-level.html',
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-options-range.html',
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-options-equipment-types.html',
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-equipment-effects.html'
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-equipment-effects.html',
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-actor-stat-block.html',
|
||||
'systems/fvtt-pegasus-rpg/templates/partial-actor-status.html'
|
||||
]
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
@@ -196,7 +216,7 @@ export class PegasusUtility {
|
||||
/* -------------------------------------------- */
|
||||
static async getEffectFromCompendium(effectName) {
|
||||
effectName = effectName.toLowerCase()
|
||||
let effect = game.items.find(item => item.data.type == 'effect' && item.name.toLowerCase() == effectName)
|
||||
let effect = game.items.contents.find(item => item.type == 'effect' && item.name.toLowerCase() == effectName)
|
||||
if (!effect) {
|
||||
let effects = await this.loadCompendium('fvtt-pegasus.effect', item => item.name.toLowerCase() == effectName)
|
||||
let objs = effects.map(i => i.toObject())
|
||||
@@ -325,17 +345,6 @@ export class PegasusUtility {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static clearDefenseState(defenderId) {
|
||||
this.defenderStore[defenderId] = undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static storeDefenseState(rollData) {
|
||||
game.socket.emit("system.fvtt-weapons-of-the-gods", {
|
||||
name: "msg_update_defense_state", data: { defenderId: rollData.defenderId, rollId: rollData.rollId }
|
||||
});
|
||||
this.updateDefenseState(rollData.defenderId, rollData.rollId);
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static updateRollData(rollData) {
|
||||
|
||||
@@ -358,13 +367,23 @@ export class PegasusUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static onSocketMesssage(msg) {
|
||||
//console.log("SOCKET MESSAGE", msg.name, game.user.character.id, msg.data.defenderId);
|
||||
static async onSocketMesssage(msg) {
|
||||
console.log("SOCKET MESSAGE", msg.name)
|
||||
if (msg.name == "msg_update_defense_state") {
|
||||
this.updateDefenseState(msg.data.defenderId, msg.data.rollId);
|
||||
this.updateDefenseState(msg.data.defenderId, msg.data.rollId)
|
||||
}
|
||||
if (msg.name == "msg_update_roll") {
|
||||
this.updateRollData(msg.data);
|
||||
this.updateRollData(msg.data)
|
||||
}
|
||||
if (msg.name == "msg_gm_item_drop" && game.user.isGM) {
|
||||
let actor = game.actors.get( msg.data.actorId )
|
||||
let item
|
||||
if (msg.data.isPack) {
|
||||
item = await fromUuid("Compendium." + msg.data.isPack + "." + msg.data.itemId)
|
||||
} else {
|
||||
item = game.items.get(msg.data.itemId)
|
||||
}
|
||||
this.addItemDropToActor( actor, item )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,9 +522,6 @@ export class PegasusUtility {
|
||||
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-generic-result.html`, rollData)
|
||||
});
|
||||
|
||||
if (rollData.defender) {
|
||||
this.storeDefenseState(rollData);
|
||||
}
|
||||
// Init stuf
|
||||
if (rollData.isInit) {
|
||||
let combat = game.combats.get(rollData.combatId)
|
||||
@@ -543,11 +559,11 @@ export class PegasusUtility {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
let bestScore = (bestRoll * 10) + index;
|
||||
rollData.bestScore = bestScore;
|
||||
rollData.finalScore = bestScore + rollData.negativeModifier + rollData.positiveModifier;
|
||||
let bestScore = (bestRoll * 10) + index
|
||||
rollData.bestScore = bestScore
|
||||
rollData.finalScore = bestScore + rollData.negativeModifier + rollData.positiveModifier
|
||||
|
||||
this.saveRollData(rollData);
|
||||
this.saveRollData(rollData)
|
||||
|
||||
this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-generic-result.html`, rollData)
|
||||
@@ -598,18 +614,19 @@ export class PegasusUtility {
|
||||
chatGM.whisper = this.getUsers(user => user.isGM);
|
||||
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
|
||||
console.log("blindMessageToGM", chatGM);
|
||||
game.socket.emit("system.fvtt-weapons-of-the-gods", { msg: "msg_gm_chat_message", data: chatGM });
|
||||
game.socket.emit("system.fvtt-pegasus-rgp", { msg: "msg_gm_chat_message", data: chatGM });
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async searchItem(dataItem) {
|
||||
let item;
|
||||
let item
|
||||
if (dataItem.pack) {
|
||||
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id);
|
||||
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id)
|
||||
} else {
|
||||
item = game.items.get(dataItem.id)
|
||||
}
|
||||
return item;
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user