Gestion de la Faune #587

Merged
uberwald merged 5 commits from VincentVk/foundryvtt-reve-de-dragon:v10 into v10 2022-12-03 23:16:36 +01:00
10 changed files with 116 additions and 76 deletions
Showing only changes of commit b1e27a9597 - Show all commits

View File

@ -132,10 +132,12 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
const destItemId = $(event.target)?.closest('.item').attr('data-item-id')
const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor.id, dragData, this.objetVersConteneur)
const callSuper = await this.actor.processDropItem(dropParams)
if (callSuper) {
await super._onDropItem(event, dragData)
const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur)
if (dropParams){
const callSuper = await this.actor.processDropItem(dropParams)
if (callSuper) {
await super._onDropItem(event, dragData)
}
}
}

View File

@ -145,7 +145,7 @@ export class RdDActor extends Actor {
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
if (this.isPersonnage()) this._prepareCharacterData(this)
if (this.isCreature()) this._prepareCreatureData(this)
if (this.isCreatureEntite()) this._prepareCreatureData(this)
if (this.isVehicule()) this._prepareVehiculeData(this)
this.computeEtatGeneral();
}
@ -193,10 +193,36 @@ export class RdDActor extends Actor {
}
}
canReceive(item) {
if (this.isCreature()) {
return item.type == 'competencecreature' || RdDItem.isItemInventaire(item);
}
if (this.isEntite()) {
return item.type == 'competencecreature';
}
if (this.isVehicule()) {
return RdDItem.isItemInventaire(item);
}
if (this.isPersonnage()) {
switch (item.type) {
case 'competencecreature': case 'tarot':
return false;
}
return true;
}
return false;
}
/* -------------------------------------------- */
isCreature() {
isCreatureEntite() {
return this.type == 'creature' || this.type == 'entite';
}
isCreature() {
return this.type == 'creature';
}
isEntite() {
return this.type == 'entite';
}
/* -------------------------------------------- */
isPersonnage() {
return this.type == 'personnage';
@ -1175,13 +1201,13 @@ export class RdDActor extends Actor {
}
let result = true;
const item = this.getObjet(itemId);
if (item?.isEquipement() && sourceActorId == targetActorId) {
if (item?.isInventaire() && sourceActorId == targetActorId) {
// rangement
if (srcId != destId && itemId != destId) { // déplacement de l'objet
const src = this.getObjet(srcId);
const dest = this.getObjet(destId);
const cible = this.getContenantOrParent(dest);
const [empilable, message] = item.isEquipementEmpilable(dest);
const [empilable, message] = item.isInventaireEmpilable(dest);
if (empilable) {
await this.regrouperEquipementsSimilaires(item, dest);
result = false;
@ -1359,7 +1385,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
computePrixTotalEquipement() {
const valeur = this.items.filter(it => it.isEquipement())
const valeur = this.items.filter(it => it.isInventaire())
.map(it => it.valeurTotale())
.reduce(Misc.sum(), 0);
return valeur;
@ -2995,7 +3021,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
getHeureNaissance() {
if (this.isCreature()) {
if (this.isCreatureEntite()) {
return 0;
}
return this.system.heure;
@ -3003,7 +3029,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
ajustementAstrologique() {
if (this.isCreature()) {
if (this.isCreatureEntite()) {
return 0;
}
// selon l'heure de naissance...

View File

@ -30,9 +30,7 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */
_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!
if ("cout" in this.item.system && this.item.isVideOuNonConteneur()) {
if (this.item.isInventaire() && this.item.isVideOuNonConteneur()) {
buttons.unshift({
class: "vendre",
icon: "fas fa-comments-dollar",
@ -73,8 +71,8 @@ export class RdDItemSheet extends ItemSheet {
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
isSoins: false,
description: await TextEditor.enrichHTML(this.item.system.description, {async: true}),
descriptionmj: await TextEditor.enrichHTML(this.item.system.descriptionmj, {async: true})
description: await TextEditor.enrichHTML(this.item.system.description, { async: true }),
descriptionmj: await TextEditor.enrichHTML(this.item.system.descriptionmj, { async: true })
}
if (this.actor) {
formData.isOwned = true;
@ -97,18 +95,18 @@ export class RdDItemSheet extends ItemSheet {
formData.competences = competences.filter(it => RdDItemCompetence.isDraconic(it));
}
if (this.item.type == 'recettecuisine') {
formData.ingredients = await TextEditor.enrichHTML(this.object.system.ingredients, {async: true})
formData.ingredients = await TextEditor.enrichHTML(this.object.system.ingredients, { async: true })
}
if (this.item.type == 'extraitpoetique') {
formData.extrait = await TextEditor.enrichHTML(this.object.system.extrait, {async: true})
formData.texte = await TextEditor.enrichHTML(this.object.system.texte, {async: true})
formData.extrait = await TextEditor.enrichHTML(this.object.system.extrait, { async: true })
formData.texte = await TextEditor.enrichHTML(this.object.system.texte, { async: true })
}
if (this.item.type == 'recettealchimique') {
RdDAlchimie.processManipulation(this.item, this.actor && this.actor.id);
formData.manipulation_update = await TextEditor.enrichHTML(this.object.system.manipulation_update, {async: true})
formData.utilisation = await TextEditor.enrichHTML(this.object.system.utilisation, {async: true})
formData.enchantement = await TextEditor.enrichHTML(this.object.system.enchantement, {async: true})
formData.sureffet = await TextEditor.enrichHTML(this.object.system.sureffet, {async: true})
formData.manipulation_update = await TextEditor.enrichHTML(this.object.system.manipulation_update, { async: true })
formData.utilisation = await TextEditor.enrichHTML(this.object.system.utilisation, { async: true })
formData.enchantement = await TextEditor.enrichHTML(this.object.system.enchantement, { async: true })
formData.sureffet = await TextEditor.enrichHTML(this.object.system.sureffet, { async: true })
}
if (this.item.type == 'gemme') {
formData.gemmeTypeList = RdDGemme.getGemmeTypeOptionList();
@ -256,8 +254,10 @@ export class RdDItemSheet extends ItemSheet {
/** @override */
_updateObject(event, formData) {
// Données de bonus de cases ?
formData['system.bonuscase'] = RdDItemSort.buildBonusCaseStringFromFormData(formData.bonusValue, formData.caseValue);
if (this.item.type == 'sort') {
// Données de bonus de cases ?
formData['system.bonuscase'] = RdDItemSort.buildBonusCaseStringFromFormData(formData.bonusValue, formData.caseValue);
}
return this.item.update(formData);
}
@ -301,7 +301,7 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
if (this.actor) {
const dropParams = RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor.id, dragData, this.objetVersConteneur);
const dropParams = RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur);
await this.actor.processDropItem(dropParams);
await this.render(true);
}

View File

@ -1,10 +1,9 @@
import { DialogItemVente } from "./dialog-item-vente.js";
import { Grammar } from "./grammar.js";
import { Monnaie } from "./item-monnaie.js";
import { RdDHerbes } from "./rdd-herbes.js";
import { RdDUtility } from "./rdd-utility.js";
const typesObjetsEquipement = [
const typesObjetsInventaire = [
"arme",
"armure",
"conteneur",
@ -70,7 +69,11 @@ export class RdDItem extends Item {
return defaultItemImg[itemType];
}
static isEquipementFieldEditable(type, field) {
static isItemInventaire(newLocal) {
return typesObjetsInventaire.includes(newLocal.type);
}
static isFieldInventaireModifiable(type, field) {
switch (field) {
case 'quantite':
if (['conteneur'].includes(type)) {
@ -78,8 +81,8 @@ export class RdDItem extends Item {
}
break;
case 'cout':
if(['monnaie'].includes(type)){
return game.user.isGM;
if (['monnaie'].includes(type)) {
return game.user.isGM;
}
break;
}
@ -98,12 +101,12 @@ export class RdDItem extends Item {
constructor(itemData, context) {
if (!itemData.img) {
itemData.img = RdDItem.getDefaultImg(itemData.type);
}
}
super(itemData, context);
}
}
static getTypesObjetsEquipement() {
return typesObjetsEquipement
static getItemTypesInventaire() {
return typesObjetsInventaire
}
static getTypesOeuvres() {
@ -113,11 +116,14 @@ export class RdDItem extends Item {
isCompetencePersonnage() {
return this.type == 'competence'
}
isCompetenceCreature() {
return this.type == 'competencecreature'
}
isCompetence() {
return typesObjetsCompetence.includes(this.type)
}
isEquipement() {
return typesObjetsEquipement.includes(this.type)
isInventaire() {
return RdDItem.isItemInventaire(this)
}
isOeuvre() {
return typesObjetsOeuvres.includes(this.type)
@ -136,7 +142,7 @@ export class RdDItem extends Item {
}
getItemGroup() {
if (this.isEquipement()) return "equipement";
if (this.isInventaire()) return "equipement";
if (this.isOeuvre()) return "oeuvre";
if (this.isDraconique()) return "draconique";
if (this.isConnaissance()) return "connaissance";
@ -180,7 +186,7 @@ export class RdDItem extends Item {
getEncTotal() {
return this.getEnc() * this.getQuantite();
}
}
getEnc() {
switch (this.type) {
@ -202,7 +208,7 @@ export class RdDItem extends Item {
prepareDerivedData() {
super.prepareDerivedData();
if (this.isEquipement()) {
if (this.isInventaire()) {
this.system.encTotal = this.getEncTotal();
if (this.isPotion()) {
this.prepareDataPotion()
@ -229,13 +235,13 @@ export class RdDItem extends Item {
case 'potion': return this._actionOrWarnQuantiteZero('Boire', warn);
case 'livre': return this._actionOrWarnQuantiteZero('Lire', warn);
case 'conteneur': return 'Ouvrir';
case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined;
case 'queue': case 'ombre': return this.system.refoulement>0 ? 'Refouler' : undefined;
case 'herbe': return this.isHerbeAPotion() ? this._actionOrWarnQuantiteZero('Décoction', warn) : undefined;
case 'queue': case 'ombre': return this.system.refoulement > 0 ? 'Refouler' : undefined;
}
return undefined;
}
_actionOrWarnQuantiteZero(actionName, warn){
_actionOrWarnQuantiteZero(actionName, warn) {
if ((this.system.quantite ?? 0) <= 0) {
if (warn) {
ui.notifications.warn(`Vous n'avez plus de ${this.name}.`);
@ -275,14 +281,14 @@ export class RdDItem extends Item {
/* -------------------------------------------- */
// détermine si deux équipements sont similaires: de même type, et avec les même champs hormis la quantité
isEquipementEmpilable(other) {
if (!other || !this.isEquipement()) {
isInventaireEmpilable(other) {
if (!other || !this.isInventaire()) {
return [false, undefined];
}
if (this.system.quantite == undefined) {
return [false, `Impossible de regrouper des ${this.type}, ils ne sont pas empilables`];
}
}
else if (this.type != other.type) {
return [false, `Impossible de regrouper des ${this.type} avec des ${other.type}`];
}
@ -309,7 +315,7 @@ export class RdDItem extends Item {
ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le proposer`);
return;
}
await DialogItemVente.display(this, async (vente) => {
await DialogItemVente.display(this, async (vente) => {
vente["properties"] = this.getProprietes();
if (vente.isOwned) {
if (vente.quantiteNbLots * vente.tailleLot > vente.quantiteMax) {
@ -318,7 +324,7 @@ export class RdDItem extends Item {
}
}
vente.jsondata = JSON.stringify(vente.item);
console.log(vente);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', vente);
ChatMessage.create(RdDUtility.chatDataSetup(html));
@ -459,7 +465,7 @@ export class RdDItem extends Item {
`<b>Fatigue</b>: ${this.system.fatigue}`,
`<b>Difficulté</b>: ${this.system.difficulte}`
].concat([
this.system.cacher_points_de_tache ? [] :`<b>Points de Tâche</b>: ${this.system.points_de_tache}`
this.system.cacher_points_de_tache ? [] : `<b>Points de Tâche</b>: ${this.system.points_de_tache}`
]).concat([
`<b>Points de Tâche atteints</b>: ${this.system.points_de_tache_courant}`]
);
@ -563,10 +569,10 @@ export class RdDItem extends Item {
return [`<b>Inconnue</b>`]
}
let properties = [
`<b>Malignité</b>: ${this.system.malignite}`,
`<b>Périodicité</b>: ${this.system.periodicite}`,
`<b>Dommages</b>: ${this.system.dommages}`
]
`<b>Malignité</b>: ${this.system.malignite}`,
`<b>Périodicité</b>: ${this.system.periodicite}`,
`<b>Dommages</b>: ${this.system.dommages}`
]
if (this.system.remedesconnus) {
properties.push(`<b>Remedes</b>: ${this.system.remedes}`)
}

View File

@ -42,7 +42,8 @@ export class Misc {
}
static typeName(type, subType) {
return game.i18n.localize(`${type.toUpperCase()}.Type${Misc.upperFirst(subType)}`);
return subType ? game.i18n.localize(`${type.toUpperCase()}.Type${Misc.upperFirst(subType)}`)
: '';
}
/**

View File

@ -246,7 +246,7 @@ export class RdDCombatManager extends Combat {
if (actions.length > 0) {
return actions;
}
if (actor.isCreature()) {
if (actor.isCreatureEntite()) {
actions = actions.concat(RdDCombatManager.listActionsCreature(actor.itemTypes['competencecreature']));
} else {
// Recupération des items 'arme'
@ -821,7 +821,7 @@ export class RdDCombat {
essais: {}
};
if (this.attacker.isCreature()) {
if (this.attacker.isCreatureEntite()) {
RdDItemCompetenceCreature.setRollDataCreature(rollData);
}
else if (arme) {
@ -1079,7 +1079,7 @@ export class RdDCombat {
show: {}
};
if (this.defender.isCreature()) {
if (this.defender.isCreatureEntite()) {
RdDItemCompetenceCreature.setRollDataCreature(defenderRoll);
}
@ -1158,7 +1158,7 @@ export class RdDCombat {
show: {}
};
if (this.defender.isCreature()) {
if (this.defender.isCreatureEntite()) {
RdDItemCompetenceCreature.setRollDataCreature(rollData);
}
return rollData;

View File

@ -45,7 +45,7 @@ export class RdDPossession {
defender: defender,
targetToken: Targets.extractTokenData(target)
};
if (attacker.isCreature()) {
if (attacker.isCreatureEntite()) {
RdDItemCompetenceCreature.setRollDataCreature(rollData)
}

View File

@ -19,17 +19,23 @@ export class RdDSheetUtility {
return $(event.currentTarget)?.parents(".item");
}
static prepareItemDropParameters(destItemId, actorId, dragData, objetVersConteneur) {
static prepareItemDropParameters(destItemId, actor, dragData, objetVersConteneur) {
const item = fromUuidSync(dragData.uuid)
return {
destId: destItemId,
targetActorId: actorId,
itemId: item.id,
sourceActorId: item.actor?.id,
srcId: objetVersConteneur[item.id],
onEnleverConteneur: () => { delete objetVersConteneur[item.id]; },
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
if (actor.canReceive(item)) {
return {
destId: destItemId,
targetActorId: actor.id,
itemId: item.id,
sourceActorId: item.actor?.id,
srcId: objetVersConteneur[item.id],
onEnleverConteneur: () => { delete objetVersConteneur[item.id]; },
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
}
}
else {
ui.notifications.warn(`Impossible de donner ${item.name} à ${actor.name}: ${item.type} / ${actor.type}`);
}
return undefined;
}
static async splitItem(item, actor, onSplit = () => { }) {

View File

@ -330,7 +330,7 @@ export class RdDUtility {
);
Handlebars.registerHelper('linkCompendium', (compendium, id, name) => `@Compendium[${compendium}.${id}]{${name}}`);
Handlebars.registerHelper('uniteQuantite', (type) => RdDItem.getUniteQuantite(type));
Handlebars.registerHelper('isEquipementFieldEditable', (type, field) => RdDItem.isEquipementFieldEditable(type, field));
Handlebars.registerHelper('isFieldInventaireModifiable', (type, field) => RdDItem.isFieldInventaireModifiable(type, field));
Handlebars.registerHelper('getFrequenceRarete', (rarete, field) => Environnement.getFrequenceRarete(rarete, field));
Handlebars.registerHelper('either', (a, b) => a ?? b);
return loadTemplates(templatePaths);
@ -344,7 +344,7 @@ export class RdDUtility {
/* -------------------------------------------- */
static async selectObjetType(actorSheet) {
let typeObjets = RdDItem.getTypesObjetsEquipement();
let typeObjets = RdDItem.getItemTypesInventaire();
let options = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
for (let typeName of typeObjets) {
options += `<option value="${typeName}">${typeName}</option>`
@ -467,8 +467,7 @@ export class RdDUtility {
formData.potions = this.arrayOrEmpty(itemTypes['potion']);
formData.ingredients = this.arrayOrEmpty(itemTypes['ingredient']);
formData.herbes = this.arrayOrEmpty(itemTypes['herbe']);
formData.monnaie = this.arrayOrEmpty(itemTypes['monnaie']);
formData.monnaie.sort(Monnaie.triValeurEntiere());
formData.monnaie = this.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere());
formData.nourritureboissons = this.arrayOrEmpty(itemTypes['nourritureboisson']);
formData.gemmes = this.arrayOrEmpty(itemTypes['gemme']);

View File

@ -1,20 +1,20 @@
<div class="form-group">
<label for="system.qualite">Qualité</label>
<input class="attribute-value" type="text" name="system.qualite" value="{{system.qualite}}" data-dtype="Number"
{{#unless (isEquipementFieldEditable type 'qualite')}}disabled{{/unless}}/>
{{#unless (isFieldInventaireModifiable type 'qualite')}}disabled{{/unless}}/>
</div>
<div class="form-group">
<label for="system.encombrement">Encombrement</label>
<input class="attribute-value" type="text" name="system.encombrement" value="{{system.encombrement}}" data-dtype="Number"
{{#unless (isEquipementFieldEditable type 'encombrement')}}disabled{{/unless}}/>
{{#unless (isFieldInventaireModifiable type 'encombrement')}}disabled{{/unless}}/>
</div>
<div class="form-group">
<label for="system.quantite">Quantité {{uniteQuantite type}}</label>
<input class="attribute-value" type="text" name="system.quantite" value="{{system.quantite}}" data-dtype="Number"
{{#unless (isEquipementFieldEditable type 'quantite')}}disabled{{/unless}}/>
{{#unless (isFieldInventaireModifiable type 'quantite')}}disabled{{/unless}}/>
</div>
<div class="form-group item-cout">
<label for="system.cout">Prix (sols) </label>
<input class="attribute-value" type="text" name="system.cout" value="{{system.cout}}" data-dtype="Number"
{{#unless (isEquipementFieldEditable type 'cout')}}disabled{{/unless}}/>
{{#unless (isFieldInventaireModifiable type 'cout')}}disabled{{/unless}}/>
</div>