RC-111 | Prevent Items from being equipped when not embedded
This commit is contained in:
parent
fd3803698a
commit
16c46e9649
3 changed files with 47 additions and 0 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs";
|
||||
import { CommonItemData } from "./Common.mjs";
|
||||
import { gameTerms } from "../../gameTerms.mjs";
|
||||
import { localizer } from "../../utils/Localizer.mjs";
|
||||
|
||||
const { fields } = foundry.data;
|
||||
const { hasProperty, mergeObject } = foundry.utils;
|
||||
|
||||
export class WeaponData extends CommonItemData {
|
||||
// MARK: Schema
|
||||
|
|
@ -50,6 +52,27 @@ export class WeaponData extends CommonItemData {
|
|||
super.prepareDerivedData();
|
||||
};
|
||||
|
||||
// #region Lifecycle
|
||||
async _preUpdate(changes, options, user) {
|
||||
if (options.force && game.settings.get(`ripcrypt`, `devMode`)) { return };
|
||||
let valid = super._preUpdate(changes, options, user);
|
||||
|
||||
if (hasProperty(changes, `system.equipped`) && !this.parent.isEmbedded) {
|
||||
ui.notifications.error(localizer(
|
||||
`RipCrypt.notifs.error.cannot-equip-not-embedded`,
|
||||
{ itemType: `@TYPES.Item.${this.parent.type}` },
|
||||
));
|
||||
mergeObject(
|
||||
changes,
|
||||
{ "-=system.equipped": null },
|
||||
{ inplace: true, performDeletions: true },
|
||||
);
|
||||
return false;
|
||||
};
|
||||
return valid;
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Getters
|
||||
get traitString() {
|
||||
return [...this.traits].join(`, `);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue