summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-08-09 21:31:02 +0300
committerAndrei Karas <akaras@inbox.ru>2017-08-09 21:31:02 +0300
commit90705929b29445a4569ff5c9ad13b7efcb304e0a (patch)
tree0dae1643b0fb33131fb918fe3a1729e879379e26
parentb3fa7a53a29a1001935514a38f140af2b816771a (diff)
downloadmanaverse-90705929b29445a4569ff5c9ad13b7efcb304e0a.tar.gz
manaverse-90705929b29445a4569ff5c9ad13b7efcb304e0a.tar.bz2
manaverse-90705929b29445a4569ff5c9ad13b7efcb304e0a.tar.xz
manaverse-90705929b29445a4569ff5c9ad13b7efcb304e0a.zip
Add different use actions for items.
Can be used from chat or from custom item menu from items.xml
-rw-r--r--src/actions/actions.cpp31
-rw-r--r--src/being/playerinfo.cpp22
-rw-r--r--src/being/playerinfo.h8
-rw-r--r--src/gui/shortcut/itemshortcut.cpp4
-rw-r--r--src/gui/windows/inventorywindow.cpp6
-rw-r--r--src/net/eathena/inventoryhandler.cpp23
-rw-r--r--src/net/eathena/inventoryhandler.h3
-rw-r--r--src/net/eathena/packetsout.inc2
-rw-r--r--src/net/inventoryhandler.h3
-rw-r--r--src/net/tmwa/inventoryhandler.cpp12
-rw-r--r--src/net/tmwa/inventoryhandler.h3
11 files changed, 98 insertions, 19 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 9fd53d926..87c63407d 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -249,10 +249,9 @@ static Being *findBeing(const std::string &name, const bool npc)
return being;
}
-static Item *getItemByInvIndex(const InputEvent &event,
+static Item *getItemByInvIndex(const int index,
const InventoryTypeT invType)
{
- const int index = atoi(event.args.c_str());
const Inventory *inv = nullptr;
switch (invType)
{
@@ -282,7 +281,8 @@ static int getAmountFromEvent(const InputEvent &event,
Item *&item0,
const InventoryTypeT invType)
{
- Item *const item = getItemByInvIndex(event, invType);
+ Item *const item = getItemByInvIndex(atoi(event.args.c_str()),
+ invType);
item0 = item;
if (item == nullptr)
return 0;
@@ -475,7 +475,8 @@ impHandler(dropItemId)
impHandler(dropItemInv)
{
- Item *const item = getItemByInvIndex(event, InventoryType::Inventory);
+ Item *const item = getItemByInvIndex(atoi(event.args.c_str()),
+ InventoryType::Inventory);
if ((item != nullptr) && !PlayerInfo::isItemProtected(item->getId()))
{
ItemAmountWindow::showWindow(ItemAmountWindowUsage::ItemDrop,
@@ -501,7 +502,8 @@ impHandler(dropItemIdAll)
impHandler(dropItemInvAll)
{
- Item *const item = getItemByInvIndex(event, InventoryType::Inventory);
+ Item *const item = getItemByInvIndex(atoi(event.args.c_str()),
+ InventoryType::Inventory);
if ((item != nullptr) && !PlayerInfo::isItemProtected(item->getId()))
PlayerInfo::dropItem(item, item->getQuantity(), Sfx_true);
return true;
@@ -1629,7 +1631,7 @@ impHandler(useItem)
// +++ ignoring item color for now
const Item *const item = inv->findItem(itemId,
ItemColor_one);
- PlayerInfo::useEquipItem(item, Sfx_true);
+ PlayerInfo::useEquipItem(item, 0, Sfx_true);
}
}
else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
@@ -1649,8 +1651,21 @@ impHandler(useItem)
impHandler(useItemInv)
{
- Item *const item = getItemByInvIndex(event, InventoryType::Inventory);
- PlayerInfo::useEquipItem(item, Sfx_true);
+ int param1 = 0;
+ int param2 = 0;
+ const std::string args = event.args;
+ if (parse2Int(args, param1, param2))
+ {
+ Item *const item = getItemByInvIndex(param1,
+ InventoryType::Inventory);
+ PlayerInfo::useEquipItem(item, param2, Sfx_true);
+ }
+ else
+ {
+ Item *const item = getItemByInvIndex(atoi(event.args.c_str()),
+ InventoryType::Inventory);
+ PlayerInfo::useEquipItem(item, 0, Sfx_true);
+ }
return true;
}
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 4429ba5f7..9f1514243 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -267,7 +267,9 @@ void useItem(const Item *const item, const Sfx sfx)
inventoryHandler->useItem(item);
}
-void useEquipItem(const Item *const item, const Sfx sfx)
+void useEquipItem(const Item *const item,
+ const int16_t useType,
+ const Sfx sfx)
{
if (item != nullptr)
{
@@ -303,7 +305,12 @@ void useEquipItem(const Item *const item, const Sfx sfx)
if (mProtectedItems.find(item->getId()) == mProtectedItems.end())
{
if (inventoryHandler != nullptr)
- inventoryHandler->useItem(item);
+ {
+ if (useType == 0)
+ inventoryHandler->useItem(item);
+ else
+ inventoryHandler->useItem(item, useType);
+ }
if (sfx == Sfx_true)
ItemSoundManager::playSfx(item, ItemSoundEvent::USE);
}
@@ -311,7 +318,9 @@ void useEquipItem(const Item *const item, const Sfx sfx)
}
}
-void useEquipItem2(const Item *const item, const Sfx sfx)
+void useEquipItem2(const Item *const item,
+ const int16_t useType,
+ const Sfx sfx)
{
if (item != nullptr)
{
@@ -339,7 +348,12 @@ void useEquipItem2(const Item *const item, const Sfx sfx)
if (sfx == Sfx_true)
ItemSoundManager::playSfx(item, ItemSoundEvent::USE);
if (inventoryHandler != nullptr)
- inventoryHandler->useItem(item);
+ {
+ if (useType == 0)
+ inventoryHandler->useItem(item);
+ else
+ inventoryHandler->useItem(item, useType);
+ }
}
}
}
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index 1c81d7761..004691e86 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -239,9 +239,13 @@ namespace PlayerInfo
void useItem(const Item *const item, const Sfx sfx);
- void useEquipItem(const Item *const item, const Sfx sfx);
+ void useEquipItem(const Item *const item,
+ const int16_t useType,
+ const Sfx sfx);
- void useEquipItem2(const Item *const item, const Sfx sfx);
+ void useEquipItem2(const Item *const item,
+ const int16_t useType,
+ const Sfx sfx);
void dropItem(const Item *const item, const int amount, const Sfx sfx);
diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp
index 7139fd74e..8c091f8c1 100644
--- a/src/gui/shortcut/itemshortcut.cpp
+++ b/src/gui/shortcut/itemshortcut.cpp
@@ -160,8 +160,8 @@ void ItemShortcut::useItem(const size_t index) const
if (itemId < SPELL_MIN_ID)
{
const Item *const item = inv->findItem(itemId, itemColor);
- if ((item != nullptr) && (item->getQuantity() != 0))
- PlayerInfo::useEquipItem(item, Sfx_true);
+ if (item != nullptr && item->getQuantity() != 0)
+ PlayerInfo::useEquipItem(item, 0, Sfx_true);
}
else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
{
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 8a3a70bdc..9fc6b6b38 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -470,11 +470,11 @@ void InventoryWindow::action(const ActionEvent &event)
if (eventId == "use")
{
- PlayerInfo::useEquipItem(item, Sfx_true);
+ PlayerInfo::useEquipItem(item, 0, Sfx_true);
}
if (eventId == "equip")
{
- PlayerInfo::useEquipItem2(item, Sfx_true);
+ PlayerInfo::useEquipItem2(item, 0, Sfx_true);
}
else if (eventId == "drop")
{
@@ -672,7 +672,7 @@ void InventoryWindow::mouseClicked(MouseEvent &event)
}
else
{
- PlayerInfo::useEquipItem(item, Sfx_true);
+ PlayerInfo::useEquipItem(item, 0, Sfx_true);
}
}
else
diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp
index f59dc4c6c..40ae67d5d 100644
--- a/src/net/eathena/inventoryhandler.cpp
+++ b/src/net/eathena/inventoryhandler.cpp
@@ -38,6 +38,7 @@
#include "debug.h"
extern int packetVersion;
+extern int serverVersion;
// this conversion from bit corrupted LOOK_* to EquipSlot
// for how it corrupted, see BeingRecv::processBeingChangeLookContinue
@@ -117,6 +118,28 @@ void InventoryHandler::useItem(const Item *const item) const
outMsg.writeInt32(item->getId(), "unused");
}
+void InventoryHandler::useItem(const Item *const item,
+ const int16_t useType) const
+{
+ if (item == nullptr)
+ return;
+
+ if (serverVersion >= 19)
+ {
+ createOutPacket(CMSG_PLAYER_INVENTORY_USE2);
+ outMsg.writeInt16(CAST_S16(
+ item->getInvIndex() + INVENTORY_OFFSET), "index");
+ outMsg.writeInt16(useType, "use type");
+ }
+ else
+ {
+ createOutPacket(CMSG_PLAYER_INVENTORY_USE);
+ outMsg.writeInt16(CAST_S16(
+ item->getInvIndex() + INVENTORY_OFFSET), "index");
+ outMsg.writeInt32(item->getId(), "unused");
+ }
+}
+
void InventoryHandler::dropItem(const Item *const item, const int amount) const
{
if (item == nullptr)
diff --git a/src/net/eathena/inventoryhandler.h b/src/net/eathena/inventoryhandler.h
index 3a804fb3d..79155ddaa 100644
--- a/src/net/eathena/inventoryhandler.h
+++ b/src/net/eathena/inventoryhandler.h
@@ -43,6 +43,9 @@ class InventoryHandler final : public Ea::InventoryHandler
void useItem(const Item *const item) const override final;
+ void useItem(const Item *const item,
+ const int16_t useType) const override final;
+
void dropItem(const Item *const item,
const int amount) const override final;
diff --git a/src/net/eathena/packetsout.inc b/src/net/eathena/packetsout.inc
index c1ad6ac4f..92c986755 100644
--- a/src/net/eathena/packetsout.inc
+++ b/src/net/eathena/packetsout.inc
@@ -259,6 +259,8 @@ packet(CMSG_SET_STATUS, 0x0b0e, 0, nullptr);
packet(CMSG_ONLINE_LIST, 0x0b0f, 0, nullptr);
+packet(CMSG_PLAYER_INVENTORY_USE2, 0x0b26, 6, nullptr);
+
#ifndef PACKETS_UPDATE
// 0
packet(CMSG_ALCHEMIST_RANKS, 0x0000, 0, nullptr);
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index a93837939..aaa4d6f67 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -51,6 +51,9 @@ class InventoryHandler notfinal
virtual void useItem(const Item *const item) const = 0;
+ virtual void useItem(const Item *const item,
+ const int16_t useType) const = 0;
+
virtual void dropItem(const Item *const item,
const int amount) const = 0;
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index e87b748c7..7afbf746e 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -98,6 +98,18 @@ void InventoryHandler::useItem(const Item *const item) const
outMsg.writeInt32(item->getId(), "item id");
}
+void InventoryHandler::useItem(const Item *const item,
+ const int16_t useType A_UNUSED) const
+{
+ if (item == nullptr)
+ return;
+
+ createOutPacket(CMSG_PLAYER_INVENTORY_USE);
+ outMsg.writeInt16(CAST_S16(
+ item->getInvIndex() + INVENTORY_OFFSET), "index");
+ outMsg.writeInt32(item->getId(), "item id");
+}
+
void InventoryHandler::dropItem(const Item *const item, const int amount) const
{
if (item == nullptr)
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index 302c52ca0..5bf67f9f1 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -43,6 +43,9 @@ class InventoryHandler final : public Ea::InventoryHandler
void useItem(const Item *const item) const override final;
+ void useItem(const Item *const item,
+ const int16_t useType) const override final;
+
void dropItem(const Item *const item,
const int amount) const override final;