Fixed so that creating regions without behaviors work for players. Fixed so that creating regions with behaviors works via GmEmit for players

This commit is contained in:
WBHarry 2026-05-02 13:54:13 +02:00
parent 4558fbdcf6
commit 02a489e8f7
4 changed files with 89 additions and 47 deletions

View file

@ -1,4 +1,4 @@
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
import { emitAsGM, emitGMCreate, GMUpdateEvent } from '../systemRegistration/socket.mjs';
export default class DhpChatMessage extends foundry.documents.ChatMessage {
targetHook = null;
@ -258,28 +258,51 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
const effects = selectedArea.effects.map(effect => this.system.action.item.effects.get(effect).uuid);
const { shape: type, size: range } = selectedArea;
const shapeData = CONFIG.Canvas.layers.regions.layerClass.getTemplateShape({ type, range });
const scene = game.scenes.get(game.user.viewedScene);
const level = scene.levels.find(x => x.isView);
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
}
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
},
{ create: true }
);
}] : [],
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 }
);
};
const needsGMExecution = effects.length > 0;
if (needsGMExecution && !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]);