This commit is contained in:
2020-06-22 10:18:03 +02:00
parent 259a7577e8
commit 30a9f08f73
9 changed files with 259 additions and 53 deletions

View File

@ -25,8 +25,21 @@ export class RdDActor extends Actor {
if (data.items) {
return super.create(data, options);
}
data.items = [];
if (data.type == "personnage")
{
let competences = [];
const pack = game.packs.get("foundryvtt-reve-de-dragon.competences");
await pack.getIndex().then(index => competences = index);
for (let comp of competences)
{
let compItem = undefined;
await pack.getEntity(comp._id).then(skill => compItem = skill);
data.items.push(compItem);
}
}
super.create(data, options);
}
/* -------------------------------------------- */
@ -173,11 +186,11 @@ export class RdDActor extends Actor {
// This an attack, generate the defense message
if ( defenseMsg ) { // target hit !
ChatMessage.create( defenseMsg );
ChatMessage.create( defenseMsg );
}
// Get damages!
if ( encaisser ) {
this.encaisserDommages( rollData );
this.encaisserDommages( rollData.attackerRoll );
}
}
@ -283,36 +296,55 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
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;
if ( blessuresData.legeres > 0 || blessuresData.graves > 0 || blessuresData.critiques > 0 ) {
let blessures = duplicate(this.data.data.blessures);
while ( blessuresData.legeres > 0 ) {
let nLegeres = 0;
for (let k=0; k<blessures.legeres.liste.length; k++) {
let bless = blessures.legeres.liste[k];
if ( !bless.active ) {
bless.active = true;
bless.loc = blessuresData.locName;
blessuresData.legeres--;
} else {
nLegeres++;
}
}
if ( nLegeres == 5) break;
}
if ( blessuresData.legeres > 0 )
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 )
while ( blessuresData.graves > 0) {
let nGraves = 0;
for (let k=0; k<blessures.graves.liste.length; k++) {
let bless = blessures.graves.liste[k];
if ( !bless.active ) {
bless.active = true;
bless.loc = blessuresData.locName;
blessuresData.graves--;
} else {
nGraves++;
}
}
if ( nLegeres == 2) break;
}
if ( blessuresData.graves > 0 )
blessuresData.critiques = 1;
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.liste[0].active = true;
blessures.critiques.liste[0].loc = blessuresData.locName;
}
this.update( { "data.blessures": blessures } );
}
}
/* -------------------------------------------- */
async rollCarac( caracName )
{
@ -370,14 +402,15 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
encaisserDommages( rollData )
encaisserDommages( attackerRoll )
{
let attackerRoll = rollData.attackerRoll;
console.log("RollData from attacker!", rollData);
//let attackerRoll = rollData.attackerRoll;
let degatsReel = attackerRoll.degats - this.computeArmure(attackerRoll.loc);
console.log("RollData from attacker!", attackerRoll, degatsReel);
let result = RdDUtility.computeBlessuresSante(degatsReel);
this.santeIncDec("vie", result.vie);
this.santeIncDec("endurance", result.vie);
this.santeIncDec("endurance", result.endurance);
result.locName = attackerRoll.loc.label; // Add the localisation namme
this.manageBlessures( result ); // Will upate the result table