mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 11:10:44 +00:00
don't rely on ticks to remove effect : ticks slow down the server and should only be used if strictly necessary
This commit is contained in:
parent
a5823406ce
commit
02eed8229f
1 changed files with 3 additions and 8 deletions
11
src/lib/plugins/effects.js
vendored
11
src/lib/plugins/effects.js
vendored
|
|
@ -35,7 +35,8 @@ module.exports.entity = function(entity, serv) {
|
||||||
amplifier: opt.amplifier || 0,
|
amplifier: opt.amplifier || 0,
|
||||||
duration: opt.duration || 30*20,
|
duration: opt.duration || 30*20,
|
||||||
particles: opt.particles || true,
|
particles: opt.particles || true,
|
||||||
end: Date.now() + (opt.duration || 30*20)*1000/20 // 1000/20 == convert from ticks to milliseconds
|
end: Date.now() + (opt.duration || 30*20)*1000/20, // 1000/20 == convert from ticks to milliseconds,
|
||||||
|
timeout:setTimeout(() => entity.removeEffect(effectId),(opt.duration || 30*20)*1000/20)
|
||||||
};
|
};
|
||||||
entity.sendEffect(effectId, opt);
|
entity.sendEffect(effectId, opt);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -43,16 +44,10 @@ module.exports.entity = function(entity, serv) {
|
||||||
};
|
};
|
||||||
|
|
||||||
entity.removeEffect = (effectId, opt) => {
|
entity.removeEffect = (effectId, opt) => {
|
||||||
|
clearTimeout(entity.effects[effectId].timeout);
|
||||||
entity.effects[effectId] = null;
|
entity.effects[effectId] = null;
|
||||||
entity.sendRemoveEffect(effectId, opt);
|
entity.sendRemoveEffect(effectId, opt);
|
||||||
};
|
};
|
||||||
|
|
||||||
serv.on('tick', () => {
|
|
||||||
Object.keys(entity.effects).forEach(effectId => {
|
|
||||||
const e = entity.effects[effectId];
|
|
||||||
if (e && e.end <= Date.now()) entity.removeEffect(effectId);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.player = function(player) {
|
module.exports.player = function(player) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue