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
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- 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
68: CommandScript("inventory_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable inventory_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

71 {
72 static ChatCommandTable inventoryCommandTable =
73 {
74 { "count", HandleInventoryCountCommand, SEC_MODERATOR, Console::No }
75 };
76
77 static ChatCommandTable commandTable =
78 {
79 { "inventory", inventoryCommandTable }
80 };
81
82 return commandTable;
83 }
@ SEC_MODERATOR
Definition: Common.h:58
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleInventoryCountCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition: cs_inventory.cpp:85

References HandleInventoryCountCommand(), and SEC_MODERATOR.

◆ HandleInventoryCountCommand()

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

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().