ManaPlus
Functions | Variables
EAthena::TradeRecv Namespace Reference

Functions

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

Variables

int mQuantity = 0
 
int mItemIndex = -1
 

Function Documentation

◆ processTradeItemAdd()

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

Definition at line 76 of file traderecv.cpp.

77 {
78  const int type = msg.readItemId("item id");
79  ItemTypeT itemType = ItemType::Unknown;
80  if (msg.getVersion() >= 20100223)
81  {
82  itemType = static_cast<ItemTypeT>(
83  msg.readUInt8("item type"));
84  }
85  const int amount = msg.readInt32("amount");
86  const uint8_t identify = msg.readUInt8("identify");
87  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
88  const uint8_t refine = msg.readUInt8("refine");
89  int cards[maxCards];
90  for (int f = 0; f < maxCards; f++)
91  cards[f] = msg.readItemId("card");
92  ItemOptionsList *options = nullptr;
93  if (msg.getVersion() >= 20150226)
94  {
95  options = new ItemOptionsList;
96  for (int f = 0; f < 5; f ++)
97  {
98  const uint16_t idx = msg.readInt16("option index");
99  const uint16_t val = msg.readInt16("option value");
100  msg.readUInt8("option param");
101  options->add(idx, val);
102  }
103  }
104 
105  if (tradeWindow != nullptr)
106  {
107  if (type == 0)
108  {
109  tradeWindow->setMoney(amount);
110  }
111  else
112  {
113  tradeWindow->addItem2(type,
114  itemType,
115  cards,
116  options,
117  4,
118  false,
119  amount,
120  refine,
122  fromBool(identify, Identified),
123  damaged,
125  Equipm_false);
126  }
127  }
128  delete options;
129 }
#define fromBool(val, name)
Definition: booldefines.h:49
#define maxCards
Definition: cards.h:25
static ItemColor getColorFromCards(const int *const cards)
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
bool Damaged
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
ItemType ::T ItemTypeT
Definition: itemtype.h:43
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ Unknown
Definition: itemtype.h:30
void add(const uint16_t index, const uint16_t value)
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65

References ItemOptionsList::add(), TradeWindow::addItem2(), Equipm_false, Favorite_false, fromBool, ItemColorManager::getColorFromCards(), maxCards, Actions::msg(), TradeWindow::setMoney(), tradeWindow, and ItemType::Unknown.

◆ processTradeItemAddResponse()

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

Definition at line 131 of file traderecv.cpp.

132 {
133  msg.readInt16("index");
134  const uint8_t res = msg.readUInt8("fail");
135  switch (res)
136  {
137  case 0: // Successfully added item
138  case 9: // silent added item
139  {
140  Item *const item = PlayerInfo::getInventory()->getItem(
141  mItemIndex);
142  if (item == nullptr)
143  return;
144  if (tradeWindow != nullptr)
145  {
146  tradeWindow->addItem2(item->getId(),
147  item->getType(),
148  item->getCards(),
149  item->getOptions(),
150  4,
151  true,
152  mQuantity,
153  item->getRefine(),
154  item->getColor(),
155  item->getIdentified(),
156  item->getDamaged(),
157  item->getFavorite(),
158  item->isEquipment());
159  }
160  item->increaseQuantity(-mQuantity);
161  mItemIndex = -1;
162  mQuantity = 0;
163  break;
164  }
165  case 1:
166  // Add item failed - player overweighted
169  break;
170  case 2:
172  break;
173  default:
176  break;
177  }
178 }
Item * getItem(const int index) const
Definition: inventory.cpp:83
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
const ItemOptionsList * getOptions() const
Definition: item.h:219
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
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
void notify(const unsigned int message)
@ TRADE_ADD_PARTNER_OVER_WEIGHT
Definition: notifytypes.h:94
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::getOptions(), Item::getRefine(), Item::getType(), Item::increaseQuantity(), Item::isEquipment(), mItemIndex, mQuantity, Actions::msg(), NotifyManager::notify(), NotifyTypes::TRADE_ADD_ERROR, NotifyTypes::TRADE_ADD_PARTNER_OVER_WEIGHT, tradeWindow, and UNIMPLEMENTEDPACKETFIELD.

◆ processTradeRequest()

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

Definition at line 57 of file traderecv.cpp.

58 {
59  const std::string &partner = msg.readString(24, "name");
60  if (msg.getVersion() >= 6)
61  {
62  msg.readInt32("char id");
63  msg.readInt16("base level");
64  }
66 }
void processTradeRequestContinue(const std::string &partner)
Definition: traderecv.cpp:145

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

◆ processTradeResponse()

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

Definition at line 68 of file traderecv.cpp.

69 {
70  const uint8_t type = msg.readUInt8("type");
71  msg.readInt32("char id");
72  msg.readInt16("base level");
74 }
void processTradeResponseContinue(const uint8_t type)
Definition: traderecv.cpp:62

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

◆ processTradeUndo()

void EAthena::TradeRecv::processTradeUndo ( Net::MessageIn msg)

Definition at line 180 of file traderecv.cpp.

181 {
183  // +++ here need clear trade window from partner side?
184 }
#define UNIMPLEMENTEDPACKET
Definition: logger.h:56

References UNIMPLEMENTEDPACKET.

Variable Documentation

◆ mItemIndex

int EAthena::TradeRecv::mItemIndex = -1

◆ mQuantity

int EAthena::TradeRecv::mQuantity = 0