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

Public Member Functions

 item_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 HandleItemRestoreCommand (ChatHandler *handler, uint32 restoreId, PlayerIdentifier player)
 
static bool HandleItemRestoreListCommand (ChatHandler *handler, PlayerIdentifier player)
 
static bool HandleItemMoveCommand (ChatHandler *handler, uint8 srcSlot, uint8 dstSlot)
 
static bool HasItemDeletionConfig ()
 
static bool HandleItemRefundCommand (ChatHandler *handler, PlayerIdentifier player, uint32 itemId, uint32 extendedCost)
 

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

◆ item_commandscript()

item_commandscript::item_commandscript ( )
inline
38: CommandScript("item_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable item_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

41 {
42 static ChatCommandTable HandleItemRestoreCommandTable =
43 {
44 { "list", HandleItemRestoreListCommand, SEC_GAMEMASTER, Console::Yes },
45 { "", HandleItemRestoreCommand, SEC_GAMEMASTER, Console::Yes },
46 };
47 static ChatCommandTable itemCommandTable =
48 {
49 { "restore", HandleItemRestoreCommandTable },
50 { "move", HandleItemMoveCommand, SEC_GAMEMASTER, Console::Yes },
51 { "refund", HandleItemRefundCommand, SEC_ADMINISTRATOR, Console::Yes },
52 };
53 static ChatCommandTable commandTable =
54 {
55 { "item", itemCommandTable }
56 };
57 return commandTable;
58 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
static bool HandleItemRestoreListCommand(ChatHandler *handler, PlayerIdentifier player)
Definition: cs_item.cpp:121
static bool HandleItemMoveCommand(ChatHandler *handler, uint8 srcSlot, uint8 dstSlot)
Definition: cs_item.cpp:159
static bool HandleItemRestoreCommand(ChatHandler *handler, uint32 restoreId, PlayerIdentifier player)
Definition: cs_item.cpp:60
static bool HandleItemRefundCommand(ChatHandler *handler, PlayerIdentifier player, uint32 itemId, uint32 extendedCost)
Definition: cs_item.cpp:183

References HandleItemMoveCommand(), HandleItemRefundCommand(), HandleItemRestoreCommand(), HandleItemRestoreListCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleItemMoveCommand()

static bool item_commandscript::HandleItemMoveCommand ( ChatHandler handler,
uint8  srcSlot,
uint8  dstSlot 
)
inlinestatic
Todo:
  • move item to other slot
160 {
161 if (srcSlot == dstSlot)
162 return true;
163
164 if (!handler->GetSession()->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0, srcSlot, true))
165 return false;
166
167 if (!handler->GetSession()->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0, dstSlot, false))
168 return false;
169
170 uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | srcSlot);
171 uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | dstSlot);
172
173 handler->GetSession()->GetPlayer()->SwapItem(src, dst);
174
175 return true;
176 }
std::uint16_t uint16
Definition: Define.h:108
#define INVENTORY_SLOT_BAG_0
Definition: Player.h:670
WorldSession * GetSession()
Definition: Chat.h:244
void SwapItem(uint16 src, uint16 dst)
Definition: PlayerStorage.cpp:3542
bool IsValidPos(uint16 pos, bool explicit_pos)
Definition: Player.h:1261
Player * GetPlayer() const
Definition: WorldSession.h:362

References WorldSession::GetPlayer(), ChatHandler::GetSession(), INVENTORY_SLOT_BAG_0, Player::IsValidPos(), and Player::SwapItem().

Referenced by GetCommands().

◆ HandleItemRefundCommand()

