#154 - COmptage des utilisations
This commit is contained in:
parent
c31306f154
commit
62ad72338a
@ -2732,6 +2732,29 @@ export class RdDActor extends Actor {
|
||||
return data;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async resetItemUse( ) {
|
||||
await this.setFlag('foundryvtt-reve-de-dragon', 'itemUse', null );
|
||||
await this.setFlag('foundryvtt-reve-de-dragon', 'itemUse', {} );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incItemUse( itemId ) {
|
||||
let itemUse = this.getFlag('foundryvtt-reve-de-dragon', 'itemUse');
|
||||
itemUse = (itemUse) ? duplicate(itemUse) : {};
|
||||
itemUse[itemId] = (itemUse[itemId]) ? itemUse[itemId] + 1 : 1;
|
||||
await this.setFlag( 'foundryvtt-reve-de-dragon', 'itemUse', itemUse);
|
||||
console.log("ITEM USE INC", itemUse);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getItemUse( itemId ) {
|
||||
let itemUse = this.getFlag('foundryvtt-reve-de-dragon', 'itemUse');
|
||||
itemUse = (itemUse) ? itemUse : {};
|
||||
console.log("ITEM USE GET", itemUse);
|
||||
return itemUse[itemId] ? itemUse[itemId] : 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* -- entites -- */
|
||||
/* retourne true si on peut continuer, false si on ne peut pas continuer */
|
||||
|
@ -9,6 +9,23 @@ import { RdDRoll } from "./rdd-roll.js";
|
||||
import { RdDRollTables } from "./rdd-rolltables.js";
|
||||
import { ReglesOptionelles } from "./regles-optionelles.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDCombatManager extends Combat {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
cleanItemUse() {
|
||||
for(let turn of this.turns) {
|
||||
turn.actor.resetItemUse()
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async nextRound() {
|
||||
console.log('New round !');
|
||||
this.cleanItemUse();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDCombat {
|
||||
|
||||
@ -39,13 +56,15 @@ export class RdDCombat {
|
||||
/* -------------------------------------------- */
|
||||
static onUpdateCombat(combat, data) {
|
||||
if (combat.data.round != 0 && combat.turns && combat.data.active) {
|
||||
RdDCombat.combatNouveauRound(combat);
|
||||
RdDCombat.combatNouveauTour(combat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static onPreDeleteCombat(combat, options) {
|
||||
if (game.user.isGM) {
|
||||
combat.cleanItemUse();
|
||||
ChatUtility.removeChatMessageContaining(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
|
||||
/*
|
||||
* TODO: support de plusieurs combats parallèles
|
||||
@ -64,7 +83,7 @@ export class RdDCombat {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static combatNouveauRound(combat) {
|
||||
static combatNouveauTour(combat) {
|
||||
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
|
||||
if (game.user.isGM) {
|
||||
// seul le GM notifie le status
|
||||
@ -358,6 +377,7 @@ export class RdDCombat {
|
||||
|
||||
let rollData = this._prepareAttaque(competence, arme);
|
||||
console.log("RdDCombat.attaque >>>", rollData);
|
||||
this.attacker.incItemUse( arme._id ); // Usage
|
||||
|
||||
const dialog = await RdDRoll.create(this.attacker, rollData,
|
||||
{
|
||||
@ -457,15 +477,24 @@ export class RdDCombat {
|
||||
if (essaisPrecedents) {
|
||||
mergeObject(attackerRoll.essais, essaisPrecedents, { overwrite: true });
|
||||
}
|
||||
|
||||
// # utilisation esquive
|
||||
let esquiveUsage = 0;
|
||||
let esquive = this.defender.getCompetence("esquive");
|
||||
if (esquive) {
|
||||
esquiveUsage = this.defender.getItemUse( esquive._id);
|
||||
}
|
||||
|
||||
const paramChatDefense = {
|
||||
passeArme: attackerRoll.passeArme,
|
||||
essais: attackerRoll.essais,
|
||||
defender: this.defender,
|
||||
attacker: this.attacker,
|
||||
attackerId: this.attackerId,
|
||||
esquiveUsage: esquiveUsage,
|
||||
defenderTokenId: this.defenderTokenId,
|
||||
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
|
||||
armes: this._filterArmesParade(this.defender.data.items, attackerRoll.competence, attackerRoll.arme),
|
||||
armes: this._filterArmesParade(this.defender, attackerRoll.competence, attackerRoll.arme),
|
||||
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
|
||||
attaqueParticuliere: attackerRoll.particuliere,
|
||||
attaqueCategorie: attackerRoll.competence.data.categorie,
|
||||
@ -510,8 +539,12 @@ export class RdDCombat {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_filterArmesParade(items, competence) {
|
||||
_filterArmesParade(defender, competence) {
|
||||
let items = defender.data.items;
|
||||
items = items.filter(item => RdDItemArme.isArmeUtilisable(item) || RdDItemCompetenceCreature.isCompetenceParade(item));
|
||||
for( let item of items) {
|
||||
item.data.nbUsage = defender.getItemUse( item._id); // Ajout du # d'utilisation ce round
|
||||
}
|
||||
switch (competence.data.categorie) {
|
||||
case 'tir':
|
||||
case 'lancer':
|
||||
@ -575,6 +608,7 @@ export class RdDCombat {
|
||||
let arme = this.defender.getArmeParade(armeParadeId);
|
||||
|
||||
console.log("RdDCombat.parade >>>", attackerRoll, armeParadeId, arme);
|
||||
this.defender.incItemUse( armeParadeId ); // Usage
|
||||
|
||||
let rollData = this._prepareParade(attackerRoll, arme);
|
||||
|
||||
@ -596,6 +630,7 @@ export class RdDCombat {
|
||||
dialog.render(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_prepareParade(attackerRoll, armeParade) {
|
||||
const compName = armeParade.data.competence;
|
||||
const armeAttaque = attackerRoll.arme;
|
||||
@ -681,6 +716,7 @@ export class RdDCombat {
|
||||
}
|
||||
console.log("RdDCombat.esquive >>>", attackerRoll, esquive);
|
||||
let rollData = this._prepareEsquive(attackerRoll, esquive);
|
||||
this.defender.incItemUse( esquive._id ); // Usage
|
||||
|
||||
const dialog = await RdDRoll.create(this.defender, rollData,
|
||||
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html' }, {
|
||||
|
@ -20,7 +20,7 @@ import { RdDCalendrier } from "./rdd-calendrier.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
import { RdDTokenHud } from "./rdd-token-hud.js";
|
||||
import { RdDCommands } from "./rdd-commands.js";
|
||||
import { RdDCombat } from "./rdd-combat.js";
|
||||
import { RdDCombatManager, RdDCombat } from "./rdd-combat.js";
|
||||
import { ChatUtility } from "./chat-utility.js";
|
||||
import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { StatusEffects } from "./status-effects.js";
|
||||
@ -219,6 +219,7 @@ Hooks.once("init", async function () {
|
||||
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, { types: ["entite"], makeDefault: true });
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, { makeDefault: true });
|
||||
CONFIG.Combat.entityClass = RdDCombatManager;
|
||||
|
||||
// Handlebar function pour container
|
||||
Handlebars.registerHelper('buildConteneur', (objet) => { return RdDUtility.buildConteneur(objet); });
|
||||
|
@ -37,19 +37,19 @@
|
||||
{{else}}
|
||||
{{#each armes as |arme key|}}
|
||||
<a class='chat-card-button' id='parer-button' data-attackerId='{{../attackerId}}' data-defenderTokenId='{{../defenderTokenId}}' data-armeid='{{arme._id }}'>
|
||||
Parer avec {{arme.name}} à {{../diffLibre }}
|
||||
Parer avec {{arme.name}} à {{../diffLibre }} (Utilisation : {{arme.data.nbUsage}})
|
||||
</a>
|
||||
<br>
|
||||
{{/each}}
|
||||
{{#if mainsNues}}
|
||||
<a class='chat-card-button' id='parer-button' data-attackerId='{{attackerId}}' data-defenderTokenId='{{defenderTokenId}}'>
|
||||
Parer à mains nues à {{diffLibre}}
|
||||
Parer à mains nues à {{diffLibre}} (Utilisation : {{arme.data.nbUsage}})
|
||||
</a>
|
||||
<br>
|
||||
{{/if}}
|
||||
{{#if (ne attaqueCategorie 'tir')}}
|
||||
<a class='chat-card-button' id='esquiver-button' data-attackerId='{{attackerId}}' data-defenderTokenId='{{defenderTokenId}}'>
|
||||
Esquiver à {{diffLibre}}
|
||||
Esquiver à {{diffLibre}} (Utilisation : {{esquiveUsage}})
|
||||
</a>
|
||||
<br>
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user