Sync WIP
This commit is contained in:
@@ -36,6 +36,9 @@ export class EcrymeActorSheet extends ActorSheet {
|
||||
system: duplicate(this.object.system),
|
||||
limited: this.object.limited,
|
||||
skills: this.actor.prepareSkills(),
|
||||
traits: this.actor.getRollTraits(),
|
||||
ideal: this.actor.getIdeal(),
|
||||
spleen: this.actor.getSpleen(),
|
||||
system: duplicate(this.object.system),
|
||||
config: duplicate(game.system.ecryme.config),
|
||||
weapons: duplicate(this.actor.getWeapons()),
|
||||
|
@@ -89,7 +89,26 @@ export class EcrymeActor extends Actor {
|
||||
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
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) {
|
||||
return this.items.find(it => it.type == "specialization" && it.id == id)
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getSpecializations(skillKey) {
|
||||
return this.items.filter(it => it.type == "specialization" && it.system.skillkey == skillKey)
|
||||
@@ -262,6 +281,12 @@ export class EcrymeActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData() {
|
||||
@@ -271,6 +296,9 @@ export class EcrymeActor extends Actor {
|
||||
rollData.actorId = this.id
|
||||
rollData.img = this.img
|
||||
rollData.isReroll = false
|
||||
rollData.traits = this.getRollTraits()
|
||||
rollData.spleen = this.getSpleen()
|
||||
rollData.ideal = this.getIdeal()
|
||||
|
||||
return rollData
|
||||
}
|
||||
@@ -279,7 +307,11 @@ export class EcrymeActor extends Actor {
|
||||
rollSkill(categKey, skillKey) {
|
||||
let skill = this.system.skills[categKey].skilllist[skillKey]
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.skill = duplicate(skill)
|
||||
skill = duplicate(skill)
|
||||
skill.categKey = categKey
|
||||
skill.skillKey = skillKey
|
||||
skill.spec = this.getSpecializations(skillKey)
|
||||
rollData.skill = skill
|
||||
rollData.mode = "skill"
|
||||
rollData.title = game.i18n.localize(skill.name)
|
||||
rollData.img = skill.img
|
||||
|
@@ -14,6 +14,14 @@ export const ECRYME_CONFIG = {
|
||||
{value: +2, text: "+2"},
|
||||
{value: +3, text: "+3"}
|
||||
],
|
||||
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",
|
||||
|
@@ -8,6 +8,7 @@ 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 = {}
|
||||
@@ -43,15 +44,22 @@ export class EcrymeUtility {
|
||||
Handlebars.registerHelper('add', function (a, b) {
|
||||
return parseInt(a) + parseInt(b);
|
||||
})
|
||||
Handlebars.registerHelper('for', function (from, to, incr, block) {
|
||||
var accum = '';
|
||||
for (var i = from; i <= to; i += incr)
|
||||
accum += block.fn(i);
|
||||
return accum;
|
||||
})
|
||||
this.buildSkillConfig()
|
||||
|
||||
}
|
||||
|
||||
/*-------------------------------------------- */
|
||||
static buildSkillConfig() {
|
||||
game.system.ecryme.config.skills = { }
|
||||
for (let categKey in game.data.template.Actor.templates.core.skills) {
|
||||
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) {
|
||||
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
|
||||
@@ -89,6 +97,32 @@ export class EcrymeUtility {
|
||||
return actor
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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.i18.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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
|
||||
@@ -105,7 +139,7 @@ export class EcrymeUtility {
|
||||
let messageId = EcrymeUtility.findChatMessageId(event.currentTarget)
|
||||
this.drawDeckCard(messageId)
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -191,7 +225,7 @@ export class EcrymeUtility {
|
||||
static async onSocketMesssage(msg) {
|
||||
console.log("SOCKET MESSAGE", msg.name)
|
||||
if (msg.name == "msg-draw-card") {
|
||||
if ( game.user.isGM && game.system.ecryme.currentTirage) {
|
||||
if (game.user.isGM && game.system.ecryme.currentTirage) {
|
||||
game.system.ecryme.currentTirage.addCard(msg.data.msgId)
|
||||
}
|
||||
}
|
||||
@@ -258,19 +292,13 @@ export class EcrymeUtility {
|
||||
/* -------------------------------------------- */
|
||||
static computeResults(rollData) {
|
||||
rollData.isSuccess = false
|
||||
if (rollData.total <= rollData.target) {
|
||||
if (!rollData.difficulty || rollData.difficulty == "-") {
|
||||
return
|
||||
}
|
||||
rollData.margin = rollData.total - rollData.difficulty
|
||||
if (rollData.total > rollData.difficulty) {
|
||||
rollData.isSuccess = true
|
||||
}
|
||||
if (rollData.total == 1) {
|
||||
rollData.isSuccess = true
|
||||
rollData.isCritical = true
|
||||
}
|
||||
if (rollData.total == 20) {
|
||||
rollData.isSuccess = false
|
||||
rollData.isFumble = true
|
||||
}
|
||||
if (rollData.total <= Math.floor(rollData.target / 3)) {
|
||||
rollData.isPart = true
|
||||
rollData.margin = Math.min(rollData.margin, rollData.skill.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,24 +306,63 @@ export class EcrymeUtility {
|
||||
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)
|
||||
|
||||
// Build the dice formula
|
||||
let diceFormula = "1d20"
|
||||
rollData.target = rollData.attr.value + rollData.bonusMalusPerso + rollData.bonusMalusSituation + rollData.bonusMalusDef + rollData.bonusMalusPortee
|
||||
if (rollData.attr.abbrev == "physique") {
|
||||
rollData.target += rollData.phyMalus
|
||||
let diceFormula = "2d6"
|
||||
if (rollData.useIdeal) {
|
||||
diceFormula = "3d6kh2"
|
||||
}
|
||||
if (rollData.useSpleen) {
|
||||
diceFormula = "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 += "+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
|
||||
rollData.diceFormula = diceFormula
|
||||
|
||||
// Performs roll
|
||||
console.log("Roll formula", diceFormula)
|
||||
let myRoll = new Roll(diceFormula).roll({ async: false })
|
||||
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
||||
rollData.roll = myRoll
|
||||
rollData.roll = duplicate(myRoll)
|
||||
rollData.total = myRoll.total
|
||||
rollData.diceSum = myRoll.terms[0].total
|
||||
|
||||
this.computeResults(rollData)
|
||||
|
||||
console.log("ERRRRR", rollData)
|
||||
let msg = await this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-ecryme/templates/chat/chat-generic-result.hbs`, rollData)
|
||||
})
|
||||
@@ -307,6 +374,22 @@ export class EcrymeUtility {
|
||||
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)
|
||||
})
|
||||
msg.setFlag("world", "rolldata", rollData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static sortArrayObjectsByName(myArray) {
|
||||
myArray.sort((a, b) => {
|
||||
@@ -404,7 +487,12 @@ export class EcrymeUtility {
|
||||
bonusMalusSituation: 0,
|
||||
bonusMalusDef: 0,
|
||||
bonusMalusPortee: 0,
|
||||
rollMode: game.settings.get("core", "rollMode")
|
||||
skillTranscendence: 0,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
difficulty: "-",
|
||||
useSpleen: false,
|
||||
useIdeal: false,
|
||||
config: duplicate(game.system.ecryme.config)
|
||||
}
|
||||
EcrymeUtility.updateWithTarget(rollData)
|
||||
return rollData
|
||||
|
@@ -5,14 +5,8 @@ export class EcrymeRollDialog extends Dialog {
|
||||
/* -------------------------------------------- */
|
||||
static async create(actor, rollData) {
|
||||
|
||||
let options = { classes: ["EcrymeDialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
|
||||
let html
|
||||
if (rollData.attr && rollData.attr.iscard) {
|
||||
html = await renderTemplate('systems/fvtt-ecryme/templates/dialogs/confrontation-dialog.hbs', rollData);
|
||||
} else {
|
||||
html = await renderTemplate('systems/fvtt-ecryme/templates/dialogs/roll-dialog-generic.hbs', 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);
|
||||
}
|
||||
|
||||
@@ -20,17 +14,17 @@ export class EcrymeRollDialog extends Dialog {
|
||||
constructor(actor, rollData, html, options, close = undefined) {
|
||||
let isCard = rollData.attr && rollData.attr.iscard
|
||||
let conf = {
|
||||
title: (isCard) ? "Jet" : "Tirage",
|
||||
title: game.i18n.localize("ECRY.ui.rolltitle"),
|
||||
content: html,
|
||||
buttons: {
|
||||
roll: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: (isCard) ? "Tirer une carte" : "Lancer le dé",
|
||||
label: game.i18n.localize("ECRY.ui.roll"),
|
||||
callback: () => { this.roll() }
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Annuler",
|
||||
label: game.i18n.localize("ECRY.ui.cancel"),
|
||||
callback: () => { this.close() }
|
||||
}
|
||||
},
|
||||
@@ -45,12 +39,7 @@ export class EcrymeRollDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
roll() {
|
||||
let isCard = this.rollData.attr && this.rollData.attr.iscard
|
||||
if (isCard) {
|
||||
EcrymeUtility.tirageConfrontationEcryme(this.rollData)
|
||||
} else {
|
||||
EcrymeUtility.rollEcryme(this.rollData)
|
||||
}
|
||||
EcrymeUtility.rollEcryme(this.rollData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -69,24 +58,30 @@ export class EcrymeRollDialog extends Dialog {
|
||||
}
|
||||
$(function () { onLoad(); });
|
||||
|
||||
html.find('#bonusMalusSituation').change((event) => {
|
||||
this.rollData.bonusMalusSituation = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#bonusMalusPerso').change((event) => {
|
||||
this.rollData.bonusMalusPerso = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#bonusMalusDef').change((event) => {
|
||||
this.rollData.bonusMalusDef = Number(event.currentTarget.value)
|
||||
html.find('#roll-difficulty').change((event) => {
|
||||
this.rollData.difficulty = Number(event.currentTarget.value) || 0
|
||||
})
|
||||
html.find('#bonusMalusPortee').change((event) => {
|
||||
this.rollData.bonusMalusPortee = Number(event.currentTarget.value)
|
||||
html.find('#roll-specialization').change((event) => {
|
||||
this.rollData.selectedSpecs = $('#roll-specialization').val()
|
||||
})
|
||||
html.find('#confrontationDegre').change((event) => {
|
||||
this.rollData.confrontationDegre = Number(event.currentTarget.value)
|
||||
html.find('#roll-trait-bonus').change((event) => {
|
||||
this.rollData.traitsBonus = $('#roll-trait-bonus').val()
|
||||
})
|
||||
html.find('#confrontationModif').change((event) => {
|
||||
this.rollData.confrontationModif = Number(event.currentTarget.value)
|
||||
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
|
||||
})
|
||||
|
||||
}
|
||||
}
|
@@ -1,8 +1,14 @@
|
||||
import { EcrymeUtility } from "../common/ecryme-utility.js";
|
||||
|
||||
export const defaultItemImg = {
|
||||
weapon: "systems/fvtt-ecryme/images/icons/weapon.webp",
|
||||
equipement: "systems/fvtt-ecryme/images/icons/equipement.webp"
|
||||
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"
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user