static bool item_commandscript::HandleItemRefundCommand ( ChatHandler handler,
PlayerIdentifier  player,
uint32  itemId,
uint32  extendedCost 
)
inlinestatic
184 {
185 ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCost);
186 if (!iece)
187 {
189 return false;
190 }
191
192 ItemTemplate const* item = sObjectMgr->GetItemTemplate(itemId);
193
194 if (!item)
195 {
197 return false;
198 }
199
200 if (Player* target = player.GetConnectedPlayer())
201 {
202 if (!target->HasItemCount(itemId, 1, true))
203 {
205 return false;
206 }
207
208 if (iece->reqhonorpoints)
209 {
210 uint32 honor = target->GetHonorPoints() + iece->reqhonorpoints;
211 if (honor > sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS))
212 {
213 handler->SendErrorMessage(LANG_CMD_ITEM_REFUND_MAX_HONOR, item->Name1, item->ItemId, sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS), target->GetHonorPoints(), iece->reqhonorpoints);
215 return false;
216 }
217
218 target->SetHonorPoints(honor);
219 ChatHandler(target->GetSession()).PSendSysMessage(LANG_CMD_ITEM_REFUNDED_HONOR, item->Name1, item->ItemId, iece->reqhonorpoints);
221 }
222
223 if (iece->reqarenapoints)
224 {
225 uint32 arenapoints = target->GetArenaPoints() + iece->reqarenapoints;
226 if (arenapoints > sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS))
227 {
228 handler->SendErrorMessage(LANG_CMD_ITEM_REFUND_MAX_AP, item->Name1, item->ItemId, sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS), target->GetArenaPoints(), iece->reqarenapoints);
230 return false;
231 }
232
233 target->SetArenaPoints(arenapoints);
234 ChatHandler(target->GetSession()).PSendSysMessage(LANG_CMD_ITEM_REFUNDED_AP, item->Name1, item->ItemId, iece->reqarenapoints);
236 }
237
238 uint8 count = 0;
239 for (uint32 const& reqItem : iece->reqitem)
240 {
241 if (reqItem)
242 {
243 target->AddItem(reqItem, iece->reqitemcount[count]);
244 }
245
246 ++count;
247 }
248
249 target->DestroyItemCount(itemId, 1, true);
250 }
251 else
252 {
253 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
255
256 ObjectGuid::LowType guid = player.GetGUID().GetCounter();
257
259 stmt->SetData(0, itemId);
260 stmt->SetData(1, guid);
261
262 PreparedQueryResult result = CharacterDatabase.Query(stmt);
263
264 if (result)
265 {
266 if (iece->reqhonorpoints)
267 {
268 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_HONORPOINTS);
269 stmt->SetData(0, guid);
270
271 PreparedQueryResult queryResult = CharacterDatabase.Query(stmt);
272
273 if (queryResult)
274 {
275 Field* fields = queryResult->Fetch();
276 if ((fields[0].Get<uint32>() + iece->reqhonorpoints) > sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS))
277 {
278 handler->SendErrorMessage(LANG_CMD_ITEM_REFUND_MAX_HONOR, item->Name1, item->ItemId, sWorld->getIntConfig(CONFIG_MAX_HONOR_POINTS), fields[0].Get<uint32>(), iece->reqhonorpoints);
279 return false;
280 }
281 }
282
284 stmt->SetData(0, iece->reqhonorpoints);
285 stmt->SetData(1, guid);
286 trans->Append(stmt);
288 }
289
290 if (iece->reqarenapoints)
291 {
292 stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ARENAPOINTS);
293 stmt->SetData(0, guid);
294
295 PreparedQueryResult queryResult = CharacterDatabase.Query(stmt);
296
297 if (queryResult)
298 {
299 Field* fields = queryResult->Fetch();
300 if ((fields[0].Get<uint32>() + iece->reqhonorpoints) > sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS))
301 {
302 handler->SendErrorMessage(LANG_CMD_ITEM_REFUND_MAX_AP, item->Name1, item->ItemId, sWorld->getIntConfig(CONFIG_MAX_ARENA_POINTS), fields[0].Get<uint32>(), iece->reqarenapoints);
303 return false;
304 }
305 }
306
308 stmt->SetData(0, iece->reqarenapoints);
309 stmt->SetData(1, guid);
310 trans->Append(stmt);
312 }
313
315 // fill mail
316 std::string msg = "Your item " + item->Name1 + " has been removed and the used currency restored. This mail contains any items used as currency.";
317 MailDraft draft("Item Refund", msg);
318
319 uint8 count = 0;
320 bool foundItems = false;
321 for (uint32 const& reqItem : iece->reqitem)
322 {
323 if (reqItem)
324 {
325 // Skip invalid items.
326 if (!sObjectMgr->GetItemTemplate(reqItem))
327 {
328 continue;
329 }
330
331 if (Item* item = Item::CreateItem(reqItem, iece->reqitemcount[count]))
332 {
333 item->SaveToDB(trans);
334 draft.AddItem(item);
335 foundItems = true;
336 }
337 }
338
339 ++count;
340 }
341
342 if (foundItems)
343 {
344 draft.SendMailTo(trans, MailReceiver(nullptr, guid), sender);
345 }
346
347 Field* fields = result->Fetch();
348
349 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
350 stmt->SetData(0, fields[0].Get<uint32>());
351 trans->Append(stmt);
352
353 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
354 stmt->SetData(0, fields[0].Get<uint32>());
355 trans->Append(stmt);
356
357 CharacterDatabase.CommitTransaction(trans);
358 }
359 else
360 {
362 return false;
363 }
364 }
365
366 return true;
367 }
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
#define sObjectMgr
Definition: ObjectMgr.h:1623
DBCStorage< ItemExtendedCostEntry > sItemExtendedCostStore(ItemExtendedCostEntryfmt)
@ CONFIG_MAX_HONOR_POINTS
Definition: IWorld.h:246
@ CONFIG_MAX_ARENA_POINTS
Definition: IWorld.h:249
@ LANG_CMD_ITEM_REFUND_MAX_HONOR
Definition: Language.h:1128
@ LANG_CMD_ITEM_REFUNDED_HONOR
Definition: Language.h:1130
@ LANG_CMD_ITEM_REFUND_MAX_AP
Definition: Language.h:1131
@ LANG_CMD_ITEM_REFUND_HONOR_FAILED
Definition: Language.h:1129
@ LANG_CMD_ITEM_REFUND_AP_FAILED
Definition: Language.h:1132
@ LANG_CMD_ITEM_REFUND_NOT_FOUND
Definition: Language.h:1134
@ LANG_CMD_ITEM_REFUNDED_AP
Definition: Language.h:1133
@ LANG_CMD_ITEM_REFUND_BAD_EXTENDED_COST
Definition: Language.h:1127
@ LANG_COMMAND_ITEMIDINVALID
Definition: Language.h:467
@ MAIL_STATIONERY_GM
Definition: Mail.h:60
@ MAIL_NORMAL
Definition: Mail.h:38
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:70
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
@ CHAR_DEL_ITEM_INSTANCE
Definition: CharacterDatabase.h:127
@ CHAR_DEL_CHAR_INVENTORY_BY_ITEM
Definition: CharacterDatabase.h:433
@ CHAR_SEL_HONORPOINTS
Definition: CharacterDatabase.h:514
@ CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY_AND_OWNER
Definition: CharacterDatabase.h:359
@ CHAR_UDP_CHAR_HONOR_POINTS_ACCUMULATIVE
Definition: CharacterDatabase.h:424
@ CHAR_SEL_ARENAPOINTS
Definition: CharacterDatabase.h:515
@ CHAR_UDP_CHAR_ARENA_POINTS_ACCUMULATIVE
Definition: CharacterDatabase.h:426
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define sWorld
Definition: World.h:444
Definition: PreparedStatement.h:158
Class used to access individual fields of database query result.
Definition: Field.h:99
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
Definition: Chat.h:39
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:213
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:218
ObjectGuid GetGUID() const
Definition: ChatCommandTags.h:180
Player * GetConnectedPlayer() const
Definition: ChatCommandTags.h:182
Definition: Item.h:220
static Item * CreateItem(uint32 item, uint32 count, Player const *player=nullptr, bool clone=false, uint32 randomPropertyId=0)
Definition: Item.cpp:1088
Definition: ItemTemplate.h:619
std::string Name1
Definition: ItemTemplate.h:624
uint32 ItemId
Definition: ItemTemplate.h:620
LowType GetCounter() const
Definition: ObjectGuid.h:145
uint32 LowType
Definition: ObjectGuid.h:122
Definition: Player.h:1064
Definition: Mail.h:84
Definition: Mail.h:106
Definition: Mail.h:120
Definition: DBCStructure.h:1185
uint32 reqarenapoints
Definition: DBCStructure.h:1188
uint32 reqitemcount[MAX_ITEM_EXTENDED_COST_REQUIREMENTS]
Definition: DBCStructure.h:1191
uint32 reqitem[MAX_ITEM_EXTENDED_COST_REQUIREMENTS]
Definition: DBCStructure.h:1190
uint32 reqhonorpoints
Definition: DBCStructure.h:1187

