ManaPlus
Public Member Functions
EAthena::CashShopHandler Class Reference

#include <cashshophandler.h>

Inheritance diagram for EAthena::CashShopHandler:
Net::CashShopHandler

Public Member Functions

 CashShopHandler ()
 
 ~CashShopHandler ()
 
void buyItem (const int points, const int itemId, const ItemColor color, const int amount) const
 
void buyItems (const int points, const std::vector< ShopItem * > &items) const
 
void close () const
 
void requestPoints () const
 
void requestTab (const int tab) const
 
void schedule () const
 
- Public Member Functions inherited from Net::CashShopHandler
 CashShopHandler ()
 

Detailed Description

Definition at line 29 of file cashshophandler.h.

Constructor & Destructor Documentation

◆ CashShopHandler()

EAthena::CashShopHandler::CashShopHandler ( )

Definition at line 40 of file cashshophandler.cpp.

40  :
42 {
43  cashShopHandler = this;
44  CashShopRecv::mBuyDialog = nullptr;
45 }
Net::CashShopHandler * cashShopHandler
Definition: net.cpp:108

References cashShopHandler, and EAthena::CashShopRecv::mBuyDialog.

◆ ~CashShopHandler()

EAthena::CashShopHandler::~CashShopHandler ( )
virtual

Reimplemented from Net::CashShopHandler.

Definition at line 47 of file cashshophandler.cpp.

48 {
49  cashShopHandler = nullptr;
50 }

References cashShopHandler.

Member Function Documentation

◆ buyItem()

void EAthena::CashShopHandler::buyItem ( const int  points,
const int  itemId,
const ItemColor  color,
const int  amount 
) const
virtual

Implements Net::CashShopHandler.

Definition at line 52 of file cashshophandler.cpp.

56 {
57  if (packetVersion < 20101124)
58  return;
59  createOutPacket(CMSG_NPC_CASH_SHOP_BUY);
60  outMsg.writeInt16(CAST_S16(10 + (2 + itemIdLen)), "len");
61  outMsg.writeInt32(points, "points");
62  outMsg.writeInt16(1, "count");
63  outMsg.writeInt16(CAST_S16(amount), "amount");
64  outMsg.writeItemId(itemId, "item id");
65 }
#define CAST_S16
Definition: cast.h:28
int itemIdLen
Definition: client.cpp:130
int packetVersion
Definition: client.cpp:125
#define createOutPacket(name)
Definition: messageout.h:37

References CAST_S16, createOutPacket, itemIdLen, and packetVersion.

◆ buyItems()

void EAthena::CashShopHandler::buyItems ( const int  points,
const std::vector< ShopItem * > &  items 
) const
virtual

Implements Net::CashShopHandler.

Definition at line 67 of file cashshophandler.cpp.

69 {
70  if (packetVersion < 20101124)
71  return;
72 
73  int cnt = 0;
74  const int pairSize = 2 + itemIdLen;
75 
76  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
77  {
78  const ShopItem *const item = *it;
79  const int usedQuantity = item->getUsedQuantity();
80  const ItemTypeT type = item->getType();
81  if (usedQuantity == 0)
82  continue;
83  if (type == ItemType::Weapon ||
84  type == ItemType::Armor ||
85  type == ItemType::PetEgg ||
86  type == ItemType::PetArmor)
87  {
88  cnt += item->getUsedQuantity();
89  }
90  else
91  {
92  cnt ++;
93  }
94  }
95 
96  if (cnt > 100)
97  return;
98 
99  createOutPacket(CMSG_NPC_CASH_SHOP_BUY);
100  outMsg.writeInt16(CAST_S16(10 + pairSize * cnt), "len");
101  outMsg.writeInt32(points, "points");
102  outMsg.writeInt16(CAST_S16(cnt), "count");
103  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
104  {
105  ShopItem *const item = *it;
106  const int usedQuantity = item->getUsedQuantity();
107  if (usedQuantity == 0)
108  continue;
109  item->increaseQuantity(usedQuantity);
110  item->increaseUsedQuantity(-usedQuantity);
111  item->update();
112  const ItemTypeT type = item->getType();
113  if (type == ItemType::Weapon ||
114  type == ItemType::Armor ||
115  type == ItemType::PetEgg ||
116  type == ItemType::PetArmor)
117  {
118  for (int f = 0; f < usedQuantity; f ++)
119  {
120  outMsg.writeInt16(CAST_S16(1), "amount");
121  outMsg.writeItemId(item->getId(),
122  "item id");
123  }
124  }
125  else
126  {
127  outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
128  outMsg.writeItemId(item->getId(), "item id");
129  }
130  }
131 }
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
@ 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(), Item::increaseQuantity(), ShopItem::increaseUsedQuantity(), itemIdLen, packetVersion, ItemType::PetArmor, ItemType::PetEgg, ShopItem::update(), and ItemType::Weapon.

◆ close()

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

Implements Net::CashShopHandler.

Definition at line 133 of file cashshophandler.cpp.

134 {
135  if (packetVersion < 20110718)
136  return;
137  createOutPacket(CMSG_NPC_CASH_SHOP_CLOSE);
138 }

References createOutPacket, and packetVersion.

◆ requestPoints()

void EAthena::CashShopHandler::requestPoints ( ) const
virtual

Implements Net::CashShopHandler.

Definition at line 140 of file cashshophandler.cpp.

141 {
142  if (packetVersion < 20110718)
143  return;
144  createOutPacket(CMSG_NPC_CASH_SHOP_OPEN);
145 }

References createOutPacket, and packetVersion.

◆ requestTab()

void EAthena::CashShopHandler::requestTab ( const int  tab) const
virtual

Implements Net::CashShopHandler.

Definition at line 147 of file cashshophandler.cpp.

148 {
149  if (packetVersion < 20110222 ||
150  packetVersion >= 20120000)
151  {
152  return;
153  }
154  createOutPacket(CMSG_NPC_CASH_SHOP_REQUEST_TAB);
155  outMsg.writeInt16(CAST_S16(tab), "tab");
156 }

References CAST_S16, createOutPacket, and packetVersion.

◆ schedule()

void EAthena::CashShopHandler::schedule ( ) const
virtual

Implements Net::CashShopHandler.

Definition at line 158 of file cashshophandler.cpp.

159 {
160  if (packetVersion < 20110614)
161  return;
162  createOutPacket(CMSG_NPC_CASH_SHOP_SCHEDULE);
163 }

References createOutPacket, and packetVersion.


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