#13 - Fight management update
This commit is contained in:
parent
a554f173c1
commit
568cb764a2
@ -127,7 +127,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
|
|||||||
// Roll Skill
|
// Roll Skill
|
||||||
html.find('.competence-label a').click((event) => {
|
html.find('.competence-label a').click((event) => {
|
||||||
let compName = event.currentTarget.text;
|
let compName = event.currentTarget.text;
|
||||||
this.actor.rollCreatureCompetence( compName );
|
this.actor.rollCompetence( compName );
|
||||||
});
|
});
|
||||||
|
|
||||||
html.find('#vie-plus').click((event) => {
|
html.find('#vie-plus').click((event) => {
|
||||||
|
@ -151,7 +151,7 @@ export class RdDActor extends Actor {
|
|||||||
// Fight management !
|
// Fight management !
|
||||||
let defenseMsg;
|
let defenseMsg;
|
||||||
let encaisser = false;
|
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
|
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
|
||||||
if (rollData.attackerRoll) { // Defense case !
|
if (rollData.attackerRoll) { // Defense case !
|
||||||
if (rolled.isSuccess) {
|
if (rolled.isSuccess) {
|
||||||
@ -231,8 +231,10 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save it for fight in the flags area
|
// Save it for fight in the flags area
|
||||||
|
console.log("Saving Flag", this);
|
||||||
await this.setFlag('world', 'rollData', null);
|
await this.setFlag('world', 'rollData', null);
|
||||||
await this.setFlag('world', 'rollData', rollData);
|
await this.setFlag('world', 'rollData', rollData);
|
||||||
|
game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData);
|
||||||
|
|
||||||
// Final chat message
|
// Final chat message
|
||||||
let chatOptions = {
|
let chatOptions = {
|
||||||
@ -246,6 +248,7 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
// This an attack, generate the defense message
|
// This an attack, generate the defense message
|
||||||
if (defenseMsg) {
|
if (defenseMsg) {
|
||||||
|
defenseMsg.rollData = duplicate(rollData);
|
||||||
if (defenseMsg.toSocket) {
|
if (defenseMsg.toSocket) {
|
||||||
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
||||||
msg: "msg_defense",
|
msg: "msg_defense",
|
||||||
@ -715,46 +718,32 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async rollCreatureCompetence( compName, armeItem=undefined, attackerRoll=undefined )
|
async rollCompetence( compName, armeItem=undefined, attackerRoll=undefined )
|
||||||
{
|
{
|
||||||
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
let compItem = RdDUtility.findCompetence( this.data.items, compName);
|
||||||
|
console.log("!!!!!!", compName, this.data.items, compItem);
|
||||||
|
// Common rollData values
|
||||||
|
let rollData = {
|
||||||
|
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 ) {
|
if ( compItem.data.iscombat ) {
|
||||||
armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
|
armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
|
||||||
}
|
}
|
||||||
compItem.data.defaut_carac = "carac_creature"; // Fake default competence
|
compItem.data.defaut_carac = "carac_creature"; // Fake default competence
|
||||||
let rollData = {
|
compItem.data.categorie = "creature"; // Fake default competence
|
||||||
"competence": compItem,
|
rollData.competence = compItem;
|
||||||
"arme": armeItem,
|
rollData.arme = armeItem;
|
||||||
"carac": { carac_creature: { label: compName, value: compItem.data.carac_value } },
|
rollData.carac = { carac_creature: { label: compName, value: compItem.data.carac_value } };
|
||||||
"bonusmalusTable": CONFIG.RDD.bonusmalus,
|
} else { // Usual competence
|
||||||
"etat": this.data.data.compteurs.etat.value,
|
rollData.competence = compItem;
|
||||||
"bmValue": (attackerRoll) ? attackerRoll.bmValue : 0,
|
rollData.arme = armeItem;
|
||||||
"attackerRoll": attackerRoll,
|
rollData.carac = this.data.data.carac;
|
||||||
"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);
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
|
||||||
@ -844,7 +833,6 @@ export class RdDActor extends Actor {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
esquiverAttaque( attackerRoll )
|
esquiverAttaque( attackerRoll )
|
||||||
{
|
{
|
||||||
console.log("Going to DODGE !!!!!!!!!", attackerRoll.bmValue);
|
|
||||||
this.rollCompetence( "esquive", undefined, attackerRoll );
|
this.rollCompetence( "esquive", undefined, attackerRoll );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,10 @@ Hooks.once("init", async function() {
|
|||||||
// preload handlebars templates
|
// preload handlebars templates
|
||||||
RdDUtility.preloadHandlebarsTemplates();
|
RdDUtility.preloadHandlebarsTemplates();
|
||||||
|
|
||||||
|
// Create useful storage space
|
||||||
|
game.system.rdd = {
|
||||||
|
rollDataHandler: {}
|
||||||
|
}
|
||||||
// Create specific settings
|
// Create specific settings
|
||||||
game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
|
game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
|
||||||
name: "configuration",
|
name: "configuration",
|
||||||
|
@ -128,6 +128,7 @@ export class RdDRollDialog extends Dialog {
|
|||||||
return etat + parseInt(rollData.bmValue);
|
return etat + parseInt(rollData.bmValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
static _getTitle(rollData) {
|
static _getTitle(rollData) {
|
||||||
if (rollData.competence) {
|
if (rollData.competence) {
|
||||||
// If a weapon is there, add it in the title
|
// If a weapon is there, add it in the title
|
||||||
|
@ -411,7 +411,8 @@ export class RdDUtility {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static findCompetence(compList, compName)
|
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)
|
static isArmeMelee( compName)
|
||||||
{
|
{
|
||||||
let comp = compName.toLowerCase();
|
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 true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -444,6 +445,7 @@ export class RdDUtility {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static buildDefenseChatCard( attacker, target, rollData )
|
static buildDefenseChatCard( attacker, target, rollData )
|
||||||
{
|
{
|
||||||
|
console.log("Attacker.defense", attacker, target, attacker.data._id, rollData.competence.data.categorie );
|
||||||
let myTarget = target.actor;
|
let myTarget = target.actor;
|
||||||
let defenseMsg = { title: "Défense en combat",
|
let defenseMsg = { title: "Défense en combat",
|
||||||
content: "<strong>"+myTarget.name+"</strong> doit se défendre : <br><span class='chat-card-button-area'>" +
|
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
|
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 = [];
|
let defenderArmes = [];
|
||||||
for (const arme of myTarget.data.items) {
|
for (const arme of myTarget.data.items) {
|
||||||
if (arme.type == "arme" && this.isArmeMelee(arme.data.competence)) {
|
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.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 = true; // True per default for all players
|
||||||
|
if (game.user.isGM) { // In GM case, only if target is a player
|
||||||
defenseMsg.toSocket = myTarget.hasPlayerOwner;
|
defenseMsg.toSocket = myTarget.hasPlayerOwner;
|
||||||
|
}
|
||||||
|
|
||||||
return defenseMsg;
|
return defenseMsg;
|
||||||
}
|
}
|
||||||
@ -491,17 +496,17 @@ export class RdDUtility {
|
|||||||
{
|
{
|
||||||
console.log(">>>>> MSG RECV", sockmsg);
|
console.log(">>>>> MSG RECV", sockmsg);
|
||||||
if ( sockmsg.msg == "msg_encaisser" ) {
|
if ( sockmsg.msg == "msg_encaisser" ) {
|
||||||
if ( game.user.isGM ) {
|
if ( game.user.isGM ) { // Seul le GM effectue l'encaissement sur la fiche
|
||||||
console.log("Encaisser ici !!!");
|
let rollData = game.system.rdd.rollDataHandler[sockmsg.data.attackerid]; // Retrieve the rolldata from the store
|
||||||
let defenderActor = game.actors.get( sockmsg.data.defenderid );
|
let defenderActor = game.actors.get( sockmsg.data.defenderid );
|
||||||
defenderActor.encaisserDommages( sockmsg.data );
|
defenderActor.encaisserDommages( rollData );
|
||||||
}
|
}
|
||||||
} else if (sockmsg.msg == "msg_defense" ) {
|
} else if (sockmsg.msg == "msg_defense" ) {
|
||||||
let defenderActor = game.actors.get( sockmsg.data.defenderid );
|
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 ( defenderActor ) {
|
||||||
if ( (game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id) ) ) {
|
if ( (game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id) ) ) {
|
||||||
console.log("User is pushing message...", game.user.name);
|
console.log("User is pushing message...", game.user.name);
|
||||||
|
defenderActor.currentRollData = duplicate(sockmsg.data.rollData);
|
||||||
sockmsg.data.whisper = [ game.user ];
|
sockmsg.data.whisper = [ game.user ];
|
||||||
sockmsg.data.blind = true;
|
sockmsg.data.blind = true;
|
||||||
sockmsg.data.rollMode = "blindroll";
|
sockmsg.data.rollMode = "blindroll";
|
||||||
@ -516,36 +521,37 @@ export class RdDUtility {
|
|||||||
{
|
{
|
||||||
html.on("click", '#encaisser-button', event => {
|
html.on("click", '#encaisser-button', event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let attackerActor = game.actors.get( event.currentTarget.attributes['data-attackerid'].value );
|
let attackerid = event.currentTarget.attributes['data-attackerid'].value;
|
||||||
let rollData = attackerActor.getFlag( "world", "rollData" );
|
let defenderid = event.currentTarget.attributes['data-defenderid'].value;
|
||||||
rollData.attackerid = event.currentTarget.attributes['data-attackerid'].value;
|
|
||||||
rollData.defenderid = event.currentTarget.attributes['data-defenderid'].value;
|
|
||||||
let defenderActor = game.actors.get( rollData.defenderid );
|
|
||||||
if ( game.user.isGM ) { // Current user is the GM -> direct access
|
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 );
|
defenderActor.encaisserDommages( rollData );
|
||||||
} else { // Emit message for GM
|
} else { // Emit message for GM
|
||||||
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
||||||
msg: "msg_encaisser",
|
msg: "msg_encaisser",
|
||||||
data: rollData
|
data: { attackerid: attackerid, defenderid: defenderid }
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
html.on("click", '#parer-button', event => {
|
html.on("click", '#parer-button', event => {
|
||||||
event.preventDefault();
|
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 defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value );
|
||||||
let armeId = event.currentTarget.attributes['data-armeid'].value;
|
let armeId = event.currentTarget.attributes['data-armeid'].value;
|
||||||
let rollData = attackerActor.getFlag( "world", "rollData" );
|
let rollData = defenderActor.currentRollData;
|
||||||
defenderActor.parerAttaque( rollData, armeId );
|
defenderActor.parerAttaque( rollData, armeId );
|
||||||
});
|
});
|
||||||
|
|
||||||
html.on("click", '#esquiver-button', event => {
|
html.on("click", '#esquiver-button', event => {
|
||||||
event.preventDefault();
|
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 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 );
|
defenderActor.esquiverAttaque( rollData );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "foundryvtt-reve-de-dragon",
|
"name": "foundryvtt-reve-de-dragon",
|
||||||
"title": "Rêve de Dragon",
|
"title": "Rêve de Dragon",
|
||||||
"description": "Rêve de Dragon RPG for FoundryVTT",
|
"description": "Rêve de Dragon RPG for FoundryVTT",
|
||||||
"version": "0.9.34",
|
"version": "0.9.35",
|
||||||
"minimumCoreVersion": "0.7.5",
|
"minimumCoreVersion": "0.7.5",
|
||||||
"compatibleCoreVersion": "0.7.6",
|
"compatibleCoreVersion": "0.7.6",
|
||||||
"templateVersion": 44,
|
"templateVersion": 44,
|
||||||
|
Loading…
Reference in New Issue
Block a user