Skip to content

Commit

Permalink
When unequipping items, update player combat stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
djasnowski committed Dec 23, 2019
1 parent f26aa61 commit 58cea46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
32 changes: 21 additions & 11 deletions server/core/utilities/wear.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Wear {
/**
* Update a player's combat attack and defense
*/
static updateCombat(playerIndex) {
static updateCombat(playerIndex, unequipping = false) {
const stats = {
attack: {
stab: 0,
Expand Down Expand Up @@ -61,17 +61,27 @@ class Wear {
stab: defStab,
} = this.getDefense({ id: val.id });

// Update attack stats
stats.attack.stab += stab;
stats.attack.slash += slash;
stats.attack.crush += crush;
stats.attack.range += range;
if (unequipping) {
stats.attack.stab -= stab;
stats.attack.slash -= slash;
stats.attack.crush -= crush;
stats.attack.range -= range;

// Update defense stats
stats.defense.stab += defStab;
stats.defense.slash += defSlash;
stats.defense.crush += defCrush;
stats.defense.range += defRange;
stats.defense.stab -= defStab;
stats.defense.slash -= defSlash;
stats.defense.crush -= defCrush;
stats.defense.range -= defRange;
} else {
stats.attack.stab += stab;
stats.attack.slash += slash;
stats.attack.crush += crush;
stats.attack.range += range;

stats.defense.stab += defStab;
stats.defense.slash += defSlash;
stats.defense.crush += defCrush;
stats.defense.range += defRange;
}
}
});

Expand Down
5 changes: 3 additions & 2 deletions server/player/pipeline/players.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export default {
const getRealPlacement = world.players[playerIndex].inventory.slots.findIndex(i => item.uuid === i.uuid);
world.players[playerIndex].inventory.slots.splice(getRealPlacement, 1);

const newPlayerStats = Wear.updateCombat(playerIndex);
world.players[playerIndex].combat = newPlayerStats;
world.players[playerIndex].combat = Wear.updateCombat(playerIndex);
Socket.broadcast('player:equippedAnItem', world.players[playerIndex]);
},

Expand Down Expand Up @@ -64,6 +63,8 @@ export default {

world.players[playerIndex].wear[getItem.slot] = null;

world.players[playerIndex].combat = Wear.updateCombat(playerIndex, true);

Socket.broadcast('player:unequippedAnItem', world.players[playerIndex]);
resolve(200);
});
Expand Down

0 comments on commit 58cea46

Please sign in to comment.