aboutsummaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r--src/content_sao.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 6caea5198..609673ed9 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -1341,6 +1341,42 @@ std::string PlayerSAO::getWieldList() const
return "main";
}
+ItemStack PlayerSAO::getWieldedItem() const
+{
+ const Inventory *inv = getInventory();
+ ItemStack ret;
+ const InventoryList *mlist = inv->getList(getWieldList());
+ if (mlist && getWieldIndex() < (s32)mlist->getSize())
+ ret = mlist->getItem(getWieldIndex());
+ if (ret.name.empty()) {
+ const InventoryList *hlist = inv->getList("hand");
+ if (hlist)
+ ret = hlist->getItem(0);
+ }
+ return ret;
+}
+
+bool PlayerSAO::setWieldedItem(const ItemStack &item)
+{
+ Inventory *inv = getInventory();
+ if (inv) {
+ InventoryList *mlist = inv->getList(getWieldList());
+ if (mlist) {
+ ItemStack olditem = mlist->getItem(getWieldIndex());
+ if (olditem.name.empty()) {
+ InventoryList *hlist = inv->getList("hand");
+ if (hlist) {
+ hlist->changeItem(0, item);
+ return true;
+ }
+ }
+ mlist->changeItem(getWieldIndex(), item);
+ return true;
+ }
+ }
+ return false;
+}
+
int PlayerSAO::getWieldIndex() const
{
return m_wield_index;