diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/buy.cpp | 4 | ||||
-rw-r--r-- | src/gui/buy.h | 2 | ||||
-rw-r--r-- | src/gui/sell.cpp | 17 | ||||
-rw-r--r-- | src/gui/sell.h | 2 | ||||
-rw-r--r-- | src/gui/shop.cpp | 8 | ||||
-rw-r--r-- | src/gui/shop.h | 2 | ||||
-rw-r--r-- | src/net/buysellhandler.cpp | 75 | ||||
-rw-r--r-- | src/net/protocol.h | 5 |
8 files changed, 43 insertions, 72 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 2a8616f8..9ac37e96 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -128,9 +128,9 @@ void BuyDialog::reset() updateButtonsAndLabels(); } -void BuyDialog::addItem(short id, int price) +void BuyDialog::addItem(int id, int amount, int price) { - mShopItems->addItem(id, price); + mShopItems->addItem(id, amount, price); mShopItemList->adjustSize(); } diff --git a/src/gui/buy.h b/src/gui/buy.h index 7834a434..875deef9 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -68,7 +68,7 @@ class BuyDialog : public Window, public gcn::ActionListener, SelectionListener /** * Adds an item to the shop inventory. */ - void addItem(short id, int price); + void addItem(int id, int amount, int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 478371b1..53746248 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -126,22 +126,9 @@ void SellDialog::reset() updateButtonsAndLabels(); } -void SellDialog::addItem(Item *item, int price) +void SellDialog::addItem(int item, int amount, int price) { - if (!item) - return; - - ITEM_SHOP item_shop; - - item_shop.name = item->getInfo().getName() - + " (" + toString(price) + " GP)"; - item_shop.price = price; - item_shop.index = item->getInvIndex(); - item_shop.id = item->getId(); - item_shop.quantity = item->getQuantity(); - item_shop.image = item->getInfo().getImage(); - - mShopItems->push_back(item_shop); + mShopItems->addItem(item, amount, price); mShopItemList->adjustSize(); } diff --git a/src/gui/sell.h b/src/gui/sell.h index b8385a6f..fc42fd1c 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -63,7 +63,7 @@ class SellDialog : public Window, gcn::ActionListener, SelectionListener /** * Adds an item to the inventory. */ - void addItem(Item *item, int price); + void addItem(int item, int amount, int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index 3d972bc2..e2fd54f2 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -40,15 +40,17 @@ std::string ShopItems::getElementAt(int i) return mItemsShop.at(i).name; } -void ShopItems::addItem(short id, int price) +void ShopItems::addItem(int id, int amount, int price) { ITEM_SHOP item_shop; + ItemInfo const &item = ItemDB::get(id); - item_shop.name = ItemDB::get(id).getName() + item_shop.name = item.getName() + " (" + toString(price) + " GP)"; item_shop.price = price; item_shop.id = id; - item_shop.image = ItemDB::get(id).getImage(); + item_shop.quantity = amount; + item_shop.image = item.getImage(); mItemsShop.push_back(item_shop); } diff --git a/src/gui/shop.h b/src/gui/shop.h index de452b5c..665e92cb 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -50,7 +50,7 @@ class ShopItems : public gcn::ListModel /** * Adds an item and its associated picture */ - void addItem(short id, int price); + void addItem(int id, int amount, int price); /** * Convenience function for adding items diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 2f22b0e6..9b96ced7 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -44,6 +44,8 @@ extern Window *buySellDialog; BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { + GPMSG_NPC_BUY, + GPMSG_NPC_SELL, 0 }; handledMessages = _messages; @@ -51,6 +53,14 @@ BuySellHandler::BuySellHandler() void BuySellHandler::handleMessage(MessageIn &msg) { + Being *being = beingManager->findBeing(msg.readShort()); + if (!being || being->getType() != Being::NPC) + { + return; + } + + current_npc = static_cast< NPC * >(being); + switch (msg.getId()) { #if 0 @@ -62,65 +72,34 @@ void BuySellHandler::handleMessage(MessageIn &msg) buySellDialog->setVisible(true); current_npc = dynamic_cast<NPC*>(beingManager->findBeing(msg.readLong())); break; +#endif - case SMSG_NPC_BUY: - msg.readShort(); // length - n_items = (msg.getLength() - 4) / 11; + case GPMSG_NPC_BUY: buyDialog->reset(); buyDialog->setMoney(player_node->getMoney()); buyDialog->setVisible(true); - for (int k = 0; k < n_items; k++) + while (msg.getUnreadLength()) { - Sint32 value = msg.readLong(); - msg.readLong(); // DCvalue - msg.readByte(); // type - Sint16 itemId = msg.readShort(); - buyDialog->addItem(itemId, value); - } - break; - - case SMSG_NPC_SELL: - msg.readShort(); // length - n_items = (msg.getLength() - 4) / 10; - if (n_items > 0) { - sellDialog->setMoney(player_node->getMoney()); - sellDialog->reset(); - sellDialog->setVisible(true); - - for (int k = 0; k < n_items; k++) - { - Sint16 index = msg.readShort(); - Sint32 value = msg.readLong(); - msg.readLong(); // OCvalue - - Item *item = player_node->getInvItem(index); - if (item && !(item->isEquipped())) { - sellDialog->addItem(item, value); - } - } - } - else { - chatWindow->chatLog("Nothing to sell", BY_SERVER); - current_npc = 0; + int itemId = msg.readShort(); + int amount = msg.readShort(); + int value = msg.readShort(); + buyDialog->addItem(itemId, amount, value); } break; - case SMSG_NPC_BUY_RESPONSE: - if (msg.readByte() == 0) { - chatWindow->chatLog("Thanks for buying", BY_SERVER); - } else { - chatWindow->chatLog("Unable to buy", BY_SERVER); - } - break; + case GPMSG_NPC_SELL: + sellDialog->setMoney(player_node->getMoney()); + sellDialog->reset(); + sellDialog->setVisible(true); - case SMSG_NPC_SELL_RESPONSE: - if (msg.readByte() == 0) { - chatWindow->chatLog("Thanks for selling", BY_SERVER); - } else { - chatWindow->chatLog("Unable to sell", BY_SERVER); + while (msg.getUnreadLength()) + { + int itemId = msg.readShort(); + int amount = msg.readShort(); + int value = msg.readShort(); + sellDialog->addItem(itemId, amount, value); } break; -#endif } } diff --git a/src/net/protocol.h b/src/net/protocol.h index a524304a..6bbe7919 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -98,11 +98,14 @@ enum { GPMSG_BEING_ATTACK = 0x0291, // W being id PGMSG_SAY = 0x02A0, // S text GPMSG_SAY = 0x02A1, // W being id, S text - GPMSG_NPC_CHOICE = 0x02B0, // W being id, B* text + GPMSG_NPC_CHOICE = 0x02B0, // W being id, { S text }* GPMSG_NPC_MESSAGE = 0x02B1, // W being id, B* text PGMSG_NPC_TALK = 0x02B2, // W being id PGMSG_NPC_TALK_NEXT = 0x02B3, // W being id PGMSG_NPC_SELECT = 0x02B4, // W being id, B choice + GPMSG_NPC_BUY = 0x02B5, // W being id, { W item id, W amount, W cost }* + GPMSG_NPC_SELL = 0x02B6, // W being id, { W item id, W amount, W cost }* + PGMSG_NPC_BUYSELL = 0x02B7, // W item id, W amount PGMSG_TRADE_REQUEST = 0x02C0, // W being id GPMSG_TRADE_REQUEST = 0x02C1, // W being id GPMSG_TRADE_START = 0x02C2, // - |