ManaPlus
Public Member Functions
EAthena::NpcHandler Class Reference

#include <npchandler.h>

Inheritance diagram for EAthena::NpcHandler:
Ea::NpcHandler Net::NpcHandler

Public Member Functions

 NpcHandler ()
 
 ~NpcHandler ()
 
void talk (const Being *const being) const
 
void nextDialog (const BeingId npcId) const
 
void closeDialog (const BeingId npcId)
 
void listInput (const BeingId npcId, const unsigned char value) const
 
void integerInput (const BeingId npcId, const int value) const
 
void stringInput (const BeingId npcId, const std::string &value) const
 
void buy (const Being *const being) const
 
void buy (const BeingId beingId) const
 
void sell (const BeingId beingId) const
 
void buyItem (const BeingId beingId, const int itemId, const ItemColor color, const int amount) const
 
void buyItems (std::vector< ShopItem * > &items) const
 
void sellItem (const BeingId beingId, const int itemId, const int amount) const
 
void sellItems (std::vector< ShopItem * > &items) const
 
void completeProgressBar () const
 
void produceMix (const int nameId, const int materialId1, const int materialId2, const int materialId3) const
 
void cooking (const CookingTypeT type, const int nameId) const
 
void repair (const int index) const
 
void refine (const int index) const
 
BeingId getNpc (Net::MessageIn &msg, const NpcActionT action)
 
void identify (const int index) const
 
void selectArrow (const int nameId) const
 
void selectAutoSpell (const int skillId) const
 
void requestAirship (const std::string &mapName, const int itemId) const
 
- Public Member Functions inherited from Ea::NpcHandler
NpcDialoggetCurrentNpcDialog () const
 
- Public Member Functions inherited from Net::NpcHandler
 NpcHandler ()
 

Additional Inherited Members

- Protected Member Functions inherited from Ea::NpcHandler
 NpcHandler ()
 

Detailed Description

Definition at line 32 of file npchandler.h.

Constructor & Destructor Documentation

◆ NpcHandler()

EAthena::NpcHandler::NpcHandler ( )

Definition at line 58 of file npchandler.cpp.

58  :
60 {
61  npcHandler = this;
62 }
Net::NpcHandler * npcHandler
Definition: net.cpp:93

References npcHandler.

◆ ~NpcHandler()

EAthena::NpcHandler::~NpcHandler ( )
virtual

Reimplemented from Net::NpcHandler.

Definition at line 64 of file npchandler.cpp.

65 {
66  npcHandler = nullptr;
67 }

References npcHandler.

Member Function Documentation

◆ buy() [1/2]

void EAthena::NpcHandler::buy ( const Being *const  being) const
virtual

Implements Net::NpcHandler.

Definition at line 137 of file npchandler.cpp.

138 {
139  if (being == nullptr)
140  return;
141  createOutPacket(CMSG_NPC_BUY_SELL_REQUEST);
142  outMsg.writeBeingId(being->getId(), "npc id");
143  outMsg.writeInt8(0, "action");
145 }
BeingId getId() const
Definition: actorsprite.h:64
BeingTypeId getSubType() const
Definition: being.h:400
#define createOutPacket(name)
Definition: messageout.h:37
BeingTypeId mNpcTypeId
Definition: npcrecv.cpp:43

References createOutPacket, ActorSprite::getId(), Being::getSubType(), and EAthena::NpcRecv::mNpcTypeId.

◆ buy() [2/2]

void EAthena::NpcHandler::buy ( const BeingId  beingId) const
virtual

Implements Net::NpcHandler.

Definition at line 147 of file npchandler.cpp.

148 {
149  createOutPacket(CMSG_NPC_BUY_SELL_REQUEST);
150  outMsg.writeBeingId(beingId, "npc id");
151  outMsg.writeInt8(0, "action");
153 }
const BeingTypeId BeingTypeId_zero
Definition: beingtypeid.h:30

References BeingTypeId_zero, createOutPacket, and EAthena::NpcRecv::mNpcTypeId.

◆ buyItem()

