@@ -38,27 +38,27 @@ define([ | |||||
extend: function (blueprint) { | extend: function (blueprint) { | ||||
if (blueprint.addActions) { | if (blueprint.addActions) { | ||||
blueprint.addActions.forEach(function (a) { | |||||
blueprint.addActions.forEach(a => { | |||||
this.actions.spliceWhere(f => f.key === a.key); | 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) | if (exists) | ||||
return; | return; | ||||
this.actions.push(a); | this.actions.push(a); | ||||
}, this); | |||||
}); | |||||
delete blueprint.addActions; | delete blueprint.addActions; | ||||
} | } | ||||
if (blueprint.removeActions) { | 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; | delete blueprint.removeActions; | ||||
} | } | ||||
@@ -85,6 +85,13 @@ module.exports = { | |||||
}, [obj.serverId]); | }, [obj.serverId]); | ||||
}, | }, | ||||
collisionStay: function (obj) { | |||||
if (!obj.player) | |||||
return; | |||||
this.callAction(obj, 'stay'); | |||||
}, | |||||
collisionExit: function (obj, force) { | collisionExit: function (obj, force) { | ||||
if (!force) { | if (!force) { | ||||
if (!obj.player) | if (!obj.player) | ||||
@@ -5,6 +5,12 @@ const fs = require('fs'); | |||||
const phaseTemplate = require('./phases/phaseTemplate'); | const phaseTemplate = require('./phases/phaseTemplate'); | ||||
const { mapList } = require('../world/mapManager'); | const { mapList } = require('../world/mapManager'); | ||||
//Internals | |||||
const phasePaths = [{ | |||||
type: 'end', | |||||
path: './phases/phaseEnd' | |||||
}]; | |||||
//Helpers | //Helpers | ||||
const applyVariablesToDescription = (desc, variables) => { | const applyVariablesToDescription = (desc, variables) => { | ||||
if (!variables) | if (!variables) | ||||
@@ -26,6 +32,10 @@ module.exports = { | |||||
init: function (instance) { | init: function (instance) { | ||||
this.instance = instance; | this.instance = instance; | ||||
this.instance.eventEmitter.emit('beforeGetEventPhasePaths', { | |||||
phasePaths | |||||
}); | |||||
const zoneName = this.instance.map.name; | const zoneName = this.instance.map.name; | ||||
const zonePath = mapList.find(z => z.name === zoneName).path; | const zonePath = mapList.find(z => z.name === zoneName).path; | ||||
const zoneEventPath = zonePath + '/' + zoneName + '/events'; | const zoneEventPath = zonePath + '/' + zoneName + '/events'; | ||||
@@ -430,8 +440,15 @@ module.exports = { | |||||
let phase = event.phases[i]; | let phase = event.phases[i]; | ||||
if (!phase) { | 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({ | phase = extend({ | ||||
instance: this.instance, | instance: this.instance, | ||||
event: event | event: event | ||||
@@ -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) { | collisionExit: function (obj) { | ||||
let cpns = this.components; | let cpns = this.components; | ||||
let cLen = cpns.length; | let cLen = cpns.length; | ||||
@@ -456,12 +456,10 @@ module.exports = { | |||||
if (objZoneName !== name) | if (objZoneName !== name) | ||||
blueprint.objZoneName = objZoneName; | 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) | if (blueprint.blocking) | ||||
this.collisionMap[blueprint.x][blueprint.y] = 1; | this.collisionMap[blueprint.x][blueprint.y] = 1; | ||||
@@ -112,6 +112,9 @@ module.exports = { | |||||
} else if ((fromX < c.x) || (fromY < c.y) || (fromX >= c.x + c.width) || (fromY >= c.y + c.height)) { | } else if ((fromX < c.x) || (fromY < c.y) || (fromX >= c.x + c.width) || (fromY >= c.y + c.height)) { | ||||
c.collisionEnter(obj); | c.collisionEnter(obj); | ||||
obj.collisionEnter(c); | 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 { | } else { | ||||
//If a callback returns true, it means we collide | //If a callback returns true, it means we collide | ||||