ManaPlus
Functions
TmwAthena::TradeRecv Namespace Reference

Functions

void processTradeRequest (Net::MessageIn &msg)
 
void processTradeItemAdd (Net::MessageIn &msg)
 
void processTradeItemAddResponse (Net::MessageIn &msg)
 
void processTradeResponse (Net::MessageIn &msg)
 

Function Documentation

◆ processTradeItemAdd()

void TmwAthena::TradeRecv::processTradeItemAdd ( Net::MessageIn msg)

Definition at line 61 of file traderecv.cpp.

62 {
63  const int amount = msg.readInt32("amount");
64  const int type = msg.readInt16("type");
65  const uint8_t identify = msg.readUInt8("identify");
66  msg.readUInt8("attribute");
67  const uint8_t refine = msg.readUInt8("refine");
68  int cards[maxCards];
69  for (int f = 0; f < maxCards; f++)
70  cards[f] = msg.readUInt16("card");
71 
72  if (tradeWindow != nullptr)
73  {
74  if (type == 0)
75  {
76  tradeWindow->setMoney(amount);
77  }
78  else
79  {
80  tradeWindow->addItem2(type,
82  cards,
83  nullptr,
84  4,
85  false,
86  amount,
87  refine,
89  fromBool(identify, Identified),
92  Equipm_false);
93  }
94  }
95 }
#define fromBool(val, name)
Definition: booldefines.h:49
#define maxCards
Definition: cards.h:25
void setMoney(const int quantity)
void addItem2(const int id, const ItemTypeT type, const int *const cards, const ItemOptionsList *const options, const int sz, const bool own, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment) const
const bool Damaged_false
Definition: damaged.h:30
const bool Equipm_false
Definition: equipm.h:30
const bool Favorite_false
Definition: favorite.h:30
bool Identified
Definition: identified.h:30
const ItemColor ItemColor_one
Definition: itemcolor.h:30
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ Unknown
Definition: itemtype.h:30
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65

References TradeWindow::addItem2(), Damaged_false, Equipm_false, Favorite_false, fromBool, ItemColor_one, maxCards, Actions::msg(), TradeWindow::setMoney(), tradeWindow, and ItemType::Unknown.

◆ processTradeItemAddResponse()

void TmwAthena::TradeRecv::processTradeItemAddResponse ( Net::MessageIn msg)

Definition at line 97 of file traderecv.cpp.

98 {
99  // Trade: New Item add response (was 0x00ea, now 01b1)
100  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
101  Item *item = nullptr;
102  if (PlayerInfo::getInventory() != nullptr)
103  item = PlayerInfo::getInventory()->getItem(index);
104 
105  if (item == nullptr)
106  {
107  if (tradeWindow != nullptr)
108  tradeWindow->receivedOk(true);
109  return;
110  }
111  const int quantity = msg.readInt16("amount");
112 
113  const uint8_t res = msg.readUInt8("status");
114  switch (res)
115  {
116  case 0:
117  // Successfully added item
118  if (tradeWindow != nullptr)
119  {
120  tradeWindow->addItem2(item->getId(),
121  item->getType(),
122  item->getCards(),
123  nullptr,
124  4,
125  true,
126  quantity,
127  item->getRefine(),
128  item->getColor(),
129  item->getIdentified(),
130  item->getDamaged(),
131  item->getFavorite(),
132  item->isEquipment());
133  }
134  item->increaseQuantity(-quantity);
135  break;
136  case 1:
137  // Add item failed - player overweighted
140  break;
141  case 2:
142  // Add item failed - player has no free slot
144  break;
145  case 3:
146  // Add item failed - non tradable item
148  break;
149  default:
152  logger->log("QQQ SMSG_TRADE_ITEM_ADD_RESPONSE: "
153  + toString(res));
154  break;
155  }
156 }
Item * getItem(const int index) const
Definition: inventory.cpp:83
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
Equipm isEquipment() const
Definition: item.h:117
int getId() const
Definition: item.h:81
Favorite getFavorite() const
Definition: item.h:205
ItemColor getColor() const
Definition: item.h:181
Identified getIdentified() const
Definition: item.h:193
ItemTypeT getType() const
Definition: item.h:225
Damaged getDamaged() const
Definition: item.h:199
const int * getCards() const
Definition: item.h:214
void increaseQuantity(const int amount)
Definition: item.h:99
void log(const char *const log_text,...)
Definition: logger.cpp:269
void receivedOk(const bool own)
static const int INVENTORY_OFFSET
Definition: inventory.h:27
Logger * logger
Definition: logger.cpp:89
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void notify(const unsigned int message)
@ TRADE_ADD_PARTNER_OVER_WEIGHT
Definition: notifytypes.h:94
@ TRADE_ADD_PARTNER_NO_SLOTS
Definition: notifytypes.h:95
@ TRADE_ADD_UNTRADABLE_ITEM
Definition: notifytypes.h:96
Inventory * getInventory()
Definition: playerinfo.cpp:195

References TradeWindow::addItem2(), Item::getCards(), Item::getColor(), Item::getDamaged(), Item::getFavorite(), Item::getId(), Item::getIdentified(), PlayerInfo::getInventory(), Inventory::getItem(), Item::getRefine(), Item::getType(), Item::increaseQuantity(), INVENTORY_OFFSET, Item::isEquipment(), Logger::log(), logger, Actions::msg(), NotifyManager::notify(), TradeWindow::receivedOk(), Catch::toString(), NotifyTypes::TRADE_ADD_ERROR, NotifyTypes::TRADE_ADD_PARTNER_NO_SLOTS, NotifyTypes::TRADE_ADD_PARTNER_OVER_WEIGHT, NotifyTypes::TRADE_ADD_UNTRADABLE_ITEM, tradeWindow, and UNIMPLEMENTEDPACKETFIELD.

◆ processTradeRequest()

void TmwAthena::TradeRecv::processTradeRequest ( Net::MessageIn msg)

Definition at line 56 of file traderecv.cpp.

57 {
58  Ea::TradeRecv::processTradeRequestContinue(msg.readString(24, "name"));
59 }
void processTradeRequestContinue(const std::string &partner)
Definition: traderecv.cpp:145

References Actions::msg(), and Ea::TradeRecv::processTradeRequestContinue().

◆ processTradeResponse()

void TmwAthena::TradeRecv::processTradeResponse ( Net::MessageIn msg)

Definition at line 158 of file traderecv.cpp.

159 {
160  if (tradePartnerName.empty() ||
163  {
164  tradeHandler->respond(false);
165  return;
166  }
167  const uint8_t type = msg.readUInt8("type");
169 }
virtual void respond(const bool accept) const
Definition: tradehandler.h:49
bool hasPermission(const Being *const being, const unsigned int flags) const
void processTradeResponseContinue(const uint8_t type)
Definition: traderecv.cpp:62
Net::TradeHandler * tradeHandler
Definition: net.cpp:98
PlayerRelationsManager playerRelations
static const unsigned int TRADE
std::string tradePartnerName
Definition: popupmenu.cpp:101

References PlayerRelationsManager::hasPermission(), Actions::msg(), playerRelations, Ea::TradeRecv::processTradeResponseContinue(), Net::TradeHandler::respond(), PlayerRelation::TRADE, tradeHandler, and tradePartnerName.