fix: Acquired recipes are now a Set (#1596)

This commit is contained in:
Kamron Batman 2023-11-17 00:04:46 -08:00 • committed by GitHub
parent 6f0c33bd10
commit a1dffd10ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 23 deletions

View file

@ -144,7 +144,7 @@ namespace Server.Mobiles
new(268, 624, 15) new(268, 624, 15)
}; };
private Dictionary<int, bool> m_AcquiredRecipes; private HashSet<int> _acquiredRecipes;
private HashSet<Mobile> _allFollowers; private HashSet<Mobile> _allFollowers;
private int m_BeardModID = -1, m_BeardModHue; private int m_BeardModID = -1, m_BeardModHue;
@ -719,7 +719,7 @@ namespace Server.Mobiles
: DateTime.MinValue; : DateTime.MinValue;
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public int KnownRecipes => m_AcquiredRecipes?.Count ?? 0; public int KnownRecipes => _acquiredRecipes?.Count ?? 0;
[CommandProperty(AccessLevel.Counselor, canModify: true)] [CommandProperty(AccessLevel.Counselor, canModify: true)]
public VirtueContext Virtues => VirtueSystem.GetOrCreateVirtues(this); public VirtueContext Virtues => VirtueSystem.GetOrCreateVirtues(this);
@ -2852,6 +2852,7 @@ namespace Server.Mobiles
switch (version) switch (version)
{ {
case 34: // Acquired Recipes is now a Set
case 33: // Removes champion title case 33: // Removes champion title
case 32: // Removes virtue properties case 32: // Removes virtue properties
case 31: // Removed Short/Long Term Elapse case 31: // Removed Short/Long Term Elapse
@ -2902,14 +2903,14 @@ namespace Server.Mobiles
if (recipeCount > 0) if (recipeCount > 0)
{ {
m_AcquiredRecipes = new Dictionary<int, bool>(); _acquiredRecipes = new HashSet<int>();
for (var i = 0; i < recipeCount; i++) for (var i = 0; i < recipeCount; i++)
{ {
var r = reader.ReadInt(); var r = reader.ReadInt();
if (reader.ReadBool()) // Don't add in recipes which we haven't gotten or have been removed if (version > 33 || reader.ReadBool()) // Don't add in recipes which we haven't gotten or have been removed
{ {
m_AcquiredRecipes.Add(r, true); _acquiredRecipes.Add(r);
} }
} }
} }
@ -3195,7 +3196,7 @@ namespace Server.Mobiles
{ {
base.Serialize(writer); base.Serialize(writer);
writer.Write(33); // version writer.Write(34); // version
if (Stabled == null) if (Stabled == null)
{ {
@ -3235,18 +3236,17 @@ namespace Server.Mobiles
writer.Write(AutoStabled); writer.Write(AutoStabled);
} }
if (m_AcquiredRecipes == null) if (_acquiredRecipes == null)
{ {
writer.Write(0); writer.Write(0);
} }
else else
{ {
writer.Write(m_AcquiredRecipes.Count); writer.Write(_acquiredRecipes.Count);
foreach (var kvp in m_AcquiredRecipes) foreach (var recipeId in _acquiredRecipes)
{ {
writer.Write(kvp.Key); writer.Write(recipeId);
writer.Write(kvp.Value);
} }
} }
@ -4458,12 +4458,11 @@ namespace Server.Mobiles
InvalidateProperties(); InvalidateProperties();
} }
public virtual bool HasRecipe(Recipe r) => r != null && HasRecipe(r.ID); public bool HasRecipe(Recipe r) => r != null && HasRecipe(r.ID);
public virtual bool HasRecipe(int recipeID) => public bool HasRecipe(int recipeID) => _acquiredRecipes?.Contains(recipeID) == true;
m_AcquiredRecipes != null && m_AcquiredRecipes.TryGetValue(recipeID, out var value) && value;
public virtual void AcquireRecipe(Recipe r) public void AcquireRecipe(Recipe r)
{ {
if (r != null) if (r != null)
{ {
@ -4471,16 +4470,15 @@ namespace Server.Mobiles
} }
} }
public virtual void AcquireRecipe(int recipeID) public void AcquireRecipe(int recipeID)
{ {
m_AcquiredRecipes ??= new Dictionary<int, bool>(); _acquiredRecipes ??= new HashSet<int>();
m_AcquiredRecipes[recipeID] = true; _acquiredRecipes.Add(recipeID);
} }
public virtual void ResetRecipes() public void RemoveRecipe(int recipeID) => _acquiredRecipes?.Remove(recipeID);
{
m_AcquiredRecipes = null; public void ResetRecipes() => _acquiredRecipes = null;
}
public void ResendBuffs() public void ResendBuffs()
{ {

View file

@ -323,7 +323,7 @@ namespace Server.SkillHandlers
chance = 100; chance = 100;
} }
return chance > Utility.Random(100); return chance >= 100 || chance > Utility.Random(100);
} }
private static bool IsValidMobileType(Mobile m, int type) => private static bool IsValidMobileType(Mobile m, int type) =>