Initial import

This commit is contained in:
2023-12-11 20:11:10 +01:00
commit db5fbb0e63
48 changed files with 7062 additions and 0 deletions

View File

@ -0,0 +1,197 @@
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { EcrymeUtility } from "../common/tedeum-utility.js";
/* -------------------------------------------- */
export class EcrymeActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-ecryme", "sheet", "actor"],
template: "systems/fvtt-ecryme/templates/actors/actor-sheet.hbs",
width: 860,
height:680,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
}
/* -------------------------------------------- */
async getData() {
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: duplicate(this.object.system),
limited: this.object.limited,
skills: this.actor.prepareSkills(),
traits: this.actor.getRollTraits(),
confrontations: this.actor.getConfrontations(),
ideal: this.actor.getIdeal(),
spleen: this.actor.getSpleen(),
impacts: this.object.getImpacts(),
config: duplicate(game.system.ecryme.config),
weapons: this.actor.getWeapons(),
maneuvers: this.actor.getManeuvers(),
impactsMalus: this.actor.getImpactsMalus(),
archetype: duplicate(this.actor.getArchetype()),
equipments: this.actor.getEquipments(),
hasCephaly: EcrymeUtility.hasCephaly(),
hasBoheme: EcrymeUtility.hasBoheme(),
hasAmertume: EcrymeUtility.hasAmertume(),
cephalySkills: this.actor.getCephalySkills(),
subActors: duplicate(this.actor.getSubActors()),
annency: this.actor.getAnnency(),
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
equipementlibre: await TextEditor.enrichHTML(this.object.system.equipementlibre, { async: true }),
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
console.log("PC : ", 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;
});
html.find('.open-annency').click(ev => {
let actorId = $(ev.currentTarget).data("annency-id")
const actor = game.actors.get(actorId)
actor.sheet.render(true)
})
// 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")
EcrymeUtility.confirmDelete(this, li).catch("Error : No deletion confirmed")
})
html.find('.item-add').click(ev => {
let dataType = $(ev.currentTarget).data("type")
this.actor.createEmbeddedDocuments('Item', [{ name: "NewItem", type: dataType }], { renderSheet: true })
})
html.find('.subactor-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
let actor = game.actors.get( actorId );
actor.sheet.render(true);
});
html.find('.subactor-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let actorId = li.data("actor-id");
this.actor.delSubActor(actorId);
});
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('.roll-skill').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkill(categKey, skillKey)
});
html.find('.roll-spec').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
let specId = $(event.currentTarget).data("spec-id")
this.actor.rollSpec(categKey, skillKey, specId)
});
html.find('.roll-skill-confront').click((event) => {
let categKey = $(event.currentTarget).data("category-key")
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollSkillConfront(categKey, skillKey)
});
html.find('.roll-cephaly').click((event) => {
let skillKey = $(event.currentTarget).data("skill-key")
this.actor.rollCephalySkillConfront(skillKey)
});
html.find('.roll-weapon-confront').click((event) => {
const li = $(event.currentTarget).parents(".item")
let weaponId = li.data("item-id");
this.actor.rollWeaponConfront(weaponId)
});
html.find('.impact-modify').click((event) => {
let impactType = $(event.currentTarget).data("impact-type")
let impactLevel = $(event.currentTarget).data("impact-level")
let modifier = Number($(event.currentTarget).data("impact-modifier"))
this.actor.modifyImpact(impactType, impactLevel, modifier)
});
html.find('.roll-weapon').click((event) => {
const armeId = $(event.currentTarget).data("arme-id")
this.actor.rollArme(armeId)
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.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;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}

View File

@ -0,0 +1,505 @@
/* -------------------------------------------- */
import { EcrymeUtility } from "../common/ecryme-utility.js";
import { EcrymeRollDialog } from "../dialogs/ecryme-roll-dialog.js";
import { EcrymeConfrontStartDialog } from "../dialogs/ecryme-confront-start-dialog.js";
/* -------------------------------------------- */
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class EcrymeActor extends Actor {
/* -------------------------------------------- */
/**
* Override the create() function to provide additional SoS functionality.
*
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} data Barebones actor data which this function adds onto.
* @param {Object} options (Unused) Additional options which customize the creation workflow.
*
*/
static async create(data, options) {
// Case of compendium global import
if (data instanceof Array) {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
return actor;
}
return super.create(data, options);
}
/* -------------------------------------------- */
async prepareData() {
super.prepareData()
}
/* -------------------------------------------- */
prepareDerivedData() {
super.prepareDerivedData();
}
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
super._preUpdate(changed, options, user);
}
/* -------------------------------------------- */
async _preCreate(data, options, user) {
await super._preCreate(data, options, user);
// Configure prototype token settings
const prototypeToken = {};
if (this.type === "pc") Object.assign(prototypeToken, {
sight: { enabled: true }, actorLink: true, disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY
});
this.updateSource({ prototypeToken });
}
/* -------------------------------------------- */
getMoneys() {
let comp = this.items.filter(item => item.type == 'money');
EcrymeUtility.sortArrayObjectsByName(comp)
return comp;
}
getArchetype() {
let comp = duplicate(this.items.find(item => item.type == 'archetype') || { name: "Pas d'archetype" })
if (comp?.system) {
comp.tarot = EcrymeUtility.getTarot(comp.system.lametutelaire)
}
return comp;
}
/* -------------------------------------------- */
buildAnnencyActorList() {
let membersFull = {}
for(let id of this.system.base.characters) {
let actor = game.actors.get(id)
membersFull[id] = { name: actor.name, id: actor.id, img: actor.img }
}
return membersFull
}
/* ----------------------- --------------------- */
addAnnencyActor(actorId) {
let members = duplicate(this.system.base.characters)
members.push(actorId)
this.update({ 'system.base.characters': members })
}
async removeAnnencyActor(actorId) {
let members = this.system.base.characters.filter(id => id != actorId)
this.update({ 'system.base.characters': members })
}
/* -------------------------------------------- */
getAnnency() {
return game.actors.find(a => a.type == 'annency' && a.system.base.characters.includes(this.id))
}
/* -------------------------------------------- */
getConfrontations() {
return this.items.filter(it => it.type == "confrontation")
}
getRollTraits() {
return this.items.filter(it => it.type == "trait" && it.system.traitype == "normal")
}
getIdeal() {
return this.items.find(it => it.type == "trait" && it.system.traitype == "ideal")
}
getSpleen() {
return this.items.find(it => it.type == "trait" && it.system.traitype == "spleen")
}
/* -------------------------------------------- */
getTrait(id) {
//console.log("TRAITS", this.items, this.items.filter(it => it.type == "trait") )
return this.items.find(it => it.type == "trait" && it._id == id)
}
/* -------------------------------------------- */
getSpecialization(id) {
let spec = this.items.find(it => it.type == "specialization" && it.id == id)
return spec
}
/* -------------------------------------------- */
getSpecializations(skillKey) {
return this.items.filter(it => it.type == "specialization" && it.system.skillkey == skillKey)
}
/* -------------------------------------------- */
prepareSkills() {
let skills = duplicate(this.system.skills)
for (let categKey in skills) {
let category = skills[categKey]
for (let skillKey in category.skilllist) {
let skill = category.skilllist[skillKey]
skill.spec = this.getSpecializations(skillKey)
}
}
return skills
}
/* -------------------------------------------- */
getCephalySkills() {
let skills = duplicate(this.system.cephaly.skilllist)
return skills
}
/* -------------------------------------------- */
getImpacts() {
let comp = duplicate(this.items.filter(item => item.type == 'impact') || [])
return comp;
}
/* -------------------------------------------- */
getWeapons() {
let comp = duplicate(this.items.filter(item => item.type == 'weapon') || [])
EcrymeUtility.sortArrayObjectsByName(comp)
return comp;
}
getManeuvers() {
let comp = duplicate(this.items.filter(item => item.type == 'maneuver') || [])
EcrymeUtility.sortArrayObjectsByName(comp)
return comp;
}
/* -------------------------------------------- */
getItemById(id) {
let item = this.items.find(item => item.id == id);
if (item) {
item = duplicate(item)
}
return item;
}
/* -------------------------------------------- */
async equipItem(itemId) {
let item = this.items.find(item => item.id == itemId)
if (item?.system) {
if (item.type == "armor") {
let armor = this.items.find(item => item.id != itemId && item.type == "armor" && item.system.equipped)
if (armor) {
ui.notifications.warn("You already have an armor equipped!")
return
}
}
if (item.type == "shield") {
let shield = this.items.find(item => item.id != itemId && item.type == "shield" && item.system.equipped)
if (shield) {
ui.notifications.warn("You already have a shield equipped!")
return
}
}
let update = { _id: item.id, "system.equipped": !item.system.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* ------------------------------------------- */
getEquipments() {
return this.items.filter(item => item.type == 'equipment')
}
/* ------------------------------------------- */
async buildContainerTree() {
let equipments = duplicate(this.items.filter(item => item.type == "equipment") || [])
for (let equip1 of equipments) {
if (equip1.system.iscontainer) {
equip1.system.contents = []
equip1.system.contentsEnc = 0
for (let equip2 of equipments) {
if (equip1._id != equip2.id && equip2.system.containerid == equip1.id) {
equip1.system.contents.push(equip2)
let q = equip2.system.quantity ?? 1
equip1.system.contentsEnc += q * equip2.system.weight
}
}
}
}
// Compute whole enc
let enc = 0
for (let item of equipments) {
//item.data.idrDice = EcrymeUtility.getDiceFromLevel(Number(item.data.idr))
if (item.system.equipped) {
if (item.system.iscontainer) {
enc += item.system.contentsEnc
} else if (item.system.containerid == "") {
let q = item.system.quantity ?? 1
enc += q * item.system.weight
}
}
}
for (let item of this.items) { // Process items/shields/armors
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.system.equipped) {
let q = item.system.quantity ?? 1
enc += q * item.system.weight
}
}
// Store local values
this.encCurrent = enc
this.containersTree = equipments.filter(item => item.system.containerid == "") // Returns the root of equipements without container
}
/* -------------------------------------------- */
async equipGear(equipmentId) {
let item = this.items.find(item => item.id == equipmentId);
if (item?.system) {
let update = { _id: item.id, "system.equipped": !item.system.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
modifyImpact(impactType, impactLevel, modifier) {
console.log(impactType, impactLevel, modifier)
let current = this.system.impacts[impactType][impactLevel]
if (modifier > 0) {
while ( EcrymeUtility.getImpactMax(impactLevel) == current && impactLevel != "major") {
impactLevel = EcrymeUtility.getNextImpactLevel(impactLevel)
current = this.system.impacts[impactType][impactLevel]
}
}
let newImpact = Math.max(this.system.impacts[impactType][impactLevel] + modifier, 0)
this.update({ [`system.impacts.${impactType}.${impactLevel}`]: newImpact})
}
/* -------------------------------------------- */
getImpactMalus(impactKey) {
let impacts = this.system.impacts[impactKey]
return - ((impacts.serious*2) + (impacts.major*4))
}
/* -------------------------------------------- */
getImpactsMalus() {
let impactsMalus = {
physical: this.getImpactMalus("physical"),
mental: this.getImpactMalus("mental"),
social: this.getImpactMalus("social")
}
return impactsMalus
}
/* -------------------------------------------- */
clearInitiative() {
this.getFlag("world", "initiative", -1)
}
/* -------------------------------------------- */
getInitiativeScore(combatId, combatantId) {
let init = Math.floor((this.system.attributs.physique.value + this.system.attributs.habilite.value) / 2)
let subValue = new Roll("1d20").roll({ async: false })
return init + (subValue.total / 100)
}
/* -------------------------------------------- */
getSubActors() {
let subActors = [];
for (let id of this.system.subactors) {
subActors.push(duplicate(game.actors.get(id)))
}
return subActors;
}
/* -------------------------------------------- */
async addSubActor(subActorId) {
let subActors = duplicate(this.system.subactors);
subActors.push(subActorId);
await this.update({ 'system.subactors': subActors });
}
/* -------------------------------------------- */
async delSubActor(subActorId) {
let newArray = [];
for (let id of this.system.subactors) {
if (id != subActorId) {
newArray.push(id);
}
}
await this.update({ 'system.subactors': newArray });
}
/* -------------------------------------------- */
async deleteAllItemsByType(itemType) {
let items = this.items.filter(item => item.type == itemType);
await this.deleteEmbeddedDocuments('Item', items);
}
/* -------------------------------------------- */
async addItemWithoutDuplicate(newItem) {
let item = this.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
if (!item) {
await this.createEmbeddedDocuments('Item', [newItem]);
}
}
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.items.get(objetId)
if (objetQ) {
let newQ = objetQ.system.quantity + incDec
if (newQ >= 0) {
await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]) // pdates one EmbeddedEntity
}
}
}
/* -------------------------------------------- */
modifyConfrontBonus( modifier ) {
let newBonus = this.system.internals.confrontbonus + modifier
this.update({'system.internals.confrontbonus': newBonus})
}
/* -------------------------------------------- */
spentSkillTranscendence(skill, value) {
let newValue = this.system.skills[skill.categKey].skilllist[skill.skillKey].value - value
newValue = Math.max(0, newValue)
this.update({ [`system.skills.${skill.categKey}.skilllist.${skill.skillKey}.value`]: newValue })
}
/* -------------------------------------------- */
getBonusList() {
let bonusList = []
for(let i=0; i<this.system.internals.confrontbonus; i++) {
bonusList.push( { value: 1, type: "bonus", location: "mainpool"})
}
return bonusList
}
/* -------------------------------------------- */
getCommonRollData() {
//this.system.internals.confrontbonus = 5 // TO BE REMOVED!!!!
let rollData = EcrymeUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.isReroll = false
rollData.traits = duplicate(this.getRollTraits())
rollData.spleen = duplicate(this.getSpleen() || {})
rollData.ideal = duplicate(this.getIdeal() || {})
rollData.confrontBonus = this.getBonusList()
return rollData
}
/* -------------------------------------------- */
getCommonSkill(categKey, skillKey) {
let skill = this.system.skills[categKey].skilllist[skillKey]
let rollData = this.getCommonRollData()
skill = duplicate(skill)
skill.categKey = categKey
skill.skillKey = skillKey
skill.spec = this.getSpecializations(skillKey)
rollData.skill = skill
rollData.img = skill.img
rollData.impactMalus = this.getImpactMalus(categKey)
return rollData
}
/* -------------------------------------------- */
rollSkill(categKey, skillKey) {
let rollData = this.getCommonSkill(categKey, skillKey)
rollData.mode = "skill"
rollData.title = game.i18n.localize(rollData.skill.name)
this.startRoll(rollData).catch("Error on startRoll")
}
/* -------------------------------------------- */
rollSpec(categKey, skillKey, specId) {
let rollData = this.getCommonSkill(categKey, skillKey)
let spec = this.items.find(it => it.type == "specialization" && it.id == specId)
rollData.mode = "skill"
rollData.selectedSpecs = [spec.id]
rollData.forcedSpec = duplicate(spec)
rollData.title = game.i18n.localize(rollData.skill.name)
this.startRoll(rollData).catch("Error on startRoll")
}
/* -------------------------------------------- */
async rollSkillConfront(categKey, skillKey) {
let rollData = this.getCommonSkill(categKey, skillKey)
rollData.mode = "skill"
rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionTotal = rollData.skill.value
rollData.preservationTotal = rollData.skill.value
rollData.applyTranscendence = "execution"
rollData.traitsBonus = duplicate(rollData.traits)
rollData.traitsMalus = duplicate(rollData.traits)
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
confrontStartDialog.render(true)
}
/* -------------------------------------------- */
async rollCephalySkillConfront(skillKey) {
let rollData = this.getCommonRollData()
rollData.mode = "cephaly"
rollData.skill = duplicate(this.system.cephaly.skilllist[skillKey])
rollData.annency = duplicate(this.getAnnency())
rollData.img = rollData.skill.img
rollData.skill.categKey = "cephaly"
rollData.skill.skillKey = skillKey
//rollData.impactMalus = this.getImpactMalus(categKey)
rollData.title = game.i18n.localize("ECRY.ui.cephaly") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionTotal = rollData.skill.value
rollData.preservationTotal = rollData.skill.value
rollData.traitsBonus = duplicate(rollData.traits)
rollData.traitsMalus = duplicate(rollData.traits)
rollData.applyTranscendence = "execution"
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
confrontStartDialog.render(true)
}
/* -------------------------------------------- */
async rollWeaponConfront(weaponId) {
let weapon = this.items.get(weaponId)
let rollData
if (weapon && weapon.system.weapontype == "melee") {
rollData = this.getCommonSkill("physical", "fencing")
} else {
rollData = this.getCommonSkill("physical", "shooting")
}
rollData.mode = "weapon"
rollData.weapon = duplicate(weapon)
rollData.title = game.i18n.localize("ECRY.ui.confrontation") + " : " + game.i18n.localize(rollData.skill.name)
rollData.executionTotal = rollData.skill.value
rollData.preservationTotal = rollData.skill.value
rollData.traitsBonus = duplicate(rollData.traits)
rollData.traitsMalus = duplicate(rollData.traits)
rollData.applyTranscendence = "execution"
let confrontStartDialog = await EcrymeConfrontStartDialog.create(this, rollData)
confrontStartDialog.render(true)
}
/* -------------------------------------------- */
rollWeapon(weaponId) {
let weapon = this.items.get(weaponId)
if (weapon) {
weapon = duplicate(weapon)
let rollData = this.getCommonRollData()
if (weapon.system.armetype == "mainsnues" || weapon.system.armetype == "epee") {
rollData.attr = { label: "(Physique+Habilité)/2", value: Math.floor((this.getPhysiqueMalus() + this.system.attributs.physique.value + this.system.attributs.habilite.value) / 2) }
} else {
rollData.attr = duplicate(this.system.attributs.habilite)
}
rollData.mode = "weapon"
rollData.weapon = weapon
rollData.img = weapon.img
rollData.title = weapon.name
this.startRoll(rollData).catch("Error on startRoll")
} else {
ui.notifications.warn("Impossible de trouver l'arme concernée ")
}
}
/* -------------------------------------------- */
async startRoll(rollData) {
let rollDialog = await EcrymeRollDialog.create(this, rollData)
rollDialog.render(true)
}
}

View File

@ -0,0 +1,40 @@
import { EcrymeUtility } from "../common/tedeum-utility.js";
/* -------------------------------------------- */
export class EcrymeCombat extends Combat {
/* -------------------------------------------- */
async rollInitiative(ids, formula = undefined, messageOptions = {} ) {
ids = typeof ids === "string" ? [ids] : ids;
for (let cId = 0; cId < ids.length; cId++) {
const c = this.combatants.get(ids[cId]);
let id = c._id || c.id;
let initBonus = c.actor ? c.actor.getInitiativeScore( this.id, id ) : -1;
await this.updateEmbeddedDocuments("Combatant", [ { _id: id, initiative: initBonus } ]);
}
return this;
}
/* -------------------------------------------- */
_onUpdate(changed, options, userId) {
}
/* -------------------------------------------- */
static async checkTurnPosition() {
while (game.combat.turn > 0) {
await game.combat.previousTurn()
}
}
/* -------------------------------------------- */
_onDelete() {
let combatants = this.combatants.contents
for (let c of combatants) {
let actor = game.actors.get(c.actorId)
actor.clearInitiative()
}
super._onDelete()
}
}

View File

@ -0,0 +1,105 @@
/* -------------------------------------------- */
import { EcrymeUtility } from "../common/tedeum-utility.js";
import { EcrymeCharacterSummary } from "./ecryme-summary-app.js"
/* -------------------------------------------- */
export class EcrymeCommands {
static init() {
if (!game.system.ecryme.commands) {
const commands = new EcrymeCommands();
commands.registerCommand({ path: ["/resume"], func: (content, msg, params) => EcrymeCharacterSummary.displayPCSummary(), descr: "Affiche la liste des PJs!" });
game.system.ecryme.commands = commands;
}
}
constructor() {
this.commandsTable = {}
}
/* -------------------------------------------- */
registerCommand(command) {
this._addCommand(this.commandsTable, command.path, '', command);
}
/* -------------------------------------------- */
_addCommand(targetTable, path, fullPath, command) {
if (!this._validateCommand(targetTable, path, command)) {
return;
}
const term = path[0];
fullPath = fullPath + term + ' '
if (path.length == 1) {
command.descr = `<strong>${fullPath}</strong>: ${command.descr}`;
targetTable[term] = command;
}
else {
if (!targetTable[term]) {
targetTable[term] = { subTable: {} };
}
this._addCommand(targetTable[term].subTable, path.slice(1), fullPath, command)
}
}
/* -------------------------------------------- */
_validateCommand(targetTable, path, command) {
if (path.length > 0 && path[0] && command.descr && (path.length != 1 || targetTable[path[0]] == undefined)) {
return true;
}
console.warn("crucibleCommands._validateCommand failed ", targetTable, path, command);
return false;
}
/* -------------------------------------------- */
/* Manage chat commands */
processChatCommand(commandLine, content = '', msg = {}) {
// Setup new message's visibility
let rollMode = game.settings.get("core", "rollMode");
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperRecipients("GM");
if (rollMode === "blindroll") msg["blind"] = true;
msg["type"] = 0;
let command = commandLine[0].toLowerCase();
let params = commandLine.slice(1);
return this.process(command, params, content, msg);
}
/* -------------------------------------------- */
process(command, params, content, msg) {
return this._processCommand(this.commandsTable, command, params, content, msg);
}
/* -------------------------------------------- */
_processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
console.log("===> Processing command")
let command = commandsTable[name];
path = path + name + " ";
if (command && command.subTable) {
if (params[0]) {
return this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path)
}
else {
this.help(msg, command.subTable);
return true;
}
}
if (command && command.func) {
const result = command.func(content, msg, params);
if (result == false) {
CrucibleCommands._chatAnswer(msg, command.descr);
}
return true;
}
return false;
}
/* -------------------------------------------- */
static _chatAnswer(msg, content) {
msg.whisper = [game.user.id];
msg.content = content;
ChatMessage.create(msg);
}
}