void EAthena::NpcHandler::buyItem ( const BeingId  beingId,
const int  itemId,
const ItemColor  color,
const int  amount 
) const
virtual

Implements Net::NpcHandler.

Definition at line 162 of file npchandler.cpp.

166 {
167  createOutPacket(CMSG_NPC_BUY_REQUEST);
168  outMsg.writeInt16(8, "len");
169  outMsg.writeInt16(CAST_S16(amount), "amount");
170  outMsg.writeItemId(itemId, "item id");
171 }
#define CAST_S16
Definition: cast.h:28

References CAST_S16, and createOutPacket.

◆ buyItems()

void EAthena::NpcHandler::buyItems ( std::vector< ShopItem * > &  items) const
virtual

Implements Net::NpcHandler.

Definition at line 173 of file npchandler.cpp.

174 {
175  int cnt = 0;
176  const int pairSize = 2 + itemIdLen;
177 
178  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
179  {
180  ShopItem *const item = *it;
181  const int usedQuantity = item->getUsedQuantity();
182  const ItemTypeT type = item->getType();
183  if (usedQuantity == 0)
184  continue;
185  if (type == ItemType::Weapon ||
186  type == ItemType::Armor ||
187  type == ItemType::PetEgg ||
188  type == ItemType::PetArmor)
189  {
190  cnt += item->getUsedQuantity();
191  }
192  else
193  {
194  cnt ++;
195  }
196  }
197 
198  if (cnt > 100)
199  return;
200 
201  createOutPacket(CMSG_NPC_BUY_REQUEST);
202  outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
203  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
204  {
205  ShopItem *const item = *it;
206  const int usedQuantity = item->getUsedQuantity();
207  if (usedQuantity == 0)
208  continue;
209  item->increaseUsedQuantity(-usedQuantity);
210  item->update();
211  const ItemTypeT type = item->getType();
212  if (type == ItemType::Weapon ||
213  type == ItemType::Armor ||
214  type == ItemType::PetEgg ||
215  type == ItemType::PetArmor)
216  {
217  for (int f = 0; f < usedQuantity; f ++)
218  {
219  outMsg.writeInt16(CAST_S16(1), "amount");
220  outMsg.writeItemId(item->getId(),
221  "item id");
222  }
223  }
224  else
225  {
226  outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
227  outMsg.writeItemId(item->getId(), "item id");
228  }
229  }
230 }
int getId() const
Definition: item.h:81
ItemTypeT getType() const
Definition: item.h:225
void increaseUsedQuantity(const int amount)
Definition: shopitem.cpp:159
int getUsedQuantity() const
Definition: shopitem.h:151
void update()
Definition: shopitem.cpp:119
int itemIdLen
Definition: client.cpp:130
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
ItemType ::T ItemTypeT
Definition: itemtype.h:43
@ Armor
Definition: itemtype.h:34
@ Weapon
Definition: itemtype.h:33
@ PetArmor
Definition: itemtype.h:37
@ PetEgg
Definition: itemtype.h:36

References ItemType::Armor, CAST_S16, createOutPacket, FOR_EACH, Item::getId(), Item::getType(), ShopItem::getUsedQuantity(), ShopItem::increaseUsedQuantity(), itemIdLen, ItemType::PetArmor, ItemType::PetEgg, ShopItem::update(), and ItemType::Weapon.

◆ closeDialog()

void EAthena::NpcHandler::closeDialog ( const BeingId  npcId)
virtual

Implements Net::NpcHandler.

Definition at line 85 of file npchandler.cpp.

86 {
87  createOutPacket(CMSG_NPC_CLOSE);
88  outMsg.writeBeingId(npcId, "npc id");
89 
90  const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId);
91  if (it != NpcDialog::mNpcDialogs.end())
92  {
93  NpcDialog *const dialog = (*it).second;
94  if (dialog != nullptr)
95  dialog->close();
96  if (dialog == Ea::NpcRecv::mDialog)
97  Ea::NpcRecv::mDialog = nullptr;
98  NpcDialog::mNpcDialogs.erase(it);
99  }
100 }
static NpcDialogs mNpcDialogs
Definition: npcdialog.h:242
virtual void close()
Definition: window.cpp:902
NpcDialog * mDialog
Definition: npcrecv.cpp:42

