Browse Source

feat #1872: More work on this

tags/v0.10.6^2
Shaun 2 years ago
parent
commit
913569200b
3 changed files with 39 additions and 14 deletions
  1. +14
    -10
      src/server/components/mob.js
  2. +1
    -0
      src/server/components/spellbook.js
  3. +24
    -4
      src/server/components/spellbook/rotationManager.js

+ 14
- 10
src/server/components/mob.js View File

@@ -113,6 +113,7 @@ module.exports = {
this.maxChaseDistance = blueprint.maxChaseDistance;
},

/* eslint-disable-next-line max-lines-per-function */
update: function () {
let obj = this.obj;

@@ -123,20 +124,22 @@ module.exports = {
//Have we reached home?
if (this.goHome) {
let distanceFromHome = Math.max(abs(this.originX - obj.x), abs(this.originY - obj.y));
if (!distanceFromHome)
if (!distanceFromHome) {
this.goHome = false;
}

//Are we too far from home?
if ((!this.goHome) && (!obj.follower) && (target)) {
if (!this.canChase(target)) {
obj.clearQueue();
obj.aggro.unAggro(target);
target = obj.aggro.getHighest();
obj.spellbook.resetRotation();
}
}

if (!this.goHome) {
//Are we too far from home?
if (!obj.follower && target) {
if (!this.canChase(target)) {
obj.clearQueue();
obj.aggro.unAggro(target);
target = obj.aggro.getHighest();
}
}

if ((target) && (target !== obj) && ((!obj.follower) || (obj.follower.master !== target))) {
//If we just started attacking, patrols need to know where home is
if (!this.target && this.patrol) {
@@ -147,10 +150,11 @@ module.exports = {
//Are we in fight mode?
this.fight(target);
return;
} else if ((!target) && (this.target)) {
} else if (!target && this.target) {
//Is fight mode over?
this.target = null;
obj.clearQueue();
obj.spellbook.resetRotation();

if (canPathHome(this))
this.goHome = true;


+ 1
- 0
src/server/components/spellbook.js View File

@@ -46,6 +46,7 @@ module.exports = {
//External helpers that should form part of the component
this.getSpellToCast = rotationManager.getSpellToCast.bind(null, this);
this.getFurthestRange = rotationManager.getFurthestRange.bind(null, this);
this.resetRotation = rotationManager.resetRotation.bind(null, this);
},

transfer: function () {


+ 24
- 4
src/server/components/spellbook/rotationManager.js View File

@@ -1,3 +1,17 @@
const getDefaultRotationSpell = rotationSpells => {
const spells = rotationSpells.filter(s => !s.atRotationTicks);

if (!spells.length)
return;

if (spells.length === 0)
return spells[0];

const randomSpell = spells[~~(Math.random() * spells.length)];

return randomSpell;
};

//Mobs that define rotations (normally bosses) use this method to determine their spell choices
const getRotationSpell = (source, target) => {
const { spells, rotation: { currentTick, spells: rotationSpells } } = source;
@@ -5,10 +19,8 @@ const getRotationSpell = (source, target) => {
//Find spell matching current tick
let rotationEntry = rotationSpells.find(s => s.atRotationTicks?.includes(currentTick));

//If no rotation spell found, use a default spell
//Todo: round-robin/random/weighted/whatever when there are more than one
if (!rotationEntry)
rotationEntry = rotationSpells.find(s => !s.atRotationTicks);
rotationEntry = getDefaultRotationSpell(rotationSpells);

if (!rotationEntry)
return;
@@ -24,7 +36,7 @@ const getRotationSpell = (source, target) => {
useSpell.cd = 0;
useSpell.manaCost = 0;
if (!useSpell.selfCast && !useSpell.canCast(target))
return;
return getDefaultRotationSpell(rotationSpells);

return useSpell;
};
@@ -104,8 +116,16 @@ const getFurthestRange = (source, target, checkCanCast) => {
return furthest;
};

const resetRotation = source => {
if (!source.rotation)
return;

source.rotation.currentTick = 0;
};

module.exports = {
tick,
resetRotation,
getSpellToCast,
getFurthestRange
};

Loading…
Cancel
Save