View File

@ -0,0 +1,86 @@
export class EcrymeHotbar {
/**
* Create a macro when dropping an entity on the hotbar
* Item - open roll dialog for item
* Actor - open actor sheet
* Journal - open journal sheet
*/
static init( ) {
Hooks.on("hotbarDrop", async (bar, documentData, slot) => {
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
if (documentData.type == "Item") {
console.log("Drop done !!!", bar, documentData, slot)
let item = documentData.data
let command = `game.system.ecryme.EcrymeHotbar.rollMacro("${item.name}", "${item.type}");`
let macro = game.macros.contents.find(m => (m.name === item.name) && (m.command === command))
if (!macro) {
macro = await Macro.create({
name: item.name,
type: "script",
img: item.img,
command: command
}, { displaySheet: false })
}
game.user.assignHotbarMacro(macro, slot);
}
// Create a macro to open the actor sheet of the actor dropped on the hotbar
else if (documentData.type == "Actor") {
let actor = game.actors.get(documentData.id);
let command = `game.actors.get("${documentData.id}").sheet.render(true)`
let macro = game.macros.contents.find(m => (m.name === actor.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: actor.data.name,
type: "script",
img: actor.data.img,
command: command
}, { displaySheet: false })
game.user.assignHotbarMacro(macro, slot);
}
}
// Create a macro to open the journal sheet of the journal dropped on the hotbar
else if (documentData.type == "JournalEntry") {
let journal = game.journal.get(documentData.id);
let command = `game.journal.get("${documentData.id}").sheet.render(true)`
let macro = game.macros.contents.find(m => (m.name === journal.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: journal.data.name,
type: "script",
img: "",
command: command
}, { displaySheet: false })
game.user.assignHotbarMacro(macro, slot);
}
}
return false;
});
}
/** Roll macro */
static rollMacro(itemName, itemType, bypassData) {
const speaker = ChatMessage.getSpeaker()
let actor
if (speaker.token) actor = game.actors.tokens[speaker.token]
if (!actor) actor = game.actors.get(speaker.actor)
if (!actor) {
return ui.notifications.warn(`Select your actor to run the macro`)
}
let item = actor.items.find(it => it.name === itemName && it.type == itemType)
if (!item ) {
return ui.notifications.warn(`Unable to find the item of the macro in the current actor`)
}
// Trigger the item roll
if (item.type === "weapon") {
return actor.rollWeapon( item.id)
}
if (item.type === "skill") {
return actor.rollSkill( item.id)
}
}
}

