Initial push
This commit is contained in:
170
modules/hawkmoon-actor-sheet.js
Normal file
170
modules/hawkmoon-actor-sheet.js
Normal file
@ -0,0 +1,170 @@
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {ActorSheet}
|
||||
*/
|
||||
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonRollDialog } from "./hawkmoon-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class HawkmoonActorSheet extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["fvtt-hawkmoon", "sheet", "actor"],
|
||||
template: "systems/fvtt-hawkmoon-cyd/templates/actor-sheet.html",
|
||||
width: 640,
|
||||
height: 720,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
|
||||
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
|
||||
editScore: false
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
const objectData = duplicate(this.object)
|
||||
|
||||
let formData = {
|
||||
title: this.title,
|
||||
id: objectData.id,
|
||||
type: objectData.type,
|
||||
img: objectData.img,
|
||||
name: objectData.name,
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
system: objectData.system,
|
||||
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
|
||||
limited: this.object.limited,
|
||||
skills: this.actor.getSkills(),
|
||||
armes: duplicate(this.actor.getWeapons()),
|
||||
protections: duplicate(this.actor.getArmors()),
|
||||
dons: duplicate(this.actor.getDons()),
|
||||
alignement: this.actor.getAlignement(),
|
||||
aspect: this.actor.getAspect(),
|
||||
marge: this.actor.getMarge(),
|
||||
tendances:duplicate(this.actor.getTendances()),
|
||||
runes:duplicate(this.actor.getRunes()),
|
||||
origine: duplicate(this.actor.getOrigine() || {}),
|
||||
heritage: duplicate(this.actor.getHeritage() || {}),
|
||||
metier: duplicate(this.actor.getMetier() || {}),
|
||||
combat: this.actor.getCombatValues(),
|
||||
equipements: duplicate(this.actor.getEquipments()),
|
||||
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
|
||||
options: this.options,
|
||||
owner: this.document.isOwner,
|
||||
editScore: this.options.editScore,
|
||||
isGM: game.user.isGM
|
||||
}
|
||||
this.formData = formData;
|
||||
|
||||
console.log("PC : ", formData, this.object);
|
||||
return formData;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) return;
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item")
|
||||
let itemId = li.data("item-id")
|
||||
const item = this.actor.items.get( itemId )
|
||||
item.sheet.render(true)
|
||||
})
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
HawkmoonUtility.confirmDelete(this, li);
|
||||
})
|
||||
html.find('.edit-item-data').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item")
|
||||
let itemId = li.data("item-id")
|
||||
let itemType = li.data("item-type")
|
||||
let itemField = $(ev.currentTarget).data("item-field")
|
||||
let dataType = $(ev.currentTarget).data("dtype")
|
||||
let value = ev.currentTarget.value
|
||||
this.actor.editItemField(itemId, itemType, itemField, dataType, value)
|
||||
})
|
||||
|
||||
html.find('.quantity-minus').click(event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.incDecQuantity( li.data("item-id"), -1 );
|
||||
} );
|
||||
html.find('.quantity-plus').click(event => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
this.actor.incDecQuantity( li.data("item-id"), +1 );
|
||||
} );
|
||||
|
||||
html.find('.roll-attribut').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item")
|
||||
let attrKey = li.data("attr-key")
|
||||
this.actor.rollAttribut(attrKey)
|
||||
})
|
||||
html.find('.roll-competence').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item")
|
||||
let attrKey = $(event.currentTarget).data("attr-key")
|
||||
let compId = li.data("item-id")
|
||||
this.actor.rollCompetence(attrKey, compId)
|
||||
})
|
||||
html.find('.roll-rune').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item")
|
||||
let runeId = li.data("item-id")
|
||||
this.actor.rollRune(runeId)
|
||||
})
|
||||
html.find('.roll-arme-offensif').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item")
|
||||
let armeId = li.data("item-id")
|
||||
this.actor.rollArmeOffensif(armeId)
|
||||
})
|
||||
html.find('.roll-arme-degats').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item")
|
||||
let armeId = li.data("item-id")
|
||||
this.actor.rollArmeDegats(armeId)
|
||||
})
|
||||
|
||||
|
||||
html.find('.lock-unlock-sheet').click((event) => {
|
||||
this.options.editScore = !this.options.editScore;
|
||||
this.render(true);
|
||||
});
|
||||
html.find('.item-equip').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
this.actor.equipItem( li.data("item-id") );
|
||||
this.render(true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
const bodyHeight = position.height - 192;
|
||||
sheetBody.css("height", bodyHeight);
|
||||
return position;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/*async _onDropItem(event, dragData) {
|
||||
let item = await HawkmoonUtility.searchItem( dragData)
|
||||
this.actor.preprocessItem( event, item, true )
|
||||
super._onDropItem(event, dragData)
|
||||
}*/
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
// Update the Actor
|
||||
return this.object.update(formData);
|
||||
}
|
||||
}
|
505
modules/hawkmoon-actor.js
Normal file
505
modules/hawkmoon-actor.js
Normal file
@ -0,0 +1,505 @@
|
||||
/* -------------------------------------------- */
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonRollDialog } from "./hawkmoon-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const __degatsBonus = [-2, -2, -1, -1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10]
|
||||
const __vitesseBonus = [-2, -2, -1, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8]
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/**
|
||||
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
||||
* @extends {Actor}
|
||||
*/
|
||||
export class HawkmoonActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/**
|
||||
* Override the create() function to provide additional SoS functionality.
|
||||
*
|
||||
* This overrided create() function adds initial items
|
||||
* Namely: Basic skills, money,
|
||||
*
|
||||
* @param {Object} data Barebones actor data which this function adds onto.
|
||||
* @param {Object} options (Unused) Additional options which customize the creation workflow.
|
||||
*
|
||||
*/
|
||||
|
||||
static async create(data, options) {
|
||||
|
||||
// Case of compendium global import
|
||||
if (data instanceof Array) {
|
||||
return super.create(data, options);
|
||||
}
|
||||
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
|
||||
if (data.items) {
|
||||
let actor = super.create(data, options);
|
||||
return actor;
|
||||
}
|
||||
|
||||
if (data.type == 'personnage') {
|
||||
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills")
|
||||
data.items = skills.map(i => i.toObject())
|
||||
}
|
||||
if (data.type == 'pnj') {
|
||||
}
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareArme(arme) {
|
||||
arme = duplicate(arme)
|
||||
let combat = this.getCombatValues()
|
||||
if (arme.system.typearme == "contact" || arme.system.typearme == "contactjet") {
|
||||
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
|
||||
arme.system.attrKey = "pui"
|
||||
arme.system.totalDegats = arme.system.degats + "+" + combat.bonusDegatsTotal
|
||||
arme.system.totalOffensif = this.system.attributs.pui.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff
|
||||
if (arme.system.isdefense) {
|
||||
arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.bonusmaniementdef
|
||||
}
|
||||
}
|
||||
if (arme.system.typearme == "jet" || arme.system.typearme == "tir") {
|
||||
arme.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "armes à distance"))
|
||||
arme.system.attrKey = "adr"
|
||||
arme.system.totalOffensif = this.system.attributs.adr.value + arme.system.competence.system.niveau + arme.system.bonusmaniementoff
|
||||
arme.system.totalDegats = arme.system.degats
|
||||
if (arme.system.isdefense) {
|
||||
arme.system.totalDefensif = combat.defenseTotal + arme.system.competence.system.niveau + arme.system.bonusmaniementdef
|
||||
}
|
||||
}
|
||||
return arme
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
prepareBouclier(bouclier) {
|
||||
bouclier = duplicate(bouclier)
|
||||
let combat = this.getCombatValues()
|
||||
bouclier.system.competence = duplicate(this.items.find(item => item.type == "competence" && item.name.toLowerCase() == "mêlée"))
|
||||
bouclier.system.attrKey = "pui"
|
||||
bouclier.system.totalDegats = bouclier.system.degats + "+" + combat.bonusDegatsTotal
|
||||
bouclier.system.totalOffensif = this.system.attributs.pui.value + bouclier.system.competence.system.niveau
|
||||
bouclier.system.isdefense = true
|
||||
bouclier.system.bonusmaniementoff = 0
|
||||
bouclier.system.totalDefensif = combat.defenseTotal + bouclier.system.competence.system.niveau + bouclier.system.bonusdefense
|
||||
return bouclier
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getWeapons() {
|
||||
let armes = []
|
||||
for (let arme of this.items) {
|
||||
if (arme.type == "arme") {
|
||||
armes.push(this.prepareArme(arme))
|
||||
}
|
||||
if (arme.type == "bouclier") {
|
||||
armes.push(this.prepareBouclier(arme))
|
||||
}
|
||||
}
|
||||
return armes
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDons() {
|
||||
return this.items.filter(item => item.type == "don")
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getTendances() {
|
||||
return this.items.filter(item => item.type == "tendance")
|
||||
}
|
||||
getRunes() {
|
||||
return this.items.filter(item => item.type == "rune")
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getEquipments() {
|
||||
return this.items.filter(item => item.type == "equipement")
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getArmors() {
|
||||
return this.items.filter(item => item.type == "protection")
|
||||
}
|
||||
getOrigine() {
|
||||
return this.items.find(item => item.type == "origine")
|
||||
}
|
||||
getMetier() {
|
||||
return this.items.find(item => item.type == "metier")
|
||||
}
|
||||
getHeritage() {
|
||||
return this.items.find(item => item.type == "heritage")
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getSkills() {
|
||||
let comp = []
|
||||
for (let item of this.items) {
|
||||
item = duplicate(item)
|
||||
if (item.type == "competence") {
|
||||
item.system.attribut1total = item.system.niveau + (this.system.attributs[item.system.attribut1]?.value || 0)
|
||||
item.system.attribut2total = item.system.niveau + (this.system.attributs[item.system.attribut2]?.value || 0)
|
||||
item.system.attribut3total = item.system.niveau + (this.system.attributs[item.system.attribut3]?.value || 0)
|
||||
if (item.system.niveau == 0) {
|
||||
item.system.attribut1total -= 3
|
||||
item.system.attribut2total -= 3
|
||||
item.system.attribut3total -= 3
|
||||
}
|
||||
item.system.attribut1label = this.system.attributs[item.system.attribut1]?.label || ""
|
||||
item.system.attribut2label = this.system.attributs[item.system.attribut2]?.label || ""
|
||||
item.system.attribut3label = this.system.attributs[item.system.attribut3]?.label || ""
|
||||
comp.push(item)
|
||||
}
|
||||
}
|
||||
return comp.sort(function (a, b) {
|
||||
let fa = a.name.toLowerCase(),
|
||||
fb = b.name.toLowerCase();
|
||||
if (fa < fb) {
|
||||
return -1;
|
||||
}
|
||||
if (fa > fb) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAspect() {
|
||||
return (this.system.balance.loi > this.system.balance.chaos) ? this.system.balance.loi : this.system.balance.chaos
|
||||
}
|
||||
getMarge() {
|
||||
return Math.abs( this.system.balance.loi - this.system.balance.chaos)
|
||||
}
|
||||
getAlignement() {
|
||||
return (this.system.balance.loi > this.system.balance.chaos) ? "loyal" : "chaotique"
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDefenseBase() {
|
||||
return this.system.attributs.tre.value + 5
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getVitesseBase() {
|
||||
return 5 + __vitesseBonus[this.system.attributs.adr.value]
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCombatValues() {
|
||||
let combat = {
|
||||
initBase: this.system.attributs.adr.value,
|
||||
initTotal: this.system.attributs.adr.value + this.system.combat.initbonus,
|
||||
bonusDegats: this.getBonusDegats(),
|
||||
bonusDegatsTotal: this.getBonusDegats() + this.system.combat.bonusdegats,
|
||||
vitesseBase: this.getVitesseBase(),
|
||||
vitesseTotal: this.getVitesseBase() + this.system.combat.vitessebonus,
|
||||
defenseBase: this.getDefenseBase(),
|
||||
defenseTotal: this.getDefenseBase() + this.system.combat.defensebonus
|
||||
}
|
||||
return combat
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareBaseData() {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async prepareData() {
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareDerivedData() {
|
||||
|
||||
if (this.type == 'personnage') {
|
||||
let newSante = this.system.sante.bonus + (this.system.attributs.pui.value + this.system.attributs.tre.value) * 2 + 5
|
||||
if (this.system.sante.base != newSante) {
|
||||
this.update({ 'system.sante.base': newSante })
|
||||
}
|
||||
let newAme = (this.system.attributs.cla.value + this.system.attributs.tre.value) * this.system.biodata.amemultiplier + 5
|
||||
if (this.system.ame.fullmax != newAme) {
|
||||
this.update({ 'system.ame.fullmax': newAme })
|
||||
}
|
||||
}
|
||||
|
||||
super.prepareDerivedData()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_preUpdate(changed, options, user) {
|
||||
|
||||
super._preUpdate(changed, options, user);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getItemById(id) {
|
||||
let item = this.items.find(item => item.id == id);
|
||||
if (item) {
|
||||
item = duplicate(item)
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async equipItem(itemId) {
|
||||
let item = this.items.find(item => item.id == itemId)
|
||||
if (item && item.system) {
|
||||
let update = { _id: item.id, "system.equipped": !item.system.equipped }
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
editItemField(itemId, itemType, itemField, dataType, value) {
|
||||
let item = this.items.find(item => item.id == itemId)
|
||||
if (item) {
|
||||
console.log("Item ", item, itemField, dataType, value)
|
||||
if (dataType.toLowerCase() == "number") {
|
||||
value = Number(value)
|
||||
} else {
|
||||
value = String(value)
|
||||
}
|
||||
let update = { _id: item.id, [`system.${itemField}`]: value };
|
||||
this.updateEmbeddedDocuments("Item", [update])
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getBonneAventure() {
|
||||
return this.system.bonneaventure.actuelle
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
changeBonneAventure(value) {
|
||||
let newBA = this.system.bonneaventure.actuelle
|
||||
newBA += value
|
||||
this.update({ 'system.bonneaventure.actuelle': newBA })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getEclat() {
|
||||
return this.system.eclat.value
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
changeEclat(value) {
|
||||
let newE = this.system.eclat.value
|
||||
newE += value
|
||||
this.update({ 'system.eclat.value': newE })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
canEclatDoubleD20() {
|
||||
return (this.getAlignement() == "loyal" && this.system.eclat.value > 0)
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
subPointsAme(runeMode, value) {
|
||||
let ame = duplicate(this.system.ame)
|
||||
if(runeMode == "prononcer") {
|
||||
ame.value -= value
|
||||
} else {
|
||||
ame.currentmax -= value
|
||||
}
|
||||
this.update( {'system.ame': ame})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
compareName(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAttribute(attrKey) {
|
||||
return this.system.attributes[attrKey]
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getBonusDegats() {
|
||||
return __degatsBonus[this.system.attributs.pui.value]
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async equipGear(equipmentId) {
|
||||
let item = this.items.find(item => item.id == equipmentId);
|
||||
if (item && item.system.data) {
|
||||
let update = { _id: item.id, "system.equipped": !item.system.equipped };
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSubActors() {
|
||||
let subActors = [];
|
||||
for (let id of this.system.subactors) {
|
||||
subActors.push(duplicate(game.actors.get(id)));
|
||||
}
|
||||
return subActors;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async addSubActor(subActorId) {
|
||||
let subActors = duplicate(this.system.subactors);
|
||||
subActors.push(subActorId);
|
||||
await this.update({ 'system.subactors': subActors });
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async delSubActor(subActorId) {
|
||||
let newArray = [];
|
||||
for (let id of this.system.subactors) {
|
||||
if (id != subActorId) {
|
||||
newArray.push(id);
|
||||
}
|
||||
}
|
||||
await this.update({ 'system.subactors': newArray });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async incDecQuantity(objetId, incDec = 0) {
|
||||
let objetQ = this.items.get(objetId)
|
||||
if (objetQ) {
|
||||
let newQ = objetQ.system.quantity + incDec;
|
||||
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]); // pdates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCompetence(compId) {
|
||||
return this.items.get(compId)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async setPredilectionUsed(compId, predIdx) {
|
||||
let comp = this.items.get(compId)
|
||||
let pred = duplicate(comp.system.predilections)
|
||||
pred[predIdx].used = true
|
||||
await this.updateEmbeddedDocuments('Item', [{ _id: compId, 'system.predilections': pred }])
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getInitiativeScore( ) {
|
||||
return Number(this.system.attributs.adr.value) + Number(this.system.combat.initbonus)
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getBestDefenseValue() {
|
||||
let defenseList = this.items.filter(item => (item.type =="arme" || item.type == "bouclier") && item.system.equipped)
|
||||
let maxDef = 0
|
||||
let bestArme
|
||||
for(let arme of defenseList) {
|
||||
if (arme.type == "arme" && arme.system.isdefense) {
|
||||
arme = this.prepareArme(arme)
|
||||
}
|
||||
if (arme.type == "bouclier" ) {
|
||||
arme = this.prepareBouclier(arme)
|
||||
}
|
||||
if ( arme.system.totalDefensif > maxDef) {
|
||||
maxDef = arme.system.totalDefensif
|
||||
bestArme = duplicate(arme)
|
||||
}
|
||||
}
|
||||
return bestArme
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData(attrKey = undefined, compId = undefined, compName = undefined) {
|
||||
let rollData = HawkmoonUtility.getBasicRollData()
|
||||
rollData.alias = this.name
|
||||
rollData.actorImg = this.img
|
||||
rollData.actorId = this.id
|
||||
rollData.img = this.img
|
||||
rollData.canEclatDoubleD20 = this.canEclatDoubleD20()
|
||||
rollData.doubleD20 = false
|
||||
rollData.attributs = HawkmoonUtility.getAttributs()
|
||||
|
||||
if (attrKey) {
|
||||
rollData.attrKey = attrKey
|
||||
if (attrKey != "tochoose") {
|
||||
rollData.actionImg = "systems/fvtt-mournblade/assets/icons/" + this.system.attributs[attrKey].labelnorm + ".webp"
|
||||
rollData.attr = duplicate(this.system.attributs[attrKey])
|
||||
}
|
||||
}
|
||||
if (compId) {
|
||||
rollData.competence = duplicate(this.items.get(compId) || {})
|
||||
rollData.actionImg = rollData.competence?.img
|
||||
}
|
||||
if (compName) {
|
||||
rollData.competence = duplicate(this.items.find( item => item.name.toLowerCase() == compName.toLowerCase()) || {})
|
||||
rollData.actionImg = rollData.competence?.img
|
||||
}
|
||||
return rollData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollAttribut(attrKey) {
|
||||
let rollData = this.getCommonRollData(attrKey)
|
||||
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
|
||||
rollDialog.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollCompetence(attrKey, compId) {
|
||||
let rollData = this.getCommonRollData(attrKey, compId)
|
||||
console.log("RollDatra", rollData)
|
||||
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
|
||||
rollDialog.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollRune(runeId) {
|
||||
let comp = this.items.find(comp => comp.type == "competence" && comp.name.toLowerCase() == "savoir : runes")
|
||||
if ( !comp) {
|
||||
ui.notifications.warn("La compétence Savoirs : Runes n'a pas été trouvée, abandon.")
|
||||
return
|
||||
}
|
||||
let rollData = this.getCommonRollData("cla", undefined, "Savoir : Runes")
|
||||
rollData.rune = duplicate(this.items.get(runeId) || {})
|
||||
rollData.difficulte = rollData.rune?.system?.seuil || 0
|
||||
rollData.runemode = "prononcer"
|
||||
rollData.runeame = 1
|
||||
console.log("runeData", rollData)
|
||||
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
|
||||
rollDialog.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollArmeOffensif(armeId) {
|
||||
let arme = this.items.get(armeId)
|
||||
if (arme.type == "arme") {
|
||||
arme = this.prepareArme(arme)
|
||||
}
|
||||
if (arme.type == "bouclier") {
|
||||
arme = this.prepareBouclier(arme)
|
||||
}
|
||||
let rollData = this.getCommonRollData(arme.system.attrKey, arme.system.competence._id)
|
||||
rollData.arme = arme
|
||||
console.log("ARME!", rollData)
|
||||
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
|
||||
rollDialog.render(true)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollArmeDegats(armeId) {
|
||||
let arme = this.items.get(armeId)
|
||||
if (arme.type == "arme") {
|
||||
arme = this.prepareArme(arme)
|
||||
}
|
||||
if (arme.type == "bouclier") {
|
||||
arme = this.prepareBouclier(arme)
|
||||
}
|
||||
let roll = new Roll(arme.system.totalDegats).roll({ async: false })
|
||||
await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
|
||||
let rollData = {
|
||||
arme: arme,
|
||||
finalResult: roll.total,
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
actionImg: arme.img,
|
||||
}
|
||||
HawkmoonUtility.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-mournblade/templates/chat-degats-result.html`, rollData)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
27
modules/hawkmoon-combat.js
Normal file
27
modules/hawkmoon-combat.js
Normal file
@ -0,0 +1,27 @@
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class HawkmoonCombat extends Combat {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollInitiative(ids, formula = undefined, messageOptions = {} ) {
|
||||
ids = typeof ids === "string" ? [ids] : ids;
|
||||
for (let cId = 0; cId < ids.length; cId++) {
|
||||
const c = this.combatants.get(ids[cId]);
|
||||
let id = c._id || c.id;
|
||||
let initBonus = c.actor ? c.actor.getInitiativeScore() : 0
|
||||
let roll = new Roll("1d10 + "+initBonus).roll({ async: false})
|
||||
await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"))
|
||||
//console.log("Init bonus", initBonus, roll.total)
|
||||
await this.updateEmbeddedDocuments("Combatant", [ { _id: id, initiative: roll.total } ]);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_onUpdate(changed, options, userId) {
|
||||
}
|
||||
|
||||
|
||||
}
|
123
modules/hawkmoon-commands.js
Normal file
123
modules/hawkmoon-commands.js
Normal file
@ -0,0 +1,123 @@
|
||||
/* -------------------------------------------- */
|
||||
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonRollDialog } from "./hawkmoon-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class HawkmoonCommands {
|
||||
|
||||
static init() {
|
||||
if (!game.system.mournblade.commands) {
|
||||
//const HawkmoonCommands = new HawkmoonCommands()
|
||||
//HawkmoonCommands.registerCommand({ path: ["/char"], func: (content, msg, params) => HawkmoonCommands.createChar(msg), descr: "Create a new character" });
|
||||
//game.system.mournblade.commands = HawkmoonCommands
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.commandsTable = {}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
registerCommand(command) {
|
||||
this._addCommand(this.commandsTable, command.path, '', command);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_addCommand(targetTable, path, fullPath, command) {
|
||||
if (!this._validateCommand(targetTable, path, command)) {
|
||||
return;
|
||||
}
|
||||
const term = path[0];
|
||||
fullPath = fullPath + term + ' '
|
||||
if (path.length == 1) {
|
||||
command.descr = `<strong>${fullPath}</strong>: ${command.descr}`;
|
||||
targetTable[term] = command;
|
||||
}
|
||||
else {
|
||||
if (!targetTable[term]) {
|
||||
targetTable[term] = { subTable: {} };
|
||||
}
|
||||
this._addCommand(targetTable[term].subTable, path.slice(1), fullPath, command)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_validateCommand(targetTable, path, command) {
|
||||
if (path.length > 0 && path[0] && command.descr && (path.length != 1 || targetTable[path[0]] == undefined)) {
|
||||
return true;
|
||||
}
|
||||
console.warn("HawkmoonCommands._validateCommand failed ", targetTable, path, command);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Manage chat commands */
|
||||
processChatCommand(commandLine, content = '', msg = {}) {
|
||||
// Setup new message's visibility
|
||||
let rollMode = game.settings.get("core", "rollMode");
|
||||
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperRecipients("GM");
|
||||
if (rollMode === "blindroll") msg["blind"] = true;
|
||||
msg["type"] = 0;
|
||||
|
||||
let command = commandLine[0].toLowerCase();
|
||||
let params = commandLine.slice(1);
|
||||
|
||||
return this.process(command, params, content, msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
process(command, params, content, msg) {
|
||||
return this._processCommand(this.commandsTable, command, params, content, msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
|
||||
console.log("===> Processing command")
|
||||
let command = commandsTable[name];
|
||||
path = path + name + " ";
|
||||
if (command && command.subTable) {
|
||||
if (params[0]) {
|
||||
return this._processCommand(command.subTable, params[0], params.slice(1), content, msg, path)
|
||||
}
|
||||
else {
|
||||
this.help(msg, command.subTable);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (command && command.func) {
|
||||
const result = command.func(content, msg, params);
|
||||
if (result == false) {
|
||||
RdDCommands._chatAnswer(msg, command.descr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async createChar(msg) {
|
||||
game.system.Hawkmoon.creator = new HawkmoonActorCreate();
|
||||
game.system.Hawkmoon.creator.start();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _chatAnswer(msg, content) {
|
||||
msg.whisper = [game.user.id];
|
||||
msg.content = content;
|
||||
ChatMessage.create(msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async poolRoll( msg) {
|
||||
let rollData = HawkmoonUtility.getBasicRollData()
|
||||
rollData.alias = "Dice Pool Roll",
|
||||
rollData.mode = "generic"
|
||||
rollData.title = `Dice Pool Roll`;
|
||||
|
||||
let rollDialog = await HawkmoonRollDialog.create( this, rollData);
|
||||
rollDialog.render( true );
|
||||
}
|
||||
|
||||
}
|
178
modules/hawkmoon-item-sheet.js
Normal file
178
modules/hawkmoon-item-sheet.js
Normal file
@ -0,0 +1,178 @@
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
|
||||
/**
|
||||
* Extend the basic ItemSheet with some very simple modifications
|
||||
* @extends {ItemSheet}
|
||||
*/
|
||||
export class HawkmoonItemSheet extends ItemSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["fvtt-hawkmoon", "sheet", "item"],
|
||||
template: "systems/fvtt-hawkmoon-cyd/templates/item-sheet.html",
|
||||
dragDrop: [{ dragSelector: null, dropSelector: null }],
|
||||
width: 620,
|
||||
height: 550
|
||||
//tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_getHeaderButtons() {
|
||||
let buttons = super._getHeaderButtons();
|
||||
// Add "Post to chat" button
|
||||
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
|
||||
buttons.unshift(
|
||||
{
|
||||
class: "post",
|
||||
icon: "fas fa-comment",
|
||||
onclick: ev => { }
|
||||
})
|
||||
return buttons
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
const bodyHeight = position.height - 192;
|
||||
sheetBody.css("height", bodyHeight);
|
||||
if (this.item.type.includes('weapon')) {
|
||||
position.width = 640;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
const objectData = duplicate(this.object)
|
||||
let formData = {
|
||||
title: this.title,
|
||||
id: this.id,
|
||||
type: objectData.type,
|
||||
img: objectData.img,
|
||||
name: objectData.name,
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
attributs: HawkmoonUtility.getAttributs(),
|
||||
system: objectData.system,
|
||||
limited: this.object.limited,
|
||||
options: this.options,
|
||||
owner: this.document.isOwner,
|
||||
description: await TextEditor.enrichHTML(this.object.system.description, {async: true}),
|
||||
mr: (this.object.type == 'specialisation'),
|
||||
isGM: game.user.isGM
|
||||
}
|
||||
|
||||
if ( objectData.type == "don") {
|
||||
formData.sacrifice = await TextEditor.enrichHTML(this.object.system.sacrifice, {async: true})
|
||||
}
|
||||
//this.options.editable = !(this.object.origin == "embeddedItem");
|
||||
console.log("ITEM DATA", formData, this);
|
||||
return formData;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_getHeaderButtons() {
|
||||
let buttons = super._getHeaderButtons();
|
||||
buttons.unshift({
|
||||
class: "post",
|
||||
icon: "fas fa-comment",
|
||||
onclick: ev => this.postItem()
|
||||
});
|
||||
return buttons
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
postItem() {
|
||||
let chatData = duplicate(HawkmoonUtility.data(this.item));
|
||||
if (this.actor) {
|
||||
chatData.actor = { id: this.actor.id };
|
||||
}
|
||||
// Don't post any image for the item (which would leave a large gap) if the default image is used
|
||||
if (chatData.img.includes("/blank.png")) {
|
||||
chatData.img = null;
|
||||
}
|
||||
// JSON object for easy creation
|
||||
chatData.jsondata = JSON.stringify(
|
||||
{
|
||||
compendium: "postedItem",
|
||||
payload: chatData,
|
||||
});
|
||||
|
||||
renderTemplate('systems/fvtt-Hawkmoon-rpg/templates/post-item.html', chatData).then(html => {
|
||||
let chatOptions = HawkmoonUtility.chatDataSetup(html);
|
||||
ChatMessage.create(chatOptions)
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) return;
|
||||
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item")
|
||||
const item = this.object.options.actor.getOwnedItem(li.data("item-id"))
|
||||
item.sheet.render(true);
|
||||
});
|
||||
|
||||
html.find('.delete-subitem').click(ev => {
|
||||
this.deleteSubitem(ev);
|
||||
})
|
||||
html.find('.edit-prediction').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred[index].name = ev.currentTarget.value
|
||||
this.object.update( { 'data.predilections': pred })
|
||||
})
|
||||
html.find('.delete-prediction').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred.splice(index,1)
|
||||
this.object.update( { 'data.predilections': pred })
|
||||
})
|
||||
html.find('.use-prediction').change(ev => {
|
||||
const li = $(ev.currentTarget).parents(".prediction-item")
|
||||
let index = li.data("prediction-index")
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred[index].used = ev.currentTarget.checked
|
||||
this.object.update( { 'data.predilections': pred })
|
||||
})
|
||||
html.find('#add-predilection').click(ev => {
|
||||
let pred = duplicate(this.object.system.predilections)
|
||||
pred.push( { name: "Nouvelle prédilection", used: false })
|
||||
this.object.update( { 'data.predilections': pred })
|
||||
})
|
||||
// Update Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
let itemId = li.data("item-id");
|
||||
let itemType = li.data("item-type");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
get template() {
|
||||
let type = this.item.type;
|
||||
return `systems/fvtt-mournblade/templates/item-${type}-sheet.html`;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
return this.object.update(formData);
|
||||
}
|
||||
}
|
31
modules/hawkmoon-item.js
Normal file
31
modules/hawkmoon-item.js
Normal file
@ -0,0 +1,31 @@
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
|
||||
export const defaultItemImg = {
|
||||
competence: "systems/fvtt-hawkmoon-cyd/assets/icons/competence.webp",
|
||||
arme: "systems/fvtt-hawkmoon-cyd/assets/icons/arme.webp",
|
||||
capacite: "systems/fvtt-hawkmoon-cyd/assets/icons/capacite.webp",
|
||||
don: "systems/fvtt-hawkmoon-cyd/assets/icons/don.webp",
|
||||
equipement: "systems/fvtt-hawkmoon-cyd/assets/icons/equipement.webp",
|
||||
monnaie: "systems/fvtt-hawkmoon-cyd/assets/icons/monnaie.webp",
|
||||
pacte: "systems/fvtt-hawkmoon-cyd/assets/icons/pacte.webp",
|
||||
predilection: "systems/fvtt-hawkmoon-cyd/assets/icons/predilection.webp",
|
||||
protection: "systems/fvtt-hawkmoon-cyd/assets/icons/protection.webp",
|
||||
rune: "systems/fvtt-hawkmoon-cyd/assets/icons/rune.webp",
|
||||
tendance: "systems/fvtt-hawkmoon-cyd/assets/icons/tendance.webp",
|
||||
traitchaotique: "systems/fvtt-hawkmoon-cyd/assets/icons/traitchaotique.webp",
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the basic ItemSheet with some very simple modifications
|
||||
* @extends {ItemSheet}
|
||||
*/
|
||||
export class HawkmoonItem extends Item {
|
||||
|
||||
constructor(data, context) {
|
||||
if (!data.img) {
|
||||
data.img = defaultItemImg[data.type];
|
||||
}
|
||||
super(data, context);
|
||||
}
|
||||
|
||||
}
|
134
modules/hawkmoon-main.js
Normal file
134
modules/hawkmoon-main.js
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Hawkmoon system
|
||||
* Author: Uberwald
|
||||
* Software License: Prop
|
||||
*/
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Import Modules
|
||||
import { HawkmoonActor } from "./hawkmoon-actor.js";
|
||||
import { HawkmoonItemSheet } from "./hawkmoon-item-sheet.js";
|
||||
import { HawkmoonActorSheet } from "./hawkmoon-actor-sheet.js";
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
import { HawkmoonCombat } from "./hawkmoon-combat.js";
|
||||
import { HawkmoonItem } from "./hawkmoon-item.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/************************************************************************************/
|
||||
Hooks.once("init", async function () {
|
||||
console.log(`Initializing Hawkmoon RPG`);
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// preload handlebars templates
|
||||
HawkmoonUtility.preloadHandlebarsTemplates();
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Set an initiative formula for the system
|
||||
CONFIG.Combat.initiative = {
|
||||
formula: "1d6",
|
||||
decimals: 1
|
||||
};
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.socket.on("system.fvtt-hawkmoon-cyd", data => {
|
||||
HawkmoonUtility.onSocketMesssage(data);
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Define custom Entity classes
|
||||
CONFIG.Combat.documentClass = HawkmoonCombat
|
||||
CONFIG.Actor.documentClass = HawkmoonActor
|
||||
CONFIG.Item.documentClass = HawkmoonItem
|
||||
game.system.hawkmon = {
|
||||
HawkmoonUtility
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Register sheet application classes
|
||||
Actors.unregisterSheet("core", ActorSheet);
|
||||
Actors.registerSheet("fvtt-hawkmoon-cyd", HawkmoonActorSheet, { types: ["personnage"], makeDefault: true })
|
||||
//Actors.registerSheet("fvtt-hawkmoon-cyd", HawkmoonNPCSheet, { types: ["npc"], makeDefault: false });
|
||||
|
||||
Items.unregisterSheet("core", ItemSheet);
|
||||
Items.registerSheet("fvtt-hawkmoon-cyd", HawkmoonItemSheet, { makeDefault: true })
|
||||
|
||||
HawkmoonUtility.init();
|
||||
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
function welcomeMessage() {
|
||||
ChatMessage.create({
|
||||
user: game.user.id,
|
||||
whisper: [game.user.id],
|
||||
content: `<div id="welcome-message-Hawkmoon"><span class="rdd-roll-part">
|
||||
<strong>Bienvenue dans Hawkmoon !</strong>
|
||||
<p>Les livres de Hawkmoon sont nécessaires pour jouer : https://www.titam-france.fr</p>
|
||||
<p>Hawkmoon est jeude rôle publié par Titam France/Sombres projets, tout les droits leur appartiennent.<p>
|
||||
` });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Register world usage statistics
|
||||
function registerUsageCount( registerKey ) {
|
||||
if ( game.user.isGM ) {
|
||||
game.settings.register(registerKey, "world-key", {
|
||||
name: "Unique world key",
|
||||
scope: "world",
|
||||
config: false,
|
||||
default: "",
|
||||
type: String
|
||||
});
|
||||
|
||||
let worldKey = game.settings.get(registerKey, "world-key")
|
||||
if ( worldKey == undefined || worldKey == "" ) {
|
||||
worldKey = randomID(32)
|
||||
game.settings.set(registerKey, "world-key", worldKey )
|
||||
}
|
||||
// Simple API counter
|
||||
let regURL = `https://www.uberwald.me/fvtt_appcount/count.php?name="${registerKey}"&worldKey="${worldKey}"&version="${game.release.generation}.${game.release.build}"&system="${game.system.id}"&systemversion="${game.system.version}"`
|
||||
//$.ajaxSetup({
|
||||
//headers: { 'Access-Control-Allow-Origin': '*' }
|
||||
//})
|
||||
$.ajax(regURL)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
Hooks.once("ready", function () {
|
||||
|
||||
HawkmoonUtility.ready();
|
||||
// User warning
|
||||
if (!game.user.isGM && game.user.character == undefined) {
|
||||
ui.notifications.info("Attention ! Aucun personnage n'est relié au joueur !");
|
||||
ChatMessage.create({
|
||||
content: "<b>ATTENTION</b> Le joueur " + game.user.name + " n'est relié à aucun personnage !",
|
||||
user: game.user._id
|
||||
});
|
||||
}
|
||||
|
||||
registerUsageCount('fvtt-hawkmoon-cyd')
|
||||
welcomeMessage()
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
Hooks.on("chatMessage", (html, content, msg) => {
|
||||
if (content[0] == '/') {
|
||||
let regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
if (game.system.mournblade.commands.processChatCommand(commands, content, msg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
79
modules/hawkmoon-roll-dialog.js
Normal file
79
modules/hawkmoon-roll-dialog.js
Normal file
@ -0,0 +1,79 @@
|
||||
import { HawkmoonUtility } from "./hawkmoon-utility.js";
|
||||
|
||||
export class HawkmoonRollDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async create(actor, rollData ) {
|
||||
|
||||
let options = { classes: ["HawkmoonDialog"], width: 340, height: 420, 'z-index': 99999 };
|
||||
let html = await renderTemplate('systems/fvtt-hawkmoon-cyd/templates/roll-dialog-generic.html', rollData);
|
||||
|
||||
return new HawkmoonRollDialog(actor, rollData, html, options );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(actor, rollData, html, options, close = undefined) {
|
||||
let conf = {
|
||||
title: "Test de Capacité",
|
||||
content: html,
|
||||
buttons: {
|
||||
rolld10: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Lancer 1d10",
|
||||
callback: () => { this.roll("1d10") }
|
||||
},
|
||||
rolld20: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Lancer 1d20",
|
||||
callback: () => { this.roll("1d20") }
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Annuler",
|
||||
callback: () => { this.close() }
|
||||
} },
|
||||
close: close
|
||||
}
|
||||
|
||||
super(conf, options);
|
||||
|
||||
this.actor = actor
|
||||
this.rollData = rollData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
roll ( dice) {
|
||||
this.rollData.mainDice = dice
|
||||
HawkmoonUtility.rollHawkmoon( this.rollData )
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
var dialog = this;
|
||||
function onLoad() {
|
||||
}
|
||||
$(function () { onLoad(); });
|
||||
|
||||
html.find('#modificateur').change(async (event) => {
|
||||
this.rollData.modificateur = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#difficulte').change(async (event) => {
|
||||
this.rollData.difficulte = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#attrKey').change(async (event) => {
|
||||
this.rollData.attrKey = String(event.currentTarget.value)
|
||||
})
|
||||
html.find('#runemode').change(async (event) => {
|
||||
this.rollData.runemode = String(event.currentTarget.value)
|
||||
})
|
||||
html.find('#runeame').change(async (event) => {
|
||||
this.rollData.runeame = Number(event.currentTarget.value)
|
||||
})
|
||||
html.find('#doubleD20').change(async (event) => {
|
||||
this.rollData.doubleD20 = event.currentTarget.checked
|
||||
})
|
||||
}
|
||||
}
|
662
modules/hawkmoon-utility.js
Normal file
662
modules/hawkmoon-utility.js
Normal file
@ -0,0 +1,662 @@
|
||||
/* -------------------------------------------- */
|
||||
import { HawkmoonCombat } from "./hawkmoon-combat.js";
|
||||
import { HawkmoonCommands } from "./hawkmoon-commands.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class HawkmoonUtility {
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async init() {
|
||||
Hooks.on('renderChatLog', (log, html, data) => HawkmoonUtility.chatListeners(html))
|
||||
Hooks.on("getChatLogEntryContext", (html, options) => HawkmoonUtility.chatRollMenu(html, options))
|
||||
|
||||
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
||||
HawkmoonUtility.pushInitiativeOptions(html, options);
|
||||
})
|
||||
Hooks.on("dropCanvasData", (canvas, data) => {
|
||||
HawkmoonUtility.dropItemOnToken(canvas, data)
|
||||
});
|
||||
|
||||
this.rollDataStore = {}
|
||||
this.defenderStore = {}
|
||||
HawkmoonCommands.init();
|
||||
|
||||
Handlebars.registerHelper('count', function (list) {
|
||||
return list.length;
|
||||
})
|
||||
Handlebars.registerHelper('includes', function (array, val) {
|
||||
return array.includes(val);
|
||||
})
|
||||
Handlebars.registerHelper('upper', function (text) {
|
||||
return text.toUpperCase();
|
||||
})
|
||||
Handlebars.registerHelper('lower', function (text) {
|
||||
return text.toLowerCase()
|
||||
})
|
||||
Handlebars.registerHelper('upperFirst', function (text) {
|
||||
if (typeof text !== 'string') return text
|
||||
return text.charAt(0).toUpperCase() + text.slice(1)
|
||||
})
|
||||
Handlebars.registerHelper('notEmpty', function (list) {
|
||||
return list.length > 0;
|
||||
})
|
||||
Handlebars.registerHelper('mul', function (a, b) {
|
||||
return parseInt(a) * parseInt(b);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getModificateurOptions() {
|
||||
let opt = []
|
||||
for (let i = -15; i <= 15; i++) {
|
||||
opt.push(`<option value="${i}">${i}</option>`)
|
||||
}
|
||||
return opt.concat("\n")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getPointAmeOptions() {
|
||||
let opt = []
|
||||
for (let i = 1; i <= 20; i++) {
|
||||
opt.push(`<option value="${i}">${i}</option>`)
|
||||
}
|
||||
return opt.concat("\n")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getAttributs() {
|
||||
return { adr: "Adresse", pui: "Puissance", cla: "Clairvoyance", pre: "Présence", tre: "Trempe" }
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static pushInitiativeOptions(html, options) {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getSkills() {
|
||||
return this.skills
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async ready() {
|
||||
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills")
|
||||
this.skills = skills.map(i => i.toObject())
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendiumData(compendium) {
|
||||
const pack = game.packs.get(compendium);
|
||||
return await pack?.getDocuments() ?? [];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumData = await HawkmoonUtility.loadCompendiumData(compendium);
|
||||
return compendiumData.filter(filter);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getOptionsStatusList() {
|
||||
return this.optionsStatusList;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static async chatListeners(html) {
|
||||
|
||||
html.on("click", '.predilection-reroll', async event => {
|
||||
let predIdx = $(event.currentTarget).data("predilection-index")
|
||||
let messageId = HawkmoonUtility.findChatMessageId(event.currentTarget)
|
||||
let message = game.messages.get(messageId)
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
await actor.setPredilectionUsed(rollData.competence._id, predIdx)
|
||||
rollData.competence = duplicate(actor.getCompetence(rollData.competence._id))
|
||||
HawkmoonUtility.rollHawkmoon(rollData)
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async preloadHandlebarsTemplates() {
|
||||
|
||||
const templatePaths = [
|
||||
'systems/fvtt-hawkmoon-cyd/templates/editor-notes-gm.html',
|
||||
'systems/fvtt-hawkmoon-cyd/templates/partial-item-description.html',
|
||||
'systems/fvtt-hawkmoon-cyd/templates/partial-list-niveau.html'
|
||||
]
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static removeChatMessageId(messageId) {
|
||||
if (messageId) {
|
||||
game.messages.get(messageId)?.delete();
|
||||
}
|
||||
}
|
||||
|
||||
static findChatMessageId(current) {
|
||||
return HawkmoonUtility.getChatMessageId(HawkmoonUtility.findChatMessage(current));
|
||||
}
|
||||
|
||||
static getChatMessageId(node) {
|
||||
return node?.attributes.getNamedItem('data-message-id')?.value;
|
||||
}
|
||||
|
||||
static findChatMessage(current) {
|
||||
return HawkmoonUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'))
|
||||
}
|
||||
|
||||
static findNodeMatching(current, predicate) {
|
||||
if (current) {
|
||||
if (predicate(current)) {
|
||||
return current;
|
||||
}
|
||||
return HawkmoonUtility.findNodeMatching(current.parentElement, predicate);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static createDirectOptionList(min, max) {
|
||||
let options = {};
|
||||
for (let i = min; i <= max; i++) {
|
||||
options[`${i}`] = `${i}`;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildListOptions(min, max) {
|
||||
let options = ""
|
||||
for (let i = min; i <= max; i++) {
|
||||
options += `<option value="${i}">${i}</option>`
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getTarget() {
|
||||
if (game.user.targets && game.user.targets.size == 1) {
|
||||
for (let target of game.user.targets) {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getDefenseState(actorId) {
|
||||
return this.defenderStore[actorId];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static updateRollData(rollData) {
|
||||
|
||||
let id = rollData.rollId;
|
||||
let oldRollData = this.rollDataStore[id] || {};
|
||||
let newRollData = mergeObject(oldRollData, rollData);
|
||||
this.rollDataStore[id] = newRollData;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static saveRollData(rollData) {
|
||||
game.socket.emit("system.fvtt-hawkmoon-cyd", {
|
||||
name: "msg_update_roll", data: rollData
|
||||
}); // Notify all other clients of the roll
|
||||
this.updateRollData(rollData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getRollData(id) {
|
||||
return this.rollDataStore[id];
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static onSocketMesssage(msg) {
|
||||
//console.log("SOCKET MESSAGE", msg.name, game.user.character.id, msg.data.defenderId);
|
||||
if (msg.name == "msg_update_defense_state") {
|
||||
this.updateDefenseState(msg.data.defenderId, msg.data.rollId);
|
||||
}
|
||||
if (msg.name == "msg_update_roll") {
|
||||
this.updateRollData(msg.data);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static chatDataSetup(content, modeOverride, isRoll = false, forceWhisper) {
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
rollMode: modeOverride || game.settings.get("core", "rollMode"),
|
||||
content: content
|
||||
};
|
||||
|
||||
if (["gmroll", "blindroll"].includes(chatData.rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);
|
||||
if (chatData.rollMode === "blindroll") chatData["blind"] = true;
|
||||
else if (chatData.rollMode === "selfroll") chatData["whisper"] = [game.user];
|
||||
|
||||
if (forceWhisper) { // Final force !
|
||||
chatData["speaker"] = ChatMessage.getSpeaker();
|
||||
chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper);
|
||||
}
|
||||
|
||||
return chatData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async showDiceSoNice(roll, rollMode) {
|
||||
if (game.modules.get("dice-so-nice")?.active) {
|
||||
if (game.dice3d) {
|
||||
let whisper = null;
|
||||
let blind = false;
|
||||
rollMode = rollMode ?? game.settings.get("core", "rollMode");
|
||||
switch (rollMode) {
|
||||
case "blindroll": //GM only
|
||||
blind = true;
|
||||
case "gmroll": //GM + rolling player
|
||||
whisper = this.getUsers(user => user.isGM);
|
||||
break;
|
||||
case "roll": //everybody
|
||||
whisper = this.getUsers(user => user.active);
|
||||
break;
|
||||
case "selfroll":
|
||||
whisper = [game.user.id];
|
||||
break;
|
||||
}
|
||||
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeResult(rollData) {
|
||||
if (rollData.mainDice == "1d20") {
|
||||
let diceValue = rollData.roll.terms[0].results[0].result
|
||||
diceValue *= (rollData.doubleD20) ? 2 : 1
|
||||
//console.log("PAIR/IMP", diceValue)
|
||||
if (diceValue % 2 == 1) {
|
||||
//console.log("PAIR/IMP2", diceValue)
|
||||
rollData.finalResult -= rollData.roll.terms[0].results[0].result // Substract value
|
||||
if (diceValue == 1 || diceValue == 11) {
|
||||
rollData.isDramatique = true
|
||||
rollData.isSuccess = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//console.log("Result : ", rollData)
|
||||
if (rollData.difficulte > 0 && !rollData.isDramatique) {
|
||||
rollData.isSuccess = (rollData.finalResult >= rollData.difficulte)
|
||||
rollData.isHeroique = ((rollData.finalResult - rollData.difficulte) >= 10)
|
||||
rollData.isDramatique = ((rollData.finalResult - rollData.difficulte) <= -10)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async rollHawkmoon(rollData) {
|
||||
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
if (rollData.attrKey == "tochoose") { // No attr selected, force address
|
||||
rollData.attrKey = "adr"
|
||||
}
|
||||
if (!rollData.attr) {
|
||||
rollData.actionImg = "systems/fvtt-hawkmoon-cyd/assets/icons/" + actor.system.attributs[rollData.attrKey].labelnorm + ".webp"
|
||||
rollData.attr = duplicate(actor.system.attributs[rollData.attrKey])
|
||||
}
|
||||
|
||||
rollData.diceFormula = rollData.mainDice
|
||||
if (rollData.doubleD20) { // Multiply result !
|
||||
rollData.diceFormula += "*2"
|
||||
if (!rollData.isReroll) {
|
||||
actor.changeEclat(-1)
|
||||
}
|
||||
}
|
||||
//console.log("BEFORE COMP", rollData)
|
||||
if (rollData.competence) {
|
||||
rollData.predilections = duplicate(rollData.competence.system.predilections.filter(pred => !pred.used) || [])
|
||||
let compmod = (rollData.competence.system.niveau == 0) ? -3 : 0
|
||||
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.system.niveau}+${rollData.modificateur}+${compmod}`
|
||||
} else {
|
||||
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
|
||||
}
|
||||
|
||||
if (rollData.arme && rollData.arme.type == "arme") {
|
||||
rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}`
|
||||
}
|
||||
|
||||
if (rollData.rune) {
|
||||
rollData.runeduree = Math.ceil((rollData.runeame + 3) / 3)
|
||||
if (rollData.runemode == "inscrire") {
|
||||
rollData.runeduree *= 2
|
||||
}
|
||||
if (rollData.runemode == "prononcer") {
|
||||
rollData.runeduree = 1
|
||||
}
|
||||
}
|
||||
|
||||
let myRoll = new Roll(rollData.diceFormula).roll({ async: false })
|
||||
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
||||
rollData.roll = myRoll
|
||||
console.log(">>>> ", myRoll)
|
||||
|
||||
rollData.finalResult = myRoll.total
|
||||
this.computeResult(rollData)
|
||||
|
||||
if (rollData.rune) {
|
||||
let subAme = rollData.runeame
|
||||
if (rollData.isEchec && !rollData.isDramatique) {
|
||||
subAme = Math.ceil((subAme + 1) / 2)
|
||||
}
|
||||
actor.subPointsAme(rollData.runemode, subAme)
|
||||
}
|
||||
|
||||
this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-generic-result.html`, rollData)
|
||||
}, rollData)
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async bonusRollHawkmoon(rollData) {
|
||||
rollData.bonusFormula = rollData.addedBonus
|
||||
|
||||
let bonusRoll = new Roll(rollData.bonusFormula).roll({ async: false })
|
||||
await this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode"));
|
||||
rollData.bonusRoll = bonusRoll
|
||||
|
||||
rollData.finalResult += rollData.bonusRoll.total
|
||||
|
||||
this.computeResult(rollData)
|
||||
|
||||
this.createChatWithRollMode(rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-generic-result.html`, rollData)
|
||||
}, rollData)
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getUsers(filter) {
|
||||
return game.users.filter(filter).map(user => user.data._id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipients(rollMode, name) {
|
||||
switch (rollMode) {
|
||||
case "blindroll": return this.getUsers(user => user.isGM);
|
||||
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
|
||||
case "selfroll": return [game.user.id];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getWhisperRecipientsAndGMs(name) {
|
||||
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
|
||||
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static blindMessageToGM(chatOptions) {
|
||||
let chatGM = duplicate(chatOptions);
|
||||
chatGM.whisper = this.getUsers(user => user.isGM);
|
||||
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
|
||||
console.log("blindMessageToGM", chatGM);
|
||||
game.socket.emit("system.fvtt-weapons-of-the-gods", { msg: "msg_gm_chat_message", data: chatGM });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async searchItem(dataItem) {
|
||||
let item;
|
||||
if (dataItem.pack) {
|
||||
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id);
|
||||
} else {
|
||||
item = game.items.get(dataItem.id)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static split3Columns(data) {
|
||||
|
||||
let array = [[], [], []];
|
||||
if (data == undefined) return array;
|
||||
|
||||
let col = 0;
|
||||
for (let key in data) {
|
||||
let keyword = data[key];
|
||||
keyword.key = key; // Self-reference
|
||||
array[col].push(keyword);
|
||||
col++;
|
||||
if (col == 3) col = 0;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async createChatMessage(name, rollMode, chatOptions, rollData = undefined) {
|
||||
switch (rollMode) {
|
||||
case "blindroll": // GM only
|
||||
if (!game.user.isGM) {
|
||||
this.blindMessageToGM(chatOptions);
|
||||
|
||||
chatOptions.whisper = [game.user.id];
|
||||
chatOptions.content = "Message only to the GM";
|
||||
}
|
||||
else {
|
||||
chatOptions.whisper = this.getUsers(user => user.isGM);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
|
||||
break;
|
||||
}
|
||||
chatOptions.alias = chatOptions.alias || name
|
||||
let msg = await ChatMessage.create(chatOptions)
|
||||
console.log("=======>", rollData)
|
||||
msg.setFlag("world", "mournblade-roll", rollData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getBasicRollData() {
|
||||
let rollData = {
|
||||
rollId: randomID(16),
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
modificateursOptions: this.getModificateurOptions(),
|
||||
pointAmeOptions: this.getPointAmeOptions(),
|
||||
difficulte: 0,
|
||||
modificateur: 0,
|
||||
}
|
||||
HawkmoonUtility.updateWithTarget(rollData)
|
||||
return rollData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static updateWithTarget(rollData) {
|
||||
let target = HawkmoonUtility.getTarget()
|
||||
if (target) {
|
||||
rollData.defenderTokenId = target.id
|
||||
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
||||
rollData.armeDefense = defender.getBestDefenseValue()
|
||||
if ( rollData.armeDefense) {
|
||||
rollData.difficulte = rollData.armeDefense.system.totalDefensif
|
||||
} else {
|
||||
ui.notifications.warn("Aucune arme de défense équipée, difficulté manuelle à positionner.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static createChatWithRollMode(name, chatOptions, rollData = undefined) {
|
||||
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions, rollData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static applyBonneAventureRoll(li, changed, addedBonus) {
|
||||
let msgId = li.data("message-id")
|
||||
let msg = game.messages.get(msgId)
|
||||
if (msg) {
|
||||
let rollData = msg.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.changeBonneAventure(changed)
|
||||
rollData.isReroll = true
|
||||
rollData.textBonus = "Bonus de Points d'Aventure"
|
||||
if (addedBonus == "reroll") {
|
||||
HawkmoonUtility.rollHawkmoon(rollData)
|
||||
} else {
|
||||
rollData.addedBonus = addedBonus
|
||||
HawkmoonUtility.bonusRollHawkmoon(rollData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static applyEclatRoll(li, changed, addedBonus) {
|
||||
let msgId = li.data("message-id")
|
||||
let msg = game.messages.get(msgId)
|
||||
if (msg) {
|
||||
let rollData = msg.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
actor.changeEclat(changed)
|
||||
rollData.isReroll = true
|
||||
rollData.textBonus = "Bonus d'Eclat"
|
||||
rollData.addedBonus = addedBonus
|
||||
HawkmoonUtility.bonusRollHawkmoon(rollData)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static chatRollMenu(html, options) {
|
||||
let canApply = li => canvas.tokens.controlled.length && li.find(".mournblade-roll").length
|
||||
let canApplyBALoyal = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
return (!rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "loyal")
|
||||
}
|
||||
let canApplyPELoyal = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
return (!rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "loyal")
|
||||
}
|
||||
let canApplyBAChaotique = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
return (!rollData.isReroll && actor.getBonneAventure() > 0 && actor.getAlignement() == "chaotique")
|
||||
}
|
||||
let canApplyBAChaotique3 = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
return (!rollData.isReroll && actor.getBonneAventure() > 2 && actor.getAlignement() == "chaotique")
|
||||
}
|
||||
let canApplyPEChaotique = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
return (!rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "chaotique")
|
||||
}
|
||||
let hasPredilection = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
if (rollData.competence) {
|
||||
let nbPred = rollData.competence.data.predilections.filter(pred => !pred.used).length
|
||||
return (!rollData.isReroll && rollData.competence && nbPred > 0)
|
||||
}
|
||||
return false
|
||||
}
|
||||
let canCompetenceDouble = function (li) {
|
||||
let message = game.messages.get(li.attr("data-message-id"))
|
||||
let rollData = message.getFlag("world", "mournblade-roll")
|
||||
let actor = game.actors.get(rollData.actorId)
|
||||
if (rollData.competence) {
|
||||
return rollData.competence.data.doublebonus
|
||||
}
|
||||
return false
|
||||
}
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouer +3 (1 point de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyBALoyal,
|
||||
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -1, "+3")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouer +6 (1 point de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyBALoyal && canCompetenceDouble,
|
||||
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -1, "+6")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouer +1d6 (1 point de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyBAChaotique,
|
||||
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -1, "+1d6")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouer +2d6 (1 point de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyBAChaotique && canCompetenceDouble,
|
||||
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -1, "+2d6")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Relancer le dé (3 points de Bonne Aventure)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyBAChaotique3,
|
||||
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -3, "reroll")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouter +10 (1 Point d'Eclat)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyPELoyal,
|
||||
callback: li => HawkmoonUtility.applyEclatRoll(li, -1, "+10")
|
||||
}
|
||||
)
|
||||
options.push(
|
||||
{
|
||||
name: "Ajouter +20 (1 Point d'Eclat)",
|
||||
icon: "<i class='fas fa-user-plus'></i>",
|
||||
condition: canApply && canApplyPELoyal && canCompetenceDouble,
|
||||
callback: li => HawkmoonUtility.applyEclatRoll(li, -1, "+20")
|
||||
}
|
||||
)
|
||||
return options
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async confirmDelete(actorSheet, li) {
|
||||
let itemId = li.data("item-id");
|
||||
let msgTxt = "<p>Are you sure to remove this Item ?";
|
||||
let buttons = {
|
||||
delete: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Yes, remove it",
|
||||
callback: () => {
|
||||
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
|
||||
li.slideUp(200, () => actorSheet.render(false));
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: "Cancel"
|
||||
}
|
||||
}
|
||||
msgTxt += "</p>";
|
||||
let d = new Dialog({
|
||||
title: "Confirm removal",
|
||||
content: msgTxt,
|
||||
buttons: buttons,
|
||||
default: "cancel"
|
||||
});
|
||||
d.render(true);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user