public void AddGameObject(GameObject gameObject) { const int retryCount = 1024; if (!Enumerable.Range(0, retryCount).Any(_ => _gameObjects.TryAdd(gameObject.ObjectId, gameObject))) throw new InvalidOperationException(); gameObject.IsSpawned = true; }
private void LoadObjectsFromStore() { if (!File.Exists(StoreFile)) return; var type = typeof (GameObject); foreach (var objectNode in XElement.Load(StoreFile).Elements("Object")) { var obj = new GameObject(); foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(e => e.CanRead && e.CanWrite)) { var attribute = objectNode.Attribute(prop.Name); if (attribute == null) continue; if (typeof (Enum).IsAssignableFrom(prop.PropertyType)) prop.SetValue(obj, Enum.Parse(prop.PropertyType, attribute.Value), null); else prop.SetValue(obj, DeserializeValue(prop.PropertyType, attribute.Value), null); } AddGameObject(obj); if (obj.Type == ObjectType.Npc) _npcAi.Restore(obj); } }
public void AddPlayer(GameObject playerObject, PacketSession playerSession) { AddGameObject(playerObject); const int retryCount = 1024; if (!Enumerable.Range(0, retryCount).Any(_ => _sessions.TryAdd(playerSession, playerObject.ObjectId))) throw new InvalidOperationException(); }