View File

@ -0,0 +1,62 @@
export const ECRYME_CONFIG = {
traitTypes: {
normal: "Normal",
spleen: "Spleen",
ideal: "Ideal"
},
weaponTypes: {
"melee": "ECRY.ui.melee",
"ranged": "ECRY.ui.ranged"
},
traitLevel: [
{value: -3, text: "-3"},
{value: -2, text: "-2"},
{value: -1, text: "-1"},
{value: +1, text: "+1"},
{value: +2, text: "+2"},
{value: +3, text: "+3"}
],
impactTypes: {
physical: "ECRY.ui.physical",
mental: "ECRY.ui.mental",
social: "ECRY.ui.social"
},
impactLevels: {
superficial: "ECRY.ui.superficial",
light: "ECRY.ui.light",
serious: "ECRY.ui.serious",
major: "ECRY.ui.major"
},
difficulty: {
"-1": {difficulty: "ECRY.ui.none", frequency: "ECRY.ui.none", value: "-"},
"8": { difficulty: "ECRY.ui.troublesome", frequency: "ECRY.ui.occasional", value: 8 },
"10": { difficulty: "ECRY.ui.difficult", frequency: "ECRY.ui.uncommon", value: 10 },
"12": { difficulty: "ECRY.ui.verydifficult", frequency: "ECRY.ui.rare", value: 12 },
"14": { difficulty: "ECRY.ui.extremdifficult", frequency: "ECRY.ui.veryrare", value: 14 },
"16": { difficulty: "ECRY.ui.increddifficult", frequency: "ECRY.ui.exceptrare", value: 16 },
},
skillLevel: {
"0": "0",
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
"10": "10"
},
costUnits: {
"ingot": {name: "ECRY.ui.ingot", value: 100000},
"ingotin": {name: "ECRY.ui.ingotin", value: 10000},
"goldcoin": {name: "ECRY.ui.goldcoin", value: 1000 },
"lige": {name: "ECRY.ui.lige", value: 100 },
"hurle": {name: "ECRY.ui.hurle", value: 10 },
"coin": {name: "ECRY.ui.coin", value: 1 }
}
}

