From 235cb3916f436dd7f881be7e20232b868b554285 Mon Sep 17 00:00:00 2001 From: Mag-nus Date: Tue, 13 Feb 2024 15:49:38 -0600 Subject: [PATCH] Improve WorldObject_Properties GetAllProperties* --- .../Events/GameEventPlayerDescription.cs | 14 +- .../Network/Structure/AppraiseInfo.cs | 14 +- .../WorldObjects/WorldObject_Properties.cs | 227 ++++++++++++++++++ 3 files changed, 241 insertions(+), 14 deletions(-) diff --git a/Source/ACE.Server/Network/GameEvent/Events/GameEventPlayerDescription.cs b/Source/ACE.Server/Network/GameEvent/Events/GameEventPlayerDescription.cs index 1225337ec7..f02e920186 100644 --- a/Source/ACE.Server/Network/GameEvent/Events/GameEventPlayerDescription.cs +++ b/Source/ACE.Server/Network/GameEvent/Events/GameEventPlayerDescription.cs @@ -64,7 +64,7 @@ private void WriteEventBody() Writer.Write(0u); Writer.Write((uint)Session.Player.WeenieType); - var _propertiesInt = Session.Player.GetAllPropertyInt().Where(x => SendOnLoginProperties.PropertiesInt.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesInt = Session.Player.GetAllPropertyIntWhere(SendOnLoginProperties.PropertiesInt); if (_propertiesInt.Count != 0) { @@ -81,7 +81,7 @@ private void WriteEventBody() } } - var _propertiesInt64 = Session.Player.GetAllPropertyInt64().Where(x => ClientProperties.PropertiesInt64.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesInt64 = Session.Player.GetAllPropertyInt64Where(ClientProperties.PropertiesInt64); if (_propertiesInt64.Count != 0) { @@ -98,7 +98,7 @@ private void WriteEventBody() } } - var _propertiesBool = Session.Player.GetAllPropertyBools().Where(x => SendOnLoginProperties.PropertiesBool.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesBool = Session.Player.GetAllPropertyBoolsWhere(SendOnLoginProperties.PropertiesBool); if (_propertiesBool.Count != 0) { @@ -115,7 +115,7 @@ private void WriteEventBody() } } - var _propertiesDouble = Session.Player.GetAllPropertyFloat().Where(x => SendOnLoginProperties.PropertiesDouble.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesDouble = Session.Player.GetAllPropertyFloatWhere(SendOnLoginProperties.PropertiesDouble); if (_propertiesDouble.Count != 0) { @@ -132,7 +132,7 @@ private void WriteEventBody() } } - var _propertiesString = Session.Player.GetAllPropertyString().Where(x => SendOnLoginProperties.PropertiesString.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesString = Session.Player.GetAllPropertyStringWhere(SendOnLoginProperties.PropertiesString); if (_propertiesString.Count != 0) { @@ -157,7 +157,7 @@ private void WriteEventBody() } } - var _propertiesDid = Session.Player.GetAllPropertyDataId().Where(x => SendOnLoginProperties.PropertiesDataId.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesDid = Session.Player.GetAllPropertyDataIdWhere(SendOnLoginProperties.PropertiesDataId); if (_propertiesDid.Count != 0) { @@ -174,7 +174,7 @@ private void WriteEventBody() } } - var _propertiesIid = Session.Player.GetAllPropertyInstanceId().Where(x => SendOnLoginProperties.PropertiesInstanceId.Contains((ushort)x.Key)).ToDictionary(i => i.Key, i => i.Value); + var _propertiesIid = Session.Player.GetAllPropertyInstanceIdWhere(SendOnLoginProperties.PropertiesInstanceId); if (_propertiesIid.Count != 0) { diff --git a/Source/ACE.Server/Network/Structure/AppraiseInfo.cs b/Source/ACE.Server/Network/Structure/AppraiseInfo.cs index 1d4a2c2130..8d600995b4 100644 --- a/Source/ACE.Server/Network/Structure/AppraiseInfo.cs +++ b/Source/ACE.Server/Network/Structure/AppraiseInfo.cs @@ -341,13 +341,13 @@ public void BuildProfile(WorldObject wo, Player examiner, bool success = true) private void BuildProperties(WorldObject wo) { - PropertiesInt = wo.GetAllPropertyInt().Where(x => ClientProperties.PropertiesInt.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesInt64 = wo.GetAllPropertyInt64().Where(x => ClientProperties.PropertiesInt64.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesBool = wo.GetAllPropertyBools().Where(x => ClientProperties.PropertiesBool.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesFloat = wo.GetAllPropertyFloat().Where(x => ClientProperties.PropertiesDouble.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesString = wo.GetAllPropertyString().Where(x => ClientProperties.PropertiesString.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesDID = wo.GetAllPropertyDataId().Where(x => ClientProperties.PropertiesDataId.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); - PropertiesIID = wo.GetAllPropertyInstanceId().Where(x => ClientProperties.PropertiesInstanceId.Contains((ushort)x.Key)).ToDictionary(x => x.Key, x => x.Value); + PropertiesInt = wo.GetAllPropertyIntWhere(ClientProperties.PropertiesInt); + PropertiesInt64 = wo.GetAllPropertyInt64Where(ClientProperties.PropertiesInt64); + PropertiesBool = wo.GetAllPropertyBoolsWhere(ClientProperties.PropertiesBool); + PropertiesFloat = wo.GetAllPropertyFloatWhere(ClientProperties.PropertiesDouble); + PropertiesString = wo.GetAllPropertyStringWhere(ClientProperties.PropertiesString); + PropertiesDID = wo.GetAllPropertyDataIdWhere(ClientProperties.PropertiesDataId); + PropertiesIID = wo.GetAllPropertyInstanceIdWhere(ClientProperties.PropertiesInstanceId); if (wo is Player player) { diff --git a/Source/ACE.Server/WorldObjects/WorldObject_Properties.cs b/Source/ACE.Server/WorldObjects/WorldObject_Properties.cs index bdc0f98ba5..1619f4b759 100644 --- a/Source/ACE.Server/WorldObjects/WorldObject_Properties.cs +++ b/Source/ACE.Server/WorldObjects/WorldObject_Properties.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; using ACE.Common; @@ -529,6 +530,232 @@ public Dictionary GetAllPropertyString() } #endregion + #region GetAllProperty Where Functions + public Dictionary GetAllPropertyBoolsWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesBool != null) + { + foreach (var kvp in Biota.PropertiesBool.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyBools != null) + { + foreach (var property in ephemeralPropertyBools.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyDataIdWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesDID != null) + { + foreach (var kvp in Biota.PropertiesDID.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyDataIds != null) + { + foreach (var property in ephemeralPropertyDataIds.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyFloatWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesFloat != null) + { + foreach (var kvp in Biota.PropertiesFloat.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyFloats != null) + { + foreach (var property in ephemeralPropertyFloats.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyInstanceIdWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesIID != null) + { + foreach (var kvp in Biota.PropertiesIID.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyInstanceIds != null) + { + foreach (var property in ephemeralPropertyInstanceIds.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyIntWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesInt != null) + { + foreach (var kvp in Biota.PropertiesInt.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyInts != null) + { + foreach (var property in ephemeralPropertyInts.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyInt64Where(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesInt64 != null) + { + foreach (var kvp in Biota.PropertiesInt64.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyInt64s != null) + { + foreach (var property in ephemeralPropertyInt64s.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value.HasValue) + results[property.Key] = property.Value.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + + public Dictionary GetAllPropertyStringWhere(HashSet keys) + { + var results = new Dictionary(); + + BiotaDatabaseLock.EnterReadLock(); + try + { + if (Biota.PropertiesString != null) + { + foreach (var kvp in Biota.PropertiesString.Where(r => keys.Contains((ushort)r.Key))) + results[kvp.Key] = kvp.Value; + } + } + finally + { + BiotaDatabaseLock.ExitReadLock(); + } + + if (ephemeralPropertyStrings != null) + { + foreach (var property in ephemeralPropertyStrings.Where(r => keys.Contains((ushort)r.Key))) + { + if (property.Value != null) + results[property.Key] = property.Value; + else + results.Remove(property.Key); + } + } + + return results; + } + #endregion + private readonly Dictionary ephemeralPositions = new Dictionary();