예제 #1
0
        /// <summary>
        /// Spawn this new into the live world
        /// </summary>
        public override void SpawnNewInWorld()
        {
            var ch = (ICharacter)DataTemplate;
            var locationAssembly = Assembly.GetAssembly(typeof(ILocation));

            if (ch.LastKnownLocationType == null)
            {
                ch.LastKnownLocationType = typeof(IRoom).Name;
            }

            var lastKnownLocType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(ch.LastKnownLocationType));

            ILocation lastKnownLoc = null;

            if (lastKnownLocType != null && !string.IsNullOrWhiteSpace(ch.LastKnownLocation))
            {
                if (lastKnownLocType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                {
                    long lastKnownLocID = long.Parse(ch.LastKnownLocation);
                    lastKnownLoc = LiveCache.Get <ILocation>(lastKnownLocID, lastKnownLocType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(lastKnownLocType, ch.LastKnownLocation);
                    lastKnownLoc = LiveCache.Get <ILocation>(cacheKey);
                }
            }

            SpawnNewInWorld(lastKnownLoc);
        }
예제 #2
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IContains spawnTo)
        {
            var bS = (IPathwayData)DataTemplate;
            var locationAssembly = Assembly.GetAssembly(typeof(Room));

            MovementDirection = MessagingUtility.TranslateDegreesToDirection(bS.DegreesFromNorth);

            BirthMark = Birthmarker.GetBirthmark(bS);
            Keywords  = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() };
            Birthdate = DateTime.Now;

            //paths need two locations
            ILocation fromLocation     = null;
            var       fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType));

            if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID))
            {
                if (fromLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                {
                    long fromLocationID = long.Parse(bS.FromLocationID);
                    fromLocation = LiveCache.Get <ILocation>(fromLocationID, fromLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID);
                    fromLocation = LiveCache.Get <ILocation>(cacheKey);
                }
            }

            ILocation toLocation     = null;
            var       toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType));

            if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID))
            {
                if (toLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                {
                    long toLocationID = long.Parse(bS.ToLocationID);
                    toLocation = LiveCache.Get <ILocation>(toLocationID, toLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID);
                    toLocation = LiveCache.Get <ILocation>(cacheKey);
                }
            }

            FromLocation    = fromLocation;
            ToLocation      = toLocation;
            CurrentLocation = fromLocation;

            Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination });
            Enter.ToSurrounding.Add(bS.VisibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.VisibleToSurroundings }));
            Enter.ToSurrounding.Add(bS.AudibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.AudibleToSurroundings }));

            fromLocation.MoveInto <IPathway>(this);
        }
예제 #3
0
        /// <summary>
        /// Does this contain the specified entity
        /// </summary>
        /// <param name="entity">the entity in question</param>
        /// <returns>yes it contains it or no it does not</returns>
        public bool Contains(T entity, string namedContainer)
        {
            if (string.IsNullOrWhiteSpace(namedContainer))
            {
                return(Contains(entity));
            }

            LiveCacheKey key = new LiveCacheKey(entity);

            return(Birthmarks[namedContainer].Any(mark => mark.KeyHash().Equals(key.KeyHash())));
        }
예제 #4
0
        /// <summary>
        /// Remove an entity from this
        /// </summary>
        /// <param name="birthMark">the entity's birthmark to remove</param>
        /// <returns>success status</returns>
        public bool Remove(ICacheKey cacheKey)
        {
            LiveCacheKey newKey = (LiveCacheKey)cacheKey;

            if (!Birthmarks[genericCollectionLabel].Any(mark => mark.KeyHash().Equals(newKey.KeyHash())))
            {
                return(false);
            }

            return(Birthmarks[genericCollectionLabel].RemoveWhere(key => key.BirthMark == newKey.BirthMark) > 0);
        }
예제 #5
0
        /// <summary>
        /// Add an entity to this
        /// </summary>
        /// <param name="entity">the entity to add</param>
        /// <returns>success status</returns>
        public bool Add(T entity)
        {
            LiveCacheKey newKey = new LiveCacheKey(entity);

            if (Birthmarks[genericCollectionLabel].Any(mark => mark.KeyHash().Equals(newKey.KeyHash())))
            {
                return(false);
            }

            return(Birthmarks[genericCollectionLabel].Add(new LiveCacheKey(entity)));
        }
예제 #6
0
        /// <summary>
        /// Remove an entity from this
        /// </summary>
        /// <param name="birthMark">the entity's birthmark to remove</param>
        /// <returns>success status</returns>
        public bool Remove(ICacheKey cacheKey, string namedContainer)
        {
            if (string.IsNullOrWhiteSpace(namedContainer))
            {
                return(Remove(cacheKey));
            }

            LiveCacheKey key = (LiveCacheKey)cacheKey;

            if (!Birthmarks[namedContainer].Any(mark => mark.KeyHash().Equals(key.KeyHash())))
            {
                return(false);
            }

            return(Birthmarks[namedContainer].RemoveWhere(keys => keys == key) > 0);
        }
