ManaPlus
Public Member Functions
EAthena::MarketHandler Class Reference

#include <markethandler.h>

Inheritance diagram for EAthena::MarketHandler:
Net::MarketHandler

Public Member Functions

 MarketHandler ()
 
 ~MarketHandler ()
 
void close () const
 
void buyItem (const int itemId, const ItemTypeT type, const ItemColor color, const int amount) const
 
void buyItems (const std::vector< ShopItem * > &items) const
 
- Public Member Functions inherited from Net::MarketHandler
 MarketHandler ()
 

Detailed Description

Definition at line 30 of file markethandler.h.

Constructor & Destructor Documentation

◆ MarketHandler()

EAthena::MarketHandler::MarketHandler ( )

Definition at line 39 of file markethandler.cpp.

39  :
41 {
42  marketHandler = this;
43  MarketRecv::mBuyDialog = nullptr;
44 }
Net::MarketHandler * marketHandler
Definition: net.cpp:116
BuyDialog * mBuyDialog
Definition: marketrecv.cpp:53

References marketHandler, and EAthena::MarketRecv::mBuyDialog.

◆ ~MarketHandler()

EAthena::MarketHandler::~MarketHandler ( )
virtual

Reimplemented from Net::MarketHandler.

Definition at line 46 of file markethandler.cpp.

47 {
48  marketHandler = nullptr;
49 }

References marketHandler.

Member Function Documentation

◆ buyItem()

void EAthena::MarketHandler::buyItem ( const int  itemId,
const ItemTypeT  type,
const ItemColor  color,
const int  amount 
) const
virtual

Implements Net::MarketHandler.

Definition at line 59 of file markethandler.cpp.

63 {
64  if (packetVersion < 20131218)
65  return;
66  const bool nonStack = type == ItemType::Weapon ||
67  type == ItemType::Armor ||
68  type == ItemType::PetEgg ||
69  type == ItemType::PetArmor;
70  int cnt = nonStack ? amount : 1;
71  const int amount2 = nonStack ? 1 : amount;
72  if (cnt > 100)
73  cnt = 100;
74 
75  createOutPacket(CMSG_NPC_MARKET_BUY);
76  outMsg.writeInt16(CAST_S16(4 + 6 * cnt), "len");
77  for (int f = 0; f < cnt; f ++)
78  {
79  outMsg.writeItemId(itemId, "item id");
80  outMsg.writeInt32(CAST_S16(amount2), "amount");
81  }
82 }
#define CAST_S16
Definition: cast.h:28
int packetVersion
Definition: client.cpp:125
#define createOutPacket(name)
Definition: messageout.h:37
@ 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, packetVersion, ItemType::PetArmor, ItemType::PetEgg, and ItemType::Weapon.

◆ buyItems()

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

Implements Net::MarketHandler.

Definition at line 84 of file markethandler.cpp.

85 {
86  if (packetVersion < 20131218)
87  return;
88  int cnt = 0;
89  const int pairSize = 6;
90 
91  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
92  {
93  const ShopItem *const item = *it;
94  const int usedQuantity = item->getUsedQuantity();
95  const ItemTypeT type = item->getType();
96  if (usedQuantity == 0)
97  continue;
98  if (type == ItemType::Weapon ||
99  type == ItemType::Armor ||
100  type == ItemType::PetEgg ||
101  type == ItemType::PetArmor)
102  {
103  cnt += item->getUsedQuantity();
104  }
105  else
106  {
107  cnt ++;
108  }
109  }
110 
111  if (cnt > 100)
112  return;
113 
114  createOutPacket(CMSG_NPC_MARKET_BUY);
115  outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
116  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
117  {
118  ShopItem *const item = *it;
119  const int usedQuantity = item->getUsedQuantity();
120  if (usedQuantity == 0)
121  continue;
122  item->increaseQuantity(usedQuantity);
123  item->increaseUsedQuantity(-usedQuantity);
124  item->update();
125  const ItemTypeT type = item->getType();
126  if (type == ItemType::Weapon ||
127  type == ItemType::Armor ||
128  type == ItemType::PetEgg ||
129  type == ItemType::PetArmor)
130  {
131  for (int f = 0; f < usedQuantity; f ++)
132  {
133  outMsg.writeItemId(item->getId(),
134  "item id");
135  outMsg.writeInt32(CAST_S16(1), "amount");
136  }
137  }
138  else
139  {
140  outMsg.writeItemId(item->getId(),
141  "item id");
142  outMsg.writeInt32(CAST_S16(usedQuantity), "amount");
143  }
144  }
145 }
int getId() const
Definition: item.h:81
ItemTypeT getType() const
Definition: item.h:225
void increaseQuantity(const int amount)
Definition: item.h:99
void increaseUsedQuantity(const int amount)
Definition: shopitem.cpp:159
int getUsedQuantity() const
Definition: shopitem.h:151
void update()
Definition: shopitem.cpp:119
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
ItemType ::T ItemTypeT
Definition: itemtype.h:43

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

◆ close()

void EAthena::MarketHandler::close ( ) const
virtual

Implements Net::MarketHandler.

Definition at line 51 of file markethandler.cpp.

52 {
53  if (packetVersion < 20131218)
54  return;
55 
56  createOutPacket(CMSG_NPC_MARKET_CLOSE);
57 }

References createOutPacket, and packetVersion.


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