Gestion des hordes et divers améliorations + traduction espagnole
This commit is contained in:
@ -7,6 +7,35 @@ import { BoLUtility } from "../system/bol-utility.js";
|
||||
*/
|
||||
export class BoLActor extends Actor {
|
||||
|
||||
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 == 'horde') {
|
||||
let weapon = {
|
||||
name: game.i18n.localize("BOL.ui.hordeAttack"), type: "item",
|
||||
img: "ui/icons/attaque_melee.webp",
|
||||
system: foundry.utils.duplicate(game.bol.config.defaultNaturalWeapon)
|
||||
}
|
||||
weapon.system.properties.attackModifiers = 1
|
||||
weapon.system.properties.damage = "1d6M"
|
||||
data.items = [ weapon ]
|
||||
|
||||
data.img = "systems/bol/ui/icons/icon-horde-token.webp"
|
||||
data.prototypeToken = { texture: "systems/bol/ui/icons/icon-horde-token.webp" }
|
||||
}
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
/** @override */
|
||||
prepareData() {
|
||||
|
||||
@ -18,9 +47,31 @@ export class BoLActor extends Actor {
|
||||
this.chartype = 'tough'
|
||||
this.villainy = true
|
||||
}
|
||||
if (this.type == "horde") {
|
||||
let weapon = this.items.find(i => i.type === "item" && i.system.subtype === "weapon")
|
||||
// Check if the horde attack is inline with the hordesize
|
||||
if (weapon?.system?.properties?.attackModifiers != this.system.hordesize) {
|
||||
this.updateEmbeddedDocuments('Item', [{ _id: weapon.id, 'system.properties.attackModifiers': this.system.hordesize }])
|
||||
}
|
||||
}
|
||||
|
||||
super.prepareData()
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onCreateOperation(documents, operation, user) {
|
||||
await super._onCreateOperation(documents, operation, user);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getTokenSizeFromHordeSize(hordeSize) {
|
||||
hordeSize = hordeSize || this.system.hordesize
|
||||
// If size > 50 then max is 50
|
||||
let size = Math.min(hordeSize, 20)
|
||||
// Compute the size of the token from 1 to 5
|
||||
let tokenSize = Math.max((size / 4), 1) // Never below 1
|
||||
return tokenSize
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _preCreate(data, options, user) {
|
||||
@ -39,7 +90,7 @@ export class BoLActor extends Actor {
|
||||
if (this.type === 'character') {
|
||||
return true
|
||||
}
|
||||
return (this.type === 'encounter' && this.chartype == "adversary")
|
||||
return (this.type === 'encounter' && this.chartype == "adversary")
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -205,7 +256,7 @@ export class BoLActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
addXPLog(type, name, cost, value) {
|
||||
let xplog = {
|
||||
name: "XP : "+game.i18n.localize(type), type: "feature",
|
||||
name: "XP : " + game.i18n.localize(type), type: "feature",
|
||||
img: "icons/magic/symbols/chevron-elipse-circle-blue.webp",
|
||||
system: {
|
||||
subtype: "xplog", properties: {
|
||||
@ -264,7 +315,7 @@ export class BoLActor extends Actor {
|
||||
xp.spent += nextXP
|
||||
this.update({ [`system.xp`]: xp })
|
||||
this.updateEmbeddedDocuments('Item', [{ _id: career._id, 'system.rank': career.system.rank + 1 }])
|
||||
this.addXPLog("career", career.name, nextXP, career.system.rank+1)
|
||||
this.addXPLog("career", career.name, nextXP, career.system.rank + 1)
|
||||
} else {
|
||||
ui.notifications.warn("Pas assez de points d'expérience !")
|
||||
}
|
||||
@ -419,7 +470,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
|
||||
isSorcerer() {
|
||||
return (this.careers.find(item => item.system.properties.sorcerer ))
|
||||
return (this.careers.find(item => item.system.properties.sorcerer))
|
||||
}
|
||||
isAlchemist() {
|
||||
return (this.careers.find(item => item.system.properties.alchemist))
|
||||
@ -612,7 +663,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
/*-------------------------------------------- */
|
||||
getSorcererBonus() {
|
||||
let sorcerer = this.careers.find(item => item.system.properties.sorcerer )
|
||||
let sorcerer = this.careers.find(item => item.system.properties.sorcerer)
|
||||
if (sorcerer) {
|
||||
return sorcerer.system.rank
|
||||
}
|
||||
@ -799,7 +850,7 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
if (this.system.resources.hp.value < -5 && !dead) {
|
||||
await this.createEmbeddedDocuments("ActiveEffect", [
|
||||
{ name: game.i18n.localize('EFFECT.StatusDead'), icon: 'icons/svg/skull.svg', statuses: 'dead' }
|
||||
{ name: game.i18n.localize('EFFECT.StatusDead'), icon: 'icons/svg/skull.svg', statuses: 'dead' }
|
||||
])
|
||||
}
|
||||
ChatMessage.create({
|
||||
@ -896,6 +947,34 @@ export class BoLActor extends Actor {
|
||||
if (data.system?.resources) {
|
||||
this.checkNumeric(data.system.resources)
|
||||
}
|
||||
// Apply changes in Horde size to Token width/height
|
||||
if (this.type == "horde" ) {
|
||||
if (data?.system?.hordesize) { // If horde size is changed}
|
||||
let newHP = data.system.hordesize * this.system.hordebasehp
|
||||
if (newHP != this.system.resources.hp.value) {
|
||||
data.system.resources = { hp: { value: newHP, max: newHP } } // Update HP
|
||||
}
|
||||
let tokenSize = this.getTokenSizeFromHordeSize(data?.system?.hordesize)
|
||||
if (this.isToken && (tokenSize !== this.token.width)) {
|
||||
this.token.update({ width: tokenSize, height: tokenSize })
|
||||
} else {
|
||||
if (tokenSize && (tokenSize !== this.prototypeToken.width)) {
|
||||
if (!foundry.utils.hasProperty(data, "prototypeToken.width")) {
|
||||
data.prototypeToken ||= {};
|
||||
data.prototypeToken.height = tokenSize;
|
||||
data.prototypeToken.width = tokenSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data?.system?.hordebasehp) {
|
||||
let newHP = this.system.hordesize * data.system.hordebasehp
|
||||
if (newHP != this.system.resources.hp.value) {
|
||||
data.system.resources = { hp: { value : newHP, max: newHP} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super._preUpdate(data, options, userId)
|
||||
}
|
||||
|
||||
@ -966,8 +1045,15 @@ export class BoLActor extends Actor {
|
||||
}
|
||||
/*-------------------------------------------- */
|
||||
async sufferDamage(damage) {
|
||||
let updates = {}
|
||||
let newHP = this.system.resources.hp.value - damage
|
||||
await this.update({ 'system.resources.hp.value': newHP })
|
||||
updates['system.resources.hp.value'] = newHP
|
||||
if (this.type == "horde") {
|
||||
let newSize = Math.ceil(newHP / this.system.hordebasehp)
|
||||
updates['system.hordesize'] = newSize
|
||||
}
|
||||
await this.update(updates)
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
217
module/actor/horde-sheet.js
Normal file
217
module/actor/horde-sheet.js
Normal file
@ -0,0 +1,217 @@
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
* @extends {ActorSheet}
|
||||
*/
|
||||
import { BoLRoll } from "../controllers/bol-rolls.js";
|
||||
import { BoLUtility } from "../system/bol-utility.js";
|
||||
|
||||
export class BoLHordeSheet extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
return foundry.utils.mergeObject(super.defaultOptions, {
|
||||
classes: ["bol", "sheet", "actor"],
|
||||
template: "systems/bol/templates/actor/horde-sheet.hbs",
|
||||
width: 860,
|
||||
height: 600,
|
||||
dragDrop: [{ dragSelector: ".items-list .item", dropSelector: null }],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }]
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
function onLoad() {
|
||||
let logoSheet = BoLUtility.getLogoActorSheet()
|
||||
$(".bol-actor-form").css("backgroundImage",`url(${logoSheet})`)
|
||||
}
|
||||
// Setup everything onload
|
||||
$(function () { onLoad(); });
|
||||
|
||||
// Everything below here is only needed if the sheet is editable
|
||||
if (!this.options.editable) return;
|
||||
|
||||
// Add Inventory Item
|
||||
html.find('.item-create').click(this._onItemCreate.bind(this));
|
||||
|
||||
// Update Inventory Item
|
||||
html.find('.item-edit').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
item.sheet.render(true);
|
||||
})
|
||||
// Equip/Unequip item
|
||||
html.find('.item-equip').click(this._onToggleEquip.bind(this));
|
||||
|
||||
html.find('.create_item').click(ev => {
|
||||
this.actor.createEmbeddedDocuments('Item', [{ name: "Nouvel Equipement", type: "item" }], { renderSheet: true });
|
||||
});
|
||||
|
||||
// Incr./Decr. career ranks
|
||||
html.find(".inc-dec-btns").click((ev) => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
if (li) {
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
if (item) {
|
||||
const dataset = ev.currentTarget.dataset;
|
||||
const operator = dataset.operator;
|
||||
const target = dataset.target;
|
||||
const incr = parseInt(dataset.incr)
|
||||
const min = parseInt(dataset.min)
|
||||
const max = parseInt(dataset.max) || 10000
|
||||
let value = eval("item." + target)
|
||||
value = value || 0
|
||||
//console.log("IncDec", item, target, value, operator, min, max)
|
||||
if (operator === "minus") {
|
||||
if (value >= min + incr) value -= incr;
|
||||
else value = min;
|
||||
}
|
||||
if (operator === "plus") {
|
||||
if (value <= max - incr) value += incr;
|
||||
else value = max;
|
||||
}
|
||||
let update = { [`${target}`]: value };
|
||||
item.update(update);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
Dialog.confirm({
|
||||
title: "Suppression",
|
||||
content: `Vous êtes sûr de vouloir supprimer cet item ?`,
|
||||
yes: () => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")])
|
||||
li.slideUp(200, () => this.render(false));
|
||||
},
|
||||
no: () => { },
|
||||
defaultYes: false,
|
||||
});
|
||||
});
|
||||
|
||||
// Rollable abilities.
|
||||
html.find('.rollable').click(this._onRoll.bind(this));
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/** @override */
|
||||
async getData(options) {
|
||||
const data = super.getData(options)
|
||||
let formData = foundry.utils.duplicate(data)
|
||||
|
||||
formData.config = game.bol.config
|
||||
formData.name = this.actor.name
|
||||
formData.img = this.actor.img
|
||||
formData.system = foundry.utils.duplicate(this.actor.system)
|
||||
formData.isGM = game.user.isGM
|
||||
formData.options = this.options
|
||||
formData.owner = this.document.isOwner
|
||||
formData.editScore = this.options.editScore
|
||||
formData.description = await TextEditor.enrichHTML(this.actor.system.description, {async: true})
|
||||
|
||||
formData.isGM = game.user.isGM
|
||||
|
||||
console.log("HORDE", formData)
|
||||
return formData;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset
|
||||
* @param {Event} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
_onItemCreate(event) {
|
||||
event.preventDefault();
|
||||
const header = event.currentTarget;
|
||||
// Get the type of item to create.
|
||||
const type = header.dataset.type;
|
||||
// Grab any data associated with this control.
|
||||
const data = foundry.utils.duplicate(header.dataset);
|
||||
// Initialize a default name.
|
||||
const name = `New ${type.capitalize()}`;
|
||||
// Prepare the item object.
|
||||
const itemData = {
|
||||
name: name,
|
||||
type: type,
|
||||
data: data
|
||||
};
|
||||
// Remove the type from the dataset since it's in the itemData.type prop.
|
||||
delete itemData.data["type"];
|
||||
|
||||
// Finally, create the item!
|
||||
return this.actor.createEmbeddedDocuments("Item", [itemData]);
|
||||
}
|
||||
|
||||
_onToggleEquip(event) {
|
||||
event.preventDefault();
|
||||
const li = $(event.currentTarget).closest(".item");
|
||||
const item = this.actor.items.get(li.data("itemId"));
|
||||
return this.actor.toggleEquipItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clickable rolls.
|
||||
* @param {Event} event The originating click event
|
||||
* @private
|
||||
*/
|
||||
_onRoll(event) {
|
||||
event.preventDefault();
|
||||
const element = event.currentTarget
|
||||
const dataset = element.dataset
|
||||
const rollType = dataset.rollType
|
||||
const li = $(event.currentTarget).closest(".item")
|
||||
switch (rollType) {
|
||||
case "attribute":
|
||||
BoLRoll.attributeCheck(this.actor, dataset.key, event)
|
||||
break;
|
||||
case "aptitude":
|
||||
BoLRoll.aptitudeCheck(this.actor, dataset.key, event)
|
||||
break;
|
||||
case "weapon":
|
||||
BoLRoll.weaponCheck(this.actor, event)
|
||||
break;
|
||||
case "spell":
|
||||
BoLRoll.spellCheck(this.actor, event)
|
||||
break;
|
||||
case "alchemy":
|
||||
BoLRoll.alchemyCheck(this.actor, event)
|
||||
break;
|
||||
case "protection":
|
||||
this.actor.rollProtection(li.data("item-id"))
|
||||
break;
|
||||
case "damage":
|
||||
this.actor.rollWeaponDamage(li.data("item-id"))
|
||||
break;
|
||||
case "aptitudexp":
|
||||
this.actor.incAptitudeXP(dataset.key)
|
||||
break;
|
||||
case "attributexp":
|
||||
this.actor.incAttributeXP(dataset.key)
|
||||
break;
|
||||
case "careerxp":
|
||||
this.actor.incCareerXP( li.data("item-id"))
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/** @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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user