Browse Source

fixes #1322

tags/v0.4.2^2
Big Bad Waffle 4 years ago
parent
commit
c023ee1078
1 changed files with 65 additions and 52 deletions
  1. +65
    -52
      src/server/config/spells/spellFireblast.js

+ 65
- 52
src/server/config/spells/spellFireblast.js View File

@@ -1,3 +1,41 @@
const getTargetPos = (physics, obj, m) => {
let targetPos = {
x: m.x,
y: m.y
};

let dx = m.x - obj.x;
let dy = m.y - obj.y;

while ((dx === 0) && (dy === 0)) {
dx = ~~(Math.random() * 2) - 1;
dy = ~~(Math.random() * 2) - 1;
}

dx = ~~(dx / Math.abs(dx));
dy = ~~(dy / Math.abs(dy));
for (let l = 0; l < this.pushback; l++) {
if (physics.isTileBlocking(targetPos.x + dx, targetPos.y + dy)) {
if (physics.isTileBlocking(targetPos.x + dx, targetPos.y)) {
if (physics.isTileBlocking(targetPos.x, targetPos.y + dy))
break;
else {
dx = 0;
targetPos.y += dy;
}
} else {
dy = 0;
targetPos.x += dx;
}
} else {
targetPos.x += dx;
targetPos.y += dy;
}
}

return targetPos;
};

module.exports = {
type: 'fireblast',

@@ -17,7 +55,7 @@ module.exports = {

const particleConfig = extend({}, this.particles);

this.obj.fireEvent('beforeSpawnParticles', this, particleConfig);
obj.fireEvent('beforeSpawnParticles', this, particleConfig);

for (let i = x - radius; i <= x + radius; i++) {
for (let j = y - radius; j <= y + radius; j++) {
@@ -46,60 +84,33 @@ module.exports = {
if (!m) {
mLen--;
continue;
}

if ((!m.aggro) || (!m.effects))
} else if (!m.aggro || !m.effects)
continue;

if (!this.obj.aggro.canAttack(m))
else if (!obj.aggro.canAttack(m))
continue;

let targetEffect = m.effects.addEffect({
type: 'stunned',
noMsg: true,
new: true
});

let targetPos = {
x: m.x,
y: m.y
};

//Find out where the mob should end up
let dx = m.x - obj.x;
let dy = m.y - obj.y;

while ((dx === 0) && (dy === 0)) {
dx = ~~(Math.random() * 2) - 1;
dy = ~~(Math.random() * 2) - 1;
}

dx = ~~(dx / Math.abs(dx));
dy = ~~(dy / Math.abs(dy));
for (let l = 0; l < this.pushback; l++) {
if (physics.isTileBlocking(targetPos.x + dx, targetPos.y + dy)) {
if (physics.isTileBlocking(targetPos.x + dx, targetPos.y)) {
if (physics.isTileBlocking(targetPos.x, targetPos.y + dy))
break;
else {
dx = 0;
targetPos.y += dy;
}
} else {
dy = 0;
targetPos.x += dx;
}
} else {
targetPos.x += dx;
targetPos.y += dy;
}
}
const targetPos = getTargetPos(physics, obj, m);

let distance = Math.max(Math.abs(m.x - targetPos.x), Math.abs(m.y - targetPos.y));
let ttl = distance * 125;

m.clearQueue();

let damage = this.getDamage(m);
m.stats.takeDamage(damage, 1, obj);

if (m.destroyed)
continue;

const eventMsg = {
success: true,
targetPos
};
m.fireEvent('beforePositionChange', eventMsg);

if (!eventMsg.success)
continue;

this.sendAnimation({
id: m.id,
components: [{
@@ -110,13 +121,14 @@ module.exports = {
}]
});

let damage = this.getDamage(m);
m.stats.takeDamage(damage, 1, obj);
let targetEffect = m.effects.addEffect({
type: 'stunned',
noMsg: true,
new: true
});

if (!m.destroyed) {
physics.removeObject(m, m.x, m.y);
this.queueCallback(this.endEffect.bind(this, m, targetPos, targetEffect), ttl, null, m);
}
physics.removeObject(m, m.x, m.y);
this.queueCallback(this.endEffect.bind(this, m, targetPos, targetEffect), ttl, null, m);
}
}
}
@@ -140,5 +152,6 @@ module.exports = {
syncer.o.y = targetPos.y;

target.instance.physics.addObject(target, target.x, target.y);
target.fireEvent('afterPositionChange', targetPos);
}
};

Loading…
Cancel
Save