예제 #7
0
 public GlobalPosition(LiveCacheKey currentZone, LiveCacheKey currentContainer)
 {
     _currentZone      = currentZone;
     _currentContainer = currentContainer;
 }
예제 #8
0
        /// <summary>
        /// Restores one character from their Current backup
        /// </summary>
        /// <param name="accountHandle">Global Account Handle for the account</param>
        /// <param name="charID">Which character to load</param>
        /// <returns></returns>
        public Player RestorePlayer(string accountHandle, long charID)
        {
            Player newPlayerToLoad = null;

            try
            {
                var currentBackupDirectory = BaseDirectory + "Players/" + accountHandle + "/" + charID.ToString() + "/Current/";

                //No backup directory? No live data.
                if (!Directory.Exists(currentBackupDirectory))
                {
                    return(null);
                }

                var playerDirectory = new DirectoryInfo(currentBackupDirectory);

                //no player file to load, derp
                if (!File.Exists(playerDirectory + charID.ToString() + ".Player"))
                {
                    return(null);
                }

                var blankEntity = Activator.CreateInstance(typeof(Player)) as Player;

                using (var stream = File.OpenRead(playerDirectory + charID.ToString() + ".Player"))
                {
                    byte[] bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);
                    newPlayerToLoad = (Player)blankEntity.DeSerialize(bytes);
                }

                //bad load, dump it
                if (newPlayerToLoad == null)
                {
                    return(null);
                }

                //abstract this out to a helper maybe?
                var locationAssembly = Assembly.GetAssembly(typeof(EntityPartial));

                var ch = (ICharacter)newPlayerToLoad.DataTemplate;
                if (ch.LastKnownLocationType == null)
                {
                    ch.LastKnownLocationType = typeof(Room).Name;
                }

                var lastKnownLocType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(ch.LastKnownLocationType));

                ILocation lastKnownLoc = null;
                if (lastKnownLocType != null && !string.IsNullOrWhiteSpace(ch.LastKnownLocation))
                {
                    if (lastKnownLocType.GetInterfaces().Contains(typeof(ISpawnAsSingleton)))
                    {
                        long lastKnownLocID = long.Parse(ch.LastKnownLocation);
                        lastKnownLoc = LiveCache.Get <ILocation>(lastKnownLocID, lastKnownLocType);
                    }
                    else
                    {
                        var cacheKey = new LiveCacheKey(lastKnownLocType, ch.LastKnownLocation);
                        lastKnownLoc = LiveCache.Get <ILocation>(cacheKey);
                    }
                }

                newPlayerToLoad.CurrentLocation = lastKnownLoc;

                //We have the player in live cache now so make it move to the right place
                newPlayerToLoad.GetFromWorldOrSpawn();

                newPlayerToLoad.UpsertToLiveWorldCache();

                //We'll need one of these per container on players
                if (Directory.Exists(playerDirectory + "Inventory/"))
                {
                    var inventoryDirectory = new DirectoryInfo(playerDirectory + "Inventory/");

                    foreach (var file in inventoryDirectory.EnumerateFiles())
                    {
                        var blankObject = Activator.CreateInstance(typeof(Inanimate)) as Inanimate;

                        using (var stream = file.Open(FileMode.Open))
                        {
                            byte[] bytes = new byte[stream.Length];
                            stream.Read(bytes, 0, (int)stream.Length);
                            var newObj = (IInanimate)blankObject.DeSerialize(bytes);
                            newObj.UpsertToLiveWorldCache();
                            newPlayerToLoad.MoveInto <IInanimate>(newObj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(newPlayerToLoad);
        }
예제 #9
0
        /// <summary>
        /// Does this contain the specified entity
        /// </summary>
        /// <param name="entity">the entity in question</param>
        /// <returns>yes it contains it or no it does not</returns>
        public bool Contains(T entity)
        {
            LiveCacheKey newKey = new LiveCacheKey(entity);

            return(Birthmarks.Values.Any(hs => hs.Any(mark => mark.KeyHash().Equals(newKey.KeyHash()))));
        }
예제 #10
0
        /// <summary>
        /// Spawn this new into the live world into a specified container
        /// </summary>
        /// <param name="spawnTo">the location/container this should spawn into</param>
        public override void SpawnNewInWorld(IContains spawnTo)
        {
            var bS = DataTemplate<IPathwayData>(); ;
            var locationAssembly = Assembly.GetAssembly(typeof(Room));

            MovementDirection = Utilities.TranslateToDirection(bS.DegreesFromNorth, bS.InclineGrade);

            BirthMark = LiveCache.GetUniqueIdentifier(bS);
            Keywords = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() };
            Birthdate = DateTime.Now;

            //paths need two locations
            ILocation fromLocation = null;
            var fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType));

            if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID))
            {
                if (fromLocationType.GetInterfaces().Contains(typeof(ISingleton)))
                {
                    long fromLocationID = long.Parse(bS.FromLocationID);
                    fromLocation = LiveCache.Get<ILocation>(fromLocationID, fromLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID);
                    fromLocation = LiveCache.Get<ILocation>(cacheKey);
                }
            }

            ILocation toLocation = null;
            var toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType));

            if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID))
            {
                if (toLocationType.GetInterfaces().Contains(typeof(ISingleton)))
                {
                    long toLocationID = long.Parse(bS.ToLocationID);
                    toLocation = LiveCache.Get<ILocation>(toLocationID, toLocationType);
                }
                else
                {
                    var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID);
                    toLocation = LiveCache.Get<ILocation>(cacheKey);
                }
            }

            FromLocation = fromLocation;
            ToLocation = toLocation;
            CurrentLocation = fromLocation;

            if (String.IsNullOrWhiteSpace(bS.MessageToActor))
                bS.MessageToActor = String.Empty;

            if (String.IsNullOrWhiteSpace(bS.MessageToDestination))
                bS.MessageToDestination = String.Empty;

            if (String.IsNullOrWhiteSpace(bS.MessageToOrigin))
                bS.MessageToOrigin = String.Empty;

            if (String.IsNullOrWhiteSpace(bS.MessageToOrigin))
                bS.MessageToOrigin = String.Empty;

            if (String.IsNullOrWhiteSpace(bS.VisibleToSurroundings))
                bS.VisibleToSurroundings = String.Empty;

            if (String.IsNullOrWhiteSpace(bS.AudibleToSurroundings))
                bS.AudibleToSurroundings = String.Empty;

            Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination });
            Enter.ToSurrounding.Add(MessagingType.Visible, new Tuple<int, IEnumerable<string>>(bS.VisibleStrength, new string[] { bS.VisibleToSurroundings }));
            Enter.ToSurrounding.Add(MessagingType.Audible, new Tuple<int, IEnumerable<string>>(bS.AudibleStrength, new string[] { bS.AudibleToSurroundings }));

            fromLocation.MoveInto<IPathway>(this);
        }
