Mana
Loading...
Searching...
No Matches
buysellhandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
23
24#include "actorspritemanager.h"
25#include "item.h"
26#include "playerinfo.h"
27
28#include "gui/buydialog.h"
29#include "gui/selldialog.h"
30
33
34namespace ManaServ {
35
37{
38 static const Uint16 _messages[] = {
41 0
42 };
43 handledMessages = _messages;
44}
45
47{
49 if (!being || being->getType() != ActorSprite::NPC)
50 {
51 return;
52 }
53
54 int npcId = being->getId();
55
56 switch (msg.getId())
57 {
58 case GPMSG_NPC_BUY:
59 {
60 auto* dialog = new BuyDialog(npcId);
61
62 dialog->reset();
63 dialog->setMoney(PlayerInfo::getAttribute(MONEY));
64
65 while (msg.getUnreadLength())
66 {
67 int itemId = msg.readInt16();
68 int amount = msg.readInt16();
69 int value = msg.readInt16();
70 dialog->addItem(itemId, amount, value);
71 }
72 break;
73 }
74
75 case GPMSG_NPC_SELL:
76 {
77 auto* dialog = new SellDialog(npcId);
78
79 dialog->reset();
80 dialog->setMoney(PlayerInfo::getAttribute(MONEY));
81
82 while (msg.getUnreadLength())
83 {
84 int itemId = msg.readInt16();
85 int amount = msg.readInt16();
86 int value = msg.readInt16();
87 dialog->addItem(new Item(itemId, amount, false), value);
88 }
89 break;
90 }
91 }
92}
93
94} // namespace ManaServ
ActorSpriteManager * actorSpriteManager
Definition game.cpp:110
Being * findBeing(int id) const
Returns a specific Being, by id;.
int getId() const
Definition actorsprite.h:63
Definition being.h:65
Type getType() const final
Returns the type of the ActorSprite.
Definition being.h:122
The buy dialog.
Definition buydialog.h:42
Represents one or more instances of a certain item type.
Definition item.h:35
void handleMessage(MessageIn &msg) override
Used for parsing an incoming message from manaserv.
Definition messagein.h:37
uint16_t readInt16()
Reads an unsigned 16-bit integer from the message.
Definition messagein.cpp:58
unsigned int getUnreadLength() const
Returns the length of unread data.
Definition messagein.h:54
uint16_t getId() const
Returns the message ID.
Definition messagein.h:44
const uint16_t * handledMessages
The sell dialog.
Definition selldialog.h:39
int getAttribute(int id)
Returns the value of the given attribute.
@ MONEY
Definition playerinfo.h:34