Data model change

This commit is contained in:
2022-07-25 21:33:00 +02:00
parent 1de5086efa
commit 732d51b8b3
7 changed files with 73 additions and 533 deletions

View File

@@ -16,7 +16,7 @@ export class CrucibleActorSheet extends ActorSheet {
template: "systems/fvtt-crucible-rpg/templates/actor-sheet.html",
width: 960,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "combat" }],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: true
});
@@ -213,29 +213,15 @@ export class CrucibleActorSheet extends ActorSheet {
this.actor.rollPool( 'phy', false, "dmg-res");
});
html.find('.roll-stat').click((event) => {
const statId = $(event.currentTarget).data("stat-key");
this.actor.rollStat(statId);
html.find('.roll-ability').click((event) => {
const abilityKey = $(event.currentTarget).data("ability-key");
this.actor.rollAbility(abilityKey);
});
html.find('.roll-mr').click((event) => {
this.actor.rollMR();
});
html.find('.roll-idr').click((event) => {
const diceValue = $(event.currentTarget).data("dice-value")
const li = $(event.currentTarget).parents(".item")
this.rollIDR( li.data("item-id"), diceValue)
})
html.find('.roll-spec').click((event) => {
html.find('.roll-skill').click((event) => {
const li = $(event.currentTarget).parents(".item");
const specId = li.data("item-id");
this.actor.rollSpec(specId);
const skillId = li.data("item-id")
this.actor.rollSkill(skillId)
});
html.find('.power-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const powerId = li.data("item-id");
this.actor.rollPower(powerId);
});
html.find('.weapon-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");

View File

@@ -361,19 +361,17 @@ export class CrucibleActor extends Actor {
}
/* -------------------------------------------- */
getCommonRollData(abKey = undefined) {
getCommonRollData(abilityKey = undefined) {
let rollData = CrucibleUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
if (abilKey) {
rollData.getRelevantSkill(abKey)
rollData.ability = this.getAbility(abKey)
rollData.skillList = this.getRelevantSkill(abKey)
rollData.selectedKill = "0"
rollData.img = `systems/fvtt-crucible-rpg/images/icons/${rollData.ability.abbrev}.webp`
if (abilityKey) {
rollData.ability = this.getAbility(abilityKey)
//rollData.skillList = this.getRelevantSkill(abilityKey)
rollData.selectedKill = undefined
}
console.log("ROLLDATA", rollData)
@@ -381,6 +379,25 @@ export class CrucibleActor extends Actor {
return rollData
}
/* -------------------------------------------- */
rollAbility(abilityKey) {
let rollData = this.getCommonRollData(abilityKey)
rollData.mode = "ability"
CrucibleUtility.rollCrucible(rollData)
}
/* -------------------------------------------- */
rollSkill(skillId) {
let skill = this.data.items.get(skillId)
if (skill) {
skill = duplicate(skill)
let abilityKey = skill.data.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.mode = "skill"
rollData.skill = skill
CrucibleUtility.rollCrucible(rollData)
}
}
/* -------------------------------------------- */
async startRoll(rollData) {

View File

@@ -262,50 +262,24 @@ export class CrucibleUtility {
let actor = game.actors.get(rollData.actorId)
let diceFormulaTab = []
for (let dice of rollData.dicePool) {
let level = dice.level
if (dice.name == "stat") {
level += rollData.statLevelBonus
}
diceFormulaTab.push(this.getFoundryDiceFromLevel(level))
let diceFormula = String(rollData.ability.value) + "d6cs>=5"
if (rollData.skill) {
diceFormula += "+" + String(rollData.skill.data.level) + "d8cs>=5"
}
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh + ' + (rollData.stat?.mod || 0)
// Performs roll
let myRoll = rollData.roll
if (!myRoll || rollData.rerollHero || rollData.rerollMomentum) { // New rolls only of no rerolls
if (!myRoll) { // New rolls only of no rerolls
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
rollData.roll = myRoll
}
// Final score and keep data
rollData.finalScore = myRoll.total
if (rollData.damages) {
let dmgFormula = this.getFoundryDiceFromLevel(rollData.damages.value)
let dmgRoll = new Roll(dmgFormula).roll({ async: false })
await this.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode"))
rollData.dmgResult = dmgRoll.total
}
rollData.nbSuccess = myRoll.total
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
});
// Init stuf
if (rollData.isInit) {
let combat = game.combats.get(rollData.combatId)
combat.updateEmbeddedDocuments("Combatant", [{ _id: rollData.combatantId, initiative: rollData.finalScore }])
}
// Stun specific -> Suffere a stun level when dmg-res
if (rollData.subKey && rollData.subKey == "dmg-res") {
actor.modifyStun(+1)
}
//this.removeUsedPerkEffects( rollData) // Unused for now
this.removeOneUseEffects(rollData) // Unused for now
})
console.log("Rolldata result", rollData)
// And save the roll
this.saveRollData(rollData)