#13 - Fight management update

This commit is contained in:
sladecraven 2020-11-12 23:50:37 +01:00
parent a554f173c1
commit 568cb764a2
6 changed files with 60 additions and 61 deletions

View File

@ -127,7 +127,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCreatureCompetence( compName );
this.actor.rollCompetence( compName );
});
html.find('#vie-plus').click((event) => {

View File

@ -151,7 +151,7 @@ export class RdDActor extends Actor {
// Fight management !
let defenseMsg;
let encaisser = false;
if (rollData.arme) {
if (rollData.arme || rollData.competence.name.toLowerCase() == 'esquive' ) {
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if (rollData.attackerRoll) { // Defense case !
if (rolled.isSuccess) {
@ -231,8 +231,10 @@ export class RdDActor extends Actor {
}
// Save it for fight in the flags area
console.log("Saving Flag", this);
await this.setFlag('world', 'rollData', null);
await this.setFlag('world', 'rollData', rollData);
game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData);
// Final chat message
let chatOptions = {
@ -246,6 +248,7 @@ export class RdDActor extends Actor {
// This an attack, generate the defense message
if (defenseMsg) {
defenseMsg.rollData = duplicate(rollData);
if (defenseMsg.toSocket) {
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_defense",
@ -714,49 +717,35 @@ export class RdDActor extends Actor {
this.rollCompetence( armeName ); //Bypass mode!
}
/* -------------------------------------------- */
async rollCreatureCompetence( compName, armeItem=undefined, attackerRoll=undefined )
{
let compItem = RdDUtility.findCompetence( this.data.items, compName);
if ( compItem.data.iscombat ) {
armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
}
compItem.data.defaut_carac = "carac_creature"; // Fake default competence
let rollData = {
"competence": compItem,
"arme": armeItem,
"carac": { carac_creature: { label: compName, value: compItem.data.carac_value } },
"bonusmalusTable": CONFIG.RDD.bonusmalus,
"etat": this.data.data.compteurs.etat.value,
"bmValue": (attackerRoll) ? attackerRoll.bmValue : 0,
"attackerRoll": attackerRoll,
"finalLevel": 0
}
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);
}
}
/* -------------------------------------------- */
async rollCompetence( compName, armeItem=undefined, attackerRoll=undefined )
{
console.log("!!!!!!", compName, armeItem);
let compItem = RdDUtility.findCompetence( this.data.items, compName);
console.log("!!!!!!", compName, this.data.items, compItem);
// Common rollData values
let rollData = {
"competence": compItem,
"arme": armeItem,
"carac": this.data.data.carac,
"bonusmalusTable": CONFIG.RDD.bonusmalus,
"etat": this.data.data.compteurs.etat.value,
"bmValue": (attackerRoll) ? attackerRoll.bmValue : 0,
"attackerRoll": attackerRoll,
"finalLevel": 0
}
bonusmalusTable: CONFIG.RDD.bonusmalus,
etat: this.data.data.compteurs.etat.value,
bmValue: (attackerRoll) ? attackerRoll.bmValue : 0,
attackerRoll: attackerRoll,
finalLevel: 0
}
if ( compItem.type == 'competencecreature') { // Specific case for Creatures
if ( compItem.data.iscombat ) {
armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
}
compItem.data.defaut_carac = "carac_creature"; // Fake default competence
compItem.data.categorie = "creature"; // Fake default competence
rollData.competence = compItem;
rollData.arme = armeItem;
rollData.carac = { carac_creature: { label: compName, value: compItem.data.carac_value } };
} else { // Usual competence
rollData.competence = compItem;
rollData.arme = armeItem;
rollData.carac = this.data.data.carac;
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (armeItem) {
new RdDRollDialog("arme", html, rollData, this ).render(true);
@ -844,7 +833,6 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
esquiverAttaque( attackerRoll )
{
console.log("Going to DODGE !!!!!!!!!", attackerRoll.bmValue);
this.rollCompetence( "esquive", undefined, attackerRoll );
}

View File

@ -88,7 +88,11 @@ Hooks.once("init", async function() {
// preload handlebars templates
RdDUtility.preloadHandlebarsTemplates();
// Create useful storage space
game.system.rdd = {
rollDataHandler: {}
}
// Create specific settings
game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
name: "configuration",

View File

@ -128,6 +128,7 @@ export class RdDRollDialog extends Dialog {
return etat + parseInt(rollData.bmValue);
}
/* -------------------------------------------- */
static _getTitle(rollData) {
if (rollData.competence) {
// If a weapon is there, add it in the title

View File

@ -411,7 +411,8 @@ export class RdDUtility {
/* -------------------------------------------- */
static findCompetence(compList, compName)
{
return compList.find(item => item.name == compName && (item.type =="competence" || item.type =="competencecreature"))
compName = compName.toLowerCase();
return compList.find(item => item.name.toLowerCase() == compName && (item.type =="competence" || item.type == "competencecreature"))
}
/* -------------------------------------------- */
@ -436,7 +437,7 @@ export class RdDUtility {
static isArmeMelee( compName)
{
let comp = compName.toLowerCase();
if (comp.match("epée") || comp.match("hache") || comp.match("fleau") || comp.match("mass") || comp.match("lance") || comp.match("hast") || comp == "dague" || comp=="bouclier")
if (comp.match("epée") || comp.match("épée") || comp.match("hache") || comp.match("fleau") || comp.match("mass") || comp.match("lance") || comp.match("hast") || comp == "dague" || comp=="bouclier")
return true;
return false;
}
@ -444,6 +445,7 @@ export class RdDUtility {
/* -------------------------------------------- */
static buildDefenseChatCard( attacker, target, rollData )
{
console.log("Attacker.defense", attacker, target, attacker.data._id, rollData.competence.data.categorie );
let myTarget = target.actor;
let defenseMsg = { title: "Défense en combat",
content: "<strong>"+myTarget.name+"</strong> doit se défendre : <br><span class='chat-card-button-area'>" +
@ -453,7 +455,7 @@ export class RdDUtility {
rollMode: true
};
if ( rollData.competence.data.categorie == "melee" ) { // Melee attack
if ( rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == 'creature') { // Melee attack or creature
let defenderArmes = [];
for (const arme of myTarget.data.items) {
if (arme.type == "arme" && this.isArmeMelee(arme.data.competence)) {
@ -481,7 +483,10 @@ export class RdDUtility {
defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "'>Esquiver</a></span>";
}
defenseMsg.toSocket = myTarget.hasPlayerOwner;
defenseMsg.toSocket = true; // True per default for all players
if (game.user.isGM) { // In GM case, only if target is a player
defenseMsg.toSocket = myTarget.hasPlayerOwner;
}
return defenseMsg;
}
@ -491,17 +496,17 @@ export class RdDUtility {
{
console.log(">>>>> MSG RECV", sockmsg);
if ( sockmsg.msg == "msg_encaisser" ) {
if ( game.user.isGM ) {
console.log("Encaisser ici !!!");
if ( game.user.isGM ) { // Seul le GM effectue l'encaissement sur la fiche
let rollData = game.system.rdd.rollDataHandler[sockmsg.data.attackerid]; // Retrieve the rolldata from the store
let defenderActor = game.actors.get( sockmsg.data.defenderid );
defenderActor.encaisserDommages( sockmsg.data );
defenderActor.encaisserDommages( rollData );
}
} else if (sockmsg.msg == "msg_defense" ) {
let defenderActor = game.actors.get( sockmsg.data.defenderid );
console.log("Defense message reçu : ", defenderActor.hasPlayerOwner, game.user.character.id, defenderActor.id);
if ( defenderActor ) {
if ( (game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id) ) ) {
console.log("User is pushing message...", game.user.name);
defenderActor.currentRollData = duplicate(sockmsg.data.rollData);
sockmsg.data.whisper = [ game.user ];
sockmsg.data.blind = true;
sockmsg.data.rollMode = "blindroll";
@ -516,36 +521,37 @@ export class RdDUtility {
{
html.on("click", '#encaisser-button', event => {
event.preventDefault();
let attackerActor = game.actors.get( event.currentTarget.attributes['data-attackerid'].value );
let rollData = attackerActor.getFlag( "world", "rollData" );
rollData.attackerid = event.currentTarget.attributes['data-attackerid'].value;
rollData.defenderid = event.currentTarget.attributes['data-defenderid'].value;
let defenderActor = game.actors.get( rollData.defenderid );
let attackerid = event.currentTarget.attributes['data-attackerid'].value;
let defenderid = event.currentTarget.attributes['data-defenderid'].value;
if ( game.user.isGM ) { // Current user is the GM -> direct access
console.log("Encaissement direct", rollData);
let rollData = game.system.rdd.rollDataHandler[attackerid];
rollData.attackerid = attackerid;
rollData.defenderid = defenderid;
let defenderActor = game.actors.get(defenderid );
defenderActor.encaisserDommages( rollData );
} else { // Emit message for GM
game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_encaisser",
data: rollData
data: { attackerid: attackerid, defenderid: defenderid }
} );
}
});
html.on("click", '#parer-button', event => {
event.preventDefault();
let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value );
//let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value );
let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value );
let armeId = event.currentTarget.attributes['data-armeid'].value;
let rollData = attackerActor.getFlag( "world", "rollData" );
let rollData = defenderActor.currentRollData;
defenderActor.parerAttaque( rollData, armeId );
});
html.on("click", '#esquiver-button', event => {
event.preventDefault();
let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value );
//let attackerActor = game.actors.get(event.currentTarget.attributes['data-attackerid'].value );
let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value );
let rollData = attackerActor.getFlag( "world", "rollData" );
let rollData = defenderActor.currentRollData;
console.log("Esquive !", rollData, defenderActor);
defenderActor.esquiverAttaque( rollData );
});

View File

@ -2,7 +2,7 @@
"name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT",
"version": "0.9.34",
"version": "0.9.35",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.6",
"templateVersion": 44,