Ver código fonte

fixes #689

tags/v0.5
Big Bad Waffle 4 anos atrás
pai
commit
ad01e69905
3 arquivos alterados com 33 adições e 1 exclusões
  1. +4
    -0
      src/server/components/aggro.js
  2. +17
    -1
      src/server/components/mob.js
  3. +12
    -0
      src/server/components/mob/canPathHome.js

+ 4
- 0
src/server/components/aggro.js Ver arquivo

@@ -399,5 +399,9 @@ module.exports = {
} else if (l.threat > 0)
l.threat *= this.threatDecay;
}
},

clearIgnoreList: function () {
this.ignoreList = [];
}
};

+ 17
- 1
src/server/components/mob.js Ver arquivo

@@ -2,6 +2,8 @@ let abs = Math.abs.bind(Math);
let rnd = Math.random.bind(Math);
let max = Math.max.bind(Math);

const canPathHome = require('./mob/canPathHome');

module.exports = {
type: 'mob',

@@ -67,7 +69,21 @@ module.exports = {
//Is fight mode over?
this.target = null;
obj.clearQueue();
this.goHome = true;

//Can we path home?
if (canPathHome(this))
this.goHome = true;
else {
this.physics.removeObject(obj, obj.x, obj.y);
obj.x = this.originX;
obj.y = this.originY;
const syncer = obj.syncer;
syncer.o.x = obj.x;
syncer.o.y = obj.y;
this.physics.addObject(obj, obj.x, obj.y);
obj.aggro.clearIgnoreList();
obj.aggro.move();
}
}
}



+ 12
- 0
src/server/components/mob/canPathHome.js Ver arquivo

@@ -0,0 +1,12 @@
module.exports = cpnMob => {
const { originX, originY, obj: { x, y, instance: { physics } } } = cpnMob;

const path = physics.getPath({ x, y }, { x: originX, y: originY });
if (!path.length)
return (x === originX && y === originY);

const { x: px, y: py } = path[path.length - 1];
const canReachHome = (px === originX && py === originY);

return canReachHome;
};

Carregando…
Cancelar
Salvar