ManaPlus
Public Member Functions
EAthena::BarterHandler Class Reference

#include <barterhandler.h>

Inheritance diagram for EAthena::BarterHandler:
Net::BarterHandler

Public Member Functions

 BarterHandler ()
 
 ~BarterHandler ()
 
void close () const
 
void buyItems (const std::vector< ShopItem * > &items) const
 
- Public Member Functions inherited from Net::BarterHandler
 BarterHandler ()
 

Detailed Description

Definition at line 30 of file barterhandler.h.

Constructor & Destructor Documentation

◆ BarterHandler()

EAthena::BarterHandler::BarterHandler ( )

Definition at line 42 of file barterhandler.cpp.

42  :
44 {
45  barterHandler = this;
46  BarterRecv::mBuyDialog = nullptr;
47 }
Net::BarterHandler * barterHandler
Definition: net.cpp:117
BuyDialog * mBuyDialog
Definition: barterrecv.cpp:35

References barterHandler, and EAthena::BarterRecv::mBuyDialog.

◆ ~BarterHandler()

EAthena::BarterHandler::~BarterHandler ( )
virtual

Reimplemented from Net::BarterHandler.

Definition at line 49 of file barterhandler.cpp.

50 {
51  barterHandler = nullptr;
52 }

References barterHandler.

Member Function Documentation

◆ buyItems()

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

Implements Net::BarterHandler.

Definition at line 66 of file barterhandler.cpp.

67 {
68  if (packetVersionMain < 20190116 &&
69  packetVersionRe < 20190116 &&
70  packetVersionZero < 20181226)
71  {
72  return;
73  }
74  int cnt = 0;
75  const int pairSize = 10 + itemIdLen;
76 
77  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
78  {
79  const ShopItem *const item = *it;
80  const int usedQuantity = item->getUsedQuantity();
81  const ItemTypeT type = item->getType();
82  if (usedQuantity == 0)
83  continue;
84  if (type == ItemType::Weapon ||
85  type == ItemType::Armor ||
86  type == ItemType::PetEgg ||
87  type == ItemType::PetArmor)
88  {
89  cnt += item->getUsedQuantity();
90  }
91  else
92  {
93  cnt ++;
94  }
95  }
96 
97  if (cnt > 100)
98  return;
99 
100  createOutPacket(CMSG_NPC_MARKET_BUY);
101  outMsg.writeInt16(CAST_S16(4 + pairSize * cnt), "len");
102  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
103  {
104  ShopItem *const item = *it;
105  const int usedQuantity = item->getUsedQuantity();
106  if (usedQuantity == 0)
107  continue;
108  item->increaseQuantity(usedQuantity);
109  item->increaseUsedQuantity(-usedQuantity);
110  item->update();
111  const ItemTypeT type = item->getType();
112  if (type == ItemType::Weapon ||
113  type == ItemType::Armor ||
114  type == ItemType::PetEgg ||
115  type == ItemType::PetArmor)
116  {
117  for (int f = 0; f < usedQuantity; f ++)
118  {
119  outMsg.writeItemId(item->getId(),
120  "item id");
121  outMsg.writeInt32(CAST_S16(1), "amount");
122  // +++ need use player inventory index
123  outMsg.writeInt16(0, "inv index");
124  outMsg.writeInt32(item->getCurrentInvIndex(),
125  "inv index");
126  }
127  }
128  else
129  {
130  outMsg.writeItemId(item->getId(),
131  "item id");
132  outMsg.writeInt32(CAST_S16(usedQuantity), "amount");
133  // +++ need use player inventory index
134  outMsg.writeInt16(0, "inv index");
135  outMsg.writeInt32(item->getCurrentInvIndex(),
136  "inv index");
137  }
138  }
139 }
#define CAST_S16
Definition: cast.h:28
int getId() const
Definition: item.h:81
ItemTypeT getType() const
Definition: item.h:225
void increaseQuantity(const int amount)
Definition: item.h:99
int getCurrentInvIndex() const
Definition: shopitem.h:108
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
int packetVersionRe
Definition: client.cpp:127
int packetVersionMain
Definition: client.cpp:126
int packetVersionZero
Definition: client.cpp:128
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#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, FOR_EACH, ShopItem::getCurrentInvIndex(), Item::getId(), Item::getType(), ShopItem::getUsedQuantity(), Item::increaseQuantity(), ShopItem::increaseUsedQuantity(), itemIdLen, packetVersionMain, packetVersionRe, packetVersionZero, ItemType::PetArmor, ItemType::PetEgg, ShopItem::update(), and ItemType::Weapon.

◆ close()

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

Implements Net::BarterHandler.

Definition at line 54 of file barterhandler.cpp.

55 {
56  if (packetVersionMain < 20190116 &&
57  packetVersionRe < 20190116 &&
58  packetVersionZero < 20181226)
59  {
60  return;
61  }
62 
63  createOutPacket(CMSG_NPC_BARTER_CLOSE);
64 }

References createOutPacket, packetVersionMain, packetVersionRe, and packetVersionZero.


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