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
|
|
@ -116,6 +116,7 @@
|
||||||
},
|
},
|
||||||
"notifs": {
|
"notifs": {
|
||||||
"error": {
|
"error": {
|
||||||
|
"cannot-equip-not-embedded": "Cannot equip an {itemType} when it isn't within an Actor",
|
||||||
"invalid-delta": "The delta for \"{name}\" is not a number, cannot finish processing the action."
|
"invalid-delta": "The delta for \"{name}\" is not a number, cannot finish processing the action."
|
||||||
},
|
},
|
||||||
"warn": {
|
"warn": {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { CommonItemData } from "./Common.mjs";
|
import { CommonItemData } from "./Common.mjs";
|
||||||
import { gameTerms } from "../../gameTerms.mjs";
|
import { gameTerms } from "../../gameTerms.mjs";
|
||||||
|
import { localizer } from "../../utils/Localizer.mjs";
|
||||||
import { requiredInteger } from "../helpers.mjs";
|
import { requiredInteger } from "../helpers.mjs";
|
||||||
|
|
||||||
const { fields } = foundry.data;
|
const { fields } = foundry.data;
|
||||||
|
const { hasProperty, mergeObject } = foundry.utils;
|
||||||
|
|
||||||
/** Used for Armour and Shields */
|
/** Used for Armour and Shields */
|
||||||
export class ProtectorData extends CommonItemData {
|
export class ProtectorData extends CommonItemData {
|
||||||
|
|
@ -41,6 +43,27 @@ export class ProtectorData extends CommonItemData {
|
||||||
super.prepareDerivedData();
|
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
|
// #region Getters
|
||||||
get locationString() {
|
get locationString() {
|
||||||
return [...this.location].join(`, `);
|
return [...this.location].join(`, `);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs";
|
import { barAttribute, optionalInteger, requiredInteger } from "../helpers.mjs";
|
||||||
import { CommonItemData } from "./Common.mjs";
|
import { CommonItemData } from "./Common.mjs";
|
||||||
import { gameTerms } from "../../gameTerms.mjs";
|
import { gameTerms } from "../../gameTerms.mjs";
|
||||||
|
import { localizer } from "../../utils/Localizer.mjs";
|
||||||
|
|
||||||
const { fields } = foundry.data;
|
const { fields } = foundry.data;
|
||||||
|
const { hasProperty, mergeObject } = foundry.utils;
|
||||||
|
|
||||||
export class WeaponData extends CommonItemData {
|
export class WeaponData extends CommonItemData {
|
||||||
// MARK: Schema
|
// MARK: Schema
|
||||||
|
|
@ -50,6 +52,27 @@ export class WeaponData extends CommonItemData {
|
||||||
super.prepareDerivedData();
|
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
|
// #region Getters
|
||||||
get traitString() {
|
get traitString() {
|
||||||
return [...this.traits].join(`, `);
|
return [...this.traits].join(`, `);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue