From 9fd44060515e6009f64da810c7755e559b458a66 Mon Sep 17 00:00:00 2001 From: Shaun Date: Sat, 17 Jun 2023 21:45:43 +0200 Subject: [PATCH] work --- src/server/clientComponents/serverActions.js | 16 +++++++-------- src/server/components/notice.js | 7 +++++++ src/server/events/events.js | 21 ++++++++++++++++++-- src/server/objects/objBase.js | 10 ++++++++++ src/server/world/map.js | 10 ++++------ src/server/world/physics.js | 3 +++ 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/server/clientComponents/serverActions.js b/src/server/clientComponents/serverActions.js index 5201dd9a..805d2585 100644 --- a/src/server/clientComponents/serverActions.js +++ b/src/server/clientComponents/serverActions.js @@ -38,27 +38,27 @@ define([ extend: function (blueprint) { if (blueprint.addActions) { - blueprint.addActions.forEach(function (a) { + blueprint.addActions.forEach(a => { this.actions.spliceWhere(f => f.key === a.key); - let exists = this.actions.some(function (ta) { - return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method)); + let exists = this.actions.some(ta => { + return (ta.action.data.targetId === a.action.data.targetId && ta.action.cpn === a.action.cpn && ta.action.method === a.action.method); }); if (exists) return; this.actions.push(a); - }, this); + }); delete blueprint.addActions; } if (blueprint.removeActions) { - blueprint.removeActions.forEach(function (a) { - this.actions.spliceWhere(function (ta) { - return ((ta.targetId === a.targetId) && (ta.cpn === a.cpn) && (ta.method === a.method)); + blueprint.removeActions.forEach(a => { + this.actions.spliceWhere(ta => { + return (ta.action.data.targetId === a.action.data.targetId && ta.action.cpn === a.action.cpn && ta.action.method === a.action.method); }); - }, this); + }); delete blueprint.removeActions; } diff --git a/src/server/components/notice.js b/src/server/components/notice.js index e5e317a2..e3395a6e 100644 --- a/src/server/components/notice.js +++ b/src/server/components/notice.js @@ -85,6 +85,13 @@ module.exports = { }, [obj.serverId]); }, + collisionStay: function (obj) { + if (!obj.player) + return; + + this.callAction(obj, 'stay'); + }, + collisionExit: function (obj, force) { if (!force) { if (!obj.player) diff --git a/src/server/events/events.js b/src/server/events/events.js index fa1ac9ee..3716a354 100644 --- a/src/server/events/events.js +++ b/src/server/events/events.js @@ -5,6 +5,12 @@ const fs = require('fs'); const phaseTemplate = require('./phases/phaseTemplate'); const { mapList } = require('../world/mapManager'); +//Internals +const phasePaths = [{ + type: 'end', + path: './phases/phaseEnd' +}]; + //Helpers const applyVariablesToDescription = (desc, variables) => { if (!variables) @@ -26,6 +32,10 @@ module.exports = { init: function (instance) { this.instance = instance; + this.instance.eventEmitter.emit('beforeGetEventPhasePaths', { + phasePaths + }); + const zoneName = this.instance.map.name; const zonePath = mapList.find(z => z.name === zoneName).path; const zoneEventPath = zonePath + '/' + zoneName + '/events'; @@ -430,8 +440,15 @@ module.exports = { let phase = event.phases[i]; if (!phase) { - let phaseFile = 'phase' + p.type[0].toUpperCase() + p.type.substr(1); - let typeTemplate = require('./phases/' + phaseFile); + let typeTemplate; + + const phasePathEntry = phasePaths.find(f => f.type === p.type); + if (!phasePathEntry) { + const phaseFile = 'phase' + p.type[0].toUpperCase() + p.type.substr(1); + typeTemplate = require('./phases/' + phaseFile); + } else + typeTemplate = require(`../${phasePathEntry.path}`); + phase = extend({ instance: this.instance, event: event diff --git a/src/server/objects/objBase.js b/src/server/objects/objBase.js index fd003959..b3ddb22b 100644 --- a/src/server/objects/objBase.js +++ b/src/server/objects/objBase.js @@ -337,6 +337,16 @@ module.exports = { } }, + collisionStay: function (obj) { + let cpns = this.components; + let cLen = cpns.length; + for (let i = 0; i < cLen; i++) { + let c = cpns[i]; + if (c.collisionStay) + c.collisionStay(obj); + } + }, + collisionExit: function (obj) { let cpns = this.components; let cLen = cpns.length; diff --git a/src/server/world/map.js b/src/server/world/map.js index d6ead04e..9f46c608 100644 --- a/src/server/world/map.js +++ b/src/server/world/map.js @@ -456,12 +456,10 @@ module.exports = { if (objZoneName !== name) blueprint.objZoneName = objZoneName; - if (this.zoneConfig) { - if ((this.zoneConfig.objects) && (this.zoneConfig.objects[objZoneName.toLowerCase()])) - extend(blueprint, this.zoneConfig.objects[objZoneName.toLowerCase()]); - else if ((this.zoneConfig.objects) && (this.zoneConfig.mobs[objZoneName.toLowerCase()])) - extend(blueprint, this.zoneConfig.mobs[objZoneName.toLowerCase()]); - } + if (this.zoneConfig?.objects?.[objZoneName.toLowerCase()]) + extend(blueprint, this.zoneConfig.objects[objZoneName.toLowerCase()]); + else if (this.zoneConfig?.mobs?.[objZoneName.toLowerCase()]) + extend(blueprint, this.zoneConfig.objects[objZoneName.toLowerCase()]); if (blueprint.blocking) this.collisionMap[blueprint.x][blueprint.y] = 1; diff --git a/src/server/world/physics.js b/src/server/world/physics.js index 39b96628..db6e9589 100644 --- a/src/server/world/physics.js +++ b/src/server/world/physics.js @@ -112,6 +112,9 @@ module.exports = { } else if ((fromX < c.x) || (fromY < c.y) || (fromX >= c.x + c.width) || (fromY >= c.y + c.height)) { c.collisionEnter(obj); obj.collisionEnter(c); + } else if ((fromX >= c.x) && (fromY >= c.y) && (fromX < c.x + c.width) && (fromY < c.y + c.height)) { + c.collisionStay(obj); + obj.collisionStay(c); } } else { //If a callback returns true, it means we collide