References Window::close(), createOutPacket, Ea::NpcRecv::mDialog, and NpcDialog::mNpcDialogs.

Referenced by getNpc().

◆ completeProgressBar()

void EAthena::NpcHandler::completeProgressBar ( ) const
virtual

Implements Net::NpcHandler.

Definition at line 273 of file npchandler.cpp.

274 {
275  createOutPacket(CMSG_NPC_COMPLETE_PROGRESS_BAR);
276 }

References createOutPacket.

◆ cooking()

void EAthena::NpcHandler::cooking ( const CookingTypeT  type,
const int  nameId 
) const
virtual

Implements Net::NpcHandler.

Definition at line 290 of file npchandler.cpp.

292 {
293  createOutPacket(CMSG_NPC_COOKING);
294  outMsg.writeInt16(CAST_S16(type), "type");
295  outMsg.writeItemId(nameId, "item id");
296 }

References CAST_S16, and createOutPacket.

◆ getNpc()

BeingId EAthena::NpcHandler::getNpc ( Net::MessageIn msg,
const NpcActionT  action 
)
virtual

Implements Net::NpcHandler.

Definition at line 333 of file npchandler.cpp.

335 {
336  const BeingId npcId = msg.readBeingId("npc id");
337 
338  const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId);
339 
340  if (diag == NpcDialog::mNpcDialogs.end())
341  {
342  Ea::NpcRecv::mDialog = nullptr;
343  // Empty dialogs don't help
344  if (action == NpcAction::Close)
345  {
346  closeDialog(npcId);
347  return npcId;
348  }
349  else if (action == NpcAction::Next)
350  {
351  nextDialog(npcId);
352  return npcId;
353  }
354  else
355  {
358  if (localPlayer != nullptr)
359  localPlayer->stopWalking(false);
361  }
362  }
363  else
364  {
365  NpcDialog *const dialog = diag->second;
366  if (Ea::NpcRecv::mDialog != nullptr && Ea::NpcRecv::mDialog != dialog)
368  Ea::NpcRecv::mDialog = dialog;
369  if (Ea::NpcRecv::mDialog != nullptr)
371  }
372  return npcId;
373 }
int BeingId
Definition: beingid.h:30
void nextDialog(const BeingId npcId) const
Definition: npchandler.cpp:79
void closeDialog(const BeingId npcId)
Definition: npchandler.cpp:85
void stopWalking(const bool sendToServer)
void saveCamera()
Definition: npcdialog.cpp:1105
void restoreCamera()
Definition: npcdialog.cpp:1115
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39

References NpcAction::Close, closeDialog(), CREATEWIDGETV, localPlayer, Ea::NpcRecv::mDialog, NpcDialog::mNpcDialogs, Actions::msg(), NpcAction::Next, nextDialog(), NpcDialog::restoreCamera(), NpcDialog::saveCamera(), and LocalPlayer::stopWalking().

◆ identify()

void EAthena::NpcHandler::identify ( const int  index) const
virtual

Implements Net::NpcHandler.

Definition at line 315 of file npchandler.cpp.

316 {
317  createOutPacket(CMSG_NPC_IDENTIFY);
318  outMsg.writeInt16(CAST_S16(index), "index");
319 }

References CAST_S16, and createOutPacket.

◆ integerInput()

void EAthena::NpcHandler::integerInput ( const BeingId  npcId,
const int  value 
) const
virtual

Implements Net::NpcHandler.

Definition at line 110 of file npchandler.cpp.

112 {
113  createOutPacket(CMSG_NPC_INT_RESPONSE);
114  outMsg.writeBeingId(npcId, "npc id");
115  outMsg.writeInt32(value, "value");
116 }

References createOutPacket.

◆ listInput()

void EAthena::NpcHandler::listInput ( const BeingId  npcId,
const unsigned char  value 
) const
virtual

