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