Core/Objects: Fixes object not being updated in ObjectAccessor
This commit is contained in:
@@ -25,6 +25,11 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
public class ObjectAccessor : Singleton<ObjectAccessor>
|
public class ObjectAccessor : Singleton<ObjectAccessor>
|
||||||
{
|
{
|
||||||
|
object _lockObject = new object();
|
||||||
|
|
||||||
|
Dictionary<ObjectGuid, Player> _players = new Dictionary<ObjectGuid, Player>();
|
||||||
|
Dictionary<ObjectGuid, Transport> _transports = new Dictionary<ObjectGuid, Transport>();
|
||||||
|
|
||||||
ObjectAccessor() { }
|
ObjectAccessor() { }
|
||||||
|
|
||||||
public WorldObject GetWorldObject(WorldObject p, ObjectGuid guid)
|
public WorldObject GetWorldObject(WorldObject p, ObjectGuid guid)
|
||||||
@@ -200,6 +205,7 @@ public class ObjectAccessor : Singleton<ObjectAccessor>
|
|||||||
// this returns Player even if he is not in world, for example teleporting
|
// this returns Player even if he is not in world, for example teleporting
|
||||||
public Player FindConnectedPlayer(ObjectGuid guid)
|
public Player FindConnectedPlayer(ObjectGuid guid)
|
||||||
{
|
{
|
||||||
|
lock (_lockObject)
|
||||||
return _players.LookupByKey(guid);
|
return _players.LookupByKey(guid);
|
||||||
}
|
}
|
||||||
public Player FindConnectedPlayerByName(string name)
|
public Player FindConnectedPlayerByName(string name)
|
||||||
@@ -209,44 +215,52 @@ public class ObjectAccessor : Singleton<ObjectAccessor>
|
|||||||
|
|
||||||
public Transport FindTransport(ObjectGuid guid)
|
public Transport FindTransport(ObjectGuid guid)
|
||||||
{
|
{
|
||||||
|
lock (_lockObject)
|
||||||
return _transports.LookupByKey(guid);
|
return _transports.LookupByKey(guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveAllPlayers()
|
public void SaveAllPlayers()
|
||||||
|
{
|
||||||
|
lock (_lockObject)
|
||||||
{
|
{
|
||||||
foreach (var pl in GetPlayers())
|
foreach (var pl in GetPlayers())
|
||||||
pl.SaveToDB();
|
pl.SaveToDB();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ICollection<Player> GetPlayers()
|
public ICollection<Player> GetPlayers()
|
||||||
{
|
{
|
||||||
|
lock (_lockObject)
|
||||||
return _players.Values;
|
return _players.Values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddObject(Player obj)
|
public void AddObject(Player obj)
|
||||||
|
{
|
||||||
|
lock (_lockObject)
|
||||||
{
|
{
|
||||||
PlayerNameMapHolder.Insert(obj);
|
PlayerNameMapHolder.Insert(obj);
|
||||||
_players.TryAdd(obj.GetGUID(), obj);
|
_players[obj.GetGUID()] = obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void AddObject(Transport obj)
|
public void AddObject(Transport obj)
|
||||||
{
|
{
|
||||||
_transports.TryAdd(obj.GetGUID(), obj);
|
lock (_lockObject)
|
||||||
|
_transports[obj.GetGUID()] = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveObject(Player obj)
|
public void RemoveObject(Player obj)
|
||||||
{
|
{
|
||||||
Player player;
|
lock (_lockObject)
|
||||||
|
{
|
||||||
PlayerNameMapHolder.Remove(obj);
|
PlayerNameMapHolder.Remove(obj);
|
||||||
_players.TryRemove(obj.GetGUID(), out player);
|
_players.Remove(obj.GetGUID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void RemoveObject(Transport obj)
|
public void RemoveObject(Transport obj)
|
||||||
{
|
{
|
||||||
Transport transport;
|
lock (_lockObject)
|
||||||
_transports.TryRemove(obj.GetGUID(), out transport);
|
_transports.Remove(obj.GetGUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConcurrentDictionary<ObjectGuid, Player> _players = new ConcurrentDictionary<ObjectGuid, Player>();
|
|
||||||
ConcurrentDictionary<ObjectGuid, Transport> _transports = new ConcurrentDictionary<ObjectGuid, Transport>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlayerNameMapHolder
|
class PlayerNameMapHolder
|
||||||
|
|||||||
Reference in New Issue
Block a user