Core/Conditions: Refactor ConditionMgr internals to get rid of separate containers for some condition source types

Port From (https://github.com/TrinityCore/TrinityCore/commit/0b5406dd882c6d96bc1be6fd0a78375c3b316415)
This commit is contained in:
hondacrx
2024-02-06 09:39:26 -05:00
parent ebcad7dbc5
commit 80936edeab
12 changed files with 292 additions and 383 deletions
+4 -4
View File
@@ -42,10 +42,10 @@ namespace Game.Loots
return AllowedForPlayer(player, loot, itemid, needs_quest, follow_loot_rules, false, conditions);
}
public static bool AllowedForPlayer(Player player, Loot loot, uint itemid, bool needs_quest, bool follow_loot_rules, bool strictUsabilityCheck, List<Condition> conditions)
public static bool AllowedForPlayer(Player player, Loot loot, uint itemid, bool needs_quest, bool follow_loot_rules, bool strictUsabilityCheck, ConditionsReference conditions)
{
// DB conditions check
if (!Global.ConditionMgr.IsObjectMeetToConditions(player, conditions))
if (!conditions.Meets(player))
return false;
ItemTemplate pProto = Global.ObjectMgr.GetItemTemplate(itemid);
@@ -180,7 +180,7 @@ namespace Game.Loots
public uint randomBonusListId;
public List<uint> BonusListIDs = new();
public ItemContext context;
public List<Condition> conditions = new(); // additional loot condition
public ConditionsReference conditions; // additional loot condition
public List<ObjectGuid> allowedGUIDs = new();
public ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
public byte count;
@@ -999,7 +999,7 @@ namespace Game.Loots
return true;
foreach (LootItem item in items)
if (!item.is_looted && item.follow_loot_rules && !item.freeforall && item.conditions.Empty())
if (!item.is_looted && item.follow_loot_rules && !item.freeforall && item.conditions.IsEmpty())
return true;
return false;
+18 -46
View File
@@ -490,7 +490,7 @@ namespace Game.Loots
public byte groupid;
public byte mincount; // mincount for drop items
public byte maxcount; // max drop count for the item mincount or Ref multiplicator
public List<Condition> conditions; // additional loot condition
public ConditionsReference conditions; // additional loot condition
public LootStoreItem(uint _itemid, uint _reference, float _chance, bool _needs_quest, ushort _lootmode, byte _groupid, byte _mincount, byte _maxcount)
{
@@ -502,7 +502,6 @@ namespace Game.Loots
groupid = _groupid;
mincount = _mincount;
maxcount = _maxcount;
conditions = new List<Condition>();
}
public bool Roll(bool rate)
@@ -581,7 +580,7 @@ namespace Game.Loots
}
public class LootStore
{
{
public LootStore(string name, string entryName, bool ratesAllowed = true)
{
m_name = name;
@@ -614,11 +613,11 @@ namespace Game.Loots
{
// all still listed ids isn't referenced
foreach (var id in lootIdSet)
Log.outError( LogFilter.Sql, "Table '{0}' entry {1} isn't {2} and not referenced from loot, and then useless.", GetName(), id, GetEntryName());
Log.outError(LogFilter.Sql, "Table '{0}' entry {1} isn't {2} and not referenced from loot, and then useless.", GetName(), id, GetEntryName());
}
public void ReportNonExistingId(uint lootId, uint ownerId)
{
Log.outError( LogFilter.Sql, "Table '{0}' Entry {1} does not exist but it is used by {2} {3}", GetName(), lootId, GetEntryName(), ownerId);
Log.outError(LogFilter.Sql, "Table '{0}' Entry {1} does not exist but it is used by {2} {3}", GetName(), lootId, GetEntryName(), ownerId);
}
public bool HaveLootFor(uint loot_id) { return m_LootTemplates.LookupByKey(loot_id) != null; }
@@ -650,14 +649,7 @@ namespace Game.Loots
return tab;
}
public void ResetConditions()
{
foreach (var pair in m_LootTemplates)
{
List<Condition> empty = new();
pair.Value.CopyConditions(empty);
}
}
public LootTemplate GetLootForConditionFill(uint loot_id)
{
var tab = m_LootTemplates.LookupByKey(loot_id);
@@ -928,14 +920,6 @@ namespace Game.Loots
return false;
}
public void CopyConditions(List<Condition> conditions)
{
foreach (var i in Entries)
i.conditions.Clear();
foreach (var group in Groups.Values)
group.CopyConditions(conditions);
}
public void CopyConditions(LootItem li)
{
// Copies the conditions list from a template item to a LootItem
@@ -1044,21 +1028,16 @@ namespace Game.Loots
foreach (var group in Groups.Values)
group.CheckLootRefs(store, ref_set);
}
public bool AddConditionItem(Condition cond)
{
if (cond == null || !cond.IsLoaded())//should never happen, checked at loading
{
Log.outError(LogFilter.Loot, "LootTemplate.addConditionItem: condition is null");
return false;
}
public bool LinkConditions(ConditionId id, ConditionsReference reference)
{
if (!Entries.Empty())
{
foreach (var i in Entries)
foreach (var item in Entries)
{
if (i.itemid == cond.SourceEntry)
if (item.itemid == id.SourceEntry)
{
i.conditions.Add(cond);
item.conditions = reference;
return true;
}
}
@@ -1066,7 +1045,7 @@ namespace Game.Loots
if (!Groups.Empty())
{
foreach (var group in Groups.Values)
foreach (var (_, group) in Groups)
{
if (group == null)
continue;
@@ -1074,11 +1053,11 @@ namespace Game.Loots
LootStoreItemList itemList = group.GetExplicitlyChancedItemList();
if (!itemList.Empty())
{
foreach (var i in itemList)
foreach (var item in itemList)
{
if (i.itemid == cond.SourceEntry)
if (item.itemid == id.SourceEntry)
{
i.conditions.Add(cond);
item.conditions = reference;
return true;
}
}
@@ -1087,11 +1066,11 @@ namespace Game.Loots
itemList = group.GetEqualChancedItemList();
if (!itemList.Empty())
{
foreach (var i in itemList)
foreach (var item in itemList)
{
if (i.itemid == cond.SourceEntry)
if (item.itemid == id.SourceEntry)
{
i.conditions.Add(cond);
item.conditions = reference;
return true;
}
}
@@ -1100,6 +1079,7 @@ namespace Game.Loots
}
return false;
}
public bool IsReference(uint id)
{
foreach (var storeItem in Entries)
@@ -1210,14 +1190,6 @@ namespace Game.Loots
}
public LootStoreItemList GetExplicitlyChancedItemList() { return ExplicitlyChanced; }
public LootStoreItemList GetEqualChancedItemList() { return EqualChanced; }
public void CopyConditions(List<Condition> conditions)
{
foreach (var i in ExplicitlyChanced)
i.conditions.Clear();
foreach (var i in EqualChanced)
i.conditions.Clear();
}
LootStoreItemList ExplicitlyChanced = new(); // Entries with chances defined in DB
LootStoreItemList EqualChanced = new(); // Zero chances - every entry takes the same chance