Parcourir la source

fixed an issue for #85 where enchanting EQd items with a full inventory lost the item

tags/v0.3.3^2
Shaun Kichenbrand il y a 4 ans
Parent
révision
78a368ea3c
4 fichiers modifiés avec 31 ajouts et 30 suppressions
  1. +6
    -21
      src/server/components/equipment.js
  2. +14
    -0
      src/server/components/equipment/helpers.js
  3. +10
    -8
      src/server/components/inventory.js
  4. +1
    -1
      src/server/config/serverConfig.js

+ 6
- 21
src/server/components/equipment.js Voir le fichier

@@ -1,3 +1,5 @@
const { applyItemStats } = require('./equipment/helpers');

module.exports = {
type: 'equipment',

@@ -116,16 +118,7 @@ module.exports = {
this.unequip(this.eq[slot], true);
}

let stats = item.stats;
for (let s in stats) {
let val = stats[s];

obj.stats.addStat(s, val);
}

(item.implicitStats || []).forEach(function (s) {
obj.stats.addStat(s.stat, s.value);
}, this);
applyItemStats(obj, item, true);

item.eq = true;
this.eq[slot] = itemId;
@@ -142,6 +135,7 @@ module.exports = {

obj.fireEvent('afterEquipItem', item);
},

unequip: function (itemId, ignoreSpaceCheck) {
let item = itemId;
if (typeof (itemId) === 'object')
@@ -168,21 +162,11 @@ module.exports = {
return;
}

let stats = item.stats;

delete item.eq;
delete this.eq[item.equipSlot];
delete item.equipSlot;

for (let s in stats) {
let val = stats[s];

obj.stats.addStat(s, -val);
}

(item.implicitStats || []).forEach(function (s) {
obj.stats.addStat(s.stat, -s.value);
}, this);
applyItemStats(obj, item, false);

inventory.setItemPosition(itemId);

@@ -198,6 +182,7 @@ module.exports = {

this.unequipAttrRqrGear();
},

unequipAll: function () {
let eq = this.eq;
Object.keys(this.eq).forEach(function (slot) {


+ 14
- 0
src/server/components/equipment/helpers.js Voir le fichier

@@ -0,0 +1,14 @@
module.exports = {
applyItemStats: ({ stats: objStats }, { stats, implicitStats = [] }, isEq) => {
for (let s in stats) {
const value = stats[s];
const useValue = isEq ? value : -value;
objStats.addStat(s, useValue);
}

implicitStats.forEach(({ stat, value }) => {
const useValue = isEq ? value : -value;
objStats.addStat(stat, useValue);
});
}
};

+ 10
- 8
src/server/components/inventory.js Voir le fichier

@@ -5,6 +5,7 @@ let classes = require('../config/spirits');
let mtx = require('../mtx/mtx');
let factions = require('../config/factions');
let itemEffects = require('../items/itemEffects');
const { applyItemStats } = require('./equipment/helpers');

module.exports = {
type: 'inventory',
@@ -143,20 +144,21 @@ module.exports = {

enchantItem: function (msg) {
let item = this.findItem(msg.itemId);
if ((!item) || (!item.slot) || (item.noAugment) || ((msg.action === 'scour') && (item.power === 0))) {
if (!item || !item.slot || item.noAugment || (msg.action === 'scour' && !item.power)) {
this.resolveCallback(msg);
return;
}

const equipment = this.obj.equipment;
if (item.eq)
equipment.unequip(item.id, true);
const obj = this.obj;

enchanter.enchant(this.obj, item, msg);
if (item.eq) {
applyItemStats(obj, item, false);
enchanter.enchant(obj, item, msg);
applyItemStats(obj, item, true);
} else
enchanter.enchant(obj, item, msg);

if (item.eq)
equipment.equip(item.id);
obj.equipment.unequipAttrRqrGear();
},

getEnchantMaterials: function (msg) {


+ 1
- 1
src/server/config/serverConfig.js Voir le fichier

@@ -8,7 +8,7 @@ module.exports = {
// sqlite
// rethink
//eslint-disable-next-line no-process-env
db: process.env.IWD_DB || 'rethink',
db: process.env.IWD_DB || 'sqlite',
//eslint-disable-next-line no-process-env
dbHost: process.env.IWD_DB_HOST || 'localhost',
//eslint-disable-next-line no-process-env


Chargement…
Annuler
Enregistrer