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
+34 -31
View File
@@ -35,18 +35,19 @@ namespace Game.Loots
StoredLootContainer storedContainer = _lootItemStorage[key];
LootItem lootItem = new();
lootItem.itemid = result.Read<uint>(1);
lootItem.count = result.Read<byte>(2);
lootItem.LootListId = result.Read<uint>(3);
lootItem.follow_loot_rules = result.Read<bool>(4);
lootItem.freeforall = result.Read<bool>(5);
lootItem.is_blocked = result.Read<bool>(6);
lootItem.is_counted = result.Read<bool>(7);
lootItem.is_underthreshold = result.Read<bool>(8);
lootItem.needs_quest = result.Read<bool>(9);
lootItem.randomBonusListId = result.Read<uint>(10);
lootItem.context = (ItemContext)result.Read<byte>(11);
StringArray bonusLists = new(result.Read<string>(12), ' ');
lootItem.type = (LootItemType)result.Read<sbyte>(1);
lootItem.itemid = result.Read<uint>(2);
lootItem.count = result.Read<byte>(3);
lootItem.LootListId = result.Read<uint>(4);
lootItem.follow_loot_rules = result.Read<bool>(5);
lootItem.freeforall = result.Read<bool>(6);
lootItem.is_blocked = result.Read<bool>(7);
lootItem.is_counted = result.Read<bool>(8);
lootItem.is_underthreshold = result.Read<bool>(9);
lootItem.needs_quest = result.Read<bool>(10);
lootItem.randomBonusListId = result.Read<uint>(11);
lootItem.context = (ItemContext)result.Read<byte>(12);
StringArray bonusLists = new(result.Read<string>(13), ' ');
foreach (string str in bonusLists)
lootItem.BonusListIDs.Add(uint.Parse(str));
@@ -177,12 +178,12 @@ namespace Game.Loots
DB.Characters.CommitTransaction(trans);
}
public void RemoveStoredLootItemForContainer(ulong containerId, uint itemId, uint count, uint itemIndex)
public void RemoveStoredLootItemForContainer(ulong containerId, LootItemType type, uint itemId, uint count, uint itemIndex)
{
if (!_lootItemStorage.ContainsKey(containerId))
return;
_lootItemStorage[containerId].RemoveItem(itemId, count, itemIndex);
_lootItemStorage[containerId].RemoveItem(type, itemId, count, itemIndex);
}
public void AddNewStoredLoot(ulong containerId, Loot loot, Player player)
@@ -248,25 +249,26 @@ namespace Game.Loots
PreparedStatement stmt = CharacterDatabase.GetPreparedStatement(CharStatements.INS_ITEMCONTAINER_ITEMS);
// container_id, item_id, item_count, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix
// container_id, item_type, item_id, item_count, item_index, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix
stmt.AddValue(0, _containerId);
stmt.AddValue(1, lootItem.itemid);
stmt.AddValue(2, lootItem.count);
stmt.AddValue(3, lootItem.LootListId);
stmt.AddValue(4, lootItem.follow_loot_rules);
stmt.AddValue(5, lootItem.freeforall);
stmt.AddValue(6, lootItem.is_blocked);
stmt.AddValue(7, lootItem.is_counted);
stmt.AddValue(8, lootItem.is_underthreshold);
stmt.AddValue(9, lootItem.needs_quest);
stmt.AddValue(10, lootItem.randomBonusListId);
stmt.AddValue(11, (uint)lootItem.context);
stmt.AddValue(1, (sbyte)lootItem.type);
stmt.AddValue(2, lootItem.itemid);
stmt.AddValue(3, lootItem.count);
stmt.AddValue(4, lootItem.LootListId);
stmt.AddValue(5, lootItem.follow_loot_rules);
stmt.AddValue(6, lootItem.freeforall);
stmt.AddValue(7, lootItem.is_blocked);
stmt.AddValue(8, lootItem.is_counted);
stmt.AddValue(9, lootItem.is_underthreshold);
stmt.AddValue(10, lootItem.needs_quest);
stmt.AddValue(11, lootItem.randomBonusListId);
stmt.AddValue(12, (uint)lootItem.context);
StringBuilder bonusListIDs = new();
foreach (int bonusListID in lootItem.BonusListIDs)
bonusListIDs.Append(bonusListID + ' ');
stmt.AddValue(12, bonusListIDs.ToString());
stmt.AddValue(13, bonusListIDs.ToString());
trans.Append(stmt);
}
@@ -295,7 +297,7 @@ namespace Game.Loots
DB.Characters.Execute(stmt);
}
public void RemoveItem(uint itemId, uint count, uint itemIndex)
public void RemoveItem(LootItemType type, uint itemId, uint count, uint itemIndex)
{
var bounds = _lootItems.LookupByKey(itemId);
foreach (var itr in bounds)
@@ -310,9 +312,10 @@ namespace Game.Loots
// Deletes a single item associated with an openable item from the DB
PreparedStatement stmt = CharacterDatabase.GetPreparedStatement(CharStatements.DEL_ITEMCONTAINER_ITEM);
stmt.AddValue(0, _containerId);
stmt.AddValue(1, itemId);
stmt.AddValue(2, count);
stmt.AddValue(3, itemIndex);
stmt.AddValue(1, (sbyte)type);
stmt.AddValue(2, itemId);
stmt.AddValue(3, count);
stmt.AddValue(4, itemIndex);
DB.Characters.Execute(stmt);
}