aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-08-26 15:02:22 +0200
committerOvahlord <dreadkiller@gmx.de>2024-08-27 17:20:43 +0200
commit18ae1540b53072c5fe10eaa80d96fed3a2e2c9a2 (patch)
tree52e3aa4ad56cdbd908fec5c9b4d239eacbf4df9d /src/server/scripts/Commands
parenta3c66fe0b870f9ccb0225d307b2b190a60d5c0ef (diff)
Core/Loot: Implemented currency loot
(cherry picked from commit 3e28ee080a1cf3c7cd332a8d1e0808505b4ea9d4) # Conflicts: # sql/base/characters_database.sql # sql/updates/auth/cata_classic/2024_08_26_00_characters.sql # sql/updates/world/cata_classic/2024_08_26_00_world.sql # src/server/game/Entities/Player/Player.cpp # src/server/game/Loot/Loot.cpp # src/server/scripts/ExilesReach/zone_exiles_reach.cpp
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_modify.cpp20
-rw-r--r--src/server/scripts/Commands/cs_npc.cpp114
2 files changed, 99 insertions, 35 deletions
diff --git a/src/server/scripts/Commands/cs_modify.cpp b/src/server/scripts/Commands/cs_modify.cpp
index e02e67a1d7c..7f570f938b6 100644
--- a/src/server/scripts/Commands/cs_modify.cpp
+++ b/src/server/scripts/Commands/cs_modify.cpp
@@ -39,6 +39,8 @@ EndScriptData */
#include "Util.h"
#include "WorldSession.h"
+using namespace Trinity::ChatCommands;
+
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
@@ -923,12 +925,9 @@ public:
return true;
}
- static bool HandleModifyCurrencyCommand(ChatHandler* handler, const char* args)
+ static bool HandleModifyCurrencyCommand(ChatHandler* handler, CurrencyTypesEntry const* currency, int32 amount)
{
- if (!*args)
- return false;
-
- Player* target = handler->getSelectedPlayer();
+ Player* target = handler->getSelectedPlayerOrSelf();
if (!target)
{
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
@@ -936,16 +935,7 @@ public:
return false;
}
- uint32 currencyId = atoi(strtok((char*)args, " "));
- const CurrencyTypesEntry* currencyType = sCurrencyTypesStore.LookupEntry(currencyId);
- if (!currencyType)
- return false;
-
- uint32 amount = atoi(strtok(nullptr, " "));
- if (!amount)
- return false;
-
- target->ModifyCurrency(currencyId, amount, CurrencyGainSource::Cheat, CurrencyDestroyReason::Cheat);
+ target->ModifyCurrency(currency->ID, amount, CurrencyGainSource::Cheat, CurrencyDestroyReason::Cheat);
return true;
}
diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp
index 81de26149c2..d14f88621c1 100644
--- a/src/server/scripts/Commands/cs_npc.cpp
+++ b/src/server/scripts/Commands/cs_npc.cpp
@@ -23,12 +23,13 @@ Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
+#include "CharacterCache.h"
#include "Chat.h"
#include "ChatCommand.h"
#include "CreatureAI.h"
#include "CreatureGroups.h"
-#include "DatabaseEnv.h"
#include "DB2Stores.h"
+#include "DatabaseEnv.h"
#include "FollowMovementGenerator.h"
#include "GameTime.h"
#include "Language.h"
@@ -1166,7 +1167,7 @@ public:
return true;
}
- static void _ShowLootEntry(ChatHandler* handler, uint32 itemId, uint8 itemCount, bool alternateString = false)
+ static void _ShowLootEntry(ChatHandler* handler, uint32 itemId, uint32 itemCount, bool alternateString = false)
{
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
char const* name = nullptr;
@@ -1178,6 +1179,18 @@ public:
itemCount, ItemQualityColors[itemTemplate ? static_cast<ItemQualities>(itemTemplate->GetQuality()) : ITEM_QUALITY_POOR], itemId, name, itemId);
}
+ static void _ShowLootCurrencyEntry(ChatHandler* handler, uint32 currencyId, uint32 count, bool alternateString = false)
+ {
+ CurrencyTypesEntry const* currency = sCurrencyTypesStore.LookupEntry(currencyId);
+ char const* name = nullptr;
+ if (currency)
+ name = currency->Name[handler->GetSessionDbcLocale()];
+ if (!name)
+ name = "Unknown currency";
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_CURRENCY, alternateString ? 6 : 3 /*number of bytes from following string*/, "\u2500\u2500",
+ count, ItemQualityColors[currency ? static_cast<ItemQualities>(currency->Quality) : ITEM_QUALITY_POOR], currencyId, count, name, currencyId);
+ }
+
static void _IterateNotNormalLootMap(ChatHandler* handler, NotNormalLootItemMap const& map, std::vector<LootItem> const& items)
{
for (NotNormalLootItemMap::value_type const& pair : map)
@@ -1190,11 +1203,72 @@ public:
for (auto it = pair.second->cbegin(); it != pair.second->cend(); ++it)
{
LootItem const& item = items[it->LootListId];
- if (!(it->is_looted) && !item.is_looted)
- _ShowLootEntry(handler, item.itemid, item.count, true);
+ if (!it->is_looted && !item.is_looted)
+ {
+ switch (item.type)
+ {
+ case LootItemType::Item:
+ _ShowLootEntry(handler, item.itemid, item.count, true);
+ break;
+ case LootItemType::Currency:
+ _ShowLootCurrencyEntry(handler, item.itemid, item.count, true);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ static void _ShowLootContents(ChatHandler* handler, bool all, Loot const* loot)
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_MONEY, loot->gold / GOLD, (loot->gold % GOLD) / SILVER, loot->gold % SILVER);
+
+ if (!all)
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot->items.size());
+ for (LootItem const& item : loot->items)
+ {
+ if (!item.is_looted)
+ {
+ switch (item.type)
+ {
+ case LootItemType::Item:
+ _ShowLootEntry(handler, item.itemid, item.count);
+ break;
+ case LootItemType::Currency:
+ _ShowLootCurrencyEntry(handler, item.itemid, item.count);
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot->items.size());
+ for (LootItem const& item : loot->items)
+ {
+ if (!item.is_looted && !item.freeforall && item.conditions.IsEmpty())
+ {
+ switch (item.type)
+ {
+ case LootItemType::Item:
+ _ShowLootEntry(handler, item.itemid, item.count);
+ break;
+ case LootItemType::Currency:
+ _ShowLootCurrencyEntry(handler, item.itemid, item.count);
+ break;
+ }
+ }
+ }
+
+ if (!loot->GetPlayerFFAItems().empty())
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, "FFA items per allowed player");
+ _IterateNotNormalLootMap(handler, loot->GetPlayerFFAItems(), loot->items);
}
}
}
+
static bool HandleNpcShowLootCommand(ChatHandler* handler, Optional<EXACT_SEQUENCE("all")> all)
{
Creature* creatureTarget = handler->getSelectedCreature();
@@ -1205,8 +1279,16 @@ public:
return false;
}
+ if (!creatureTarget->isDead())
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NOT_DEAD_OR_NO_LOOT, creatureTarget->GetName().c_str());
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+
Loot const* loot = creatureTarget->m_loot.get();
- if (!creatureTarget->isDead() || !loot || loot->isLooted())
+ if ((!loot || loot->isLooted())
+ && !std::ranges::count_if(creatureTarget->m_personalLoot, std::not_fn(&Loot::isLooted), &std::unordered_map<ObjectGuid, std::unique_ptr<Loot>>::value_type::second))
{
handler->PSendSysMessage(LANG_COMMAND_NOT_DEAD_OR_NO_LOOT, creatureTarget->GetName().c_str());
handler->SetSentErrorMessage(true);
@@ -1214,26 +1296,18 @@ public:
}
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_HEADER, creatureTarget->GetName().c_str(), creatureTarget->GetEntry());
- handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_MONEY, loot->gold / GOLD, (loot->gold % GOLD) / SILVER, loot->gold % SILVER);
- if (!all)
- {
- handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot->items.size());
- for (LootItem const& item : loot->items)
- if (!item.is_looted)
- _ShowLootEntry(handler, item.itemid, item.count);
- }
+ if (loot)
+ _ShowLootContents(handler, all.has_value(), loot);
else
{
- handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot->items.size());
- for (LootItem const& item : loot->items)
- if (!item.is_looted && !item.freeforall && item.conditions.IsEmpty())
- _ShowLootEntry(handler, item.itemid, item.count);
+ using namespace std::string_view_literals;
- if (!loot->GetPlayerFFAItems().empty())
+ for (auto const& [lootOwner, personalLoot] : creatureTarget->m_personalLoot)
{
- handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, "FFA items per allowed player");
- _IterateNotNormalLootMap(handler, loot->GetPlayerFFAItems(), loot->items);
+ CharacterCacheEntry const* character = sCharacterCache->GetCharacterCacheByGuid(lootOwner);
+ handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, Trinity::StringFormat("Personal loot for {}", character ? character->Name : ""sv));
+ _ShowLootContents(handler, all.has_value(), personalLoot.get());
}
}