View File

@ -0,0 +1,745 @@
/* -------------------------------------------- */
import { EcrymeCommands } from "../app/tedeum-commands.js";
/* -------------------------------------------- */
const __maxImpacts = { superficial: 4, light: 3, serious: 2, major: 1 }
const __nextImpacts = { superficial: "light", light: "serious", serious: "major", major: "major" }
const __effect2Impact = ["none", "superficial", "superficial", "light", "light", "serious", "serious", "major", "major"]
const __cephalySuccess = {
1: "cephaly-success-2",
2: "cephaly-success-2",
3: "cephaly-success-4",
4: "cephaly-success-4",
5: "cephaly-success-6",
6: "cephaly-success-6",
7: "cephaly-success-8",
8: "cephaly-success-8",
9: "cephaly-success-9",
10: "cephaly-success-10"
}
const __cephalyFailure = {
1: "cephaly-failure-2",
2: "cephaly-failure-2",
3: "cephaly-failure-4",
4: "cephaly-failure-4",
5: "cephaly-failure-6",
6: "cephaly-failure-6",
7: "cephaly-failure-8",
8: "cephaly-failure-8",
9: "cephaly-failure-9",
10: "cephaly-failure-10"
}
/* -------------------------------------------- */
export class EcrymeUtility {
/* -------------------------------------------- */
static async init() {
Hooks.on('renderChatLog', (log, html, data) => EcrymeUtility.chatListeners(html));
Hooks.on("getChatLogEntryContext", (html, options) => EcrymeUtility.chatMenuManager(html, options));
this.rollDataStore = {}
this.defenderStore = {}
EcrymeCommands.init();
}
/* -------------------------------------------- */
static async ready() {
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
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)
})
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
})
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
Handlebars.registerHelper('add', function (a, b) {
return parseInt(a) + parseInt(b);
})
Handlebars.registerHelper('valueAtIndex', function (arr, idx) {
return arr[idx];
})
Handlebars.registerHelper('for', function (from, to, incr, block) {
let accum = '';
for (let i = from; i <= to; i += incr)
accum += block.fn(i);
return accum;
})
Handlebars.registerHelper('isGM', function () {
return game.user.isGM
})
game.settings.register("fvtt-ecryme", "ecryme-game-level", {
name: game.i18n.localize("ECRY.settings.gamelevel"),
label: game.i18n.localize("ECRY.settings.gamelevelhelp"),
scope: 'world',
config: true,
type: String,
choices: {
"level_e": game.i18n.localize("ECRY.settings.cogs"),
"level_c": game.i18n.localize("ECRY.settings.cephaly"),
"level_b": game.i18n.localize("ECRY.settings.boheme"),
"level_a": game.i18n.localize("ECRY.settings.amertume"),
},
restricted: true
})
this.buildSkillConfig()
}
/*-------------------------------------------- */
static hasCephaly() {
let level = game.settings.get("fvtt-ecryme", "ecryme-game-level")
return level != "level_e"
}
/*-------------------------------------------- */
static hasBoheme() {
let level = game.settings.get("fvtt-ecryme", "ecryme-game-level")
return level == "level_b" || level == "level_a"
}
/*-------------------------------------------- */
static hasAmertume() {
let level = game.settings.get("fvtt-ecryme", "ecryme-game-level")
return level == "level_a"
}
/*-------------------------------------------- */
static buildSkillConfig() {
game.system.ecryme.config.skills = {}
for (let categKey in game.data.template.Actor.templates.core.skills) {
let category = game.data.template.Actor.templates.core.skills[categKey]
for (let skillKey in category.skilllist) {
let skill = duplicate(category.skilllist[skillKey])
skill.categKey = categKey // Auto reference the category
game.system.ecryme.config.skills[skillKey] = skill
}
}
}
/*-------------------------------------------- */
static upperFirst(text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium)
return await pack?.getDocuments() ?? []
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await EcrymeUtility.loadCompendiumData(compendium)
return compendiumData.filter(filter)
}
/* -------------------------------------------- */
static getActorFromRollData(rollData) {
let actor = game.actors.get(rollData.actorId)
if (rollData.tokenId) {
let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId)
if (token) {
actor = token.actor
}
}
return actor
}
/* -------------------------------------------- */
static getImpactFromEffect(effectValue) {
if (effectValue >= __effect2Impact.length) {
return "major"
}
return __effect2Impact[effectValue]
}
/* -------------------------------------------- */
static async processConfrontation() {
let confront = {
type: "confront-data",
rollData1: this.confrontData1,
rollData2: this.confrontData2,
}
// Compute margin
confront.marginExecution = this.confrontData1.executionTotal - this.confrontData2.preservationTotal
confront.marginPreservation = this.confrontData1.preservationTotal - this.confrontData2.executionTotal
console.log(confront.marginExecution, confront.marginPreservation)
// Filter margin
let maxMargin // Dummy max
if (confront.marginExecution > 0) { // Successful hit
// Limit with skill+spec
maxMargin = confront.rollData1.skill.value + ((confront.rollData1.spec) ? 2 : 0)
confront.marginExecution = Math.min(confront.marginExecution, maxMargin)
} else { // Failed hit
maxMargin = confront.rollData2.skill.value + ((confront.rollData2.spec) ? 2 : 0)
confront.marginExecution = -Math.min(Math.abs(confront.marginExecution), maxMargin)
}
if (confront.marginPreservation > 0) { // Successful defense
// Limit with skill+spec
maxMargin = confront.rollData1.skill.value + ((confront.rollData1.spec) ? 2 : 0)
confront.marginPreservation = Math.min(confront.marginPreservation, maxMargin)
} else { // Failed defense
maxMargin = confront.rollData2.skill.value + ((confront.rollData2.spec) ? 2 : 0)
confront.marginPreservation = - Math.min(Math.abs(confront.marginPreservation), maxMargin)
}
// Compute effects
confront.effectExecution = confront.marginExecution
if (confront.rollData1.weapon && confront.marginExecution > 0) {
confront.effectExecution += confront.rollData1.weapon.system.effect
confront.impactExecution = this.getImpactFromEffect(confront.effectExecution)
}
if (confront.marginExecution < 0) {
confront.bonus2 = -confront.marginExecution
}
confront.effectPreservation = confront.marginPreservation
if (confront.rollData2.weapon && confront.marginPreservation < 0) {
confront.effectPreservation = - (Math.abs(confront.marginPreservation) + confront.rollData2.weapon.system.effect)
confront.impactPreservation = this.getImpactFromEffect(Math.abs(confront.effectPreservation))
}
if (confront.marginPreservation > 0) {
confront.bonus1 = -confront.marginPreservation
}
let msg = await this.createChatWithRollMode(this.confrontData1.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-confrontation-result.hbs`, confront)
})
await msg.setFlag("world", "ecryme-rolldata", confront)
console.log("Confront result", confront)
this.lastConfront = confront
}
/* -------------------------------------------- */
static async manageCephalyDifficulty(rollData, difficulty) {
rollData.difficulty = Number(difficulty)
if (rollData.executionTotal > difficulty) {
rollData.marginExecution = rollData.executionTotal - difficulty
rollData.cephalySuccess = "ECRY.rule." + __cephalySuccess[(rollData.marginExecution > 10) ? 10 : rollData.marginExecution]
} else {
rollData.marginExecution = -1
}
if (rollData.preservationTotal < difficulty) {
rollData.marginPreservation = difficulty - rollData.preservationTotal
rollData.cephalyFailure = "ECRY.rule." + __cephalyFailure[(rollData.marginPreservation > 10) ? 10 : rollData.marginPreservation]
} else {
rollData.marginPreservation = -1
}
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-cephaly-result.hbs`, rollData)
})
msg.setFlag("world", "ecryme-rolldata", rollData)
console.log("Cephaly result", rollData)
}
/* -------------------------------------------- */
static manageConfrontation(rollData) {
console.log("Confront", rollData)
// Auto - Reset
if (this.confrontData1 && this.confrontData2) {
this.confrontData1 = undefined
this.confrontData2 = undefined
}
// Then attribute
if (!this.confrontData1) {
this.confrontData1 = rollData
} else if (this.confrontData1 && this.confrontData1.rollId != rollData.rollId) {
this.confrontData2 = rollData
this.processConfrontation().catch("Error during confrontation processing")
} else {
ui.notifications.warn(game.i18n.localize("ECRY.warn.confrontalready"))
}
}
/* -------------------------------------------- */
static chatMenuManager(html, options) {
let canTranscendRoll = []
for (let i = 1; i <= 10; i++) {
canTranscendRoll[i] = function (li) {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "rolldata")
//console.log(">>>>>>>>>>>>>>>>>>>>>>>>>> Menu !!!!", rollData)
if (rollData.skill && i <= rollData.skill.value && !rollData.transcendUsed && rollData.spec) {
return true
}
return false
}
options.push({
name: game.i18n.localize("ECRY.chat.spectranscend") + i,
icon: '<i class="fas fa-plus-square"></i>',
condition: canTranscendRoll[i],
callback: li => {
let message = game.messages.get(li.attr("data-message-id"))
let rollData = message.getFlag("world", "rolldata")
EcrymeUtility.transcendFromSpec(rollData, i).catch("Error on Transcend")
}
})
}
}
/* -------------------------------------------- */
static async chatListeners(html) {
html.on("click", '.button-select-confront', event => {
let messageId = EcrymeUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let rollData = message.getFlag("world", "ecryme-rolldata")
ui.notifications.info( game.i18n.localize("ECRY.chat.confrontselect"))
EcrymeUtility.manageConfrontation(rollData)
})
html.on("click", '.button-apply-cephaly-difficulty', event => {
let messageId = EcrymeUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let rollData = message.getFlag("world", "ecryme-rolldata")
let difficulty = $("#" + rollData.rollId + "-cephaly-difficulty").val()
EcrymeUtility.manageCephalyDifficulty(rollData, difficulty)
})
html.on("click", '.button-apply-impact', event => {
let messageId = EcrymeUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let actor = game.actors.get($(event.currentTarget).data("actor-id"))
actor.modifyImpact($(event.currentTarget).data("impact-type"), $(event.currentTarget).data("impact"), 1)
})
html.on("click", '.button-apply-bonus', event => {
let messageId = EcrymeUtility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
let actor = game.actors.get($(event.currentTarget).data("actor-id"))
actor.modifyConfrontBonus($(event.currentTarget).data("bonus"))
})
}
/* -------------------------------------------- */
static async preloadHandlebarsTemplates() {
const templatePaths = [
'systems/fvtt-ecryme/templates/actors/editor-notes-gm.hbs',
'systems/fvtt-ecryme/templates/items/partial-item-nav.hbs',
'systems/fvtt-ecryme/templates/items/partial-item-equipment.hbs',
'systems/fvtt-ecryme/templates/items/partial-item-description.hbs',
'systems/fvtt-ecryme/templates/dialogs/partial-common-roll-dialog.hbs',
'systems/fvtt-ecryme/templates/dialogs/partial-confront-dice-area.hbs',
'systems/fvtt-ecryme/templates/dialogs/partial-confront-bonus-area.hbs',
'systems/fvtt-ecryme/templates/actors/partial-impacts.hbs',
]
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static removeChatMessageId(messageId) {
if (messageId) {
game.messages.get(messageId)?.delete();
}
}
static findChatMessageId(current) {
return EcrymeUtility.getChatMessageId(EcrymeUtility.findChatMessage(current));
}
static getChatMessageId(node) {
return node?.attributes.getNamedItem('data-message-id')?.value;
}
static findChatMessage(current) {
return EcrymeUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'));
}
static findNodeMatching(current, predicate) {
if (current) {
if (predicate(current)) {
return current;
}
return EcrymeUtility.findNodeMatching(current.parentElement, predicate);
}
return undefined;
}
/* -------------------------------------------- */
static createDirectOptionList(min, max) {
let options = {};
for (let i = min; i <= max; i++) {
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static buildListOptions(min, max) {
let options = ""
for (let i = min; i <= max; i++) {
options += `<option value="${i}">${i}</option>`
}
return options;
}
/* -------------------------------------------- */
static getTarget() {
if (game.user.targets) {
for (let target of game.user.targets) {
return target
}
}
return undefined
}
/* -------------------------------------------- */
static updateRollData(rollData) {
let id = rollData.rollId
let oldRollData = this.rollDataStore[id] || {}
let newRollData = mergeObject(oldRollData, rollData)
this.rollDataStore[id] = newRollData
}
/* -------------------------------------------- */
static async onSocketMesssage(msg) {
console.log("SOCKET MESSAGE", msg)
if (msg.name == "msg_gm_chat_message") {
let rollData = msg.data.rollData
if ( game.user.isGM ) {
let chatMsg = await this.createChatMessage(rollData.alias, "blindroll", {
content: await renderTemplate(msg.data.template, rollData),
whisper: game.user.id
})
chatMsg.setFlag("world", "ecryme-rolldata", rollData)
}
}
}
/* -------------------------------------------- */
static async searchItem(dataItem) {
let item
if (dataItem.pack) {
let id = dataItem.id || dataItem._id
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
item = items[0] || undefined
} else {
item = game.items.get(dataItem.id)
}
return item
}
/* -------------------------------------------- */
static chatDataSetup(content, modeOverride, forceWhisper, isRoll = false) {
let chatData = {
user: game.user.id,
rollMode: modeOverride || game.settings.get("core", "rollMode"),
content: content
};
if (["gmroll", "blindroll"].includes(chatData.rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);
if (chatData.rollMode === "blindroll") chatData["blind"] = true;
else if (chatData.rollMode === "selfroll") chatData["whisper"] = [game.user];
if (forceWhisper) { // Final force !
chatData["speaker"] = ChatMessage.getSpeaker();
chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper);
}
return chatData;
}
/* -------------------------------------------- */
static getImpactMax(impactLevel) {
return __maxImpacts[impactLevel]
}
static getNextImpactLevel(impactLevel) {
return __nextImpacts[impactLevel]
}
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode) {
if (game.modules.get("dice-so-nice")?.active) {
if (game.dice3d) {
let whisper = null;
let blind = false;
rollMode = rollMode ?? game.settings.get("core", "rollMode");
switch (rollMode) {
case "blindroll": //GM only
whisper = this.getUsers(user => user.isGM);
blind = true;
break
case "gmroll": //GM + rolling player
whisper = this.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = this.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user.id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
}
/* -------------------------------------------- */
static computeResults(rollData) {
rollData.isSuccess = false
if (!rollData.difficulty || rollData.difficulty == "-") {
return
}
rollData.margin = rollData.total - rollData.difficulty
if (rollData.total > rollData.difficulty) {
rollData.isSuccess = true
let maxMargin = rollData.skill.value + ((rollData.spec) ? 2 : 0)
rollData.margin = Math.min(rollData.margin, maxMargin)
}
}
/* -------------------------------------------- */
static computeRollFormula(rollData, actor, isConfrontation = false) {
// Build the dice formula
let diceFormula = (isConfrontation) ? "4d6" : "2d6"
if (rollData.useIdeal) {
diceFormula = (isConfrontation) ? "5d6kh2" : "3d6kh2"
}
if (rollData.useSpleen) {
diceFormula = (isConfrontation) ? "5d6kl2" : "3d6kl2"
}
if (rollData.skill) {
diceFormula += "+" + rollData.skill.value
}
if (rollData.skillTranscendence) {
diceFormula += "+" + rollData.skillTranscendence
actor.spentSkillTranscendence(rollData.skill, rollData.skillTranscendence)
}
if (rollData.selectedSpecs && rollData.selectedSpecs.length > 0) {
rollData.spec = actor.getSpecialization(rollData.selectedSpecs[0])
diceFormula += "+" + (String(rollData.spec.system?.bonus) || "2")
}
rollData.bonusMalusTraits = 0
if (rollData.traitsBonus && rollData.traitsBonus.length > 0) {
rollData.traitsBonusList = []
for (let id of rollData.traitsBonus) {
let trait = actor.getTrait(id)
console.log(trait, id)
rollData.traitsBonusList.push(trait)
rollData.bonusMalusTraits += trait.system.level
}
}
if (rollData.traitsMalus && rollData.traitsMalus.length > 0) {
rollData.traitsMalusList = []
for (let id of rollData.traitsMalus) {
let trait = actor.getTrait(id)
rollData.traitsMalusList.push(trait)
rollData.bonusMalusTraits -= trait.system.level
}
}
diceFormula += "+" + rollData.bonusMalusTraits
diceFormula += "+" + rollData.bonusMalusPerso
diceFormula += "+" + rollData.impactMalus
if (rollData.annency) {
diceFormula += "+" + rollData.annencyBonus
}
rollData.diceFormula = diceFormula
return diceFormula
}
/* -------------------------------------------- */
static async rollEcryme(rollData) {
let actor = game.actors.get(rollData.actorId)
// Fix difficulty
if (!rollData.difficulty || rollData.difficulty == "-") {
rollData.difficulty = 0
}
rollData.difficulty = Number(rollData.difficulty)
let diceFormula = this.computeRollFormula(rollData, actor)
// Performs roll
let myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = duplicate(myRoll)
rollData.total = myRoll.total
rollData.diceSum = myRoll.terms[0].total
this.computeResults(rollData)
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
})
await msg.setFlag("world", "ecryme-rolldata", rollData)
console.log("Rolldata result", rollData)
}
/* -------------------------------------------- */
static async transcendFromSpec(rollData, value) {
rollData.total += value
rollData.transcendUsed = true
this.computeResults(rollData)
//console.log("Adding spec", value, rollData.total)
let actor = game.actors.get(rollData.actorId)
actor.spentSkillTranscendence(rollData.skill, value)
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
})
await msg.setFlag("world", "ecryme-rolldata", rollData)
}
/* -------------------------------------------- */
static sortArrayObjectsByName(myArray) {
myArray.sort((a, b) => {
let fa = a.name.toLowerCase();
let fb = b.name.toLowerCase();
if (fa < fb) {
return -1;
}
if (fa > fb) {
return 1;
}
return 0;
})
}
/* -------------------------------------------- */
static getUsers(filter) {
return game.users.filter(filter).map(user => user.id);
}
/* -------------------------------------------- */
static getWhisperRecipients(rollMode, name) {
switch (rollMode) {
case "blindroll": return this.getUsers(user => user.isGM);
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
case "useronly": return this.getWhisperRecipientsOnly(name);
case "selfroll": return [game.user.id];
}
return undefined;
}
/* -------------------------------------------- */
static getWhisperRecipientsOnly(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1
}
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
}
/* -------------------------------------------- */
static blindMessageToGM(chatData) {
chatData.whisper = this.getUsers(user => user.isGM);
console.log("blindMessageToGM", chatData);
game.socket.emit("system.fvtt-ecryme", { name: "msg_gm_chat_message", data: chatData });
}
/* -------------------------------------------- */
static split3Columns(data) {
let array = [[], [], []];
if (data == undefined) return array;
let col = 0;
for (let key in data) {
let keyword = data[key];
keyword.key = key; // Self-reference
array[col].push(keyword);
col++;
if (col == 3) col = 0;
}
return array;
}
/* -------------------------------------------- */
static async createChatMessage(name, rollMode, chatOptions) {
switch (rollMode) {
case "blindroll": // GM only
if (!game.user.isGM) {
chatOptions.whisper = [game.user.id];
} else {
chatOptions.whisper = this.getUsers(user => user.isGM);
}
break;
default:
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
break;
}
chatOptions.alias = chatOptions.alias || name;
return await ChatMessage.create(chatOptions);
}
/* -------------------------------------------- */
static getBasicRollData() {
let rollData = {
rollId: randomID(16),
type: "roll-data",
bonusMalusPerso: 0,
bonusMalusSituation: 0,
bonusMalusDef: 0,
annencyBonus: 0,
bonusMalusPortee: 0,
skillTranscendence: 0,
rollMode: game.settings.get("core", "rollMode"),
difficulty: "-",
useSpleen: false,
useIdeal: false,
impactMalus: 0,
config: duplicate(game.system.ecryme.config)
}
EcrymeUtility.updateWithTarget(rollData)
return rollData
}
/* -------------------------------------------- */
static updateWithTarget(rollData) {
let target = EcrymeUtility.getTarget()
if (target) {
rollData.defenderTokenId = target.id
}
}
/* -------------------------------------------- */
static async createChatWithRollMode(name, chatOptions) {
return await this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
}
/* -------------------------------------------- */
static async confirmDelete(actorSheet, li) {
let itemId = li.data("item-id");
let msgTxt = "<p>Are you sure to remove this Item ?";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Yes, remove it",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Cancel"
}
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirm removal",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
}