예제 #11
0
        /// <summary>
        /// Restores one character from their Current backup
        /// </summary>
        /// <param name="accountHandle">Global Account Handle for the account</param>
        /// <param name="charID">Which character to load</param>
        /// <returns></returns>
        public IPlayer RestorePlayer(string accountHandle, long charID)
        {
            IPlayer newPlayerToLoad = null;

            try
            {
                var currentBackupDirectory = BaseDirectory + accountHandle + "/" + CurrentDirectoryName + charID.ToString() + "/";

                //No backup directory? No live data.
                if (!VerifyDirectory(currentBackupDirectory, false))
                    return null;

                var playerDirectory = new DirectoryInfo(currentBackupDirectory);

                var playerFilePath = playerDirectory + GetPlayerFilename(charID);

                var fileData = ReadCurrentFileByPath(playerFilePath);

                //no player file to load, derp
                if (fileData.Length == 0)
                    return null;

                var blankEntity = Activator.CreateInstance(typeof(IPlayer)) as IPlayer;
                newPlayerToLoad = (IPlayer)blankEntity.FromBytes(fileData);

                //bad load, dump it
                if (newPlayerToLoad == null)
                    return null;

                //abstract this out to a helper maybe?
                var locationAssembly = Assembly.GetAssembly(typeof(ILocation));

                var ch = newPlayerToLoad.DataTemplate<ICharacter>();
                if (ch.LastKnownLocationType == null)
                    ch.LastKnownLocationType = typeof(IRoom).Name;

                var lastKnownLocType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(ch.LastKnownLocationType));

                ILocation lastKnownLoc = null;
                if (lastKnownLocType != null && !string.IsNullOrWhiteSpace(ch.LastKnownLocation))
                {
                    if (lastKnownLocType.GetInterfaces().Contains(typeof(ISingleton)))
                    {
                        long lastKnownLocID = long.Parse(ch.LastKnownLocation);
                        lastKnownLoc = LiveCache.Get<ILocation>(lastKnownLocID, lastKnownLocType);
                    }
                    else
                    {
                        var cacheKey = new LiveCacheKey(lastKnownLocType, ch.LastKnownLocation);
                        lastKnownLoc = LiveCache.Get<ILocation>(cacheKey);
                    }
                }

                newPlayerToLoad.CurrentLocation = lastKnownLoc;

                //We have the player in live cache now so make it move to the right place
                newPlayerToLoad.GetFromWorldOrSpawn();
                newPlayerToLoad.UpsertToLiveWorldCache();

                //We'll need one of these per container on players
                if (Directory.Exists(playerDirectory + "Inventory/"))
                {
                    var inventoryDirectory = new DirectoryInfo(playerDirectory + "Inventory/");

                    foreach (var file in inventoryDirectory.EnumerateFiles())
                    {
                        var blankObject = Activator.CreateInstance(typeof(IInanimate)) as IInanimate;

                        var newObj = (IInanimate)blankObject.FromBytes(ReadFile(file));
                        newObj.UpsertToLiveWorldCache();
                        newPlayerToLoad.MoveInto(newObj);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return newPlayerToLoad;
        }