ManaPlus
Public Member Functions
EAthena::VendingHandler Class Reference

#include <vendinghandler.h>

Inheritance diagram for EAthena::VendingHandler:
Net::VendingHandler

Public Member Functions

 VendingHandler ()
 
 ~VendingHandler ()
 
void close () const
 
void open (const Being *const being) const
 
void buy (const Being *const being, const int index, const int amount) const
 
void buy2 (const Being *const being, const int vendId, const int index, const int amount) const
 
void buyItems (const Being *const being, const std::vector< ShopItem * > &items) const
 
void createShop (const std::string &name, const bool flag, const std::vector< ShopItem * > &items) const
 
- Public Member Functions inherited from Net::VendingHandler
 VendingHandler ()
 

Detailed Description

Definition at line 29 of file vendinghandler.h.

Constructor & Destructor Documentation

◆ VendingHandler()

EAthena::VendingHandler::VendingHandler ( )

Definition at line 42 of file vendinghandler.cpp.

43 {
44  vendingHandler = this;
45  VendingRecv::mBuyDialog = nullptr;
46 }
BuyDialog * mBuyDialog
Definition: vendingrecv.cpp:69
Net::VendingHandler * vendingHandler
Definition: net.cpp:122

References EAthena::VendingRecv::mBuyDialog, and vendingHandler.

◆ ~VendingHandler()

EAthena::VendingHandler::~VendingHandler ( )
virtual

Reimplemented from Net::VendingHandler.

Definition at line 48 of file vendinghandler.cpp.

49 {
50  vendingHandler = nullptr;
51 }

References vendingHandler.

Member Function Documentation

◆ buy()

void EAthena::VendingHandler::buy ( const Being *const  being,
const int  index,
const int  amount 
) const
virtual

Implements Net::VendingHandler.

Definition at line 68 of file vendinghandler.cpp.

71 {
72  if (being == nullptr)
73  return;
74 
75  createOutPacket(CMSG_VENDING_BUY);
76  outMsg.writeInt16(12, "len");
77  outMsg.writeBeingId(being->getId(), "account id");
78  outMsg.writeInt16(CAST_S16(amount), "amount");
79  outMsg.writeInt16(CAST_S16(index), "index");
80 }
#define CAST_S16
Definition: cast.h:28
BeingId getId() const
Definition: actorsprite.h:64
#define createOutPacket(name)
Definition: messageout.h:37

References CAST_S16, createOutPacket, and ActorSprite::getId().

◆ buy2()

void EAthena::VendingHandler::buy2 ( const Being *const  being,
const int  vendId,
const int  index,
const int  amount 
) const
virtual

Implements Net::VendingHandler.

Definition at line 117 of file vendinghandler.cpp.

121 {
122  if (being == nullptr)
123  return;
124 
125  createOutPacket(CMSG_VENDING_BUY2);
126  outMsg.writeInt16(16, "len");
127  outMsg.writeBeingId(being->getId(), "account id");
128  outMsg.writeInt32(vendId, "vend id");
129  outMsg.writeInt16(CAST_S16(amount), "amount");
130  outMsg.writeInt16(CAST_S16(index), "index");
131 }

References CAST_S16, createOutPacket, and ActorSprite::getId().

◆ buyItems()

void EAthena::VendingHandler::buyItems ( const Being *const  being,
const std::vector< ShopItem * > &  items 
) const
virtual

Implements Net::VendingHandler.

Definition at line 82 of file vendinghandler.cpp.

84 {
85  int cnt = 0;
86  const int pairSize = 4;
87 
88  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
89  {
90  ShopItem *const item = *it;
91  const int usedQuantity = item->getUsedQuantity();
92  if (usedQuantity == 0)
93  continue;
94  cnt ++;
95  }
96 
97  if (cnt > 100)
98  return;
99 
100  createOutPacket(CMSG_VENDING_BUY);
101  outMsg.writeInt16(CAST_S16(4 + 4 + pairSize * cnt), "len");
102  outMsg.writeBeingId(being->getId(), "account id");
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  outMsg.writeInt16(CAST_S16(usedQuantity), "amount");
113  outMsg.writeInt16(CAST_S16(item->getInvIndex()), "index");
114  }
115 }
int getInvIndex() const
Definition: item.h:165
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

References CAST_S16, createOutPacket, FOR_EACH, ActorSprite::getId(), Item::getInvIndex(), ShopItem::getUsedQuantity(), Item::increaseQuantity(), ShopItem::increaseUsedQuantity(), and ShopItem::update().

◆ close()

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

Implements Net::VendingHandler.

Definition at line 53 of file vendinghandler.cpp.

54 {
55  createOutPacket(CMSG_VENDING_CLOSE);
57 }
void enableVending(const bool b)
Definition: playerinfo.cpp:658

References createOutPacket, and PlayerInfo::enableVending().

◆ createShop()

void EAthena::VendingHandler::createShop ( const std::string &  name,
const bool  flag,
const std::vector< ShopItem * > &  items 
) const
virtual

Implements Net::VendingHandler.

Definition at line 133 of file vendinghandler.cpp.

136 {
137  createOutPacket(CMSG_VENDING_CREATE_SHOP);
138  outMsg.writeInt16(CAST_S16(85 + items.size() * 8), "len");
139  outMsg.writeString(name, 80, "shop name");
140  outMsg.writeInt8(CAST_S8(flag ? 1 : 0), "flag");
141  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
142  {
143  const ShopItem *const item = *it;
144  outMsg.writeInt16(CAST_S16(
145  item->getInvIndex() + INVENTORY_OFFSET), "index");
146  outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
147  outMsg.writeInt32(item->getPrice(), "price");
148  }
149 }
#define CAST_S8
Definition: cast.h:26
int getQuantity() const
Definition: item.h:105
int getPrice() const
Definition: shopitem.h:132
static const int INVENTORY_OFFSET
Definition: inventory.h:27

References CAST_S16, CAST_S8, createOutPacket, FOR_EACH, Item::getInvIndex(), ShopItem::getPrice(), Item::getQuantity(), and INVENTORY_OFFSET.

◆ open()

void EAthena::VendingHandler::open ( const Being *const  being) const
virtual

Implements Net::VendingHandler.

Definition at line 59 of file vendinghandler.cpp.

60 {
61  if (being == nullptr)
62  return;
63 
64  createOutPacket(CMSG_VENDING_LIST_REQ);
65  outMsg.writeBeingId(being->getId(), "account id");
66 }

References createOutPacket, and ActorSprite::getId().


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