View File

@ -0,0 +1,86 @@
import { EcrymeUtility } from "../common/ecryme-utility.js";
export class EcrymeRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData) {
let options = { classes: ["ecryme-roll-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
let html = await renderTemplate('systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs', rollData);
return new EcrymeRollDialog(actor, rollData, html, options);
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let conf = {
title: game.i18n.localize("ECRY.ui.rolltitle"),
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: game.i18n.localize("ECRY.ui.roll"),
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: game.i18n.localize("ECRY.ui.cancel"),
callback: () => { this.close() }
}
},
close: close
}
super(conf, options);
this.actor = actor;
this.rollData = rollData;
}
/* -------------------------------------------- */
roll() {
EcrymeUtility.rollEcryme(this.rollData)
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await renderTemplate("systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs", this.rollData)
this.data.content = content
this.render(true)
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
var dialog = this;
function onLoad() {
}
$(function () { onLoad(); });
html.find('#bonusMalusPerso').change((event) => {
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
})
html.find('#roll-difficulty').change((event) => {
this.rollData.difficulty = Number(event.currentTarget.value) || 0
})
html.find('#roll-specialization').change((event) => {
this.rollData.selectedSpecs = $('#roll-specialization').val()
})
html.find('#roll-trait-bonus').change((event) => {
this.rollData.traitsBonus = $('#roll-trait-bonus').val()
})
html.find('#roll-trait-malus').change((event) => {
this.rollData.traitsMalus = $('#roll-trait-malus').val()
})
html.find('#roll-select-transcendence').change((event) => {
this.rollData.skillTranscendence = Number($('#roll-select-transcendence').val())
})
html.find('#roll-use-spleen').change((event) => {
this.rollData.useSpleen = event.currentTarget.checked
})
html.find('#roll-use-ideal').change((event) => {
this.rollData.useIdeal = event.currentTarget.checked
})
}
}

