Tirage des tarots
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
import { MaleficesUtility } from "./malefices-utility.js";
|
||||
import { MaleficesRollDialog } from "./malefices-roll-dialog.js";
|
||||
import { MaleficesTirageTarotDialog } from "./malefices-tirage-tarot-dialog.js"
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class MaleficesCommands {
|
||||
@ -9,7 +10,7 @@ export class MaleficesCommands {
|
||||
static init() {
|
||||
if (!game.system.malefices.commands) {
|
||||
const commands = new MaleficesCommands();
|
||||
//crucibleCommands.registerCommand({ path: ["/char"], func: (content, msg, params) => crucibleCommands.createChar(msg), descr: "Create a new character" });
|
||||
commands.registerCommand({ path: ["/tirage"], func: (content, msg, params) => MaleficesCommands.createTirage(msg), descr: "Tirage des tarots" });
|
||||
//crucibleCommands.registerCommand({ path: ["/pool"], func: (content, msg, params) => crucibleCommands.poolRoll(msg), descr: "Generic Roll Window" });
|
||||
game.system.malefices.commands = commands;
|
||||
}
|
||||
@ -100,18 +101,30 @@ export class MaleficesCommands {
|
||||
static _chatAnswer(msg, content) {
|
||||
msg.whisper = [game.user.id];
|
||||
msg.content = content;
|
||||
ChatMessage.create(msg);
|
||||
ChatMessage.create(msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async poolRoll( msg) {
|
||||
let rollData = MaleficesUtility.getBasicRollData()
|
||||
rollData.alias = "Dice Pool Roll",
|
||||
rollData.mode = "generic"
|
||||
rollData.title = `Dice Pool Roll`;
|
||||
|
||||
let rollDialog = await MaleficesRollDialog.create( this, rollData);
|
||||
rollDialog.render( true );
|
||||
static async createTirage(msg) {
|
||||
if (game.user.isGM) {
|
||||
let tirageData = {
|
||||
state: 'select-player',
|
||||
nbCard: 0,
|
||||
maxPlayerCard: 5,
|
||||
maxSecretCard: 1,
|
||||
cards: [],
|
||||
players: duplicate(game.users),
|
||||
secretCards: [],
|
||||
deck: MaleficesUtility.getTarots()
|
||||
}
|
||||
for (let i = 0; i < 5; i++) {
|
||||
tirageData.cards.push({ name: "???", img: "systems/fvtt-malefices/images/tarots/background.webp" })
|
||||
}
|
||||
tirageData.secretCards.push({ name: "???", img: "systems/fvtt-malefices/images/tarots/background.webp" })
|
||||
|
||||
let tirageDialog = await MaleficesTirageTarotDialog.create(this, tirageData)
|
||||
tirageDialog.render(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -111,7 +111,7 @@ Hooks.on("chatMessage", (html, content, msg) => {
|
||||
if (content[0] == '/') {
|
||||
let regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
if (game.system.Malefices.commands.processChatCommand(commands, content, msg)) {
|
||||
if (game.system.malefices.commands.processChatCommand(commands, content, msg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
155
modules/malefices-tirage-tarot-dialog.js
Normal file
155
modules/malefices-tirage-tarot-dialog.js
Normal file
@ -0,0 +1,155 @@
|
||||
import { MaleficesUtility } from "./malefices-utility.js";
|
||||
|
||||
export class MaleficesTirageTarotDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async create(actor, tirageData) {
|
||||
|
||||
let options = { classes: ["MaleficesDialog"], width: 820, height: 740, 'z-index': 99999 };
|
||||
let html = await renderTemplate('systems/fvtt-malefices/templates/dialogs/tirage-tarot-dialog.hbs', tirageData);
|
||||
|
||||
return new MaleficesTirageTarotDialog(actor, tirageData, html, options);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(actor, tirageData, html, options, close = undefined) {
|
||||
let conf = {
|
||||
title: "Tirage des tarots",
|
||||
content: html,
|
||||
buttons: {
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Fermer/Annuler",
|
||||
callback: () => { this.close() }
|
||||
}
|
||||
},
|
||||
close: close
|
||||
}
|
||||
|
||||
super(conf, options);
|
||||
|
||||
this.actor = actor;
|
||||
this.tirageData = tirageData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async sendCardRequest() {
|
||||
this.tirageData.state = 'waiting-user-card'
|
||||
let msg = await MaleficesUtility.createChatMessage(this.tirageData.user.name, "useronly", {
|
||||
content: await renderTemplate(`systems/fvtt-malefices/templates/chat/request-tarot-card.hbs`, this.tirageData)
|
||||
})
|
||||
//msg.setFlag("world", "tirage-data", this.tirageData)
|
||||
console.log("MSG IS", msg)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
drawCard() {
|
||||
let index = Math.round(Math.random() * (this.tirageData.deck.length-1))
|
||||
let selectedCard = this.tirageData.deck[index]
|
||||
selectedCard.system.ispositif = true
|
||||
if ( selectedCard.system.isdualside) { // Cas des cartes pouvant avoir 2 sens
|
||||
selectedCard.system.ispositif = (Math.random() > 0.5)
|
||||
}
|
||||
console.log("CARD SELECTED:", selectedCard)
|
||||
// Cas spécial de la Roue de la Fortune
|
||||
if ( selectedCard.name.toLowerCase().includes("fortune")) {
|
||||
this.tirageData.maxPlayerCard += 1
|
||||
this.tirageData.maxSecretCard += 1
|
||||
}
|
||||
let newList = []
|
||||
for(let card of this.tirageData.deck) {
|
||||
if (card.name != selectedCard.name) {
|
||||
newList.push(card)
|
||||
}
|
||||
}
|
||||
this.tirageData.deck = newList
|
||||
|
||||
return selectedCard
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addCard( msgId ) {
|
||||
MaleficesUtility.removeChatMessageId(msgId)
|
||||
|
||||
let selectedCard = this.drawCard()
|
||||
selectedCard.system.isgm = false
|
||||
await MaleficesUtility.createChatMessage(this.tirageData.user.name, "gmroll", {
|
||||
content: await renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, selectedCard)
|
||||
})
|
||||
if (this.tirageData.cards[0].name == "???") {
|
||||
this.tirageData.cards.shift()
|
||||
}
|
||||
this.tirageData.cards.push(selectedCard)
|
||||
this.tirageData.nbCard++
|
||||
|
||||
if (this.tirageData.nbCard == this.tirageData.maxPlayerCard) {
|
||||
for (let i=0; i<this.tirageData.maxSecretCard; i++) {
|
||||
let selectedCard = this.drawCard()
|
||||
selectedCard.system.isgm = true
|
||||
await MaleficesUtility.createChatMessage(this.tirageData.user.name, "blindroll", {
|
||||
content: await renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, selectedCard)
|
||||
})
|
||||
if (this.tirageData.secretCards[0].name == "???") {
|
||||
this.tirageData.secretCards.shift()
|
||||
}
|
||||
this.tirageData.secretCards.push(selectedCard)
|
||||
}
|
||||
this.tirageData.actors = duplicate(game.actors)
|
||||
this.tirageData.state = 'attribute-to-actor'
|
||||
}else {
|
||||
this.sendCardRequest()
|
||||
}
|
||||
this.refreshDialog()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processSelectedPlayer() {
|
||||
let user = game.users.get(this.tirageData.playerId)
|
||||
this.tirageData.user = user
|
||||
this.tirageData.players = null
|
||||
console.log("Going to work with ", user.name)
|
||||
game.system.malefices.currentTirage = this
|
||||
this.refreshDialog()
|
||||
this.sendCardRequest()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
attributeToActor(actorId) {
|
||||
let actor = game.actors.get(actorId)
|
||||
if (actor) {
|
||||
actor.createEmbeddedDocuments('Item', this.tirageData.cards)
|
||||
actor.createEmbeddedDocuments('Item', this.tirageData.secretCards)
|
||||
ui.notifications.info("Les cartes ont été attribuées à " + actor.name)
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async refreshDialog() {
|
||||
const content = await renderTemplate("systems/fvtt-malefices/templates/dialogs/tirage-tarot-dialog.hbs", this.tirageData)
|
||||
this.data.content = content
|
||||
this.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
var dialog = this;
|
||||
function onLoad() {
|
||||
}
|
||||
$(function () { onLoad(); });
|
||||
|
||||
html.find('#playerId').change((event) => {
|
||||
if ( event.currentTarget.value != "none") {
|
||||
dialog.tirageData.playerId = event.currentTarget.value
|
||||
dialog.processSelectedPlayer()
|
||||
}
|
||||
})
|
||||
html.find('#actorId').change((event) => {
|
||||
if ( event.currentTarget.value != "none") {
|
||||
let actorId = event.currentTarget.value
|
||||
dialog.attributeToActor(actorId)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
/* -------------------------------------------- */
|
||||
import { MaleficesCombat } from "./malefices-combat.js";
|
||||
import { MaleficesCommands } from "./malefices-commands.js";
|
||||
|
||||
|
||||
@ -89,6 +88,14 @@ export class MaleficesUtility {
|
||||
}
|
||||
return actor
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static drawDeckCard(msgId) {
|
||||
if (game.user.isGM) {
|
||||
game.system.malefices.currentTirage.addCard(msgId)
|
||||
} else {
|
||||
game.socket.emit( "system.fvtt-malefices", {name: "msg-draw-card", data: {msgId: msgId}})
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
@ -102,6 +109,11 @@ export class MaleficesUtility {
|
||||
rollData.isReroll = true
|
||||
this.rollMalefices(rollData)
|
||||
})
|
||||
html.on("click", '.draw-tarot-card', event => {
|
||||
let messageId = MaleficesUtility.findChatMessageId(event.currentTarget)
|
||||
this.drawDeckCard(messageId)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -185,21 +197,10 @@ export class MaleficesUtility {
|
||||
/* -------------------------------------------- */
|
||||
static async onSocketMesssage(msg) {
|
||||
console.log("SOCKET MESSAGE", msg.name)
|
||||
if (msg.name == "msg_update_roll") {
|
||||
this.updateRollData(msg.data)
|
||||
}
|
||||
if (msg.name == "msg_gm_process_attack_defense") {
|
||||
this.processSuccessResult(msg.data)
|
||||
}
|
||||
if (msg.name == "msg_gm_item_drop" && game.user.isGM) {
|
||||
let actor = game.actors.get(msg.data.actorId)
|
||||
let item
|
||||
if (msg.data.isPack) {
|
||||
item = await fromUuid("Compendium." + msg.data.isPack + "." + msg.data.itemId)
|
||||
} else {
|
||||
item = game.items.get(msg.data.itemId)
|
||||
if (msg.name == "msg-draw-card") {
|
||||
if ( game.user.isGM && game.system.malefices.currentTirage) {
|
||||
game.system.malefices.currentTirage.addCard(msg.data.msgId)
|
||||
}
|
||||
this.addItemDropToActor(actor, item)
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,11 +332,17 @@ export class MaleficesUtility {
|
||||
switch (rollMode) {
|
||||
case "blindroll": return this.getUsers(user => user.isGM);
|
||||
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
|
||||
case "useronly": return this.getWhisperRecipientsOnly(name);
|
||||
case "selfroll": return [game.user.id];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipientsOnly(name) {
|
||||
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
|
||||
return recep1
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipientsAndGMs(name) {
|
||||
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
|
||||
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
|
||||
@ -369,7 +376,7 @@ export class MaleficesUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static createChatMessage(name, rollMode, chatOptions) {
|
||||
static async createChatMessage(name, rollMode, chatOptions) {
|
||||
switch (rollMode) {
|
||||
case "blindroll": // GM only
|
||||
if (!game.user.isGM) {
|
||||
@ -387,7 +394,7 @@ export class MaleficesUtility {
|
||||
break;
|
||||
}
|
||||
chatOptions.alias = chatOptions.alias || name;
|
||||
return ChatMessage.create(chatOptions);
|
||||
return await ChatMessage.create(chatOptions);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -413,8 +420,8 @@ export class MaleficesUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static createChatWithRollMode(name, chatOptions) {
|
||||
return this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
|
||||
static async createChatWithRollMode(name, chatOptions) {
|
||||
return await this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user