Fix bestiary import

This commit is contained in:
2022-11-10 23:43:51 +01:00
parent 927ddf1328
commit f88fbf977d
20 changed files with 607 additions and 25 deletions

View File

@ -43,6 +43,7 @@ export class HawkmoonActorSheet extends ActorSheet {
protections: duplicate(this.actor.getArmors()),
historique: duplicate(this.actor.getHistorique() || {}),
talents: duplicate(this.actor.getTalents() || {}),
talentsCell: this.getCelluleTalents(),
profils: duplicate(this.actor.getProfils() || {}),
combat: this.actor.getCombatValues(),
equipements: duplicate(this.actor.getEquipments()),
@ -58,7 +59,20 @@ export class HawkmoonActorSheet extends ActorSheet {
return formData;
}
/* -------------------------------------------- */
getCelluleTalents( ) {
let talents = []
for(let cellule of game.actors) {
if (cellule.type == "cellule") {
let found = cellule.system.members.find( it => it.id == this.actor.id)
if (found) {
talents = talents.concat( cellule.getTalents() )
}
}
}
return talents
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
@ -105,10 +119,14 @@ export class HawkmoonActorSheet extends ActorSheet {
this.actor.incDecQuantity( li.data("item-id"), +1 );
} );
html.find('.roll-initiative').click((event) => {
this.actor.rollAttribut("pre", 1)
})
html.find('.roll-attribut').click((event) => {
const li = $(event.currentTarget).parents(".item")
let attrKey = li.data("attr-key")
this.actor.rollAttribut(attrKey)
this.actor.rollAttribut(attrKey, 2)
})
html.find('.roll-competence').click((event) => {
const li = $(event.currentTarget).parents(".item")

View File

@ -82,7 +82,18 @@ export class HawkmoonActor extends Actor {
return armes
}
/* -------------------------------------------- */
/* ----------------------- --------------------- */
addMember( actorId) {
let members = duplicate(this.system.members)
members.push( {id: actorId} )
this.update ({'system.members': members})
}
async removeMember(actorId) {
let members = this.system.members.filter(it => it.id != actorId )
this.update ({'system.members': members})
}
/* ----------------------- --------------------- */
getEquipments() {
return this.items.filter(item => item.type == "equipement")
}
@ -99,6 +110,12 @@ export class HawkmoonActor extends Actor {
getTalents() {
return this.items.filter(item => item.type == "talent")
}
getRessources() {
return this.items.filter(item => item.type == "ressource")
}
getContacts() {
return this.items.filter(item => item.type == "contact")
}
/* -------------------------------------------- */
getSkills() {
let comp = []
@ -396,16 +413,13 @@ export class HawkmoonActor extends Actor {
}
/* -------------------------------------------- */
getBestDefenseValue() {
let defenseList = this.items.filter(item => (item.type == "arme" || item.type == "bouclier") && item.system.equipped)
let defenseList = this.items.filter(item => (item.type == "arme") && item.system.equipped)
let maxDef = 0
let bestArme
for (let arme of defenseList) {
if (arme.type == "arme" && arme.system.isdefense) {
if (arme.type == "arme" ) {
arme = this.prepareArme(arme)
}
if (arme.type == "bouclier") {
arme = this.prepareBouclier(arme)
}
if (arme.system.totalDefensif > maxDef) {
maxDef = arme.system.totalDefensif
bestArme = duplicate(arme)
@ -470,8 +484,9 @@ export class HawkmoonActor extends Actor {
}
/* -------------------------------------------- */
async rollAttribut(attrKey) {
async rollAttribut(attrKey, multiplier = 1) {
let rollData = this.getCommonRollData(attrKey)
rollData.multiplier = multiplier
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
rollDialog.render(true)
}
@ -479,6 +494,7 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
async rollCompetence(attrKey, compId) {
let rollData = this.getCommonRollData(attrKey, compId)
rollData.multiplier = 1 // Attr multiplier, always 1 in competence mode
console.log("RollDatra", rollData)
let rollDialog = await HawkmoonRollDialog.create(this, rollData)
rollDialog.render(true)

View File

@ -0,0 +1,165 @@
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { HawkmoonUtility } from "./hawkmoon-utility.js";
import { HawkmoonAutomation } from "./hawkmoon-automation.js";
/* -------------------------------------------- */
const __ALLOWED_ITEM_CELLULE = { "talent": 1, "ressource": 1, "contact": 1}
/* -------------------------------------------- */
export class HawkmoonCelluleSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["fvtt-hawkmoon-cyd", "sheet", "actor"],
template: "systems/fvtt-hawkmoon-cyd/templates/cellule-sheet.html",
width: 640,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "talents" }],
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,
talents: duplicate(this.actor.getTalents() || {}),
ressources: duplicate(this.actor.getRessources()),
contacts: duplicate(this.actor.getContacts()),
members: this.getMembers(),
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
console.log("CELLULE : ", formData, this.object);
return formData;
}
/* -------------------------------------------- */
getMembers( ) {
let membersFull = []
for(let def of this.actor.system.members) {
let actor = game.actors.get(def.id)
membersFull.push( { name: actor.name, id: actor.id, img: actor.img } )
}
return membersFull
}
/* -------------------------------------------- */
/** @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('.actor-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let actorId = li.data("actor-id")
const actor = game.actors.get(actorId)
actor.sheet.render(true)
})
html.find('.actor-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item")
let actorId = li.data("actor-id")
this.actor.removeMember(actorId)
})
// 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('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
}
/* -------------------------------------------- */
async _onDropActor(event, dragData) {
const actor = fromUuidSync(dragData.uuid)
if (actor) {
this.actor.addMember(actor.id)
} else {
ui.notifications.warn("Cet acteur n'a pas été trouvé.")
}
super._onDropActor(event)
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
let data = event.dataTransfer.getData('text/plain')
let dataItem = JSON.parse(data)
let item = fromUuidSync(dataItem.uuid)
if (item.pack) {
item = await HawkmoonUtility.searchItem(item)
}
if ( __ALLOWED_ITEM_CELLULE[item.type]) {
super._onDropItem(event, dragData)
return
}
ui.notifications("Ce type d'item n'est pas autorisé sur une Cellule.")
}
/* -------------------------------------------- */
/** @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;
}
}

View File

@ -11,6 +11,7 @@
import { HawkmoonActor } from "./hawkmoon-actor.js";
import { HawkmoonItemSheet } from "./hawkmoon-item-sheet.js";
import { HawkmoonActorSheet } from "./hawkmoon-actor-sheet.js";
import { HawkmoonCelluleSheet } from "./hawkmoon-cellule-sheet.js";
import { HawkmoonUtility } from "./hawkmoon-utility.js";
import { HawkmoonCombat } from "./hawkmoon-combat.js";
import { HawkmoonItem } from "./hawkmoon-item.js";
@ -31,7 +32,7 @@ Hooks.once("init", async function () {
/* -------------------------------------------- */
// Set an initiative formula for the system
CONFIG.Combat.initiative = {
formula: "1d6",
formula: "1d10",
decimals: 1
};
@ -54,7 +55,7 @@ Hooks.once("init", async function () {
// 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 });
Actors.registerSheet("fvtt-hawkmoon-cyd", HawkmoonCelluleSheet, { types: ["cellule"], makeDefault: false });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("fvtt-hawkmoon-cyd", HawkmoonItemSheet, { makeDefault: true })

View File

@ -42,6 +42,23 @@ export class HawkmoonUtility {
return parseInt(a) * parseInt(b);
})
game.settings.register("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo", {
name: "Logo de pause",
scope: "world",
config: true,
requiresReload: true,
default: "logo_pause_resistance",
type: String,
choices: { // If choices are defined, the resulting setting will be a select menu
"hawkmoon_logo": "Hawmoon (Texte)",
"logo_pause_resistance": "Résistance",
"logo_pause_hawkmoon_stone": "Hawkmoon (Pierre)",
"logo_pause_hawkmoon_violet": "Hawkmoon (Violet)",
"logo_pause_hawkmoon_beiget": "Hawkmoon (Beige)",
"logo_pause_hawkmoon_rouge": "Hawkmoon (Rouge)"
},
})
}
/* -------------------------------------------- */
@ -79,6 +96,11 @@ export class HawkmoonUtility {
static async ready() {
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills")
this.skills = skills.map(i => i.toObject())
// Setup pause logo
let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo") + ".webp"
let logoImg = document.querySelector('#pause').children[0]
logoImg.setAttribute('style', `content: url(${logoPause})`)
}
/* -------------------------------------------- */
@ -333,7 +355,7 @@ export class HawkmoonUtility {
}
}
} else {
rollData.diceFormula += `+${rollData.attr.value}*2+${rollData.modificateur}`
rollData.diceFormula += `+${rollData.attr.value}*${rollData.multiplier}+${rollData.modificateur}`
}
// Ajout adversités