Implements Net::NpcHandler.

Definition at line 102 of file npchandler.cpp.

104 {
105  createOutPacket(CMSG_NPC_LIST_CHOICE);
106  outMsg.writeBeingId(npcId, "npc id");
107  outMsg.writeInt8(value, "value");
108 }

References createOutPacket.

◆ nextDialog()

void EAthena::NpcHandler::nextDialog ( const BeingId  npcId) const
virtual

Implements Net::NpcHandler.

Definition at line 79 of file npchandler.cpp.

80 {
81  createOutPacket(CMSG_NPC_NEXT_REQUEST);
82  outMsg.writeBeingId(npcId, "npc id");
83 }

References createOutPacket.

Referenced by getNpc().

◆ produceMix()

void EAthena::NpcHandler::produceMix ( const int  nameId,
const int  materialId1,
const int  materialId2,
const int  materialId3 
) const
virtual

Implements Net::NpcHandler.

Definition at line 278 of file npchandler.cpp.

282 {
283  createOutPacket(CMSG_NPC_PRODUCE_MIX);
284  outMsg.writeItemId(nameId, "item id");
285  outMsg.writeItemId(materialId1, "material 1");
286  outMsg.writeItemId(materialId2, "material 2");
287  outMsg.writeItemId(materialId3, "material 3");
288 }

References createOutPacket.

◆ refine()

void EAthena::NpcHandler::refine ( const int  index) const
virtual

Implements Net::NpcHandler.

Definition at line 309 of file npchandler.cpp.

310 {
311  createOutPacket(CMSG_NPC_REFINE);
312  outMsg.writeInt32(index, "index");
313 }

References createOutPacket.

◆ repair()

void EAthena::NpcHandler::repair ( const int  index) const
virtual

Implements Net::NpcHandler.

Definition at line 298 of file npchandler.cpp.

299 {
300  createOutPacket(CMSG_NPC_REPAIR);
301  outMsg.writeInt16(CAST_S16(index), "index");
302  // unused fields.
303  outMsg.writeItemId(0, "item id");
304  outMsg.writeInt8(0, "refine");
305  for (int f = 0; f < maxCards; f ++)
306  outMsg.writeItemId(0, "card");
307 }
#define maxCards
Definition: cards.h:25

References CAST_S16, createOutPacket, and maxCards.

◆ requestAirship()

void EAthena::NpcHandler::requestAirship ( const std::string &  mapName,
const int  itemId 
) const
virtual

Implements Net::NpcHandler.

Definition at line 375 of file npchandler.cpp.

377 {
378  if (packetVersionRe < 20180321 &&
379  packetVersionMain < 20180620 &&
380  packets_zero == false)
381  {
382  return;
383  }
384  createOutPacket(CMSG_PRIVATE_AIRSHIP_REQUEST);
385  outMsg.writeString(mapName, 16, "map name");
386  outMsg.writeItemId(itemId, "item");
387 }
bool packets_zero
Definition: client.cpp:133
int packetVersionRe
Definition: client.cpp:127
int packetVersionMain
Definition: client.cpp:126

References createOutPacket, packets_zero, packetVersionMain, and packetVersionRe.

◆ selectArrow()

void EAthena::NpcHandler::selectArrow ( const int  nameId) const
virtual

Implements Net::NpcHandler.

Definition at line 321 of file npchandler.cpp.

322 {
323  createOutPacket(CMSG_NPC_SELECT_ARROW);
324  outMsg.writeItemId(nameId, "item id");
325 }

References createOutPacket.

◆ selectAutoSpell()

void EAthena::NpcHandler::selectAutoSpell ( const int  skillId) const
virtual

Implements Net::NpcHandler.

Definition at line 327 of file npchandler.cpp.

328 {
329  createOutPacket(CMSG_NPC_SELECT_AUTO_SPELL);
330  outMsg.writeInt32(CAST_S16(skillId), "skill id");
331 }

References CAST_S16, and createOutPacket.

◆ sell()

void EAthena::NpcHandler::sell ( const BeingId  beingId) const
virtual