References MailDraft::AddItem(), CHAR_DEL_CHAR_INVENTORY_BY_ITEM, CHAR_DEL_ITEM_INSTANCE, CHAR_SEL_ARENAPOINTS, CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY_AND_OWNER, CHAR_SEL_HONORPOINTS, CHAR_UDP_CHAR_ARENA_POINTS_ACCUMULATIVE, CHAR_UDP_CHAR_HONOR_POINTS_ACCUMULATIVE, CharacterDatabase, CONFIG_MAX_ARENA_POINTS, CONFIG_MAX_HONOR_POINTS, Item::CreateItem(), Field::Get(), Acore::ChatCommands::PlayerIdentifier::GetConnectedPlayer(), ObjectGuid::GetCounter(), Acore::ChatCommands::PlayerIdentifier::GetGUID(), ItemTemplate::ItemId, LANG_CMD_ITEM_REFUND_AP_FAILED, LANG_CMD_ITEM_REFUND_BAD_EXTENDED_COST, LANG_CMD_ITEM_REFUND_HONOR_FAILED, LANG_CMD_ITEM_REFUND_MAX_AP, LANG_CMD_ITEM_REFUND_MAX_HONOR, LANG_CMD_ITEM_REFUND_NOT_FOUND, LANG_CMD_ITEM_REFUNDED_AP, LANG_CMD_ITEM_REFUNDED_HONOR, LANG_COMMAND_ITEMIDINVALID, MAIL_NORMAL, MAIL_STATIONERY_GM, ItemTemplate::Name1, ChatHandler::PSendSysMessage(), ItemExtendedCostEntry::reqarenapoints, ItemExtendedCostEntry::reqhonorpoints, ItemExtendedCostEntry::reqitem, ItemExtendedCostEntry::reqitemcount, ChatHandler::SendErrorMessage(), MailDraft::SendMailTo(), PreparedStatementBase::SetData(), sItemExtendedCostStore, sObjectMgr, and sWorld.

