On ne peut pas tout donner

Limitation des types d'objets pouvant être donnés à différents acteurs
This commit is contained in:
Vincent Vandemeulebrouck 2022-12-03 15:33:16 +01:00
parent eaac9564b4
commit b1e27a9597
10 changed files with 116 additions and 76 deletions

View File

@ -132,12 +132,14 @@ 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 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)
}
}
}
/* -------------------------------------------- */
async createItem(name, type) {

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) {
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,7 +81,7 @@ export class RdDItem extends Item {
}
break;
case 'cout':
if(['monnaie'].includes(type)){
if (['monnaie'].includes(type)) {
return game.user.isGM;
}
break;
@ -102,8 +105,8 @@ export class RdDItem extends Item {
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";
@ -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()
@ -230,12 +236,12 @@ export class RdDItem extends Item {
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 '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,8 +281,8 @@ 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];
}
@ -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}`]
);

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,11 +19,12 @@ 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)
if (actor.canReceive(item)) {
return {
destId: destItemId,
targetActorId: actorId,
targetActorId: actor.id,
itemId: item.id,
sourceActorId: item.actor?.id,
srcId: objetVersConteneur[item.id],
@ -31,6 +32,11 @@ export class RdDSheetUtility {
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 = () => { }) {
const dialog = await DialogSplitItem.create(item, async (item, split) => {

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>