Séparation défense et encaissement
This commit is contained in:
parent
3975d7f529
commit
ea4b7a7b22
@ -20,7 +20,9 @@ export class RdDCombat {
|
|||||||
if (target == undefined) {
|
if (target == undefined) {
|
||||||
ui.notifications.warn("Vous devez choisir une seule cible à attaquer!");
|
ui.notifications.warn("Vous devez choisir une seule cible à attaquer!");
|
||||||
}
|
}
|
||||||
return this.create(attacker, target ? target.actor : undefined, target)
|
const defender = target ? target.actor : undefined;
|
||||||
|
const defenderTokenId = target ? target.data._id : undefined;
|
||||||
|
return this.create(attacker, defender, defenderTokenId, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -34,8 +36,8 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static create(attacker, defender, target = undefined) {
|
static create(attacker, defender, defenderTokenId, target = undefined) {
|
||||||
return new RdDCombat(attacker, defender, target)
|
return new RdDCombat(attacker, defender, defenderTokenId, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -45,22 +47,40 @@ export class RdDCombat {
|
|||||||
|
|
||||||
const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
|
const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
|
||||||
if (dataDefenderTokenId) {
|
if (dataDefenderTokenId) {
|
||||||
let defenderToken = canvas.tokens.get(dataDefenderTokenId.value);
|
const defenderTokenId = dataDefenderTokenId.value;
|
||||||
|
let defenderToken = canvas.tokens.get(defenderTokenId);
|
||||||
let defender = defenderToken.actor;
|
let defender = defenderToken.actor;
|
||||||
|
|
||||||
return this.create(attacker, defender);
|
return RdDCombat.create(attacker, defender, defenderTokenId);
|
||||||
}
|
}
|
||||||
return this.createUsingTarget(attacker)
|
return RdDCombat.createUsingTarget(attacker)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
constructor(attacker, defender, target) {
|
static _sendRollMessage(sender, recipient, defenderTokenId, topic, message, rollData) {
|
||||||
this.attacker = attacker;
|
let chatMessage = {
|
||||||
this.defender = defender;
|
content: message,
|
||||||
this.target = target;
|
whisper: ChatUtility.getWhisperRecipients("blindroll", recipient.name),
|
||||||
this.attackerId = this.attacker.data._id;
|
};
|
||||||
this.defenderId = this.defender.data._id;
|
|
||||||
this.defenderTokenId = target ? target.data._id : undefined;
|
// envoyer le message au destinataire
|
||||||
|
if (!game.user.isGM || recipient.hasPlayerOwner) {
|
||||||
|
let data = {
|
||||||
|
attackerId: sender ? sender.data._id : undefined,
|
||||||
|
defenderId: recipient ? recipient.data._id : undefined,
|
||||||
|
defenderTokenId: defenderTokenId,
|
||||||
|
rollData: duplicate(rollData),
|
||||||
|
rollMode: true
|
||||||
|
};
|
||||||
|
mergeObject(data, chatMessage);
|
||||||
|
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: topic, data: data});
|
||||||
|
} else {
|
||||||
|
chatMessage.whisper = [game.user];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (game.user.isGM) { // Always push the message to the MJ
|
||||||
|
ChatMessage.create(chatMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -73,6 +93,16 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
constructor(attacker, defender, defenderTokenId, target) {
|
||||||
|
this.attacker = attacker;
|
||||||
|
this.defender = defender;
|
||||||
|
this.target = target;
|
||||||
|
this.attackerId = this.attacker.data._id;
|
||||||
|
this.defenderId = this.defender.data._id;
|
||||||
|
this.defenderTokenId = defenderTokenId;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async onEvent(button, event) {
|
async onEvent(button, event) {
|
||||||
let rollData = game.system.rdd.rollDataHandler[this.attackerId];
|
let rollData = game.system.rdd.rollDataHandler[this.attackerId];
|
||||||
@ -91,7 +121,6 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static isEchec(rollData) {
|
static isEchec(rollData) {
|
||||||
switch (rollData.surprise) {
|
switch (rollData.surprise) {
|
||||||
@ -240,55 +269,43 @@ export class RdDCombat {
|
|||||||
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
||||||
|
|
||||||
if (this.target) {
|
if (this.target) {
|
||||||
this._messageDefenseur(rollData);
|
this._sendMessageDefense(rollData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
_messageDefenseur(rollData) {
|
_sendMessageDefense(rollData) {
|
||||||
console.log("RdDCombat._messageDefenseur", rollData, " / ", this.attacker, this.target, this.target.actor.isToken, this.attacker.data._id, rollData.competence.data.categorie);
|
console.log("RdDCombat._sendMessageDefense", rollData, " / ", this.attacker, this.target, this.attackerId, rollData.competence.data.categorie);
|
||||||
|
|
||||||
let content = "<strong>" + this.defender.name + "</strong> doit se défendre :<span class='chat-card-button-area'>";
|
let message = this._buildMessageDefense(rollData);
|
||||||
|
// encaisser
|
||||||
|
message += this._buildMessageEncaisser(rollData) + "</span>";
|
||||||
|
|
||||||
|
RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, rollData);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildMessageDefense(rollData) {
|
||||||
|
let message = "<strong>" + this.defender.name + "</strong> doit se défendre :<span class='chat-card-button-area'>";
|
||||||
|
|
||||||
if (this.defender.getSurprise() != 'totale') {
|
if (this.defender.getSurprise() != 'totale') {
|
||||||
// parades
|
// parades
|
||||||
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence.data.categorie)) {
|
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence.data.categorie)) {
|
||||||
content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
|
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
|
||||||
}
|
}
|
||||||
// corps à corps
|
// corps à corps
|
||||||
if (rollData.dmg.mortalite != 'mortel') {
|
if (rollData.dmg.mortalite != 'mortel') {
|
||||||
content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
|
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
|
||||||
}
|
}
|
||||||
// esquive
|
// esquive
|
||||||
if (rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == "lancer" || rollData.competence.data.categorie == 'competencecreature') {
|
if (rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == "lancer" || rollData.competence.data.categorie == 'competencecreature') {
|
||||||
content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Esquiver</a>";
|
message += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Esquiver</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
// encaisser
|
_buildMessageEncaisser(rollData) {
|
||||||
content += "<br><a class='chat-card-button' id='encaisser-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !</a>";
|
return "<br><a class='chat-card-button' id='encaisser-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !</a>";
|
||||||
content += "</span>"
|
|
||||||
|
|
||||||
let defense = {
|
|
||||||
title: "Défense en combat",
|
|
||||||
content: content,
|
|
||||||
whisper: ChatUtility.getWhisperRecipients("blindroll", this.defender.name),
|
|
||||||
attackerId: this.attackerId,
|
|
||||||
defenderTokenId: this.defenderTokenId,
|
|
||||||
rollMode: true,
|
|
||||||
rollData: duplicate(rollData)
|
|
||||||
};
|
|
||||||
|
|
||||||
// envoyer le message de defense
|
|
||||||
if (!game.user.isGM || this.defender.hasPlayerOwner) {
|
|
||||||
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: defense });
|
|
||||||
} else {
|
|
||||||
defense.whisper = [game.user];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.user.isGM) { // Always push the message to the MJ
|
|
||||||
ChatMessage.create(defense);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -296,7 +313,7 @@ export class RdDCombat {
|
|||||||
switch (categorie) {
|
switch (categorie) {
|
||||||
case 'tir':
|
case 'tir':
|
||||||
case 'lancer':
|
case 'lancer':
|
||||||
return items.filter(item =>
|
return items.filter(item =>
|
||||||
item.type == 'arme' &&
|
item.type == 'arme' &&
|
||||||
item.data.competence.toLowerCase().match("bouclier"));
|
item.data.competence.toLowerCase().match("bouclier"));
|
||||||
default:
|
default:
|
||||||
@ -479,7 +496,8 @@ export class RdDCombat {
|
|||||||
|
|
||||||
await this.computeRecul(rollData, true);
|
await this.computeRecul(rollData, true);
|
||||||
// TODO: gestion message pour chance/encaissement
|
// TODO: gestion message pour chance/encaissement
|
||||||
this.encaisser(rollData.attackerRoll);
|
this._sendMessageEncaisser(rollData.attackerRoll);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -575,10 +593,10 @@ export class RdDCombat {
|
|||||||
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
||||||
|
|
||||||
await this.computeRecul(rollData, true);
|
await this.computeRecul(rollData, true);
|
||||||
this.encaisser(rollData.attackerRoll);
|
this._sendMessageEncaisser(rollData.attackerRoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async computeDeteriorationArme(rollData) {
|
async computeDeteriorationArme(rollData) {
|
||||||
const attackerRoll = rollData.attackerRoll;
|
const attackerRoll = rollData.attackerRoll;
|
||||||
@ -661,11 +679,10 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
encaisser(attackerRoll) {
|
_sendMessageEncaisser(rollData){
|
||||||
// TODO: gestion message pour chance/encaissement
|
let message = "<strong>" + this.defender.name + "</strong> doit:" + this._buildMessageEncaisser(rollData);
|
||||||
this.encaisser(attackerRoll, this.defenderTokenId);
|
RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_encaisser", message, rollData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user