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
 

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)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ inventory_commandscript()

inventory_commandscript::inventory_commandscript ( )
inline
68: CommandScript("inventory_commandscript") { }
Definition: ScriptMgr.h:850

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:67
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
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 handler->SetSentErrorMessage(true);
96 return false;
97 }
98
99 Player* target = player->GetConnectedPlayer();
100 if (!target)
101 {
103 handler->SetSentErrorMessage(true);
104 return false;
105 }
106
107 std::array<uint32, MAX_ITEM_SUBCLASS_CONTAINER> freeSlotsInBags = { };
108 uint32 freeSlotsForBags = 0;
109 bool haveFreeSlot = false;
110
111 // Check backpack
112 for (uint8 slot = INVENTORY_SLOT_ITEM_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
113 {
114 if (!target->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
115 {
116 haveFreeSlot = true;
117 ++freeSlotsInBags[ITEM_SUBCLASS_CONTAINER];
118 }
119 }
120
121 // Check bags
123 {
124 if (Bag* bag = target->GetBagByPos(i))
125 {
126 if (ItemTemplate const* bagTemplate = bag->GetTemplate())
127 {
128 if (bagTemplate->Class == ITEM_CLASS_CONTAINER || bagTemplate->Class == ITEM_CLASS_QUIVER)
129 {
130 haveFreeSlot = true;
131 freeSlotsInBags[bagTemplate->SubClass] += bag->GetFreeSlots();
132 }
133 }
134 }
135 else
136 {
137 ++freeSlotsForBags;
138 }
139 }
140
141 std::ostringstream str;
142
143 if (haveFreeSlot)
144 {
145 str << "Player " << target->GetName() << " have ";
146 bool initialize = true;
147
149 {
150 if (uint32 freeSlots = freeSlotsInBags[i])
151 {
152 std::string bagSpecString = bagSpecsToString[i];
153 if (!initialize)
154 {
155 str << ", ";
156 }
157
158 str << "|c";
159 str << std::hex << bagSpecsColors[i] << std::dec;
160 str << freeSlots << " in " << bagSpecString << " bags|r";
161
162 initialize = false;
163 }
164 }
165 }
166 else
167 {
168 str << "Player " << target->GetName() << " does not have free slots in their bags";
169 }
170
171 if (freeSlotsForBags)
172 {
173 str << " and also has " << freeSlotsForBags << " free slots for bags";
174 }
175
176 str << ".";
177
178 handler->SendSysMessage(str.str().c_str());
179
180 return true;
181 }
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
@ ITEM_SUBCLASS_CONTAINER
Definition: ItemTemplate.h:338
#define MAX_ITEM_SUBCLASS_CONTAINER
Definition: ItemTemplate.h:349
@ ITEM_CLASS_QUIVER
Definition: ItemTemplate.h:311
@ ITEM_CLASS_CONTAINER
Definition: ItemTemplate.h:301
@ INVENTORY_SLOT_ITEM_START
Definition: Player.h:706
@ INVENTORY_SLOT_ITEM_END
Definition: Player.h:707
@ INVENTORY_SLOT_BAG_START
Definition: Player.h:700
@ INVENTORY_SLOT_BAG_END
Definition: Player.h:701
#define INVENTORY_SLOT_BAG_0
Definition: Player.h:671
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:522
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
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)
Definition: ChatCommandTags.h:189
Definition: Bag.h:28
Definition: ItemTemplate.h:628
std::string const & GetName() const
Definition: Object.h:446
Definition: Player.h:1046
Bag * GetBagByPos(uint8 slot) const
Definition: PlayerStorage.cpp:488
Item * GetItemByPos(uint16 pos) const
Definition: PlayerStorage.cpp:472

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::SendSysMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().