Browse Source

Sync shield amount and add shield bar

merge-requests/579/head
kckckc 2 years ago
parent
commit
45f168fae8
4 changed files with 70 additions and 3 deletions
  1. +52
    -0
      src/server/clientComponents/effects/shield.js
  2. +4
    -0
      src/server/config/clientConfig.js
  3. +14
    -1
      src/server/config/effects/effectShield.js
  4. +0
    -2
      src/server/mods/class-necromancer/spells/spellBloodBarrier.js

+ 52
- 0
src/server/clientComponents/effects/shield.js View File

@@ -0,0 +1,52 @@
define([

], function (

) {
const shieldEffect = {
bar: null,
visible: true,

amount: 1,
maxAmount: 1,

init: function () {
if (this.obj.stats) {
this.bar = this.obj.stats.addBar({
color: 0x533399,
innerColor: 0xa24eff,
calcPercent: () => (this.amount / this.maxAmount),
isVisible: () => this.visible
});

this.obj.stats.updateBars();
}
},

extend: function (data) {
this.amount = data.amount;
this.maxAmount = data.maxAmount;

if (this.obj.stats)
this.obj.stats.updateBars();
},

destroy: function () {
if (this.bar && this.obj.stats)
this.obj.stats.removeBar(this.bar);
},

setVisible: function (visible) {
this.visible = visible;

if (this.obj.stats)
this.obj.stats.updateBars();
}
};

return {
templates: {
shield: shieldEffect
}
};
});

+ 4
- 0
src/server/config/clientConfig.js View File

@@ -226,6 +226,10 @@ module.exports = {
extends: 'effects',
path: 'server/clientComponents/effects/auras.js'
});
config.clientComponents.push({
extends: 'effects',
path: 'server/clientComponents/effects/shield.js'
});

events.emit('onBeforeGetClientConfig', config);



+ 14
- 1
src/server/config/effects/effectShield.js View File

@@ -4,13 +4,26 @@ module.exports = {
amount: 0,
maxAmount: 0,

init: function () {
this.syncExtend({
amount: this.amount,
maxAmount: this.maxAmount
});
},

events: {
beforeTakeDamage: function (damage, source) {
if (this.amount > 0) {
let mitigatedAmount = Math.min(damage.amount, this.amount);
damage.amount -= mitigatedAmount;
this.amount -= mitigatedAmount;

//Sync new values to client
this.syncExtend({
amount: this.amount,
maxAmount: this.maxAmount
});
}

if (this.amount <= 0)


+ 0
- 2
src/server/mods/class-necromancer/spells/spellBloodBarrier.js View File

@@ -42,8 +42,6 @@ module.exports = {
target.effects.addEffect({
type: 'shield',
ttl: this.frenzyDuration,
new: true,
noMsg: true,
amount: amount,
maxAmount: amount
});


Loading…
Cancel
Save