Gestion intensite
This commit is contained in:
144
modules/imperium5-actor-pm-sheet.js
Normal file
144
modules/imperium5-actor-pm-sheet.js
Normal file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {ActorSheet}
|
||||
*/
|
||||
|
||||
import { Imperium5Utility } from "./imperium5-utility.js";
|
||||
import { Imperium5RollDialog } from "./imperium5-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class Imperium5ActorPMSheet extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["fvtt-imperium5", "sheet", "actor"],
|
||||
template: "systems/fvtt-imperium5/templates/actor-pm-sheet.html",
|
||||
width: 720,
|
||||
height: 760,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
|
||||
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
||||
editScore: true
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
let actorData = duplicate(this.object.system)
|
||||
|
||||
let formData = {
|
||||
title: this.title,
|
||||
id: this.actor.id,
|
||||
type: this.actor.type,
|
||||
img: this.actor.img,
|
||||
name: this.actor.name,
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
system: actorData,
|
||||
archetype: this.actor.getArchetype(),
|
||||
specialites: this.actor.getSpecialites(),
|
||||
familiarites: this.actor.getFamiliarites(),
|
||||
nature: this.actor.getNatureProfonde(),
|
||||
traits: this.actor.getTraits(),
|
||||
symbioses: this.actor.getSymbioses(),
|
||||
equipements: this.actor.getEquipements(),
|
||||
capacites: this.actor.getCapacites(),
|
||||
singularites: this.actor.getSingularites(),
|
||||
contacts: this.actor.getContacts(),
|
||||
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
|
||||
limited: this.object.limited,
|
||||
options: this.options,
|
||||
owner: this.document.isOwner,
|
||||
editScore: this.options.editScore,
|
||||
isGM: game.user.isGM
|
||||
}
|
||||
this.formData = formData;
|
||||
|
||||
console.log("PM : ", formData, this.object);
|
||||
return formData;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) return;
|
||||
|
||||
html.bind("keydown", function(e) { // Ignore Enter in actores sheet
|
||||
if (e.keyCode === 13) return false;
|
||||
});
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
let itemId = li.data("item-id");
|
||||
const item = this.actor.items.get( itemId );
|
||||
item.sheet.render(true);
|
||||
});
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
Imperium5Utility.confirmDelete(this, li);
|
||||
});
|
||||
|
||||
|
||||
html.find('.quantity-minus').click(event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.incDecQuantity( li.data("item-id"), -1 );
|
||||
} );
|
||||
html.find('.quantity-plus').click(event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.incDecQuantity( li.data("item-id"), +1 );
|
||||
} );
|
||||
|
||||
html.find('.lock-unlock-sheet').click((event) => {
|
||||
this.options.editScore = !this.options.editScore;
|
||||
this.render(true);
|
||||
});
|
||||
html.find('.item-link a').click((event) => {
|
||||
const itemId = $(event.currentTarget).data("item-id")
|
||||
const item = this.actor.getOwnedItem(itemId);
|
||||
item.sheet.render(true);
|
||||
});
|
||||
html.find('.item-equip').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
this.actor.equipItem( li.data("item-id") );
|
||||
this.render(true);
|
||||
});
|
||||
html.find('.update-field').change(ev => {
|
||||
const fieldName = $(ev.currentTarget).data("field-name");
|
||||
let value = Number(ev.currentTarget.value);
|
||||
this.actor.update( { [`${fieldName}`]: value } );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
const bodyHeight = position.height - 192;
|
||||
sheetBody.css("height", bodyHeight);
|
||||
return position;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDropItemUNUSED(event, dragData) {
|
||||
let item = await Imperium5Utility.searchItem( dragData)
|
||||
if (item == undefined) {
|
||||
item = this.actor.items.get( dragData.data._id )
|
||||
}
|
||||
//this.actor.preprocessItem( event, item, true )
|
||||
super._onDropItem(event, dragData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
// Update the Actor
|
||||
return this.object.update(formData);
|
||||
}
|
||||
}
|
||||
@@ -59,32 +59,6 @@ export class Imperium5ActorSheet extends ActorSheet {
|
||||
return formData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async openGenericRoll() {
|
||||
let rollData = Imperium5Utility.getBasicRollData()
|
||||
rollData.alias = "Dice Pool Roll",
|
||||
rollData.mode = "generic"
|
||||
rollData.title = `Dice Pool Roll`
|
||||
rollData.img = "icons/dice/d12black.svg"
|
||||
|
||||
let rollDialog = await Imperium5RollDialog.create( this.actor, rollData);
|
||||
rollDialog.render( true );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollIDR( itemId, diceValue) {
|
||||
let item = this.actor.items.get( itemId) ?? {name: "Unknown"}
|
||||
let myRoll = new Roll(diceValue+"x").roll({ async: false })
|
||||
await Imperium5Utility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
|
||||
content: `${this.actor.name} has roll IDR for ${item.name} : ${myRoll.total}`
|
||||
}
|
||||
ChatMessage.create(chatData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
@@ -183,7 +157,6 @@ export class Imperium5ActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDropItemUNUSED(event, dragData) {
|
||||
console.log(">>>>>> DROPPED!!!!")
|
||||
let item = await Imperium5Utility.searchItem( dragData)
|
||||
if (item == undefined) {
|
||||
item = this.actor.items.get( dragData.data._id )
|
||||
|
||||
@@ -111,6 +111,10 @@ export class Imperium5Actor extends Actor {
|
||||
let item = duplicate(this.items.filter( it => it.type == "contact") || [] )
|
||||
return item
|
||||
}
|
||||
getResources() {
|
||||
let item = duplicate(this.items.filter( it => it.type == "equipement" || it.type == "singularite" || it.type == "capacite" || it.type == "contact") || [] )
|
||||
return item
|
||||
}
|
||||
getUnusedParadigmes() {
|
||||
let paraList = []
|
||||
for(let k in this.system.paradigmes) {
|
||||
@@ -276,6 +280,8 @@ export class Imperium5Actor extends Actor {
|
||||
rollData.img = this.img
|
||||
rollData.capacites = this.getUnusedCapacites()
|
||||
rollData.paradigmes = this.getUnusedParadigmes()
|
||||
rollData.ressources = this.getResources()
|
||||
rollData.selectedRessources = []
|
||||
rollData.selectedParadigme = "none"
|
||||
rollData.karma = this.system.karma.value
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { Imperium5Actor } from "./imperium5-actor.js";
|
||||
import { Imperium5ItemSheet } from "./imperium5-item-sheet.js";
|
||||
import { Imperium5ActorSheet } from "./imperium5-actor-sheet.js";
|
||||
import { Imperium5ActorPMSheet } from "./imperium5-actor-pm-sheet.js";
|
||||
import { Imperium5Utility } from "./imperium5-utility.js";
|
||||
import { Imperium5Combat } from "./imperium5-combat.js";
|
||||
import { Imperium5Item } from "./imperium5-item.js";
|
||||
@@ -50,6 +51,7 @@ Hooks.once("init", async function () {
|
||||
// Register sheet application classes
|
||||
Actors.unregisterSheet("core", ActorSheet)
|
||||
Actors.registerSheet("fvtt-imperium5", Imperium5ActorSheet, { types: ["character"], makeDefault: true })
|
||||
Actors.registerSheet("fvtt-imperium5", Imperium5ActorPMSheet, { types: ["pm"], makeDefault: true })
|
||||
|
||||
Items.unregisterSheet("core", ItemSheet)
|
||||
Items.registerSheet("fvtt-imperium5", Imperium5ItemSheet, { makeDefault: true } )
|
||||
|
||||
@@ -68,14 +68,14 @@ export class Imperium5RollDialog extends Dialog {
|
||||
this.rollData.useArchetype = event.currentTarget.checked
|
||||
this.updatePCPool()
|
||||
})
|
||||
html.find('#select-use-aide').change(async (event) => {
|
||||
this.rollData.useAide = event.currentTarget.checked
|
||||
html.find('#select-aide-pj').change(async (event) => {
|
||||
this.rollData.nbAide = Number(event.currentTarget.value)
|
||||
this.updatePCPool()
|
||||
})
|
||||
html.find('#select-use-karma').change(async (event) => {
|
||||
this.rollData.useKarma = event.currentTarget.checked
|
||||
this.updatePCPool()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export class Imperium5Utility {
|
||||
/* -------------------------------------------- */
|
||||
static async init() {
|
||||
Hooks.on('renderChatLog', (log, html, data) => Imperium5Utility.chatListeners(html));
|
||||
Hooks.on("getChatLogEntryContext", (html, options) => Imperium5Utility.chatRollMenu(html, options))
|
||||
|
||||
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
||||
Imperium5Utility.pushInitiativeOptions(html, options);
|
||||
@@ -53,11 +54,11 @@ export class Imperium5Utility {
|
||||
for (var i = from; i < to; i += incr)
|
||||
accum += block.fn(i);
|
||||
return accum;
|
||||
})
|
||||
Handlebars.registerHelper('times', function(n, block) {
|
||||
})
|
||||
Handlebars.registerHelper('times', function (n, block) {
|
||||
var accum = '';
|
||||
for(var i = 1; i <= n; ++i)
|
||||
accum += block.fn(i);
|
||||
for (var i = 1; i <= n; ++i)
|
||||
accum += block.fn(i);
|
||||
return accum;
|
||||
})
|
||||
}
|
||||
@@ -72,9 +73,9 @@ export class Imperium5Utility {
|
||||
default: false,
|
||||
type: Boolean
|
||||
})
|
||||
game.settings.register("fvtt-imperium5", "use-singularite", {
|
||||
name: "Utilisation complémentaire des Singularités",
|
||||
hint: "Si coché, les Singularités peuvent permettre de réduire de 1 la valeur d'un dé",
|
||||
game.settings.register("fvtt-imperium5", "use-specialite", {
|
||||
name: "Utilisation complémentaire des Spécialités",
|
||||
hint: "Si coché, les Spécialités peuvent permettre de réduire de 1 la valeur d'un dé",
|
||||
scope: "world",
|
||||
config: true,
|
||||
default: false,
|
||||
@@ -129,11 +130,11 @@ export class Imperium5Utility {
|
||||
this.applyParadigme(rollData, paraKey)
|
||||
})
|
||||
|
||||
html.on("click", '.apply-singularite', event => {
|
||||
html.on("click", '.apply-specialite', event => {
|
||||
let resultIndex = $(event.currentTarget).data("result-index")
|
||||
let rollData = this.getRollDataFromMessage(event)
|
||||
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
|
||||
this.applySingularite(rollData, resultIndex)
|
||||
this.applySpecialite(rollData, resultIndex)
|
||||
})
|
||||
|
||||
html.on("change", '.transfer-success', event => {
|
||||
@@ -142,7 +143,24 @@ export class Imperium5Utility {
|
||||
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
|
||||
this.applySuccessTransfer(rollData, nbSuccess)
|
||||
})
|
||||
|
||||
|
||||
html.on("change", '.select-ressource', async event => {
|
||||
// Filter / remove the ressource
|
||||
let rollData = this.getRollDataFromMessage(event)
|
||||
let ressource = rollData.ressources.find(r => r._id == event.currentTarget.value)
|
||||
rollData.selectedRessources.push(ressource)
|
||||
rollData.ressources = rollData.ressources.filter(r => r._id != event.currentTarget.value)
|
||||
rollData.realSuccessPC--;
|
||||
this.computeIntensite(rollData)
|
||||
// Update the roll data in the message
|
||||
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
|
||||
})
|
||||
msg.setFlag("world", "imperium5-roll-data", rollData)
|
||||
this.removeChatMessageId(rollData.previousMessageId)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -237,24 +255,22 @@ export class Imperium5Utility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static updateRollData(rollData) {
|
||||
|
||||
let id = rollData.rollId;
|
||||
let oldRollData = this.rollDataStore[id] || {};
|
||||
let newRollData = mergeObject(oldRollData, rollData);
|
||||
this.rollDataStore[id] = newRollData;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static saveRollData(rollData) {
|
||||
game.socket.emit("system.fvtt-imperium5", {
|
||||
name: "msg_update_roll", data: rollData
|
||||
}); // Notify all other clients of the roll
|
||||
this.updateRollData(rollData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getRollData(id) {
|
||||
return this.rollDataStore[id];
|
||||
static chatRollMenu(html, options) {
|
||||
let canApply = li => canvas.tokens.controlled.length && li.find(".imperium5-roll").length
|
||||
let canApplyIntensite = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "imperium5-roll-data")
|
||||
return (rollData.currentIntensite > 0)
|
||||
}
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouer +3 (1 point de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyIntensite,
|
||||
callback: li => Imperium5Utility.applyBonneAventureRoll(li, -1, "+3")
|
||||
}
|
||||
)
|
||||
return options
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -330,7 +346,7 @@ export class Imperium5Utility {
|
||||
let capa = rollData.capacites.find(c => c._id == rollData.usedCapacite)
|
||||
capaDice = capa.system.aide
|
||||
}
|
||||
let val = rollData.ame.value + capaDice + ((rollData.useKarma) ? 1 : 0) + ((rollData.useArchetype) ? 1 : 0) + ((rollData.useAide) ? 1 : 0) + rollData.ameMalus
|
||||
let val = rollData.ame.value + capaDice + ((rollData.useKarma) ? 1 : 0) + ((rollData.useArchetype) ? 1 : 0) + rollData.nbAide + rollData.ameMalus
|
||||
return Math.max(val, 0)
|
||||
}
|
||||
|
||||
@@ -350,8 +366,21 @@ export class Imperium5Utility {
|
||||
if (rollData.useEntropieReussite && myRoll.terms[2].results[0].result == 7) {
|
||||
rollData.successGM++
|
||||
}
|
||||
// Calcul unité de narration
|
||||
rollData.nbUnitesNarration = Math.max(rollData.successPC - 1, 0)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeIntensite(rollData) {
|
||||
rollData.totalIntensite = 0
|
||||
let pi = 3
|
||||
let nbSuccess = rollData.realSuccessPC
|
||||
while (nbSuccess) {
|
||||
rollData.totalIntensite += pi
|
||||
pi = 2 // 3 for the first, 2 after
|
||||
nbSuccess--
|
||||
}
|
||||
for(let r of rollData.selectedRessources) {
|
||||
rollData.totalIntensite += r.system.ressource
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -386,6 +415,7 @@ export class Imperium5Utility {
|
||||
// Calcul réussites
|
||||
this.computeReussites(rollData)
|
||||
rollData.realSuccessPC = rollData.successPC // To manage source transfer
|
||||
this.computeIntensite(rollData)
|
||||
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
|
||||
@@ -412,12 +442,12 @@ export class Imperium5Utility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async applySingularite(rollData, resultIndex) {
|
||||
static async applySpecialite(rollData, resultIndex) {
|
||||
let res = rollData.resultsPC[resultIndex]
|
||||
res.result = (res.result > 1) ? res.result-1 : res.result
|
||||
res.result = (res.result > 1) ? res.result - 1 : res.result
|
||||
this.computeReussites(rollData)
|
||||
rollData.useSingularites = false
|
||||
rollData.singulariteApplied = true
|
||||
rollData.useSpecialite = false
|
||||
rollData.specialiteApplied = true
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
|
||||
})
|
||||
@@ -428,10 +458,9 @@ export class Imperium5Utility {
|
||||
/* ------------------------- ------------------- */
|
||||
static async applySuccessTransfer(rollData, nbSuccess) {
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.transferToSource( nbSuccess)
|
||||
actor.transferToSource(nbSuccess)
|
||||
rollData.realSuccessPC -= nbSuccess
|
||||
rollData.sourceTransfer = nbSuccess
|
||||
rollData.nbUnitesNarration = Math.max(rollData.realSuccessPC - 1, 0)
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
|
||||
})
|
||||
@@ -439,36 +468,6 @@ export class Imperium5Utility {
|
||||
this.removeChatMessageId(rollData.previousMessageId)
|
||||
}
|
||||
|
||||
/* ------------------------- ------------------- */
|
||||
static async updateRoll(rollData) {
|
||||
|
||||
let diceResults = rollData.diceResults
|
||||
let sortedRoll = []
|
||||
for (let i = 0; i < 10; i++) {
|
||||
sortedRoll[i] = 0;
|
||||
}
|
||||
for (let dice of diceResults) {
|
||||
sortedRoll[dice.result]++
|
||||
}
|
||||
let index = 0;
|
||||
let bestRoll = 0;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (sortedRoll[i] > bestRoll) {
|
||||
bestRoll = sortedRoll[i]
|
||||
index = i
|
||||
}
|
||||
}
|
||||
let bestScore = (bestRoll * 10) + index
|
||||
rollData.bestScore = bestScore
|
||||
rollData.finalScore = bestScore + rollData.negativeModifier + rollData.positiveModifier
|
||||
|
||||
this.saveRollData(rollData)
|
||||
|
||||
this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-generic-result.html`, rollData)
|
||||
});
|
||||
}
|
||||
|
||||
/* ------------------------- ------------------- */
|
||||
static async rerollDice(actorId, diceIndex = -1) {
|
||||
let actor = game.actors.get(actorId)
|
||||
@@ -562,12 +561,13 @@ export class Imperium5Utility {
|
||||
realiteDice: 0,
|
||||
ameMalus: 0,
|
||||
useArchetype: false,
|
||||
useAide: false,
|
||||
nbAide: 0,
|
||||
useKarma: false,
|
||||
usedCapacite: "none",
|
||||
seuil: 2,
|
||||
currentIntensite: -1,
|
||||
nbSuccessSource: 0,
|
||||
useSingularites: game.settings.get("fvtt-imperium5", "use-singularite"),
|
||||
useSpecialite: game.settings.get("fvtt-imperium5", "use-specialite"),
|
||||
useEntropieReussite: game.settings.get("fvtt-imperium5", "use-entropie-reussite")
|
||||
}
|
||||
Imperium5Utility.updateWithTarget(rollData)
|
||||
|
||||
Reference in New Issue
Block a user