summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/inventory.cpp37
-rw-r--r--src/game-server/item.cpp4
-rw-r--r--src/game-server/item.hpp12
3 files changed, 29 insertions, 24 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index f560ce50..94dea47a 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -209,7 +209,9 @@ void Inventory::equip_sub(unsigned int newCount, IdSlotMap::const_iterator &it)
void Inventory::prepare()
{
- if (!mDelayed) return;
+ if (!mDelayed)
+ return;
+
Possessions *poss = &mClient->getPossessions();
if (mPoss == poss)
mPoss = new Possessions(*poss);
@@ -546,26 +548,31 @@ unsigned int Inventory::move(unsigned int slot1, unsigned int slot2, unsigned in
unsigned int Inventory::removeFromSlot(unsigned int slot, unsigned int amount)
{
prepare();
+
InventoryData::iterator it = mPoss->inventory.find(slot);
+
+ // When the given slot doesn't exist, we can't remove anything
if (it == mPoss->inventory.end())
return amount;
- unequip(slot);
+
+ // Check if an item of the same class exists elsewhere in the inventory
+ bool exists = false;
+ for (InventoryData::const_iterator it2 = mPoss->inventory.begin(),
+ it2_end = mPoss->inventory.end();
+ it2 != it2_end; ++it2)
{
- bool exists = false;
- for (InventoryData::const_iterator it2 = mPoss->inventory.begin(),
- it2_end = mPoss->inventory.end();
- it2 != it2_end;
- ++it2)
- if (it2->second.itemId == it->second.itemId
+ if (it2->second.itemId == it->second.itemId
&& it->first != it2->first)
- {
- exists = true;
- break;
- }
- if (!exists && it->second.itemId)
- itemManager->getItem(it->second.itemId)
- ->useTrigger(mClient, ITT_LEAVE_INVY);
+ {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists && it->second.itemId) {
+ if (ItemClass *ic = itemManager->getItem(it->second.itemId))
+ ic->useTrigger(mClient, ITT_LEAVE_INVY);
}
+
unsigned int sub = std::min(amount, it->second.amount);
amount -= sub;
it->second.amount -= sub;
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp
index d2d2c1d8..35684470 100644
--- a/src/game-server/item.cpp
+++ b/src/game-server/item.cpp
@@ -76,7 +76,9 @@ void ItemEffectScript::dispell(Being *itemUser)
bool ItemClass::useTrigger(Being *itemUser, ItemTriggerType trigger)
{
- if (!trigger) return false;
+ if (!trigger)
+ return false;
+
std::pair<std::multimap< ItemTriggerType, ItemEffectInfo * >::iterator,
std::multimap< ItemTriggerType, ItemEffectInfo * >::iterator>
rn = mEffects.equal_range(trigger);
diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp
index 3ccfe2bf..2c3f9224 100644
--- a/src/game-server/item.hpp
+++ b/src/game-server/item.hpp
@@ -143,7 +143,10 @@ class ItemClass
{
public:
ItemClass(int id, unsigned int maxperslot)
- : mDatabaseID(id), mSpriteID(0), mMaxPerSlot(maxperslot)
+ : mDatabaseID(id)
+ , mSpriteID(0)
+ , mCost(0)
+ , mMaxPerSlot(maxperslot)
{}
~ItemClass() { resetEffects(); }
@@ -155,12 +158,6 @@ class ItemClass
bool useTrigger(Being *itemUser, ItemTriggerType trigger);
/**
- * Gets item weight.
- */
- int getWeight() const
- { return mWeight; }
-
- /**
* Gets unit cost of these items.
*/
int getCost() const
@@ -232,7 +229,6 @@ class ItemClass
unsigned short mDatabaseID; /**< Item reference information */
/** The sprite that should be shown to the character */
unsigned short mSpriteID;
- unsigned short mWeight; /**< Weight of the item. */
unsigned short mCost; /**< Unit cost the item. */
/** Max item amount per slot in inventory. */
unsigned int mMaxPerSlot;