View File

@ -0,0 +1,185 @@
import { EcrymeUtility } from "../common/tedeum-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class EcrymeItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-ecryme", "sheet", "item"],
template: "systems/fvtt-ecryme/templates/item-sheet.hbs",
dragDrop: [{ dragSelector: null, dropSelector: null }],
width: 620,
height: 580,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }]
});
}
/* -------------------------------------------- */
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
// Add "Post to chat" button
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
buttons.unshift(
{
class: "post",
icon: "fas fa-comment",
onclick: ev => { }
})
return buttons
}
/* -------------------------------------------- */
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
if (this.item.type.includes('weapon')) {
position.width = 640;
}
return position;
}
/* -------------------------------------------- */
async getData() {
let formData = {
title: this.title,
id: this.id,
type: this.object.type,
img: this.object.img,
name: this.object.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
system: duplicate(this.object.system),
config: duplicate(game.system.ecryme.config),
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
isGM: game.user.isGM
}
if ( this.object.type == "archetype") {
formData.tarots = EcrymeUtility.getTarots()
}
this.options.editable = !(this.object.origin == "embeddedItem");
console.log("ITEM DATA", formData, this);
return formData;
}
/* -------------------------------------------- */
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
buttons.unshift({
class: "post",
icon: "fas fa-comment",
onclick: ev => this.postItem()
});
return buttons
}
/* -------------------------------------------- */
postItem() {
let chatData = duplicate(this.item)
if (this.actor) {
chatData.actor = { id: this.actor.id };
}
// Don't post any image for the item (which would leave a large gap) if the default image is used
if (chatData.img.includes("/blank.png")) {
chatData.img = null;
}
// JSON object for easy creation
chatData.jsondata = JSON.stringify(
{
compendium: "postedItem",
payload: chatData,
});
renderTemplate('systems/Ecryme/templates/post-item.html', chatData).then(html => {
let chatOptions = EcrymeUtility.chatDataSetup(html);
ChatMessage.create(chatOptions)
});
}
/* -------------------------------------------- */
async viewSubitem(ev) {
let levelIndex = Number($(ev.currentTarget).parents(".item").data("level-index"))
let choiceIndex = Number($(ev.currentTarget).parents(".item").data("choice-index"))
let featureId = $(ev.currentTarget).parents(".item").data("feature-id")
let itemData = this.object.system.levels[levelIndex].choices[choiceIndex].features[featureId]
if (itemData.name != 'None') {
let item = await Item.create(itemData, { temporary: true });
item.system.origin = "embeddedItem";
new EcrymeItemSheet(item).render(true);
}
}
/* -------------------------------------------- */
async deleteSubitem(ev) {
let field = $(ev.currentTarget).data('type');
let idx = Number($(ev.currentTarget).data('index'));
let oldArray = this.object.system[field];
let itemData = this.object.system[field][idx];
if (itemData.name != 'None') {
let newArray = [];
for (var i = 0; i < oldArray.length; i++) {
if (i != idx) {
newArray.push(oldArray[i]);
}
}
this.object.update({ [`system.${field}`]: newArray });
}
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.object.options.actor.getOwnedItem(li.data("item-id"));
item.sheet.render(true);
});
html.find('.delete-subitem').click(ev => {
this.deleteSubitem(ev);
});
// Update Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let itemId = li.data("item-id");
let itemType = li.data("item-type");
});
}
/* -------------------------------------------- */
get template() {
let type = this.item.type;
return `systems/fvtt-ecryme/templates/items/item-${type}-sheet.hbs`
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
return this.object.update(formData)
}
}

