diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-12-19 15:15:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-12-19 15:15:44 +0300 |
commit | f0315000bcf20685471966d2f25cd8e9f35e8230 (patch) | |
tree | b5b51e2880191696d6217181d5aa4d5c5341265f | |
parent | 5615f8dde421e8d44c5e49a5a44ab7e69cb543a5 (diff) | |
download | plus-f0315000bcf20685471966d2f25cd8e9f35e8230.tar.gz plus-f0315000bcf20685471966d2f25cd8e9f35e8230.tar.bz2 plus-f0315000bcf20685471966d2f25cd8e9f35e8230.tar.xz plus-f0315000bcf20685471966d2f25cd8e9f35e8230.zip |
add ability to give more than one item to npc. (evol only)
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 36 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.h | 2 | ||||
-rw-r--r-- | src/inventory.cpp | 15 | ||||
-rw-r--r-- | src/inventory.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/npchandler.cpp | 8 |
5 files changed, 53 insertions, 10 deletions
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 1c2a6cc1d..36f7bedc8 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -360,16 +360,38 @@ void NpcDialog::action(const gcn::ActionEvent &event) if (!client->limitPackets(PACKET_NPC_INPUT)) return; - const Item *const item = mInventory->getItem(0); std::string str; - if (item) + const int sz = mInventory->getNumberOfSlotsUsed(); + if (sz == 0) { - str = strprintf("%d,%d", item->getId(), - item->getColor()); + str = "0,0"; } else { - str = "0,0"; + const Item *item = mInventory->getItem(0); + if (item) + { + str = strprintf("%d,%d", item->getId(), + item->getColor()); + } + else + { + str = "0,0"; + } + for (int f = 1; f < sz; f ++) + { + str.append(";"); + item = mInventory->getItem(f); + if (item) + { + str.append(strprintf("%d,%d", item->getId(), + item->getColor())); + } + else + { + str.append("0,0"); + } + } } // need send selected item @@ -597,11 +619,11 @@ void NpcDialog::integerRequest(const int defaultValue, const int min, buildLayout(); } -void NpcDialog::itemRequest() +void NpcDialog::itemRequest(const int size) { mActionState = NPC_ACTION_INPUT; mInputState = NPC_INPUT_ITEM; - + mInventory->resize(size); buildLayout(); } diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index 27efcee2f..1736f5567 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -164,7 +164,7 @@ class NpcDialog final : public Window, void integerRequest(const int defaultValue = 0, const int min = 0, const int max = 2147483647); - void itemRequest(); + void itemRequest(const int size); void move(const int amount); diff --git a/src/inventory.cpp b/src/inventory.cpp index 61500fb7a..9a82f192b 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -268,3 +268,18 @@ std::string Inventory::getName() const } } } + +void Inventory::resize(const unsigned int newSize) +{ + clear(); + if (mSize == newSize) + return; + + for (unsigned i = 0; i < mSize; i++) + delete mItems[i]; + delete [] mItems; + + mSize = newSize; + mItems = new Item*[mSize]; + std::fill_n(mItems, mSize, static_cast<Item*>(nullptr)); +} diff --git a/src/inventory.h b/src/inventory.h index e9949dc52..17855a064 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -160,6 +160,8 @@ class Inventory final std::string getName() const A_WARN_UNUSED; + void resize(const unsigned int newSize); + protected: typedef std::list<InventoryListener*> InventoryListenerList; InventoryListenerList mInventoryListeners; diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 1356dbf8c..bb53ef33f 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -329,10 +329,14 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg, const int npcId) mDialog->clearRows(); break; case 10: // send selected item id + { + int invSize = msg.readInt32(); + if (!invSize) + invSize = 1; if (mDialog) - mDialog->itemRequest(); + mDialog->itemRequest(invSize); break; - + } default: logger->log("unknown npc command: %d", cmd); break; |