@rpgjs/server 5.0.0-alpha.36 → 5.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +278 -36
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +34 -3
- package/package.json +4 -4
- package/src/Player/MoveManager.ts +12 -2
- package/src/Player/Player.ts +6 -3
- package/src/rooms/map.ts +280 -22
package/dist/index.js
CHANGED
|
@@ -16895,7 +16895,30 @@ class RpgCommonMap {
|
|
|
16895
16895
|
const eventsMap = this.events();
|
|
16896
16896
|
const isSelfPlayer = !!playersMap[self.uuid];
|
|
16897
16897
|
const isOtherPlayer = !!playersMap[other.uuid];
|
|
16898
|
+
const isSelfEvent = !!eventsMap[self.uuid];
|
|
16898
16899
|
const isOtherEvent = !!eventsMap[other.uuid];
|
|
16900
|
+
const readScenarioOwnerId = (owner2) => {
|
|
16901
|
+
const scenarioOwnerId = owner2?._scenarioOwnerId ?? owner2?.scenarioOwnerId;
|
|
16902
|
+
return typeof scenarioOwnerId === "string" && scenarioOwnerId.length > 0 ? scenarioOwnerId : void 0;
|
|
16903
|
+
};
|
|
16904
|
+
const selfScenarioOwnerId = readScenarioOwnerId(selfOwner);
|
|
16905
|
+
const otherScenarioOwnerId = readScenarioOwnerId(otherOwner);
|
|
16906
|
+
if (selfScenarioOwnerId) {
|
|
16907
|
+
if (isOtherPlayer && other.uuid !== selfScenarioOwnerId) {
|
|
16908
|
+
return false;
|
|
16909
|
+
}
|
|
16910
|
+
if (isOtherEvent && otherScenarioOwnerId !== selfScenarioOwnerId) {
|
|
16911
|
+
return false;
|
|
16912
|
+
}
|
|
16913
|
+
}
|
|
16914
|
+
if (otherScenarioOwnerId) {
|
|
16915
|
+
if (isSelfPlayer && self.uuid !== otherScenarioOwnerId) {
|
|
16916
|
+
return false;
|
|
16917
|
+
}
|
|
16918
|
+
if (isSelfEvent && selfScenarioOwnerId !== otherScenarioOwnerId) {
|
|
16919
|
+
return false;
|
|
16920
|
+
}
|
|
16921
|
+
}
|
|
16899
16922
|
if (isSelfPlayer && isOtherPlayer) {
|
|
16900
16923
|
if (typeof selfOwner._throughOtherPlayer === "function") {
|
|
16901
16924
|
try {
|
|
@@ -19012,8 +19035,16 @@ function WithMoveManager(Base) {
|
|
|
19012
19035
|
stopMoveTo() {
|
|
19013
19036
|
const map = this.getCurrentMap();
|
|
19014
19037
|
if (!map) return;
|
|
19015
|
-
|
|
19016
|
-
|
|
19038
|
+
let strategies = [];
|
|
19039
|
+
try {
|
|
19040
|
+
strategies = this.getActiveMovements();
|
|
19041
|
+
} catch (error) {
|
|
19042
|
+
const message = error?.message ?? "";
|
|
19043
|
+
if (message.includes("unable to resolve entity")) {
|
|
19044
|
+
return;
|
|
19045
|
+
}
|
|
19046
|
+
throw error;
|
|
19047
|
+
}
|
|
19017
19048
|
const toRemove = strategies.filter((s) => s instanceof SeekAvoid || s instanceof LinearRepulsion);
|
|
19018
19049
|
if (toRemove.length > 0) {
|
|
19019
19050
|
toRemove.forEach((strategy) => {
|
|
@@ -22652,9 +22683,12 @@ const _RpgPlayer = class _RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
22652
22683
|
const map2 = this.getCurrentMap();
|
|
22653
22684
|
if (!map2) return;
|
|
22654
22685
|
const { events } = map2;
|
|
22686
|
+
const visibleMapEvents = Object.values(events?.() ?? {}).filter(
|
|
22687
|
+
(event) => map2.isEventVisibleForPlayer?.(event, this) ?? true
|
|
22688
|
+
);
|
|
22655
22689
|
const arrayEvents = [
|
|
22656
22690
|
...Object.values(this.events()),
|
|
22657
|
-
...
|
|
22691
|
+
...visibleMapEvents
|
|
22658
22692
|
];
|
|
22659
22693
|
for (let event of arrayEvents) {
|
|
22660
22694
|
if (event.onChanges) event.onChanges(this);
|
|
@@ -22781,7 +22815,7 @@ const _RpgPlayer = class _RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
22781
22815
|
entities.forEach((entity) => {
|
|
22782
22816
|
const event = map2.getEvent(entity.uuid);
|
|
22783
22817
|
const player = map2.getPlayer(entity.uuid);
|
|
22784
|
-
if (event) {
|
|
22818
|
+
if (event && (!map2.isEventVisibleForPlayer || map2.isEventVisibleForPlayer(event, this))) {
|
|
22785
22819
|
event.execMethod("onInShape", [shape, this]);
|
|
22786
22820
|
if (event._inShapes) {
|
|
22787
22821
|
event._inShapes.add(shape);
|
|
@@ -22799,7 +22833,7 @@ const _RpgPlayer = class _RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
22799
22833
|
entities.forEach((entity) => {
|
|
22800
22834
|
const event = map2.getEvent(entity.uuid);
|
|
22801
22835
|
const player = map2.getPlayer(entity.uuid);
|
|
22802
|
-
if (event) {
|
|
22836
|
+
if (event && (!map2.isEventVisibleForPlayer || map2.isEventVisibleForPlayer(event, this))) {
|
|
22803
22837
|
event.execMethod("onOutShape", [shape, this]);
|
|
22804
22838
|
if (event._inShapes) {
|
|
22805
22839
|
event._inShapes.delete(shape);
|
|
@@ -27614,6 +27648,23 @@ function superRefine(fn) {
|
|
|
27614
27648
|
return _superRefine(fn);
|
|
27615
27649
|
}
|
|
27616
27650
|
|
|
27651
|
+
var EventMode = /* @__PURE__ */ ((EventMode2) => {
|
|
27652
|
+
EventMode2["Shared"] = "shared";
|
|
27653
|
+
EventMode2["Scenario"] = "scenario";
|
|
27654
|
+
return EventMode2;
|
|
27655
|
+
})(EventMode || {});
|
|
27656
|
+
function EventData(options) {
|
|
27657
|
+
return (target) => {
|
|
27658
|
+
target.mode = options.mode || "shared" /* Shared */;
|
|
27659
|
+
target.width = options.width;
|
|
27660
|
+
target.height = options.height;
|
|
27661
|
+
target.hitbox = options.hitbox;
|
|
27662
|
+
target._name = options.name;
|
|
27663
|
+
target.prototype._name = options.name;
|
|
27664
|
+
target.prototype.mode = target.mode;
|
|
27665
|
+
};
|
|
27666
|
+
}
|
|
27667
|
+
|
|
27617
27668
|
var __defProp$2 = Object.defineProperty;
|
|
27618
27669
|
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
27619
27670
|
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
@@ -27920,6 +27971,14 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
27920
27971
|
this._shapeEntities = /* @__PURE__ */ new Map();
|
|
27921
27972
|
/** Enable/disable automatic tick processing (useful for unit tests) */
|
|
27922
27973
|
this._autoTickEnabled = true;
|
|
27974
|
+
/** Runtime templates for scenario events to instantiate per player */
|
|
27975
|
+
this._scenarioEventTemplates = [];
|
|
27976
|
+
/** Runtime registry of event mode by id */
|
|
27977
|
+
this._eventModeById = /* @__PURE__ */ new Map();
|
|
27978
|
+
/** Runtime registry of scenario owner by event id */
|
|
27979
|
+
this._eventOwnerById = /* @__PURE__ */ new Map();
|
|
27980
|
+
/** Runtime registry of spawned scenario event ids by player id */
|
|
27981
|
+
this._scenarioEventIdsByPlayer = /* @__PURE__ */ new Map();
|
|
27923
27982
|
this.autoSync = true;
|
|
27924
27983
|
this.hooks.callHooks("server-map-onStart", this).subscribe();
|
|
27925
27984
|
const isTest = room.env.TEST === "true" ? true : false;
|
|
@@ -27955,6 +28014,147 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
27955
28014
|
map.height = this.isPositiveNumber(worldMapInfo?.height) ? worldMapInfo.height : SAFE_MAP_HEIGHT;
|
|
27956
28015
|
}
|
|
27957
28016
|
}
|
|
28017
|
+
normalizeEventMode(mode) {
|
|
28018
|
+
return mode === EventMode.Scenario || mode === "scenario" ? EventMode.Scenario : EventMode.Shared;
|
|
28019
|
+
}
|
|
28020
|
+
resolveEventMode(eventObj) {
|
|
28021
|
+
if (!eventObj) return EventMode.Shared;
|
|
28022
|
+
if (eventObj.mode !== void 0) {
|
|
28023
|
+
return this.normalizeEventMode(eventObj.mode);
|
|
28024
|
+
}
|
|
28025
|
+
const eventDef = eventObj.event ?? eventObj;
|
|
28026
|
+
if (eventDef?.mode !== void 0) {
|
|
28027
|
+
return this.normalizeEventMode(eventDef.mode);
|
|
28028
|
+
}
|
|
28029
|
+
if (typeof eventDef === "function") {
|
|
28030
|
+
const staticMode = eventDef.mode;
|
|
28031
|
+
const prototypeMode = eventDef.prototype?.mode;
|
|
28032
|
+
if (staticMode !== void 0) {
|
|
28033
|
+
return this.normalizeEventMode(staticMode);
|
|
28034
|
+
}
|
|
28035
|
+
if (prototypeMode !== void 0) {
|
|
28036
|
+
return this.normalizeEventMode(prototypeMode);
|
|
28037
|
+
}
|
|
28038
|
+
}
|
|
28039
|
+
return EventMode.Shared;
|
|
28040
|
+
}
|
|
28041
|
+
resolveScenarioOwnerId(eventObj) {
|
|
28042
|
+
if (!eventObj) return void 0;
|
|
28043
|
+
const ownerId = eventObj.scenarioOwnerId ?? eventObj._scenarioOwnerId ?? eventObj.event?.scenarioOwnerId ?? eventObj.event?._scenarioOwnerId;
|
|
28044
|
+
return typeof ownerId === "string" && ownerId.length > 0 ? ownerId : void 0;
|
|
28045
|
+
}
|
|
28046
|
+
normalizeEventObject(eventObj) {
|
|
28047
|
+
if (eventObj && typeof eventObj === "object" && "event" in eventObj) {
|
|
28048
|
+
return eventObj;
|
|
28049
|
+
}
|
|
28050
|
+
return {
|
|
28051
|
+
event: eventObj
|
|
28052
|
+
};
|
|
28053
|
+
}
|
|
28054
|
+
cloneEventTemplate(eventObj) {
|
|
28055
|
+
const clone = { ...eventObj };
|
|
28056
|
+
if (clone.event && typeof clone.event === "object") {
|
|
28057
|
+
clone.event = { ...clone.event };
|
|
28058
|
+
}
|
|
28059
|
+
return clone;
|
|
28060
|
+
}
|
|
28061
|
+
buildRuntimeEventId(baseId, mode, scenarioOwnerId) {
|
|
28062
|
+
const fallbackId = baseId || generateShortUUID$1();
|
|
28063
|
+
if (mode !== EventMode.Scenario || !scenarioOwnerId) {
|
|
28064
|
+
return fallbackId;
|
|
28065
|
+
}
|
|
28066
|
+
const scopedId = `${fallbackId}::${scenarioOwnerId}`;
|
|
28067
|
+
if (!this.events()[scopedId]) {
|
|
28068
|
+
return scopedId;
|
|
28069
|
+
}
|
|
28070
|
+
return `${scopedId}::${generateShortUUID$1()}`;
|
|
28071
|
+
}
|
|
28072
|
+
setEventRuntimeMetadata(eventId, mode, scenarioOwnerId) {
|
|
28073
|
+
this._eventModeById.set(eventId, mode);
|
|
28074
|
+
if (mode === EventMode.Scenario && scenarioOwnerId) {
|
|
28075
|
+
this._eventOwnerById.set(eventId, scenarioOwnerId);
|
|
28076
|
+
const ids = this._scenarioEventIdsByPlayer.get(scenarioOwnerId) ?? /* @__PURE__ */ new Set();
|
|
28077
|
+
ids.add(eventId);
|
|
28078
|
+
this._scenarioEventIdsByPlayer.set(scenarioOwnerId, ids);
|
|
28079
|
+
return;
|
|
28080
|
+
}
|
|
28081
|
+
this._eventOwnerById.delete(eventId);
|
|
28082
|
+
}
|
|
28083
|
+
clearEventRuntimeMetadata(eventId) {
|
|
28084
|
+
this._eventModeById.delete(eventId);
|
|
28085
|
+
const ownerId = this._eventOwnerById.get(eventId);
|
|
28086
|
+
if (ownerId) {
|
|
28087
|
+
const ids = this._scenarioEventIdsByPlayer.get(ownerId);
|
|
28088
|
+
if (ids) {
|
|
28089
|
+
ids.delete(eventId);
|
|
28090
|
+
if (ids.size === 0) {
|
|
28091
|
+
this._scenarioEventIdsByPlayer.delete(ownerId);
|
|
28092
|
+
}
|
|
28093
|
+
}
|
|
28094
|
+
}
|
|
28095
|
+
this._eventOwnerById.delete(eventId);
|
|
28096
|
+
}
|
|
28097
|
+
getEventModeById(eventId) {
|
|
28098
|
+
const runtimeMode = this._eventModeById.get(eventId);
|
|
28099
|
+
if (runtimeMode) {
|
|
28100
|
+
return runtimeMode;
|
|
28101
|
+
}
|
|
28102
|
+
const event = this.getEvent(eventId);
|
|
28103
|
+
return this.normalizeEventMode(event?.mode);
|
|
28104
|
+
}
|
|
28105
|
+
getScenarioOwnerIdByEventId(eventId) {
|
|
28106
|
+
const runtimeOwnerId = this._eventOwnerById.get(eventId);
|
|
28107
|
+
if (runtimeOwnerId) {
|
|
28108
|
+
return runtimeOwnerId;
|
|
28109
|
+
}
|
|
28110
|
+
const event = this.getEvent(eventId);
|
|
28111
|
+
const ownerId = event?._scenarioOwnerId ?? event?.scenarioOwnerId;
|
|
28112
|
+
return typeof ownerId === "string" && ownerId.length > 0 ? ownerId : void 0;
|
|
28113
|
+
}
|
|
28114
|
+
isEventVisibleForPlayer(eventOrId, playerOrId) {
|
|
28115
|
+
const playerId = typeof playerOrId === "string" ? playerOrId : playerOrId?.id;
|
|
28116
|
+
if (!playerId) {
|
|
28117
|
+
return false;
|
|
28118
|
+
}
|
|
28119
|
+
const eventId = typeof eventOrId === "string" ? eventOrId : eventOrId?.id;
|
|
28120
|
+
if (!eventId) {
|
|
28121
|
+
return false;
|
|
28122
|
+
}
|
|
28123
|
+
const mode = this.getEventModeById(eventId);
|
|
28124
|
+
if (mode === EventMode.Shared) {
|
|
28125
|
+
return true;
|
|
28126
|
+
}
|
|
28127
|
+
const ownerId = this.getScenarioOwnerIdByEventId(eventId);
|
|
28128
|
+
return ownerId === playerId;
|
|
28129
|
+
}
|
|
28130
|
+
async spawnScenarioEventsForPlayer(player) {
|
|
28131
|
+
if (!player?.id || this._scenarioEventTemplates.length === 0) {
|
|
28132
|
+
return;
|
|
28133
|
+
}
|
|
28134
|
+
this.removeScenarioEventsForPlayer(player.id);
|
|
28135
|
+
for (const template of this._scenarioEventTemplates) {
|
|
28136
|
+
const clone = this.cloneEventTemplate(template);
|
|
28137
|
+
await this.createDynamicEvent(clone, { mode: EventMode.Scenario, scenarioOwnerId: player.id });
|
|
28138
|
+
}
|
|
28139
|
+
}
|
|
28140
|
+
removeScenarioEventsForPlayer(playerId) {
|
|
28141
|
+
const ids = this._scenarioEventIdsByPlayer.get(playerId);
|
|
28142
|
+
if (!ids || ids.size === 0) {
|
|
28143
|
+
return;
|
|
28144
|
+
}
|
|
28145
|
+
for (const eventId of [...ids]) {
|
|
28146
|
+
const event = this.getEvent(eventId);
|
|
28147
|
+
if (event && typeof event.remove === "function") {
|
|
28148
|
+
try {
|
|
28149
|
+
event.remove();
|
|
28150
|
+
continue;
|
|
28151
|
+
} catch {
|
|
28152
|
+
}
|
|
28153
|
+
}
|
|
28154
|
+
this.removeEvent(eventId);
|
|
28155
|
+
}
|
|
28156
|
+
this._scenarioEventIdsByPlayer.delete(playerId);
|
|
28157
|
+
}
|
|
27958
28158
|
/**
|
|
27959
28159
|
* Setup collision detection between players, events, and shapes
|
|
27960
28160
|
*
|
|
@@ -28039,7 +28239,7 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28039
28239
|
}
|
|
28040
28240
|
const eventId = player.id === entityA.uuid ? entityB.uuid : entityA.uuid;
|
|
28041
28241
|
const event = this.getEvent(eventId);
|
|
28042
|
-
if (event) {
|
|
28242
|
+
if (event && this.isEventVisibleForPlayer(eventId, player)) {
|
|
28043
28243
|
activeCollisions.add(collisionKey);
|
|
28044
28244
|
event.execMethod("onPlayerTouch", [player]);
|
|
28045
28245
|
}
|
|
@@ -28102,6 +28302,7 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28102
28302
|
*/
|
|
28103
28303
|
interceptorPacket(player, packet, conn) {
|
|
28104
28304
|
let obj = {};
|
|
28305
|
+
let packetValue = packet?.value;
|
|
28105
28306
|
if (!player) {
|
|
28106
28307
|
return null;
|
|
28107
28308
|
}
|
|
@@ -28124,13 +28325,25 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28124
28325
|
};
|
|
28125
28326
|
}
|
|
28126
28327
|
}
|
|
28328
|
+
if (packetValue && typeof packetValue === "object" && packetValue.events && typeof packetValue.events === "object") {
|
|
28329
|
+
const eventEntries = Object.entries(packetValue.events);
|
|
28330
|
+
const filteredEntries = eventEntries.filter(([eventId]) => this.isEventVisibleForPlayer(eventId, player));
|
|
28331
|
+
if (filteredEntries.length !== eventEntries.length) {
|
|
28332
|
+
packetValue = { ...packetValue };
|
|
28333
|
+
if (filteredEntries.length === 0) {
|
|
28334
|
+
delete packetValue.events;
|
|
28335
|
+
} else {
|
|
28336
|
+
packetValue.events = Object.fromEntries(filteredEntries);
|
|
28337
|
+
}
|
|
28338
|
+
}
|
|
28339
|
+
}
|
|
28127
28340
|
if (typeof packet.value == "string") {
|
|
28128
28341
|
return packet;
|
|
28129
28342
|
}
|
|
28130
28343
|
return {
|
|
28131
28344
|
...packet,
|
|
28132
28345
|
value: {
|
|
28133
|
-
...
|
|
28346
|
+
...packetValue,
|
|
28134
28347
|
...obj
|
|
28135
28348
|
}
|
|
28136
28349
|
};
|
|
@@ -28186,6 +28399,7 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28186
28399
|
body.owner = player;
|
|
28187
28400
|
}
|
|
28188
28401
|
this.updateHitbox(player.id, player.x(), player.y(), width, height);
|
|
28402
|
+
await this.spawnScenarioEventsForPlayer(player);
|
|
28189
28403
|
if (this.stopAllSoundsBeforeJoin) {
|
|
28190
28404
|
player.stopAllSounds();
|
|
28191
28405
|
}
|
|
@@ -28236,6 +28450,7 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28236
28450
|
await this._onLeave(player);
|
|
28237
28451
|
}
|
|
28238
28452
|
await lastValueFrom(this.hooks.callHooks("server-player-onLeaveMap", player, this));
|
|
28453
|
+
this.removeScenarioEventsForPlayer(player.id);
|
|
28239
28454
|
player.pendingInputs = [];
|
|
28240
28455
|
player.lastProcessedInputTs = 0;
|
|
28241
28456
|
player._lastFramePositions = null;
|
|
@@ -28272,10 +28487,10 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28272
28487
|
}
|
|
28273
28488
|
onAction(player, action) {
|
|
28274
28489
|
const collisions = this.getCollisions(player.id);
|
|
28275
|
-
const events = collisions.map((id) => this.getEvent(id));
|
|
28490
|
+
const events = collisions.map((id) => this.getEvent(id)).filter((event) => !!event && this.isEventVisibleForPlayer(event, player));
|
|
28276
28491
|
if (events.length > 0) {
|
|
28277
28492
|
events.forEach((event) => {
|
|
28278
|
-
event
|
|
28493
|
+
event.execMethod("onAction", [player, action]);
|
|
28279
28494
|
});
|
|
28280
28495
|
}
|
|
28281
28496
|
player.execMethod("onInput", [action]);
|
|
@@ -28401,9 +28616,22 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28401
28616
|
this.clearWeather();
|
|
28402
28617
|
}
|
|
28403
28618
|
await lastValueFrom(this.hooks.callHooks("server-map-onBeforeUpdate", map, this));
|
|
28619
|
+
this._scenarioEventTemplates = [];
|
|
28620
|
+
this._eventModeById.clear();
|
|
28621
|
+
this._eventOwnerById.clear();
|
|
28622
|
+
this._scenarioEventIdsByPlayer.clear();
|
|
28404
28623
|
this.loadPhysic();
|
|
28405
28624
|
for (let event of map.events ?? []) {
|
|
28406
|
-
|
|
28625
|
+
const normalizedEvent = this.normalizeEventObject(event);
|
|
28626
|
+
const mode = this.resolveEventMode(normalizedEvent);
|
|
28627
|
+
if (mode === EventMode.Scenario) {
|
|
28628
|
+
this._scenarioEventTemplates.push(this.cloneEventTemplate(normalizedEvent));
|
|
28629
|
+
continue;
|
|
28630
|
+
}
|
|
28631
|
+
await this.createDynamicEvent(normalizedEvent, { mode: EventMode.Shared });
|
|
28632
|
+
}
|
|
28633
|
+
for (const player of this.getPlayers()) {
|
|
28634
|
+
await this.spawnScenarioEventsForPlayer(player);
|
|
28407
28635
|
}
|
|
28408
28636
|
this.dataIsReady$.complete();
|
|
28409
28637
|
await lastValueFrom(this.hooks.callHooks("server-map-onLoad", this));
|
|
@@ -28817,22 +29045,28 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28817
29045
|
* }
|
|
28818
29046
|
* });
|
|
28819
29047
|
*/
|
|
28820
|
-
async createDynamicEvent(eventObj) {
|
|
28821
|
-
|
|
28822
|
-
eventObj = {
|
|
28823
|
-
event: eventObj
|
|
28824
|
-
};
|
|
28825
|
-
}
|
|
29048
|
+
async createDynamicEvent(eventObj, options = {}) {
|
|
29049
|
+
eventObj = this.normalizeEventObject(eventObj);
|
|
28826
29050
|
const value = await lastValueFrom(this.hooks.callHooks("server-event-onBeforeCreated", eventObj, this));
|
|
28827
29051
|
value.filter((v) => v).forEach((v) => {
|
|
28828
29052
|
eventObj = v;
|
|
28829
29053
|
});
|
|
28830
|
-
const
|
|
28831
|
-
|
|
29054
|
+
const event = eventObj.event;
|
|
29055
|
+
const x = typeof eventObj.x === "number" ? eventObj.x : 0;
|
|
29056
|
+
const y = typeof eventObj.y === "number" ? eventObj.y : 0;
|
|
29057
|
+
const requestedMode = options.mode ?? this.resolveEventMode(eventObj);
|
|
29058
|
+
const mode = this.normalizeEventMode(requestedMode);
|
|
29059
|
+
const ownerFromData = options.scenarioOwnerId ?? this.resolveScenarioOwnerId(eventObj);
|
|
29060
|
+
const scenarioOwnerId = mode === EventMode.Scenario ? ownerFromData : void 0;
|
|
29061
|
+
const effectiveMode = mode === EventMode.Scenario && scenarioOwnerId ? EventMode.Scenario : EventMode.Shared;
|
|
29062
|
+
if (mode === EventMode.Scenario && !scenarioOwnerId) {
|
|
29063
|
+
console.warn("Scenario event created without owner id. Falling back to shared mode.");
|
|
29064
|
+
}
|
|
29065
|
+
const id = this.buildRuntimeEventId(eventObj.id, effectiveMode, scenarioOwnerId);
|
|
28832
29066
|
let eventInstance;
|
|
28833
29067
|
if (this.events()[id]) {
|
|
28834
29068
|
console.warn(`Event ${id} already exists on map`);
|
|
28835
|
-
return;
|
|
29069
|
+
return void 0;
|
|
28836
29070
|
}
|
|
28837
29071
|
if (typeof event === "function") {
|
|
28838
29072
|
eventInstance = new event();
|
|
@@ -28855,11 +29089,21 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28855
29089
|
eventInstance = new DynamicEvent();
|
|
28856
29090
|
if (event.name) eventInstance.name.set(event.name);
|
|
28857
29091
|
}
|
|
29092
|
+
eventInstance.mode = effectiveMode;
|
|
29093
|
+
if (effectiveMode === EventMode.Scenario && scenarioOwnerId) {
|
|
29094
|
+
eventInstance._scenarioOwnerId = scenarioOwnerId;
|
|
29095
|
+
eventInstance.scenarioOwnerId = scenarioOwnerId;
|
|
29096
|
+
} else {
|
|
29097
|
+
delete eventInstance._scenarioOwnerId;
|
|
29098
|
+
delete eventInstance.scenarioOwnerId;
|
|
29099
|
+
}
|
|
28858
29100
|
eventInstance.map = this;
|
|
28859
29101
|
eventInstance.context = context;
|
|
28860
29102
|
await eventInstance.teleport({ x, y });
|
|
28861
29103
|
this.events()[id] = eventInstance;
|
|
29104
|
+
this.setEventRuntimeMetadata(id, effectiveMode, scenarioOwnerId);
|
|
28862
29105
|
await eventInstance.execMethod("onInit");
|
|
29106
|
+
return id;
|
|
28863
29107
|
}
|
|
28864
29108
|
/**
|
|
28865
29109
|
* Get an event by its ID
|
|
@@ -28945,6 +29189,9 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
28945
29189
|
getEvents() {
|
|
28946
29190
|
return Object.values(this.events());
|
|
28947
29191
|
}
|
|
29192
|
+
getEventsForPlayer(playerOrId) {
|
|
29193
|
+
return this.getEvents().filter((event) => this.isEventVisibleForPlayer(event, playerOrId));
|
|
29194
|
+
}
|
|
28948
29195
|
/**
|
|
28949
29196
|
* Get the first event that matches a condition
|
|
28950
29197
|
*
|
|
@@ -29015,6 +29262,18 @@ let RpgMap = class extends RpgCommonMap {
|
|
|
29015
29262
|
* ```
|
|
29016
29263
|
*/
|
|
29017
29264
|
removeEvent(eventId) {
|
|
29265
|
+
const event = this.getEvent(eventId);
|
|
29266
|
+
if (event) {
|
|
29267
|
+
try {
|
|
29268
|
+
event.stopMoveTo?.();
|
|
29269
|
+
} catch {
|
|
29270
|
+
}
|
|
29271
|
+
try {
|
|
29272
|
+
event.breakRoutes?.(true);
|
|
29273
|
+
} catch {
|
|
29274
|
+
}
|
|
29275
|
+
}
|
|
29276
|
+
this.clearEventRuntimeMetadata(eventId);
|
|
29018
29277
|
delete this.events()[eventId];
|
|
29019
29278
|
}
|
|
29020
29279
|
/**
|
|
@@ -30070,23 +30329,6 @@ class LocalStorageSaveStorageStrategy {
|
|
|
30070
30329
|
}
|
|
30071
30330
|
}
|
|
30072
30331
|
|
|
30073
|
-
var EventMode = /* @__PURE__ */ ((EventMode2) => {
|
|
30074
|
-
EventMode2["Shared"] = "shared";
|
|
30075
|
-
EventMode2["Scenario"] = "scenario";
|
|
30076
|
-
return EventMode2;
|
|
30077
|
-
})(EventMode || {});
|
|
30078
|
-
function EventData(options) {
|
|
30079
|
-
return (target) => {
|
|
30080
|
-
target.mode = options.mode || "shared" /* Shared */;
|
|
30081
|
-
target.width = options.width;
|
|
30082
|
-
target.height = options.height;
|
|
30083
|
-
target.hitbox = options.hitbox;
|
|
30084
|
-
target._name = options.name;
|
|
30085
|
-
target.prototype._name = options.name;
|
|
30086
|
-
target.prototype.mode = target.mode;
|
|
30087
|
-
};
|
|
30088
|
-
}
|
|
30089
|
-
|
|
30090
30332
|
function MapData(options) {
|
|
30091
30333
|
return (target) => {
|
|
30092
30334
|
target.file = options.file;
|