Referenced by GetCommands().

◆ HandleItemRestoreCommand()

static bool item_commandscript::HandleItemRestoreCommand ( ChatHandler handler,
uint32  restoreId,
PlayerIdentifier  player 
)
inlinestatic
61 {
62 if (!restoreId)
63 {
64 return false;
65 }
66
68 {
70 return false;
71 }
72
73 // Check existence of item in recovery table
75 stmt->SetData(0, restoreId);
76 PreparedQueryResult fields = CharacterDatabase.Query(stmt);
77
78 if (!fields || !(*fields)[1].Get<uint32>() || (*fields)[3].Get<uint32>() != player.GetGUID().GetCounter())
79 {
81 return false;
82 }
83
84 // Mail item to player
85 uint32 itemEntry = (*fields)[1].Get<uint32>();
86 uint32 itemCount = (*fields)[2].Get<uint32>();
87
88 if (Player* onlinePlayer = player.GetConnectedPlayer())
89 {
90 onlinePlayer->SendItemRetrievalMail({ { itemEntry, itemCount } });
91 }
92
93 else
94 {
95 MailSender sender(MAIL_CREATURE, 34337 /* The Postmaster */);
96 MailDraft draft("Recovered Item", "We recovered a lost item in the twisting nether and noted that it was yours.$B$BPlease find said object enclosed.");
97
98 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
99
100 // Save to prevent loss at next mail load. Item deletes on fail
101 if (Item* item = Item::CreateItem(itemEntry, itemCount, 0))
102 {
103 item->SaveToDB(trans);
104 draft.AddItem(item);
105 }
106
107 draft.SendMailTo(trans, MailReceiver(player.GetGUID().GetCounter()), sender);
108 CharacterDatabase.CommitTransaction(trans);
109 }
110
111 // Remove from recovery table
113 delStmt->SetData(0, (*fields)[0].Get<uint32>());
114 CharacterDatabase.Execute(delStmt);
115
116 std::string nameLink = handler->playerLink(player.GetName());
117 handler->PSendSysMessage(LANG_MAIL_SENT, nameLink);
118 return true;
119 }
@ LANG_COMMAND_DISABLED
Definition: Language.h:1125
@ LANG_ITEM_RESTORE_MISSING
Definition: Language.h:234
@ LANG_MAIL_SENT
Definition: Language.h:209
@ MAIL_CREATURE
Definition: Mail.h:40
@ CHAR_DEL_RECOVERY_ITEM_BY_RECOVERY_ID
Definition: CharacterDatabase.h:510
@ CHAR_SEL_RECOVERY_ITEM
Definition: CharacterDatabase.h:507
std::string playerLink(std::string const &name) const
Definition: Chat.h:233
std::string const & GetName() const
Definition: ChatCommandTags.h:179
static bool HasItemDeletionConfig()
Definition: cs_item.cpp:178

