Scriptable Areas RFC
shawncplus opened this issue · comments
Scenario
- I want to be able to customize the respawning behavior of an area
- I want to be able to detect a player entering/leaving an area (currently has to be done as an individual script/behavior on every room in the area)
Current Solution
None. Not currently possible without modifying core
Proposal
Current manifest.yml
title: Limbo
info:
respawnInterval: 30
Proposed
# my-bundle/areas/limbo/manifest.yml
title: Limbo
script: 'limbo.js' # found in ./scripts/limbo.js
behaviors:
# found in some-bundle/behaviors/area/progressive-respawn.js
progressive-respawn:
interval: 30
some-bundle/behaviors/area/progressive-repawn.js
would look something like this
module.exports = {
updateTick: state => function (config) {
this._lastRespawnTick = this._lastRespawnTick || Date.now();
const sinceLastTick = Date.now() - this._lastRespawnTick;
if (sinceLastTick >= config.interval * 1000) {
for (const [, room] of this.rooms) {
room.emit('respawnTick')
}
}
},
roomAdded: state => function(config, room) {
room.on('respawnTick', () => {
// do per-room respawn stuff here
});
},
};
Hurdles
Will be a subtle BC break from 3.x. Nothing will explode but people's areas will just stop respawning. Other then that this is quite straightforward, no headaches as Area
is already a scriptable entity, it's just not exposed to bundles.
This is now implemented in the scriptable-areas
branches of the ranviermud
and core
repos. There is also a new bundle to go along with this (though the bundle-install
command will handle installing it for you) called https://github.com/RanvierMUD/progressive-respawn
Merged to core