plein de truc
This commit is contained in:
+112
-113
@@ -1,30 +1,30 @@
|
||||
import { VERMINE } from "./config.mjs";
|
||||
import { getActorSkillScore,updateActorSkillScore } from "./functions.mjs";
|
||||
import { getActorSkillScore, updateActorSkillScore } from "./functions.mjs";
|
||||
|
||||
export class VermineFight {
|
||||
|
||||
async performTest(enemyAchievement, enemyConservation, skillKey, skill, params, actor) {
|
||||
const dicePool = (params.spleen != undefined || params.purpose != undefined) ? '5' : '4';
|
||||
const r = new Roll(dicePool +`d6`);
|
||||
const r = new Roll(dicePool + `d6`);
|
||||
let diceString = '';
|
||||
let dicePoolHint = '';
|
||||
let discardedRoll = false;
|
||||
let discardedRoll = false;
|
||||
let bonus = 0;
|
||||
let bonusText = '/+';
|
||||
let currentSkillScore = skill;
|
||||
|
||||
|
||||
r.roll(); // dice are rolled
|
||||
if (params.usure != undefined){
|
||||
if (params.usure != undefined) {
|
||||
currentSkillScore += params.usure;
|
||||
bonus += params.usure;
|
||||
}
|
||||
|
||||
if (params.specialization != undefined){
|
||||
if (params.specialization != undefined) {
|
||||
currentSkillScore += 2;
|
||||
}
|
||||
|
||||
if (params.trait != undefined){
|
||||
if (params.trait != undefined) {
|
||||
currentSkillScore += params.trait;
|
||||
bonus += params.trait;
|
||||
}
|
||||
@@ -32,28 +32,28 @@ export class VermineFight {
|
||||
bonusText += bonus;
|
||||
|
||||
let targetText = game.i18n.format('VERMINE.Selected') + ' : ' + game.i18n.format(skillKey) + " " + skill + bonusText;
|
||||
if (params.specialization != undefined){
|
||||
targetText += " (S)";
|
||||
if (params.specialization != undefined) {
|
||||
targetText += " (S)";
|
||||
}
|
||||
// tri par ordre croissant
|
||||
r.terms[0].results.sort((a,b) => a.result - b.result );
|
||||
|
||||
if (params.purpose != undefined){
|
||||
r.terms[0].results.sort((a, b) => a.result - b.result);
|
||||
|
||||
if (params.purpose != undefined) {
|
||||
discardedRoll = r.terms[0].results.shift();
|
||||
dicePoolHint = ' - ' + game.i18n.format('VERMINE.PurposeTrait');
|
||||
} else if (params.spleen != undefined){
|
||||
} else if (params.spleen != undefined) {
|
||||
discardedRoll = r.terms[0].results.pop();
|
||||
dicePoolHint = ' - ' + game.i18n.format('VERMINE.SpleenTrait');
|
||||
}
|
||||
}
|
||||
const discardedRollText = (discardedRoll.result != undefined) ? '<div class="discarded-roll">' + discardedRoll.result + '</div>' : "";
|
||||
|
||||
for (let i = 0; i < r.terms[0].results.length; i++) {
|
||||
let result = r.terms[0].results[i].result;
|
||||
diceString += '<li class="roll die d6 die-'+ i +'">' + result + '</li>';
|
||||
diceString += '<li class="roll die d6 die-' + i + '">' + result + '</li>';
|
||||
}
|
||||
|
||||
let hintText = game.i18n.format('VERMINE.ConfrontationHint');
|
||||
|
||||
|
||||
// Build a dynamic html using the variables from above.
|
||||
const html = `
|
||||
<div class="vermine2047 roll confrontation">
|
||||
@@ -73,7 +73,7 @@ export class VermineFight {
|
||||
</div>
|
||||
</section>
|
||||
</div>` +
|
||||
`<p class="step1-text" id="step1">` + hintText + `</p>
|
||||
`<p class="step1-text" id="step1">` + hintText + `</p>
|
||||
<div class="row">
|
||||
<a class="inline-block button add-to-achievement">` + game.i18n.format('VERMINE.Achievement') + `</a>
|
||||
<a class="inline-block button add-to-conservation">` + game.i18n.format('VERMINE.Conservation') + `</a>
|
||||
@@ -109,10 +109,10 @@ export class VermineFight {
|
||||
|
||||
if (actor)
|
||||
conf.speaker = ChatMessage.getSpeaker({ actor: actor });
|
||||
// Send's Chat Message to foundry, if items are missing they will appear as false or undefined and this not be rendered.
|
||||
ChatMessage.create(conf).then((msg) => {
|
||||
// Send's Chat Message to foundry, if items are missing they will appear as false or undefined and this not be rendered.
|
||||
ChatMessage.create(conf).then((msg) => {
|
||||
return msg;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static instance = null;
|
||||
@@ -123,7 +123,7 @@ export class VermineFight {
|
||||
return VermineFight.instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// data injected to char data
|
||||
static previousValues = {
|
||||
dicePool: 4,
|
||||
@@ -136,34 +136,34 @@ export class VermineFight {
|
||||
|
||||
static rollerTemplate = 'systems/vermine2047/templates/fight.html';
|
||||
static CombatResultTemplate = 'systems/vermine2047/templates/fight-result.html';
|
||||
|
||||
|
||||
static async chatMessageHandler(message, html, data) {
|
||||
// console.log("accès au fin du fin", message._id);
|
||||
|
||||
// sélection du dé actif
|
||||
html.on("click", '.confrontation .die.d6', event => {
|
||||
const diceResult = parseInt($(event.target).html(),10);
|
||||
const diceResult = parseInt($(event.target).html(), 10);
|
||||
html.find('.confrontation .die.d6').removeClass('active');
|
||||
$(event.target).addClass('active');
|
||||
});
|
||||
|
||||
// sélection des dés d'accomplissement
|
||||
html.on("click", '.confrontation .add-to-achievement', event => {
|
||||
const diceResult = parseInt(html.find('.confrontation .die.d6.active').html(),10);
|
||||
const diceResult = parseInt(html.find('.confrontation .die.d6.active').html(), 10);
|
||||
html.find('.confrontation .die.d6.active').removeClass('min').addClass('max');
|
||||
});
|
||||
|
||||
// sélection des dés de conservation
|
||||
html.on("click", '.confrontation .add-to-conservation', event => {
|
||||
const diceResult = parseInt(html.find('.confrontation .die.d6.active').html(),10);
|
||||
const diceResult = parseInt(html.find('.confrontation .die.d6.active').html(), 10);
|
||||
html.find('.confrontation .die.d6.active').removeClass('max').addClass('min');
|
||||
});
|
||||
|
||||
// reset de la sélection des pools
|
||||
html.on("click", '.confrontation .reset', event => {
|
||||
html.find('.confrontation .die.d6')
|
||||
.removeClass('max')
|
||||
.removeClass('min');
|
||||
.removeClass('max')
|
||||
.removeClass('min');
|
||||
});
|
||||
|
||||
// résolution de la confrontation
|
||||
@@ -172,10 +172,10 @@ export class VermineFight {
|
||||
let conservationDice = 0;
|
||||
let achievementBasis = 0;
|
||||
let conservationBasis = 0;
|
||||
html.find('.confrontation .die.d6.max').each(function(index){
|
||||
html.find('.confrontation .die.d6.max').each(function (index) {
|
||||
achievementDice += parseInt($(this).html(), 10);
|
||||
});
|
||||
html.find('.confrontation .die.d6.min').each(function(index){
|
||||
html.find('.confrontation .die.d6.min').each(function (index) {
|
||||
conservationDice += parseInt($(this).html(), 10);
|
||||
});
|
||||
|
||||
@@ -189,8 +189,8 @@ export class VermineFight {
|
||||
html.find('td.conservation-result').html(conservationBasis + conservationDice);
|
||||
|
||||
// calcul des marges
|
||||
const achievementMargin = achievementBasis + achievementDice - parseInt(html.find('td.adv-achievement-result').html(),10);
|
||||
const conservationMargin = conservationBasis + conservationDice - parseInt(html.find('td.adv-conservation-result').html(),10);
|
||||
const achievementMargin = achievementBasis + achievementDice - parseInt(html.find('td.adv-achievement-result').html(), 10);
|
||||
const conservationMargin = conservationBasis + conservationDice - parseInt(html.find('td.adv-conservation-result').html(), 10);
|
||||
html.find('td.achievement-margin').html(achievementMargin);
|
||||
html.find('td.conservation-margin').html(conservationMargin);
|
||||
|
||||
@@ -206,7 +206,7 @@ export class VermineFight {
|
||||
// supprime le masquage des résultats du dé
|
||||
html.off("click", ".dice-roll");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* main class function
|
||||
* @returns
|
||||
@@ -217,30 +217,30 @@ export class VermineFight {
|
||||
// get the actor
|
||||
try {
|
||||
actor = game.user.character;
|
||||
} catch(e){
|
||||
throw("Aucun personnage défini !");
|
||||
} catch (e) {
|
||||
throw ("Aucun personnage défini !");
|
||||
}
|
||||
|
||||
if (actor == null && externalData.speakerId != undefined && externalData.speakerId != null){
|
||||
if (actor == null && externalData.speakerId != undefined && externalData.speakerId != null) {
|
||||
// on récupère le speakerId, et de là l'objet actor
|
||||
actor = game.actors.get(externalData.speakerId);
|
||||
actor = game.actors.get(externalData.speakerId);
|
||||
VermineFight.previousValues['speakerName'] = actor.name;
|
||||
VermineFight.previousValues['speakerImg'] = actor.img;
|
||||
VermineFight.previousValues['speakerImg'] = actor.img;
|
||||
} else {
|
||||
VermineFight.previousValues['speakerName'] = "Anonyme";
|
||||
}
|
||||
|
||||
// get the data
|
||||
let charData = (externalData) => {
|
||||
let o = Object.assign({ _template: VermineFight.rollerTemplate }, {...VermineFight.previousValues, ...externalData});
|
||||
let o = Object.assign({ _template: VermineFight.rollerTemplate }, { ...VermineFight.previousValues, ...externalData });
|
||||
return o;
|
||||
};
|
||||
let data = charData(externalData);
|
||||
console.log(data);
|
||||
let data = charData(externalData);
|
||||
console.log(data);
|
||||
|
||||
// render template
|
||||
let html = await renderTemplate(data._template, data);
|
||||
|
||||
|
||||
let ui = new Dialog({
|
||||
title: game.i18n.localize("VERMINE.FightTool"),
|
||||
content: html,
|
||||
@@ -257,7 +257,7 @@ export class VermineFight {
|
||||
switch (e.name) {
|
||||
case "skill":
|
||||
case "cephalic":
|
||||
if (e.value !== ''){
|
||||
if (e.value !== '') {
|
||||
skillKey = e.value;
|
||||
}
|
||||
break;
|
||||
@@ -270,31 +270,31 @@ export class VermineFight {
|
||||
case "usure":
|
||||
params.usure = +e.value;
|
||||
break;
|
||||
case "trait":
|
||||
params.trait = +e.value;
|
||||
break;
|
||||
case "purpose":
|
||||
case "trait":
|
||||
params.trait = +e.value;
|
||||
break;
|
||||
case "purpose":
|
||||
params.purpose = true;
|
||||
break;
|
||||
case "spleen":
|
||||
params.spleen = true;
|
||||
break;
|
||||
break;
|
||||
case "adv-skill":
|
||||
enemySkill = +e.value;
|
||||
break;
|
||||
case "achievement":
|
||||
enemySkill = +e.value;
|
||||
break;
|
||||
case "achievement":
|
||||
enemyAchievement = +e.value;
|
||||
break;
|
||||
case "conservation":
|
||||
enemyConservation = +e.value;
|
||||
break;
|
||||
}
|
||||
enemyConservation = +e.value;
|
||||
break;
|
||||
}
|
||||
});
|
||||
// prise en compte de l'usure sur la feuille de perso
|
||||
if (params.usure != undefined){
|
||||
const newSpentScore = getActorSkillScore(actor, skillKey, 'spent') + params.usure;
|
||||
console.log(newSpentScore);
|
||||
updateActorSkillScore(actor, skillKey, 'spent', newSpentScore);
|
||||
if (params.usure != undefined) {
|
||||
const newSpentScore = getActorSkillScore(actor, skillKey, 'spent') + params.usure;
|
||||
console.log(newSpentScore);
|
||||
updateActorSkillScore(actor, skillKey, 'spent', newSpentScore);
|
||||
}
|
||||
|
||||
return VermineFight.get().performTest(enemyAchievement + enemySkill, enemyConservation + enemySkill, skillKey, skill, params, actor);
|
||||
@@ -309,10 +309,10 @@ export class VermineFight {
|
||||
h.on("change", 'select[name="skill"]', event => {
|
||||
const skillLabel = $(event.target).val();
|
||||
const currentSkillScore = getActorSkillScore(actor, skillLabel) - getActorSkillScore(actor, skillLabel, 'spent');
|
||||
if (parseInt(currentSkillScore,10) >= 0){
|
||||
if (parseInt(currentSkillScore, 10) >= 0) {
|
||||
h.find('input#skillScore').val(currentSkillScore);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}, { width: 601, height: 'fit-content' });
|
||||
ui.render(true);
|
||||
@@ -321,7 +321,7 @@ export class VermineFight {
|
||||
}
|
||||
|
||||
export class VermineCombat extends Combat {
|
||||
_encounterCheck(){
|
||||
_encounterCheck() {
|
||||
console.log('encounter combat object', this);
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ export class VermineCombat extends Combat {
|
||||
}*/
|
||||
const combatant = this.combatants.get(ids[0]);
|
||||
let token = canvas.scene.tokens.get(combatant.tokenId);
|
||||
combatant.type = game.actors.get( combatant.actorId)?.type;
|
||||
combatant.type = game.actors.get(combatant.actorId)?.type;
|
||||
combatant.disposition = token.disposition;
|
||||
let enemies = [];
|
||||
|
||||
@@ -346,7 +346,7 @@ export class VermineCombat extends Combat {
|
||||
let token = canvas.scene.tokens.get(cbt.tokenId);
|
||||
let enemy = token.actor;
|
||||
const isEnemy = (token.disposition == -1) ? true : false;
|
||||
if (isEnemy){
|
||||
if (isEnemy) {
|
||||
enemies.push({
|
||||
id: enemy.id,
|
||||
name: enemy.name,
|
||||
@@ -363,12 +363,12 @@ export class VermineCombat extends Combat {
|
||||
return (token.disposition == 1 && cbt.id != combatant.id) ? true : false;
|
||||
});
|
||||
|
||||
if (combatant.type != 'character'){
|
||||
let warningDialogHTML = await renderTemplate('systems/vermine2047/templates/dialogs/warning.html', {
|
||||
if (combatant.type != 'character') {
|
||||
let warningDialogHTML = await renderTemplate('systems/vermine2047/templates/dialogs/warning.html', {
|
||||
warningText: "Seuls les PJs peuvent initier des confrontations. Relancer l'opération au tour du PJ actif."
|
||||
});
|
||||
Dialog.prompt({
|
||||
title: "Avertissement",
|
||||
Dialog.prompt({
|
||||
title: "Avertissement",
|
||||
content: warningDialogHTML,
|
||||
label: 'Okay !',
|
||||
callback: () => {
|
||||
@@ -378,10 +378,10 @@ export class VermineCombat extends Combat {
|
||||
} else {
|
||||
// étape 2 : on envoie les infos
|
||||
let fightingActor = game.actors.get(combatant.actorId);
|
||||
VermineFight.ui({
|
||||
speakerId: combatant.actorId,
|
||||
VermineFight.ui({
|
||||
speakerId: combatant.actorId,
|
||||
speakerWeapons: fightingActor.items.filter(item => item.type == 'weapon'),
|
||||
speakerExperience:fightingActor.system.attributes.experience.value,
|
||||
speakerExperience: fightingActor.system.attributes.experience.value,
|
||||
speakerEffects: token.actor.effects,
|
||||
adversaries: enemies,
|
||||
allies: allies
|
||||
@@ -409,7 +409,7 @@ export class VermineCombat extends Combat {
|
||||
|
||||
return super.startCombat();
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************/
|
||||
_onDelete() {
|
||||
/*let combatants = this.combatants.contents
|
||||
@@ -425,30 +425,10 @@ export class VermineCombat extends Combat {
|
||||
export class VermineCombatTracker extends CombatTracker {
|
||||
|
||||
get template() {
|
||||
return "systems/vermine2047/templates/combat-tracker.hbs";
|
||||
return "systems/vermine2047/templates/combat-tracker.hbs";
|
||||
}
|
||||
|
||||
async getData(options) {
|
||||
const context = await super.getData(options);
|
||||
|
||||
if (!context.hasCombat) {
|
||||
return context;
|
||||
}
|
||||
|
||||
for (let [i, combatant] of context.combat.turns.entries()) {
|
||||
context.turns[i].hasActed = combatant.getFlag("world", "hasActed");
|
||||
context.turns[i].isPlayer = combatant.actor.type == "player";
|
||||
context.turns[i].isNpc = combatant.actor.type == "npc";
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
get template() {
|
||||
return "systems/gods-system/templates/combat/tracker.hbs";
|
||||
}
|
||||
|
||||
async getData(options) {
|
||||
const context = await super.getData(options);
|
||||
|
||||
if (!context.hasCombat) {
|
||||
@@ -456,39 +436,58 @@ async getData(options) {
|
||||
}
|
||||
|
||||
for (let [i, combatant] of context.combat.turns.entries()) {
|
||||
context.turns[i].attitude = combatant.getFlag("world", "attitude");
|
||||
context.turns[i].isPlayer = combatant.actor.type == "character";
|
||||
context.turns[i].isNpc = combatant.actor.type == "npc";
|
||||
context.turns[i].isCreature = combatant.actor.type == "creature";
|
||||
context.turns[i].hasActed = combatant.getFlag("world", "hasActed");
|
||||
context.turns[i].isPlayer = combatant.actor.type == "player";
|
||||
context.turns[i].isNpc = combatant.actor.type == "npc";
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
/* -------------------------------------------- */
|
||||
get template() {
|
||||
return "systems/vermine2047/templates/combat-tracker.hbs";
|
||||
}
|
||||
|
||||
async getData(options) {
|
||||
const context = await super.getData(options);
|
||||
|
||||
if (!context.hasCombat) {
|
||||
return context;
|
||||
}
|
||||
|
||||
for (let [i, combatant] of context.combat.turns.entries()) {
|
||||
context.turns[i].attitude = combatant.getFlag("world", "attitude");
|
||||
context.turns[i].isPlayer = combatant.actor.type == "character";
|
||||
context.turns[i].isNpc = combatant.actor.type == "npc";
|
||||
context.turns[i].isCreature = combatant.actor.type == "creature";
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
html.find(".status").click(this._setStatut.bind(this));
|
||||
}
|
||||
html.find("[data-attitude]").click(this._setStatut.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Use to put an attitude to an actor
|
||||
* @param {*} event
|
||||
*/
|
||||
async _setStatut(event) {
|
||||
/**
|
||||
* @description Use to put an attitude to an actor
|
||||
* @param {*} event
|
||||
*/
|
||||
async _setStatut(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const btn = event.currentTarget;
|
||||
const attitude = btn.dataset.attitude;
|
||||
const li = btn.closest(".combatant");
|
||||
const combat = this.viewed;
|
||||
const combatant = combat.combatants.get(li.dataset.combatantId);
|
||||
|
||||
if ($(btn).hasClass('offensive'))
|
||||
await combatant.setFlag("world", "attitude", "offensive");
|
||||
else if ($(btn).hasClass('active'))
|
||||
await combatant.setFlag("world", "attitude", "active");
|
||||
else if ($(btn).hasClass('passive'))
|
||||
await combatant.setFlag("world", "attitude", "passive");
|
||||
else
|
||||
await combatant.setFlag("world", "attitude", null);
|
||||
}
|
||||
let flag = combatant.getFlag("world", "attitude");
|
||||
if (flag == attitude) {
|
||||
return await combatant.setFlag("world", "attitude", null);
|
||||
} else {
|
||||
return await combatant.setFlag("world", "attitude", attitude);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user