View File

@ -0,0 +1,27 @@
import { EcrymeUtility } from "../common/ecryme-utility.js";
export const defaultItemImg = {
weapon: "systems/fvtt-ecryme/images/icons/icon_weapon.webp",
equipment: "systems/fvtt-ecryme/images/icons/icon_equipment.webp",
contact: "systems/fvtt-ecryme/images/icons/icon_contact.webp",
boheme: "systems/fvtt-ecryme/images/icons/icon_boheme.webp",
trait: "systems/fvtt-ecryme/images/icons/icon_trait.webp",
annency: "systems/fvtt-ecryme/images/icons/icon_annency.webp",
skill: "systems/fvtt-ecryme/images/icons/icon_skill.webp",
specialization: "systems/fvtt-ecryme/images/icons/icon_spec.webp"
}
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
export class EcrymeItem extends Item {
constructor(data, context) {
if (!data.img) {
data.img = defaultItemImg[data.type];
}
super(data, context);
}
}

147
modules/tedeum-main.js Normal file
View File

@ -0,0 +1,147 @@
/**
* Ecryme system
* Author: Uberwald
* Software License: Prop
*/
/* -------------------------------------------- */
/* -------------------------------------------- */
// Import Modules
import { EcrymeActor } from "./actors/ecryme-actor.js";
import { EcrymeItemSheet } from "./items/tedeum-item-sheet.js";
import { EcrymeActorSheet } from "./actors/ecryme-actor-sheet.js";
import { EcrymeAnnencySheet } from "./actors/ecryme-annency-sheet.js";
import { EcrymeUtility } from "./common/ecryme-utility.js";
import { EcrymeCombat } from "./app/ecryme-combat.js";
import { EcrymeItem } from "./items/ecryme-item.js";
import { EcrymeHotbar } from "./app/ecryme-hotbar.js"
import { EcrymeCharacterSummary } from "./app/ecryme-summary-app.js"
import { ECRYME_CONFIG } from "./common/ecryme-config.js"
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
/************************************************************************************/
Hooks.once("init", async function () {
console.log(`Initializing Ecryme RPG`);
game.system.ecryme = {
config: ECRYME_CONFIG,
EcrymeHotbar
}
/* -------------------------------------------- */
// preload handlebars templates
EcrymeUtility.preloadHandlebarsTemplates();
/* -------------------------------------------- */
// Set an initiative formula for the system
CONFIG.Combat.initiative = {
formula: "1d6",
decimals: 1
};
/* -------------------------------------------- */
game.socket.on("system.fvtt-ecryme", data => {
EcrymeUtility.onSocketMesssage(data)
});
/* -------------------------------------------- */
// Define custom Entity classes
CONFIG.Combat.documentClass = EcrymeCombat
CONFIG.Actor.documentClass = EcrymeActor
CONFIG.Item.documentClass = EcrymeItem
/* -------------------------------------------- */
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("fvtt-ecryme", EcrymeActorSheet, { types: ["pc"], makeDefault: true });
Actors.registerSheet("fvtt-ecryme", EcrymeActorSheet, { types: ["npc"], makeDefault: true });
Actors.registerSheet("fvtt-ecryme", EcrymeAnnencySheet, { types: ["annency"], makeDefault: false });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("fvtt-ecryme", EcrymeItemSheet, { makeDefault: true });
EcrymeUtility.init()
console.log("Babele INIT!")
Babele.get().setSystemTranslationsDir("translated")
});
/* -------------------------------------------- */
function welcomeMessage() {
if (game.user.isGM) {
ChatMessage.create({
user: game.user.id,
whisper: [game.user.id],
content: `<div id="welcome-message-ecryme"><span class="rdd-roll-part">
<strong>Bienvenu dans Ecryme !</strong>` });
}
}
/* -------------------------------------------- */
// Register world usage statistics
function registerUsageCount(registerKey) {
if (game.user.isGM) {
game.settings.register(registerKey, "world-key", {
name: "Unique world key",
scope: "world",
config: false,
default: "",
type: String
});
let worldKey = game.settings.get(registerKey, "world-key")
if (worldKey == undefined || worldKey == "") {
worldKey = randomID(32)
game.settings.set(registerKey, "world-key", worldKey)
}
// Simple API counter
let regURL = `https://www.uberwald.me/fvtt_appcount/count.php?name="${registerKey}"&worldKey="${worldKey}"&version="${game.release.generation}.${game.release.build}"&system="${game.system.id}"&systemversion="${game.system.version}"`
//$.ajaxSetup({
//headers: { 'Access-Control-Allow-Origin': '*' }
//})
$.ajax(regURL)
}
}
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("ready", function () {
// User warning
if (!game.user.isGM && game.user.character == undefined) {
ui.notifications.info("Attention ! Aucun personnage relié au joueur !");
ChatMessage.create({
content: "<b>WARNING</b> Le joueur " + game.user.name + " n'est pas relié à un personnage !",
user: game.user._id
});
}
registerUsageCount(game.system.id)
welcomeMessage();
EcrymeUtility.ready()
EcrymeCharacterSummary.ready()
})
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.on("chatMessage", (html, content, msg) => {
if (content[0] == '/') {
let regExp = /(\S+)/g;
let commands = content.match(regExp);
if (game.system.ecryme.commands.processChatCommand(commands, content, msg)) {
return false;
}
}
return true;
});