References MailDraft::AddItem(), CHAR_DEL_RECOVERY_ITEM_BY_RECOVERY_ID, CHAR_SEL_RECOVERY_ITEM, CharacterDatabase, Item::CreateItem(), Acore::ChatCommands::PlayerIdentifier::GetConnectedPlayer(), ObjectGuid::GetCounter(), Acore::ChatCommands::PlayerIdentifier::GetGUID(), Acore::ChatCommands::PlayerIdentifier::GetName(), HasItemDeletionConfig(), LANG_COMMAND_DISABLED, LANG_ITEM_RESTORE_MISSING, LANG_MAIL_SENT, MAIL_CREATURE, ChatHandler::playerLink(), ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), MailDraft::SendMailTo(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleItemRestoreListCommand()

static bool item_commandscript::HandleItemRestoreListCommand ( ChatHandler handler,
PlayerIdentifier  player 
)
inlinestatic
122 {
124 {
126 return false;
127 }
128
130 stmt->SetData(0, player.GetGUID().GetCounter());
131 PreparedQueryResult disposedItems = CharacterDatabase.Query(stmt);
132
133 if (!disposedItems)
134 {
136 return false;
137 }
138
139 do
140 {
141 Field* fields = disposedItems->Fetch();
142 uint32 id = fields[0].Get<uint32>();
143 uint32 itemId = fields[1].Get<uint32>();
144 uint32 count = fields[2].Get<uint32>();
145
146 std::string itemName = "";
147 if (ItemTemplate const* item = sObjectMgr->GetItemTemplate(itemId))
148 {
149 itemName = item->Name1;
150 }
151
152 handler->PSendSysMessage(LANG_ITEM_RESTORE_LIST, id, itemName, itemId, count);
153 } while (disposedItems->NextRow());
154
155 return true;
156 }
@ LANG_ITEM_RESTORE_LIST
Definition: Language.h:232
@ LANG_ITEM_RESTORE_LIST_EMPTY
Definition: Language.h:233
@ CHAR_SEL_RECOVERY_ITEM_LIST
Definition: CharacterDatabase.h:508
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113

References CHAR_SEL_RECOVERY_ITEM_LIST, CharacterDatabase, Field::Get(), ObjectGuid::GetCounter(), Acore::ChatCommands::PlayerIdentifier::GetGUID(), HasItemDeletionConfig(), LANG_COMMAND_DISABLED, LANG_ITEM_RESTORE_LIST, LANG_ITEM_RESTORE_LIST_EMPTY, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and sObjectMgr.

Referenced by GetCommands().

◆ HasItemDeletionConfig()

static bool item_commandscript::HasItemDeletionConfig ( )
inlinestatic
179 {
180 return sWorld->getBoolConfig(CONFIG_ITEMDELETE_METHOD) || sWorld->getBoolConfig(CONFIG_ITEMDELETE_VENDOR);
181 }
@ CONFIG_ITEMDELETE_METHOD
Definition: IWorld.h:165
@ CONFIG_ITEMDELETE_VENDOR
Definition: IWorld.h:166

References CONFIG_ITEMDELETE_METHOD, CONFIG_ITEMDELETE_VENDOR, and sWorld.

Referenced by HandleItemRestoreCommand(), and HandleItemRestoreListCommand().