Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve WorldObject_Properties GetAllProperties* #4109

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
14 changes: 7 additions & 7 deletions Source/ACE.Server/Network/Structure/AppraiseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
227 changes: 227 additions & 0 deletions Source/ACE.Server/WorldObjects/WorldObject_Properties.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

using ACE.Common;
Expand Down Expand Up @@ -529,6 +530,232 @@ public Dictionary<PropertyString, string> GetAllPropertyString()
}
#endregion

#region GetAllProperty Where Functions
public Dictionary<PropertyBool, bool> GetAllPropertyBoolsWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyBool, bool>();

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<PropertyDataId, uint> GetAllPropertyDataIdWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyDataId, uint>();

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<PropertyFloat, double> GetAllPropertyFloatWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyFloat, double>();

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<PropertyInstanceId, uint> GetAllPropertyInstanceIdWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyInstanceId, uint>();

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<PropertyInt, int> GetAllPropertyIntWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyInt, int>();

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<PropertyInt64, long> GetAllPropertyInt64Where(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyInt64, long>();

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<PropertyString, string> GetAllPropertyStringWhere(HashSet<ushort> keys)
{
var results = new Dictionary<PropertyString, string>();

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<PositionType, Position> ephemeralPositions = new Dictionary<PositionType, Position>();

Expand Down