mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-05 20:34:15 +02:00
[Fix] Player Created Regions (#1855)
* Fixed so that creating regions without behaviors work for players. Fixed so that creating regions with behaviors works via GmEmit for players * Updated previous uses of emitAsGM to emitGMUpdate * Fixed linting * Update module/documents/chatMessage.mjs Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com> --------- Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
This commit is contained in:
parent
54d1b2bdc0
commit
edbf5aa55f
13 changed files with 108 additions and 69 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
|
||||
import { emitGMUpdate, emitGMCreate, GMUpdateEvent } from '../systemRegistration/socket.mjs';
|
||||
|
||||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||
targetHook = null;
|
||||
|
|
@ -214,7 +214,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
const action = this.system.action;
|
||||
if (!action || !action?.hasSave) return;
|
||||
game.system.api.fields.ActionFields.SaveField.rollSave.call(action, token.actor, event).then(result =>
|
||||
emitAsGM(
|
||||
emitGMUpdate(
|
||||
GMUpdateEvent.UpdateSaveMessage,
|
||||
game.system.api.fields.ActionFields.SaveField.updateSaveMessage.bind(
|
||||
action,
|
||||
|
|
@ -259,27 +259,47 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
const { shape: type, size: range } = selectedArea;
|
||||
const shapeData = CONFIG.Canvas.layers.regions.layerClass.getTemplateShape({ type, range });
|
||||
|
||||
await canvas.regions.placeRegion(
|
||||
{
|
||||
name: selectedArea.name,
|
||||
shapes: [shapeData],
|
||||
restriction: { enabled: false, type: 'move', priority: 0 },
|
||||
behaviors: [
|
||||
{
|
||||
name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'),
|
||||
type: 'applyActiveEffect',
|
||||
system: {
|
||||
effects: effects
|
||||
}
|
||||
}
|
||||
],
|
||||
displayMeasurements: true,
|
||||
locked: false,
|
||||
ownership: { default: CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE },
|
||||
visibility: CONST.REGION_VISIBILITY.ALWAYS
|
||||
},
|
||||
{ create: true }
|
||||
);
|
||||
const scene = game.scenes.get(game.user.viewedScene);
|
||||
const level = scene.levels.find(x => x.isView);
|
||||
|
||||
const regionData = {
|
||||
name: selectedArea.name,
|
||||
levels: level ? [level.id] : [],
|
||||
shapes: [shapeData],
|
||||
restriction: { enabled: false, type: 'move', priority: 0 },
|
||||
behaviors:
|
||||
effects.length > 0
|
||||
? [
|
||||
{
|
||||
name: game.i18n.localize('TYPES.RegionBehavior.applyActiveEffect'),
|
||||
type: 'applyActiveEffect',
|
||||
system: {
|
||||
effects: effects
|
||||
}
|
||||
}
|
||||
]
|
||||
: [],
|
||||
displayMeasurements: true,
|
||||
locked: false,
|
||||
ownership: { default: CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE },
|
||||
visibility: CONST.REGION_VISIBILITY.ALWAYS
|
||||
};
|
||||
const placeRegion = data => {
|
||||
canvas.regions.placeRegion(data, { create: true });
|
||||
};
|
||||
|
||||
// Regions with effects must be placed by the GM
|
||||
if (effects.length > 0 && !game.user.isGM) {
|
||||
if (!game.users.activeGM)
|
||||
return ui.notifications.error(
|
||||
game.i18n.localize('DAGGERHEART.UI.Notifications.behaviorRegionRequiresGM')
|
||||
);
|
||||
|
||||
const region = await canvas.regions.placeRegion(regionData, { create: false });
|
||||
emitGMCreate('Region', placeRegion, region, scene.id);
|
||||
} else {
|
||||
placeRegion(regionData);
|
||||
}
|
||||
};
|
||||
|
||||
if (this.system.action.areas.length === 1) createArea(this.system.action.areas[0]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue