ManaPlus
Public Member Functions
TmwAthena::NpcHandler Class Reference

#include <npchandler.h>

Inheritance diagram for TmwAthena::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
 
BeingId getNpc (Net::MessageIn &msg, const NpcActionT action)
 
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
 
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()

TmwAthena::NpcHandler::NpcHandler ( )

Definition at line 46 of file npchandler.cpp.

46  :
48 {
49  npcHandler = this;
50 }
Net::NpcHandler * npcHandler
Definition: net.cpp:93

References npcHandler.

◆ ~NpcHandler()

TmwAthena::NpcHandler::~NpcHandler ( )
virtual

Reimplemented from Net::NpcHandler.

Definition at line 52 of file npchandler.cpp.

53 {
54  npcHandler = nullptr;
55 }

References npcHandler.

Member Function Documentation

◆ buy() [1/2]

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

Implements Net::NpcHandler.

Definition at line 115 of file npchandler.cpp.

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 }
BeingId getId() const
Definition: actorsprite.h:64
#define createOutPacket(name)
Definition: messageout.h:37

References createOutPacket, and ActorSprite::getId().

◆ buy() [2/2]

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

Implements Net::NpcHandler.

Definition at line 124 of file npchandler.cpp.

125 {
126  createOutPacket(CMSG_NPC_BUY_SELL_REQUEST);
127  outMsg.writeBeingId(beingId, "npc id");
128  outMsg.writeInt8(0, "action");
129 }

References createOutPacket.

◆ buyItem()

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

Implements Net::NpcHandler.

Definition at line 138 of file npchandler.cpp.

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 }
#define CAST_S16
Definition: cast.h:28

References CAST_S16, and createOutPacket.

◆ buyItems()

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

Implements Net::NpcHandler.

Definition at line 149 of file npchandler.cpp.

150 {
151 }

◆ closeDialog()

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

Implements Net::NpcHandler.

Definition at line 72 of file npchandler.cpp.

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 }
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 TmwAthena::NpcHandler::completeProgressBar ( ) const
virtual

Implements Net::NpcHandler.

Definition at line 168 of file npchandler.cpp.

169 {
170 }

◆ cooking()

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

Implements Net::NpcHandler.

Definition at line 179 of file npchandler.cpp.

181 {
182 }

◆ getNpc()

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

Implements Net::NpcHandler.

Definition at line 204 of file npchandler.cpp.

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  {
229  if (localPlayer != nullptr)
230  localPlayer->stopWalking(false);
232  }
233  }
234  else
235  {
236  NpcDialog *const dialog = diag->second;
237  if (Ea::NpcRecv::mDialog != nullptr && Ea::NpcRecv::mDialog != dialog)
239  Ea::NpcRecv::mDialog = dialog;
240  if (Ea::NpcRecv::mDialog != nullptr)
242  }
243  return npcId;
244 }
int BeingId
Definition: beingid.h:30
void stopWalking(const bool sendToServer)
void saveCamera()
Definition: npcdialog.cpp:1105
void restoreCamera()
Definition: npcdialog.cpp:1115
void nextDialog(const BeingId npcId) const
Definition: npchandler.cpp:66
void closeDialog(const BeingId npcId)
Definition: npchandler.cpp:72
#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 TmwAthena::NpcHandler::identify ( const int  index) const
virtual

Implements Net::NpcHandler.

Definition at line 192 of file npchandler.cpp.

193 {
194 }

◆ integerInput()

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

Implements Net::NpcHandler.

Definition at line 97 of file npchandler.cpp.

99 {
100  createOutPacket(CMSG_NPC_INT_RESPONSE);
101  outMsg.writeBeingId(npcId, "npc id");
102  outMsg.writeInt32(value, "value");
103 }

References createOutPacket.

◆ listInput()

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

Implements Net::NpcHandler.

Definition at line 89 of file npchandler.cpp.

91 {
92  createOutPacket(CMSG_NPC_LIST_CHOICE);
93  outMsg.writeBeingId(npcId, "npc id");
94  outMsg.writeInt8(value, "value");
95 }

References createOutPacket.

◆ nextDialog()

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

Implements Net::NpcHandler.

Definition at line 66 of file npchandler.cpp.

67 {
68  createOutPacket(CMSG_NPC_NEXT_REQUEST);
69  outMsg.writeBeingId(npcId, "npc id");
70 }

References createOutPacket.

Referenced by getNpc().

◆ produceMix()

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

Implements Net::NpcHandler.

Definition at line 172 of file npchandler.cpp.

176 {
177 }

◆ refine()

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

Implements Net::NpcHandler.

Definition at line 188 of file npchandler.cpp.

189 {
190 }

◆ repair()

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

Implements Net::NpcHandler.

Definition at line 184 of file npchandler.cpp.

185 {
186 }

◆ requestAirship()

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

Implements Net::NpcHandler.

Definition at line 246 of file npchandler.cpp.

248 {
249 }

◆ selectArrow()

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

Implements Net::NpcHandler.

Definition at line 196 of file npchandler.cpp.

197 {
198 }

◆ selectAutoSpell()

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

Implements Net::NpcHandler.

Definition at line 200 of file npchandler.cpp.

201 {
202 }

◆ sell()

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

Implements Net::NpcHandler.

Definition at line 131 of file npchandler.cpp.

132 {
133  createOutPacket(CMSG_NPC_BUY_SELL_REQUEST);
134  outMsg.writeBeingId(beingId, "npc id");
135  outMsg.writeInt8(1, "action");
136 }

References createOutPacket.

◆ sellItem()

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

Implements Net::NpcHandler.

Definition at line 153 of file npchandler.cpp.

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 }
static const int INVENTORY_OFFSET
Definition: inventory.h:27

References CAST_S16, createOutPacket, and INVENTORY_OFFSET.

◆ sellItems()

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

Implements Net::NpcHandler.

Definition at line 164 of file npchandler.cpp.

165 {
166 }

◆ stringInput()

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

Implements Net::NpcHandler.

Definition at line 105 of file npchandler.cpp.

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 }
#define CAST_S32
Definition: cast.h:30

References CAST_S16, CAST_S32, and createOutPacket.

◆ talk()

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

Implements Net::NpcHandler.

Definition at line 57 of file npchandler.cpp.

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 }

References createOutPacket, and ActorSprite::getId().


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