using System;
using ACE.Entity;
using ACE.Entity.Enum;
using ACE.Server.WorldObjects;
namespace ACE.Server.Entity
{
///
/// This is a light weight object that holds a weak reference to a WorldObject.
/// In addition, it also caches values from that WorldObject incase the reference is released.
/// This way, we can still access values that we may have needed from the WorldObject after it is gone.
///
public class WorldObjectInfo : WorldObjectInfo
{
public T Value;
public WorldObjectInfo(WorldObject worldObject, T value) : base(worldObject)
{
Value = value;
}
public WorldObjectInfo(WorldObject worldObject) : base(worldObject)
{
}
}
///
/// This is a light weight object that holds a weak reference to a WorldObject.
/// In addition, it also caches values from that WorldObject incase the reference is released.
/// This way, we can still access values that we may have needed from the WorldObject after it is gone.
///
public class WorldObjectInfo
{
public readonly WeakReference WorldObjectRef;
public readonly ObjectGuid Guid;
public readonly string Name;
public readonly uint WeenieClassId;
public readonly WeenieType WeenieType;
public WorldObjectInfo(WorldObject worldObject)
{
WorldObjectRef = new WeakReference(worldObject);
Guid = worldObject.Guid;
Name = worldObject.Name;
WeenieClassId = worldObject.WeenieClassId;
WeenieType = worldObject.WeenieType;
}
///
/// If you use this function, you should cache and re-use the result in a local code space.
/// You should not hold on to the result, nor should you use this function too aggressively.
///
public WorldObject TryGetWorldObject()
{
WorldObjectRef.TryGetTarget(out var worldObject);
return worldObject;
}
}
}