Implements Net::NpcHandler.

Definition at line 155 of file npchandler.cpp.

156 {
157  createOutPacket(CMSG_NPC_BUY_SELL_REQUEST);
158  outMsg.writeBeingId(beingId, "npc id");
159  outMsg.writeInt8(1, "action");
160 }

References createOutPacket.

◆ sellItem()

void EAthena::NpcHandler::sellItem ( const BeingId  beingId,
const int  itemId,
const int  amount 
) const
virtual

Implements Net::NpcHandler.

Definition at line 232 of file npchandler.cpp.

234 {
235  createOutPacket(CMSG_NPC_SELL_REQUEST);
236  outMsg.writeInt16(8, "len");
237  outMsg.writeInt16(CAST_S16(itemId + INVENTORY_OFFSET),
238  "item index");
239  outMsg.writeInt16(CAST_S16(amount), "amount");
240 }
static const int INVENTORY_OFFSET
Definition: inventory.h:27

References CAST_S16, createOutPacket, and INVENTORY_OFFSET.

◆ sellItems()

void EAthena::NpcHandler::sellItems ( std::vector< ShopItem * > &  items) const
virtual

Implements Net::NpcHandler.

Definition at line 242 of file npchandler.cpp.

243 {
244  const int pairSize = 4;
245  int cnt = 0;
246 
247  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
248  {
249  ShopItem *const item = *it;
250  const int usedQuantity = item->getUsedQuantity();
251  if (usedQuantity == 0)
252  continue;
253  cnt ++;
254  }
255 
256  createOutPacket(CMSG_NPC_SELL_REQUEST);
257  outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
258  FOR_EACH (STD_VECTOR<ShopItem*>::iterator, it, items)
259  {
260  ShopItem *const item = *it;
261  const int usedQuantity = item->getUsedQuantity();
262  if (usedQuantity == 0)
263  continue;
264  item->increaseUsedQuantity(-usedQuantity);
265  item->update();
266  outMsg.writeInt16(CAST_S16(
268  "item index");
269  outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
270  }
271 }
int getCurrentInvIndex() const
Definition: shopitem.h:108

References CAST_S16, createOutPacket, FOR_EACH, ShopItem::getCurrentInvIndex(), ShopItem::getUsedQuantity(), ShopItem::increaseUsedQuantity(), INVENTORY_OFFSET, and ShopItem::update().

◆ stringInput()

void EAthena::NpcHandler::stringInput ( const BeingId  npcId,
const std::string &  value 
) const
virtual

Implements Net::NpcHandler.

Definition at line 118 of file npchandler.cpp.

120 {
121  createOutPacket(CMSG_NPC_STR_RESPONSE);
122  if (packetVersion >= 20151029)
123  {
124  outMsg.writeInt16(CAST_S16(value.length() + 8), "len");
125  outMsg.writeBeingId(npcId, "npc id");
126  outMsg.writeString(value, CAST_S32(value.length()), "value");
127  }
128  else
129  {
130  outMsg.writeInt16(CAST_S16(value.length() + 9), "len");
131  outMsg.writeBeingId(npcId, "npc id");
132  outMsg.writeString(value, CAST_S32(value.length()), "value");
133  outMsg.writeInt8(0, "null byte");
134  }
135 }
#define CAST_S32
Definition: cast.h:30
int packetVersion
Definition: client.cpp:125

References CAST_S16, CAST_S32, createOutPacket, and packetVersion.

◆ talk()

void EAthena::NpcHandler::talk ( const Being *const  being) const
virtual

Implements Net::NpcHandler.

Definition at line 69 of file npchandler.cpp.

70 {
71  if (being == nullptr)
72  return;
73  createOutPacket(CMSG_NPC_TALK);
74  outMsg.writeBeingId(being->getId(), "npc id");
75  outMsg.writeInt8(0, "unused");
77 }

References createOutPacket, ActorSprite::getId(), Being::getSubType(), and EAthena::NpcRecv::mNpcTypeId.


The documentation for this class was generated from the following files: