Gestion des paradigmes

This commit is contained in:
2022-10-20 23:59:31 +02:00
parent b0c59c6104
commit b6dac470e9
9 changed files with 206 additions and 119 deletions

View File

@@ -143,22 +143,11 @@ export class Imperium5ActorSheet extends ActorSheet {
this.actor.incDecQuantity( li.data("item-id"), +1 );
} );
html.find('.roll-ame').click((event) => {
html.find('.roll-ame-button').click((event) => {
const ameKey = $(event.currentTarget).data("ame-key")
this.actor.rollAme(ameKey)
});
html.find('.roll-spec').click((event) => {
const li = $(event.currentTarget).parents(".item");
const specId = li.data("item-id");
this.actor.rollSpec(specId);
});
html.find('.weapon-damage-roll').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weaponId = li.data("item-id");
this.actor.rollWeapon(weaponId, true);
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;

View File

@@ -111,6 +111,17 @@ export class Imperium5Actor extends Actor {
let item = duplicate(this.items.filter( it => it.type == "contact") || [] )
return item
}
getUnusedParadigmes() {
let paraList = []
for(let k in this.system.paradigmes) {
let para = this.system.paradigmes[k]
if (!para.used) {
para.key = k
paraList.push(duplicate(para))
}
}
return paraList
}
/* -------------------------------------------- */
incDecKarma( value ) {
@@ -156,10 +167,6 @@ export class Imperium5Actor extends Actor {
/* -------------------------------------------- */
getInitiativeScore(combatId, combatantId) {
if (this.type == 'character') {
this.rollMR(true, combatId, combatantId)
}
console.log("Init required !!!!")
return -1;
}
@@ -213,6 +220,13 @@ export class Imperium5Actor extends Actor {
}
}
}
/* -------------------------------------------- */
setParadigmeUsed(paraKey) {
let para = duplicate(this.system.paradigmes)
para[paraKey].used = true
this.update( {'system.paradigmes': para} )
}
/* -------------------------------------------- */
/* ROLL SECTION
@@ -250,6 +264,8 @@ export class Imperium5Actor extends Actor {
rollData.actorId = this.id
rollData.img = this.img
rollData.capacites = this.getUnusedCapacites()
rollData.paradigmes = this.getUnusedParadigmes()
rollData.selectedParadigme = "none"
rollData.karma = this.system.karma.value
return rollData

View File

@@ -91,9 +91,13 @@ export class Imperium5Utility {
/* -------------------------------------------- */
static async chatListeners(html) {
html.on("click", '.view-item-from-chat', event => {
game.system.pegasus.creator.openItemView(event)
html.on("click", '.button-apply-paradigme', event => {
let paraKey = $(event.currentTarget).data("para-key")
let rollData = this.getRollDataFromMessage(event)
rollData.previousMessageId = Imperium5Utility.findChatMessageId(event.currentTarget)
this.applyParadigme(rollData, paraKey)
})
}
/* -------------------------------------------- */
@@ -152,6 +156,12 @@ export class Imperium5Utility {
}
return undefined;
}
/* -------------------------------------------- */
static getRollDataFromMessage(event) {
let messageId = Imperium5Utility.findChatMessageId(event.currentTarget)
let message = game.messages.get(messageId)
return message.getFlag("world", "imperium5-roll-data")
}
/* -------------------------------------------- */
static createDirectOptionList(min, max) {
@@ -279,6 +289,16 @@ export class Imperium5Utility {
return Math.max(val, 0)
}
/* -------------------------------------------- */
static computeReussites(rollData) {
let myRoll = rollData.roll
rollData.successPC = myRoll.terms[0].results.filter(res => res.result <= rollData.seuil).length
rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= rollData.seuil).length
rollData.bonPresage = myRoll.terms[2].results[0].result == 1
rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8
rollData.nbUnitesNarration = Math.max( rollData.successPC-1, 0)
}
/* -------------------------------------------- */
static async rollImperium5(rollData) {
@@ -308,16 +328,24 @@ export class Imperium5Utility {
}
// Calcul réussites
rollData.successPC = myRoll.terms[0].results.filter(res => res.result <= 2).length
rollData.successGM = myRoll.terms[4].results.filter(res => res.result <= 2).length
rollData.bonPresage = myRoll.terms[2].results[0].result == 1
rollData.mauvaisPresage = myRoll.terms[2].results[0].result == 8
rollData.nbUnitesNarration = Math.max( rollData.successPC-1, 0)
this.computeReussites(rollData)
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-imperium5/templates/chat-generic-result.html`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
msg.setFlag("world", "imperium5-roll-data", rollData)
}
/* ------------------------- ------------------- */
static async processParadigmeRoll(rollData) {
this.computeReussites(rollData)
rollData.paradigmes = []
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)
}
/* ------------------------- ------------------- */
@@ -445,12 +473,24 @@ export class Imperium5Utility {
useArchetype: false,
useAide: false,
useKarma: false,
usedCapacite: "none"
usedCapacite: "none",
seuil: 2
}
Imperium5Utility.updateWithTarget(rollData)
return rollData
}
/* -------------------------------------------- */
static applyParadigme(rollData, paraKey) {
let actor = game.actors.get(rollData.actorId)
let para = actor.system.paradigmes[paraKey]
rollData.seuil = para.value
rollData.usedParadigme = para.label
actor.setParadigmeUsed(paraKey)
this.processParadigmeRoll(rollData)
}
/* -------------------------------------------- */
static updateWithTarget(rollData) {
let objectDefender