ManaPlus
Public Member Functions | Private Member Functions | Private Attributes
DropShortcut Class Reference

#include <dropshortcut.h>

Inheritance diagram for DropShortcut:
ShortcutBase

Public Member Functions

 DropShortcut ()
 
 ~DropShortcut ()
 
void dropFirst () const
 
void dropItems (const int cnt)
 
- Public Member Functions inherited from ShortcutBase
 ShortcutBase (const std::string &itemName, const std::string &colorName, const int maxSize)
 
virtual ~ShortcutBase ()
 
void load ()
 
void save () const
 
int getItem (const size_t index) const
 
ItemColor getItemColor (const size_t index) const
 
int getItemCount () const
 
int getItemSelected () const
 
void setItem (const size_t index)
 
void setItems (const size_t index, const int itemId, const ItemColor color)
 
void setItemSelected (const int itemId)
 
void setItemSelected (const Item *const item)
 
bool isItemSelected () const
 
void removeItem (const size_t index)
 
void clear (const bool isSave)
 

Private Member Functions

bool dropItem (const int cnt)
 

Private Attributes

int mLastDropIndex
 

Detailed Description

The class which keeps track of the item shortcuts.

Definition at line 33 of file dropshortcut.h.

Constructor & Destructor Documentation

◆ DropShortcut()

DropShortcut::DropShortcut ( )

Constructor.

Definition at line 42 of file dropshortcut.cpp.

42  :
43  ShortcutBase("drop", "dropColor", DROP_SHORTCUT_ITEMS),
45 {
46  clear(false);
47  load();
48 }
int mLastDropIndex
Definition: dropshortcut.h:64
ShortcutBase(const std::string &itemName, const std::string &colorName, const int maxSize)
void clear(const bool isSave)
static const int DROP_SHORTCUT_ITEMS

References ShortcutBase::clear(), and ShortcutBase::load().

◆ ~DropShortcut()

DropShortcut::~DropShortcut ( )

Destructor.

Definition at line 50 of file dropshortcut.cpp.

51 {
52 }

Member Function Documentation

◆ dropFirst()

void DropShortcut::dropFirst ( ) const

Drop first item.

Definition at line 54 of file dropshortcut.cpp.

55 {
56  if (localPlayer == nullptr)
57  return;
58 
60  return;
61 
62  const int itemId = getItem(0);
63  const ItemColor itemColor = getItemColor(0);
64  if (PlayerInfo::isItemProtected(itemId))
65  return;
66 
67  if (itemId > 0)
68  {
69  const Item *const item = PlayerInfo::getInventory()
70  ->findItem(itemId, itemColor);
71  if ((item != nullptr) && (item->getQuantity() != 0))
72  {
73  const int cnt = settings.quickDropCounter;
75  {
76  PlayerInfo::dropItem(item, cnt, Sfx_true);
77  }
78  else
79  {
80  for (int i = 0; i < cnt; i++)
82  }
83  }
84  }
85 }
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:94
Definition: item.h:50
int getQuantity() const
Definition: item.h:105
bool isServerBuggy() const
Definition: localplayer.h:276
unsigned int quickDropCounter
Definition: settings.h:139
int getItem(const size_t index) const
Definition: shortcutbase.h:71
ItemColor getItemColor(const size_t index) const
Definition: shortcutbase.h:74
uint16_t ItemColor
Definition: itemcolor.h:30
LocalPlayer * localPlayer
bool limitPackets(const PacketTypeT type)
void dropItem(const Item *const item, const int amount, const Sfx sfx)
Definition: playerinfo.cpp:354
Inventory * getInventory()
Definition: playerinfo.cpp:195
bool isItemProtected(const int id)
Definition: playerinfo.cpp:515
Settings settings
Definition: settings.cpp:32
const bool Sfx_false
Definition: sfx.h:30
const bool Sfx_true
Definition: sfx.h:30

References PlayerInfo::dropItem(), Inventory::findItem(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), Item::getQuantity(), PlayerInfo::isItemProtected(), LocalPlayer::isServerBuggy(), PacketLimiter::limitPackets(), localPlayer, PacketType::PACKET_DROP, Settings::quickDropCounter, settings, Sfx_false, and Sfx_true.

Referenced by CrazyMoves::crazyMoveAd().

◆ dropItem()

bool DropShortcut::dropItem ( const int  cnt)
private

Drop item in cicle.

Definition at line 114 of file dropshortcut.cpp.

115 {
116  const Inventory *const inv = PlayerInfo::getInventory();
117  if (inv == nullptr)
118  return false;
119 
120  int itemId = 0;
121  ItemColor itemColor = ItemColor_one;
123  itemId < 1)
124  {
125  if (!PlayerInfo::isItemProtected(itemId))
126  {
127  itemId = getItem(mLastDropIndex);
128  itemColor = getItemColor(mLastDropIndex);
129  }
130  mLastDropIndex ++;
131  }
132 
133  if (itemId > 0)
134  {
135  const Item *const item = inv->findItem(itemId, itemColor);
136  if ((item != nullptr) &&
137  item->getQuantity() > 0)
138  {
139  PlayerInfo::dropItem(item, cnt, Sfx_true);
140  return true;
141  }
142  }
144  mLastDropIndex = 0;
145 
146  if (itemId < 1)
147  {
149  itemId < 1)
150  {
151  if (!PlayerInfo::isItemProtected(itemId))
152  {
153  itemId = getItem(mLastDropIndex);
154  itemColor = getItemColor(mLastDropIndex);
155  }
156  mLastDropIndex++;
157  }
158  if (itemId > 0)
159  {
160  const Item *const item = inv->findItem(itemId, itemColor);
161  if ((item != nullptr) && item->getQuantity() > 0)
162  {
163  PlayerInfo::dropItem(item, cnt, Sfx_true);
164  return true;
165  }
166  }
168  mLastDropIndex = 0;
169  }
170  return false;
171 }
const ItemColor ItemColor_one
Definition: itemcolor.h:30

References DROP_SHORTCUT_ITEMS, PlayerInfo::dropItem(), Inventory::findItem(), PlayerInfo::getInventory(), ShortcutBase::getItem(), ShortcutBase::getItemColor(), Item::getQuantity(), PlayerInfo::isItemProtected(), ItemColor_one, mLastDropIndex, and Sfx_true.

Referenced by dropItems().

◆ dropItems()

void DropShortcut::dropItems ( const int  cnt)

Drop all items in cicle.

Definition at line 87 of file dropshortcut.cpp.

88 {
89  if (localPlayer == nullptr)
90  return;
91 
93  {
95  return;
96  }
97 
98  int n = 0;
99  const int sz = settings.quickDropCounter;
100  for (int f = 0; f < 9; f++)
101  {
102  for (int i = 0; i < sz; i++)
103  {
105  return;
106  if (dropItem(1))
107  n++;
108  }
109  if (n >= cnt)
110  break;
111  }
112 }
bool dropItem(const int cnt)

References dropItem(), LocalPlayer::isServerBuggy(), PacketLimiter::limitPackets(), localPlayer, PacketType::PACKET_DROP, Settings::quickDropCounter, and settings.

Referenced by CrazyMoves::crazyMoveAd().

Field Documentation

◆ mLastDropIndex

int DropShortcut::mLastDropIndex
private

Definition at line 64 of file dropshortcut.h.

Referenced by dropItem().


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