ManaPlus
npchandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "net/tmwa/npchandler.h"
24 
25 #include "being/localplayer.h"
26 
27 #include "const/net/inventory.h"
28 
29 #include "gui/windows/npcdialog.h"
30 
32 
33 #include "net/messagein.h"
34 
35 #include "net/tmwa/messageout.h"
36 #include "net/tmwa/protocolout.h"
37 
38 #include "net/ea/npcrecv.h"
39 
40 #include "debug.h"
41 
42 namespace TmwAthena
43 {
44 
46  Ea::NpcHandler()
47 {
48  npcHandler = this;
49 }
50 
52 {
53  npcHandler = nullptr;
54 }
55 
56 void NpcHandler::talk(const Being *const being) const
57 {
58  if (being == nullptr)
59  return;
61  outMsg.writeBeingId(being->getId(), "npc id");
62  outMsg.writeInt8(0, "unused");
63 }
64 
65 void NpcHandler::nextDialog(const BeingId npcId) const
66 {
68  outMsg.writeBeingId(npcId, "npc id");
69 }
70 
72 {
74  outMsg.writeBeingId(npcId, "npc id");
75 
76  const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId);
77  if (it != NpcDialog::mNpcDialogs.end())
78  {
79  NpcDialog *const dialog = (*it).second;
80  if (dialog != nullptr)
81  dialog->close();
82  if (dialog == Ea::NpcRecv::mDialog)
83  Ea::NpcRecv::mDialog = nullptr;
84  NpcDialog::mNpcDialogs.erase(it);
85  }
86 }
87 
88 void NpcHandler::listInput(const BeingId npcId,
89  const unsigned char value) const
90 {
92  outMsg.writeBeingId(npcId, "npc id");
93  outMsg.writeInt8(value, "value");
94 }
95 
97  const int value) const
98 {
100  outMsg.writeBeingId(npcId, "npc id");
101  outMsg.writeInt32(value, "value");
102 }
103 
105  const std::string &value) const
106 {
108  outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
109  outMsg.writeBeingId(npcId, "npc id");
110  outMsg.writeString(value, CAST_S32(value.length()), "value");
111  outMsg.writeInt8(0, "null byte");
112 }
113 
114 void NpcHandler::buy(const Being *const being) const
115 {
116  if (being == nullptr)
117  return;
119  outMsg.writeBeingId(being->getId(), "npc id");
120  outMsg.writeInt8(0, "action");
121 }
122 
123 void NpcHandler::buy(const BeingId beingId) const
124 {
126  outMsg.writeBeingId(beingId, "npc id");
127  outMsg.writeInt8(0, "action");
128 }
129 
130 void NpcHandler::sell(const BeingId beingId) const
131 {
133  outMsg.writeBeingId(beingId, "npc id");
134  outMsg.writeInt8(1, "action");
135 }
136 
138  const int itemId,
139  const ItemColor color A_UNUSED,
140  const int amount) const
141 {
143  outMsg.writeInt16(8, "len");
144  outMsg.writeInt16(CAST_S16(amount), "amount");
145  outMsg.writeInt16(CAST_S16(itemId), "item id");
146 }
147 
148 void NpcHandler::buyItems(STD_VECTOR<ShopItem*> &items A_UNUSED) const
149 {
150 }
151 
153  const int itemId,
154  const int amount) const
155 {
157  outMsg.writeInt16(8, "len");
158  outMsg.writeInt16(CAST_S16(
159  itemId + INVENTORY_OFFSET), "index");
160  outMsg.writeInt16(CAST_S16(amount), "amount");
161 }
162 
163 void NpcHandler::sellItems(STD_VECTOR<ShopItem*> &items A_UNUSED) const
164 {
165 }
166 
168 {
169 }
170 
171 void NpcHandler::produceMix(const int nameId A_UNUSED,
172  const int materialId1 A_UNUSED,
173  const int materialId2 A_UNUSED,
174  const int materialId3 A_UNUSED) const
175 {
176 }
177 
179  const int nameId A_UNUSED) const
180 {
181 }
182 
183 void NpcHandler::repair(const int index A_UNUSED) const
184 {
185 }
186 
187 void NpcHandler::refine(const int index A_UNUSED) const
188 {
189 }
190 
191 void NpcHandler::identify(const int index A_UNUSED) const
192 {
193 }
194 
195 void NpcHandler::selectArrow(const int nameId A_UNUSED) const
196 {
197 }
198 
199 void NpcHandler::selectAutoSpell(const int skillId A_UNUSED) const
200 {
201 }
202 
204  const NpcActionT action)
205 {
206  const BeingId npcId = msg.readBeingId("npc id");
207 
208  const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId);
209 
210  if (diag == NpcDialog::mNpcDialogs.end())
211  {
212  Ea::NpcRecv::mDialog = nullptr;
213  // Empty dialogs don't help
214  if (action == NpcAction::Close)
215  {
216  closeDialog(npcId);
217  return npcId;
218  }
219  else if (action == NpcAction::Next)
220  {
221  nextDialog(npcId);
222  return npcId;
223  }
224  else
225  {
228  if (localPlayer != nullptr)
229  localPlayer->stopWalking(false);
231  }
232  }
233  else
234  {
235  NpcDialog *const dialog = diag->second;
236  if (Ea::NpcRecv::mDialog != nullptr && Ea::NpcRecv::mDialog != dialog)
238  Ea::NpcRecv::mDialog = dialog;
239  if (Ea::NpcRecv::mDialog != nullptr)
241  }
242  return npcId;
243 }
244 
245 void NpcHandler::requestAirship(const std::string &mapName A_UNUSED,
246  const int itemId A_UNUSED) const
247 {
248 }
249 
250 } // namespace TmwAthena
void refine(const int index) const
Definition: npchandler.cpp:187
int CMSG_NPC_CLOSE
Definition: protocolout.cpp:70
void sell(const BeingId beingId) const
Definition: npchandler.cpp:130
NpcAction ::T NpcActionT
Definition: npcaction.h:32
int CMSG_NPC_LIST_CHOICE
Definition: protocolout.cpp:71
void requestAirship(const std::string &mapName, const int itemId) const
Definition: npchandler.cpp:245
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
void buyItem(const BeingId beingId, const int itemId, const ItemColor color, const int amount) const
Definition: npchandler.cpp:137
void buyItems(std::vector< ShopItem *> &items) const
Definition: npchandler.cpp:148
BeingId getId() const
Definition: actorsprite.h:63
NpcDialog * mDialog
Definition: npcrecv.cpp:41
void stopWalking(const bool sendToServer)
int BeingId
Definition: beingid.h:29
static const int INVENTORY_OFFSET
Definition: inventory.h:26
int CMSG_NPC_NEXT_REQUEST
Definition: protocolout.cpp:69
uint16_t ItemColor
Definition: itemcolor.h:29
bool msg(InputEvent &event)
Definition: chat.cpp:38
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
void stringInput(const BeingId npcId, const std::string &value) const
Definition: npchandler.cpp:104
int CMSG_NPC_BUY_SELL_REQUEST
Definition: protocolout.cpp:74
void restoreCamera()
Definition: npcdialog.cpp:1114
BeingId getNpc(Net::MessageIn &msg, const NpcActionT action)
Definition: npchandler.cpp:203
virtual void close()
Definition: window.cpp:901
void sellItem(const BeingId beingId, const int itemId, const int amount) const
Definition: npchandler.cpp:152
void selectArrow(const int nameId) const
Definition: npchandler.cpp:195
#define CAST_S32
Definition: cast.h:29
void listInput(const BeingId npcId, const unsigned char value) const
Definition: npchandler.cpp:88
static NpcDialogs mNpcDialogs
Definition: npcdialog.h:241
void buy(const Being *const being) const
Definition: npchandler.cpp:114
LocalPlayer * localPlayer
int CMSG_NPC_BUY_REQUEST
Definition: protocolout.cpp:75
void talk(const Being *const being) const
Definition: npchandler.cpp:56
int CMSG_NPC_INT_RESPONSE
Definition: protocolout.cpp:72
void selectAutoSpell(const int skillId) const
Definition: npchandler.cpp:199
void nextDialog(const BeingId npcId) const
Definition: npchandler.cpp:65
void identify(const int index) const
Definition: npchandler.cpp:191
void cooking(const CookingTypeT type, const int nameId) const
Definition: npchandler.cpp:178
#define createOutPacket(name)
Definition: messageout.h:36
void integerInput(const BeingId npcId, const int value) const
Definition: npchandler.cpp:96
void saveCamera()
Definition: npcdialog.cpp:1104
void repair(const int index) const
Definition: npchandler.cpp:183
void produceMix(const int nameId, const int materialId1, const int materialId2, const int materialId3) const
Definition: npchandler.cpp:171
void closeDialog(const BeingId npcId)
Definition: npchandler.cpp:71
#define A_UNUSED
Definition: localconsts.h:159
CookingType ::T CookingTypeT
Definition: cookingtype.h:35
int CMSG_NPC_TALK
Definition: protocolout.cpp:68
void sellItems(std::vector< ShopItem *> &items) const
Definition: npchandler.cpp:163
int CMSG_NPC_SELL_REQUEST
Definition: protocolout.cpp:76
Net::NpcHandler * npcHandler
Definition: net.cpp:90
#define CAST_S16
Definition: cast.h:27
Definition: being.h:93
void completeProgressBar() const
Definition: npchandler.cpp:167
int CMSG_NPC_STR_RESPONSE
Definition: protocolout.cpp:73