forked from public/foundryvtt-reve-de-dragon
Preliminary verssion for fight
This commit is contained in:
181
module/actor.js
181
module/actor.js
@ -25,6 +25,9 @@ export class RdDActor extends Actor {
|
||||
return super.create(data, options);
|
||||
}
|
||||
super.create(data, options);
|
||||
|
||||
// Create flags data
|
||||
await this.setFlag("foundryvtt-reve-de-dragon", "rollData", {} );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -48,10 +51,12 @@ export class RdDActor extends Actor {
|
||||
_prepareCharacterData(actorData) {
|
||||
// Initialize empty items
|
||||
RdDUtility.computeCarac(actorData.data);
|
||||
this.computeEtatGeneral();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
performRoll( rollData ) {
|
||||
async performRoll( rollData ) {
|
||||
|
||||
let myroll = new Roll("d100");
|
||||
myroll.roll();
|
||||
let quality = "Echec";
|
||||
@ -66,38 +71,73 @@ export class RdDActor extends Actor {
|
||||
let xpcomp = (Math.abs(rollData.finalLevel) % 2 == 1) ? xpcarac+1 : xpcarac;
|
||||
xpmsg = "<br>Points d'expérience gagné ! " + xpcarac + " - " + xpcomp;
|
||||
}
|
||||
tache = 4;
|
||||
rollData.pointsDeTache = 4;
|
||||
} else if (result <= (rollData.rollTarget.score /2) ) {
|
||||
quality = "Réussite Significative";
|
||||
tache = 2;
|
||||
rollData.pointsDeTache = 2;
|
||||
} else if (result <= (rollData.rollTarget.score) ) {
|
||||
quality = "Réussite Normale";
|
||||
tache = 1;
|
||||
rollData.pointsDeTache = 1;
|
||||
} else if (result < (rollData.rollTarget.epart) ) {
|
||||
quality = "Echec Normal";
|
||||
tache = 0;
|
||||
rollData.pointsDeTache = 0;
|
||||
} else if (result < (rollData.rollTarget.etotal) ) {
|
||||
quality = "Echec Particulier";
|
||||
tache = -2;
|
||||
rollData.pointsDeTache = -2;
|
||||
} else if (result >= (rollData.rollTarget.etotal) ) {
|
||||
quality = "Echec Total";
|
||||
tache = -4;
|
||||
rollData.pointsDeTache = -4;
|
||||
}
|
||||
|
||||
let chatOptions = { "content": "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong><br>Jet : " +
|
||||
// Weapon management
|
||||
let defenseMsg;
|
||||
let specialStr = "<br>Points de taches : " + rollData.pointsDeTache; // Per default
|
||||
if ( rollData.arme ) { // In case of fight, replace the "tache" per dommages + localization. "tache" indicates if result is OK or not
|
||||
if ( rollData.pointsDeTache > 0 ) {
|
||||
let myroll = new Roll("2d10");
|
||||
myroll.roll();
|
||||
rollData.degats = parseInt(myroll.result) + parseInt(rollData.arme.data.dommages) + parseInt(this.data.data.attributs.plusdom.value);
|
||||
rollData.loc = RdDUtility.getLocalisation();
|
||||
for (let target of game.user.targets) {
|
||||
console.log("Target", target);
|
||||
specialStr = "<br><strong>Cible</strong> : " + target.actor.data.name;
|
||||
defenseMsg = { title: "Défense en combat",
|
||||
content: "Action de défense en combat!<br><span class='chat-card-button-area'><a class='chat-card-button' id='encaisser-button' data-attackerid='"+
|
||||
this.data._id + "' data-defenderid='" + target.actor.data._id + "'>Encaisser !</a></span>",
|
||||
whisper: ChatMessage.getWhisperRecipients(target.actor.data.name) };
|
||||
}
|
||||
specialStr += "<br>Dommages : " + rollData.degats + "<br>Localisation : " + rollData.loc.label;
|
||||
} else {
|
||||
specialStr = "<br>Echec ! Pas de dommages";
|
||||
}
|
||||
}
|
||||
|
||||
// Save it for fight
|
||||
await this.setFlag( "foundryvtt-reve-de-dragon", "rollData", undefined );
|
||||
await this.setFlag( "foundryvtt-reve-de-dragon", "rollData", rollData );
|
||||
console.log("MINE:", this);
|
||||
|
||||
let chatOptions = { content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong><br>Jet : " +
|
||||
rollData.selectedCarac.value + " / " + rollData.finalLevelStr + " - " + rollData.rollTarget.score + "%<br><strong>Résutat : </strong>" + myroll.total + "<br>" +
|
||||
"<strong>" + quality + "</strong><br>Points de taches : " + tache + xpmsg,
|
||||
"title": "Test"
|
||||
"<strong>" + quality + "</strong>" + specialStr + xpmsg,
|
||||
user: game.user._id,
|
||||
title: "Résultat du test"
|
||||
}
|
||||
ChatMessage.create( chatOptions );
|
||||
|
||||
if ( defenseMsg ) { // target hit !
|
||||
ChatMessage.create( defenseMsg );
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateCarac( caracName, caracValue )
|
||||
{
|
||||
let data = this.data.data;
|
||||
data.carac[caracName].value = caracValue; // Force update ?
|
||||
RdDUtility.computeCarac( data );
|
||||
//let data = this.data.data;
|
||||
let caracpath = "data.carac." + caracName + ".value"
|
||||
this.update( { caracpath: caracValue } );
|
||||
//data.carac[caracName].value = caracValue; // Force update ?
|
||||
//RdDUtility.computeCarac( data );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -126,24 +166,27 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
testSiSonne( endurance )
|
||||
testSiSonne( sante, endurance )
|
||||
{
|
||||
let myroll = new Roll("d20");
|
||||
myroll.roll();
|
||||
let result = myroll.total;
|
||||
if ( result <= endurance.value)
|
||||
this.data.data.sante.sonne.value = false;
|
||||
sante.sonne.value = false;
|
||||
if ( result > endurance.value || result == 20) // 20 is always a failure
|
||||
this.data.data.sante.sonne.value = true;
|
||||
sante.sonne.value = true;
|
||||
if (result == 1) {
|
||||
this.data.data.sante.sonne.value = false;
|
||||
this.data.data.carac.constitution.xp++; // 1 XP on 1 !
|
||||
sante.sonne.value = false;
|
||||
let xp = parseInt(this.data.data.carac.constitution.xp) + parseInt(1);
|
||||
this.update( {"data.carac.constitution.xp": xp } ); // +1 XP !
|
||||
// TODO : Output to chat
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
santeIncDec(name, inc ) {
|
||||
let data = this.data.data.sante[name];
|
||||
async santeIncDec(name, inc ) {
|
||||
const sante = duplicate(this.data.data.sante);
|
||||
let data = sante[name];
|
||||
let lastValue = data.value; // Useful for Endurance and Sonné
|
||||
data.value = data.value + inc;
|
||||
if ( data.value > data.max ) data.value = data.max;
|
||||
@ -151,13 +194,13 @@ export class RdDActor extends Actor {
|
||||
|
||||
if (name == "endurance") {
|
||||
if ( inc < 0 ) // Each endurance lost -> fatigue lost
|
||||
this.data.data.sante.fatigue.value = this.data.data.sante.fatigue.value - inc
|
||||
sante.fatigue.value = sante.fatigue.value - inc
|
||||
|
||||
// If endurance is 0 -> -1 vie
|
||||
if ( data.value == 0 ) {
|
||||
this.data.data.sante.vie.value = this.data.data.sante.vie.value - 1;
|
||||
sante.vie.value = sante.vie.value - 1;
|
||||
}
|
||||
let diffVie = this.data.data.sante.vie.max - this.data.data.sante.vie.value;
|
||||
let diffVie = sante.vie.max - sante.vie.value;
|
||||
if ( data.value > data.max - (diffVie*2) ) {
|
||||
data.value = data.max - (diffVie*2);
|
||||
}
|
||||
@ -167,20 +210,53 @@ export class RdDActor extends Actor {
|
||||
if (data.value > maxEnd ) data.value = maxEnd;
|
||||
if ( blessures.critiques.nombre > 0 && data.value > 1) data.value = 1;
|
||||
|
||||
if (lastValue - data.value > 1) this.testSiSonne(data); // Peut-être sonné si 2 points d'endurance perdus d'un coup
|
||||
if (lastValue - data.value > 1) this.testSiSonne(sante, data); // Peut-être sonné si 2 points d'endurance perdus d'un coup
|
||||
}
|
||||
|
||||
let diffEndurance = this.data.data.sante.endurance.max - this.data.data.sante.endurance.value;
|
||||
if ( this.data.data.sante.fatigue.value < diffEndurance) // If endurance lost, then the same amount of fatigue cannot be recovered
|
||||
this.data.data.sante.fatigue.value = diffEndurance;
|
||||
|
||||
console.log(">>>> NEW VI", name, data.value);
|
||||
this.computeEtatGeneral();
|
||||
let diffEndurance = sante.endurance.max - this.data.data.sante.endurance.value;
|
||||
if ( sante.fatigue.value < diffEndurance) // If endurance lost, then the same amount of fatigue cannot be recovered
|
||||
sante.fatigue.value = diffEndurance;
|
||||
|
||||
await this.update( {"data.sante": sante } );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollArme( armeName ) {
|
||||
let armeItem = RdDUtility.findCompetence( this.data.items, armeName);
|
||||
manageBlessures( blessuresData )
|
||||
{
|
||||
let blessures = duplicate(this.data.data.blessures);
|
||||
if (blessuresData.legeres > 0 ) {
|
||||
blessures.legeres.nombre += 1;
|
||||
if ( blessures.legeres.nombre > 5 ) {
|
||||
blessures.legeres.nombre = 5;
|
||||
blessuresData.graves += 1;
|
||||
} else {
|
||||
blessures.legeres.liste[blessures.legeres.nombre-1].etat = "active";
|
||||
blessures.legeres.liste[blessures.legeres.nombre-1].loc = blessuresData.locName;
|
||||
}
|
||||
}
|
||||
if ( blessuresData.graves > 0 ) {
|
||||
blessures.graves.nombre += 1;
|
||||
if ( blessures.graves.nombre > 2 ) {
|
||||
blessures.graves.nombre = 2;
|
||||
blessuresData.critiques += 1;
|
||||
} else {
|
||||
blessures.graves.liste[blessures.graves.nombre-1].etat = "active";
|
||||
blessures.graves.liste[blessures.graves.nombre-1].loc = blessuresData.locName;
|
||||
}
|
||||
}
|
||||
if ( blessuresData.critiques > 0 ) {
|
||||
blessuresData.endurance = this.data.data.sante.endurance.value; // Patch with real endurance current value (ie end -> 0 when critique)
|
||||
blessures.critiques.nombre = 1;
|
||||
blessures.critiques.liste[0].etat = "active";
|
||||
blessures.critiques.liste[0].loc = blessuresData.locName;
|
||||
}
|
||||
if ( blessuresData.legeres > 0 || blessuresData.graves > 0 || blessuresData.critiques > 0 )
|
||||
this.update( { "data.blessures": blessures } );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollArme( armeName ) {
|
||||
let armeItem = RdDUtility.findCompetence( this.data.items, armeName );
|
||||
this.rollCompetence( armeItem.data.competence, armeItem );
|
||||
}
|
||||
|
||||
@ -197,11 +273,44 @@ export class RdDActor extends Actor {
|
||||
"bmValue": 0,
|
||||
"finalLevel": 0
|
||||
}
|
||||
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
||||
new RdDRollDialog("competence", html, rollData, this ).render(true);
|
||||
}
|
||||
|
||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
||||
if (armeItem) {
|
||||
new RdDRollDialog("arme", html, rollData, this ).render(true);
|
||||
} else {
|
||||
new RdDRollDialog("competence", html, rollData, this ).render(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeArmure( locData )
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
encaisserDommages( attackerActor )
|
||||
{
|
||||
let attackerRoll = attackerActor.getFlag("foundryvtt-reve-de-dragon", "rollData");
|
||||
console.log("RollData!", attackerActor, attackerRoll);
|
||||
let degatsReel = attackerRoll.degats - this.computeArmure(attackerRoll.loc);
|
||||
let result = RdDUtility.computeBlessuresSante(degatsReel);
|
||||
this.santeIncDec("vie", result.vie);
|
||||
this.santeIncDec("endurance", result.vie);
|
||||
|
||||
result.locName = attackerRoll.loc.label; // Add the localisation namme
|
||||
this.manageBlessures( result ); // Will upate the result table
|
||||
ChatMessage.create( {title: "Blessures !", content: this.data.name + " a encaissé : " +
|
||||
"<br>" + result.legeres + " légères, " + result.graves + " graves et " +
|
||||
result.critiques + " critique." +
|
||||
"<br>Et perdu : " +
|
||||
"<br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie" } );
|
||||
|
||||
this.computeEtatGeneral();
|
||||
this.sheet.render(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
getRollData() {
|
||||
|
Reference in New Issue
Block a user