This commit is contained in:
2022-03-06 20:07:41 +01:00
parent e321ba6ec2
commit 0ce493bc92
25 changed files with 735 additions and 327 deletions

View File

@@ -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
}
/* -------------------------------------------- */