Core/Loot: Implemented currency loot

Port From (https://github.com/TrinityCore/TrinityCore/commit/3e28ee080a1cf3c7cd332a8d1e0808505b4ea9d4)
This commit is contained in:
Hondacrx
2024-10-09 00:18:14 -04:00
parent 57858e1bed
commit 4c3074d462
11 changed files with 494 additions and 214 deletions
+2 -13
View File
@@ -611,11 +611,8 @@ namespace Game.Chat
}
[Command("currency", RBACPermissions.CommandModifyCurrency)]
static bool HandleModifyCurrencyCommand(CommandHandler handler, StringArguments args)
static bool HandleModifyCurrencyCommand(CommandHandler handler, CurrencyTypesRecord currency, int amount)
{
if (args.Empty())
return false;
Player target = handler.GetSelectedPlayerOrSelf();
if (target == null)
{
@@ -624,15 +621,7 @@ namespace Game.Chat
return false;
}
uint currencyId = args.NextUInt32();
if (!CliDB.CurrencyTypesStorage.ContainsKey(currencyId))
return false;
uint amount = args.NextUInt32();
if (amount == 0)
return false;
target.ModifyCurrency(currencyId, (int)amount, CurrencyGainSource.Cheat, CurrencyDestroyReason.Cheat);
target.ModifyCurrency(currency.Id, amount, CurrencyGainSource.Cheat, CurrencyDestroyReason.Cheat);
return true;
}
+87 -14
View File
@@ -316,23 +316,23 @@ namespace Game.Chat
return false;
}
if (!creatureTarget.IsDead())
{
handler.SendSysMessage(CypherStrings.CommandNotDeadOrNoLoot, creatureTarget.GetName());
return false;
}
Loot loot = creatureTarget._loot;
if (creatureTarget.IsDead() || loot == null || loot.IsLooted())
if ((loot == null || loot.IsLooted()) && creatureTarget.m_personalLoot.Count(p => p.Value.IsLooted()) == 0)
{
handler.SendSysMessage(CypherStrings.CommandNotDeadOrNoLoot, creatureTarget.GetName());
return false;
}
handler.SendSysMessage(CypherStrings.CommandNpcShowlootHeader, creatureTarget.GetName(), creatureTarget.GetEntry());
handler.SendSysMessage(CypherStrings.CommandNpcShowlootMoney, loot.gold / MoneyConstants.Gold, (loot.gold % MoneyConstants.Gold) / MoneyConstants.Silver, loot.gold % MoneyConstants.Silver);
if (all.Equals("all", StringComparison.OrdinalIgnoreCase)) // nonzero from strcmp <. not equal
{
handler.SendSysMessage(CypherStrings.CommandNpcShowlootLabel, "Standard items", loot.items.Count);
foreach (LootItem item in loot.items)
if (!item.is_looted)
_ShowLootEntry(handler, item.itemid, item.count);
}
if (loot != null)
_ShowLootContents(handler, all == "all", loot);
else
{
handler.SendSysMessage(CypherStrings.CommandNpcShowlootLabel, "Standard items", loot.items.Count);
@@ -340,10 +340,11 @@ namespace Game.Chat
if (!item.is_looted && !item.freeforall && item.conditions.IsEmpty())
_ShowLootEntry(handler, item.itemid, item.count);
if (!loot.GetPlayerFFAItems().Empty())
foreach (var (lootOwner, personalLoot) in creatureTarget.m_personalLoot)
{
handler.SendSysMessage(CypherStrings.CommandNpcShowlootLabel2, "FFA items per allowed player");
_IterateNotNormalLootMap(handler, loot.GetPlayerFFAItems(), loot.items);
var character = Global.CharacterCacheStorage.GetCharacterCacheByGuid(lootOwner);
handler.SendSysMessage(CypherStrings.CommandNpcShowlootLabel2, $"Personal loot for {(character != null ? character.Name : "")}");
_ShowLootContents(handler, all == "all", personalLoot);
}
}
@@ -515,7 +516,7 @@ namespace Game.Chat
return true;
}
static void _ShowLootEntry(CommandHandler handler, uint itemId, byte itemCount, bool alternateString = false)
static void _ShowLootEntry(CommandHandler handler, uint itemId, uint itemCount, bool alternateString = false)
{
string name = "Unknown item";
@@ -526,6 +527,18 @@ namespace Game.Chat
handler.SendSysMessage(alternateString ? CypherStrings.CommandNpcShowlootEntry2 : CypherStrings.CommandNpcShowlootEntry,
itemCount, ItemConst.ItemQualityColors[(int)(itemTemplate != null ? itemTemplate.GetQuality() : ItemQuality.Poor)], itemId, name, itemId);
}
static void _ShowLootCurrencyEntry(CommandHandler handler, uint currencyId, uint count, bool alternateString = false)
{
CurrencyTypesRecord currency = CliDB.CurrencyTypesStorage.LookupByKey(currencyId);
string name = "Unknown currency";
if (currency != null)
name = currency.Name;
handler.SendSysMessage(CypherStrings.CommandNpcShowLootCurrency, alternateString ? 6 : 3 /*number of bytes from following string*/, "\u2500\u2500",
count, ItemConst.ItemQualityColors[currency != null ? currency.Quality : (int)ItemQuality.Poor], currencyId, count, name, currencyId);
}
static void _IterateNotNormalLootMap(CommandHandler handler, MultiMap<ObjectGuid, NotNormalLootItem> map, List<LootItem> items)
{
foreach (var key in map.Keys)
@@ -542,7 +555,67 @@ namespace Game.Chat
{
LootItem item = items[it.LootListId];
if (!it.is_looted && !item.is_looted)
_ShowLootEntry(handler, item.itemid, item.count, true);
{
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(CommandHandler handler, bool all, Loot loot)
{
handler.SendSysMessage(CypherStrings.CommandNpcShowlootMoney, loot.gold / MoneyConstants.Gold, (loot.gold % MoneyConstants.Gold) / MoneyConstants.Silver, loot.gold % MoneyConstants.Silver);
if (!all)
{
handler.SendSysMessage(CypherStrings.CommandNpcShowlootLabel, "Standard items", loot.items.Count);
foreach (LootItem item in 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.SendSysMessage(CypherStrings.CommandNpcShowlootLabel, "Standard items", loot.items.Count);
foreach (LootItem item in 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.SendSysMessage(CypherStrings.CommandNpcShowlootLabel2, "FFA items per allowed player");
_IterateNotNormalLootMap(handler, loot.GetPlayerFFAItems(), loot.items);
}
}
}