AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
inventory_commandscript Class Reference
Inheritance diagram for inventory_commandscript:
CommandScript ScriptObject

Public Member Functions

 inventory_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleInventoryCountCommand (ChatHandler *handler, Optional< PlayerIdentifier > player)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ inventory_commandscript()

inventory_commandscript::inventory_commandscript ( )
inline
69: CommandScript("inventory_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable inventory_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

72 {
73 static ChatCommandTable inventoryCommandTable =
74 {
76 };
77
78 static ChatCommandTable commandTable =
79 {
80 { "inventory", inventoryCommandTable }
81 };
82
83 return commandTable;
84 }
static bool HandleInventoryCountCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition cs_inventory.cpp:86
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_ADDITEM
Definition RBAC.h:319

References HandleInventoryCountCommand(), and rbac::RBAC_PERM_COMMAND_ADDITEM.

◆ HandleInventoryCountCommand()

static bool inventory_commandscript::HandleInventoryCountCommand ( ChatHandler handler,
Optional< PlayerIdentifier player 
)
inlinestatic
87 {
88 if (!player)
89 {
90 player = PlayerIdentifier::FromTargetOrSelf(handler);
91 }
92
93 if (!player)
94 {
96 return false;
97 }
98
99 Player* target = player->GetConnectedPlayer();
100 if (!target)
101 {
103 return false;
104 }
105
106 std::array<uint32, MAX_ITEM_SUBCLASS_CONTAINER> freeSlotsInBags = { };
107 uint32 freeSlotsForBags = 0;
108 bool haveFreeSlot = false;
109
110 // Check backpack
111 for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
112 {
113 if (!target->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
114 {
115 haveFreeSlot = true;
116 ++freeSlotsInBags[ITEM_SUBCLASS_CONTAINER];
117 }
118 }
119
120 // Check bags
122 {
123 if (Bag* bag = target->GetBagByPos(i))
124 {
125 if (ItemTemplate const* bagTemplate = bag->GetTemplate())
126 {
127 if (bagTemplate->Class == ITEM_CLASS_CONTAINER || bagTemplate->Class == ITEM_CLASS_QUIVER)
128 {
129 haveFreeSlot = true;
130 freeSlotsInBags[bagTemplate->SubClass] += bag->GetFreeSlots();
131 }
132 }
133 }
134 else
135 {
136 ++freeSlotsForBags;
137 }
138 }
139
140 std::ostringstream str;
141
142 if (haveFreeSlot)
143 {
144 str << "Player " << target->GetName() << " have ";
145 bool initialize = true;
146
148 {
149 if (uint32 freeSlots = freeSlotsInBags[i])
150 {
151 std::string bagSpecString = bagSpecsToString[i];
152 if (!initialize)
153 {
154 str << ", ";
155 }
156
157 str << "|c";
158 str << std::hex << bagSpecsColors[i] << std::dec;
159 str << freeSlots << " in " << bagSpecString << " bags|r";
160
161 initialize = false;
162 }
163 }
164 }
165 else
166 {
167 str << "Player " << target->GetName() << " does not have free slots in their bags";
168 }
169
170 if (freeSlotsForBags)
171 {
172 str << " and also has " << freeSlotsForBags << " free slots for bags";
173 }
174
175 str << ".";
176
177 handler->SendSysMessage(str.str().c_str());
178
179 return true;
180 }
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
@ ITEM_SUBCLASS_CONTAINER
Definition ItemTemplate.h:329
#define MAX_ITEM_SUBCLASS_CONTAINER
Definition ItemTemplate.h:340
@ ITEM_CLASS_QUIVER
Definition ItemTemplate.h:302
@ ITEM_CLASS_CONTAINER
Definition ItemTemplate.h:292
@ LANG_PLAYER_NOT_FOUND
Definition Language.h:548
@ INVENTORY_SLOT_ITEM_START
Definition Player.h:691
@ INVENTORY_SLOT_ITEM_END
Definition Player.h:692
@ INVENTORY_SLOT_BAG_START
Definition Player.h:685
@ INVENTORY_SLOT_BAG_END
Definition Player.h:686
#define INVENTORY_SLOT_BAG_0
Definition Player.h:656
Definition Bag.h:28
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:168
Definition Player.h:1084
Bag * GetBagByPos(uint8 slot) const
Definition PlayerStorage.cpp:460
Item * GetItemByPos(uint16 pos) const
Definition PlayerStorage.cpp:444
std::string const & GetName() const
Definition Object.h:528
constexpr std::array< uint32, MAX_ITEM_SUBCLASS_CONTAINER > bagSpecsColors
Definition cs_inventory.cpp:38
constexpr std::array< const char *, MAX_ITEM_SUBCLASS_CONTAINER > bagSpecsToString
Definition cs_inventory.cpp:25
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition ChatCommandTags.h:189
Definition ItemTemplate.h:619

References bagSpecsColors, bagSpecsToString, Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf(), Player::GetBagByPos(), Player::GetItemByPos(), WorldObject::GetName(), INVENTORY_SLOT_BAG_0, INVENTORY_SLOT_BAG_END, INVENTORY_SLOT_BAG_START, INVENTORY_SLOT_ITEM_END, INVENTORY_SLOT_ITEM_START, ITEM_CLASS_CONTAINER, ITEM_CLASS_QUIVER, ITEM_SUBCLASS_CONTAINER, LANG_PLAYER_NOT_FOUND, MAX_ITEM_SUBCLASS_CONTAINER, ChatHandler::SendErrorMessage(), and ChatHandler::SendSysMessage().

Referenced by GetCommands().


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