示例#1
0
文件: Get.cs 项目: Cloudxtreme/NetMud
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var       sb    = new List <string>();
            var       thing = (IEntity)Subject;
            var       actor = (IContains)Actor;
            IContains place;

            string toRoomMessage = "$A$ gets $S$.";

            if (Target != null)
            {
                place         = (IContains)Target;
                toRoomMessage = "$A$ gets $S$ from $T$.";
                sb.Add("You get $S$ from $T$.");
            }
            else
            {
                place = (IContains)OriginLocation;
                sb.Add("You get $S$.");
            }

            place.MoveFrom(thing);
            actor.MoveInto(thing);

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { toRoomMessage }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, thing, (IEntity)Target, OriginLocation, null);
        }
示例#2
0
        public override void Execute()
        {
            //NPCs dont need to use this
            if (!Actor.GetType().GetInterfaces().Contains(typeof(IPlayer)))
            {
                return;
            }

            var returnStrings = new List <string>();
            var sb            = new StringBuilder();

            var commandsAssembly = Assembly.GetAssembly(typeof(CommandParameterAttribute));

            var loadedCommands = commandsAssembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(ICommand)));

            loadedCommands = loadedCommands.Where(comm => comm.GetCustomAttributes <CommandPermissionAttribute>().Any(att => att.MinimumRank <= ((ICharacter)Actor.DataTemplate).GamePermissionsRank));

            returnStrings.Add("Commands:");

            foreach (var commandName in loadedCommands.Select(comm => comm.Name))
            {
                sb.Append(commandName + ", ");
            }

            if (sb.Length > 0)
            {
                sb.Length -= 2;
            }

            returnStrings.Add(sb.ToString());

            var messagingObject = new MessageCluster(returnStrings, new string[] { }, new string[] { }, new string[] { }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, null, null);
        }
示例#3
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var       newObject = (INonPlayerCharacter)Subject;
            var       sb        = new List <string>();
            IContains spawnTo;

            //No target = spawn to room you're in
            if (Target != null)
            {
                spawnTo = (IContains)Target;
            }
            else
            {
                spawnTo = OriginLocation;
            }

            var entityObject = new Intelligence(newObject, spawnTo);

            //TODO: keywords is janky, location should have its own identifier name somehow for output purposes - DISPLAY short/long NAME
            sb.Add(string.Format("{0} spawned to {1}", entityObject.DataTemplate.Name, spawnTo.Keywords[0]));

            var messagingObject = new MessageCluster(sb, new string[] { "You are ALIVE" }, new string[] { "You have been given $S$" }, new string[] { "$S$ appears in the $T$." }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, entityObject, spawnTo, OriginLocation, null);
        }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb = new List <string>();

            sb.Add(String.Format("You say '{0}'", Subject));

            //TODO: language outputs
            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { String.Format("$A$ says '{0}'", Subject) }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation, null);
        }
示例#6
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var moveTo = (ILocation)Subject;
            var sb     = new List <string>();

            sb.Add("You teleport.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ disappears in a puff of smoke." }, new string[] { "$A$ appears out of nowhere." });

            messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation, null);

            moveTo.MoveInto <Player>((Player)Actor);
        }
示例#7
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb    = new List <string>();
            var thing = (IEntity)Subject;
            var place = (IContains)Target;
            var actor = (IContains)Actor;

            actor.MoveFrom(thing);
            place.MoveInto(thing);

            sb.Add("You put $S$ in the $T$.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ puts $S$ in the $T$." }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, thing, (IEntity)place, OriginLocation, null);
        }
示例#8
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var       sb    = new List <string>();
            var       thing = (IEntity)Subject;
            var       actor = (IContains)Actor;
            IContains place = (IContains)OriginLocation;

            actor.MoveFrom(thing);
            place.MoveInto(thing);

            sb.Add("You drop $S$.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ drops $S$." }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, thing, null, OriginLocation, null);
        }
示例#9
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb  = new List <string>();
            var chr = (IMobile)Actor;

            sb.Add("You look through your belongings.");

            foreach (var thing in chr.Inventory.EntitiesContained())
            {
                sb.AddRange(thing.RenderToLook(chr));
            }

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ sifts through $G$ belongings." }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation, null);
        }
示例#10
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb = new List <string>();

            var player = (Player)Actor;

            sb.Add("You save your life.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation, null);

            var hotBack = new HotBackup(HostingEnvironment.MapPath("/HotBackup/"));

            //Save the player out
            hotBack.WriteOnePlayer(player);
        }
示例#11
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb = new List <string>();

            //Just do a look on the room
            if (Subject == null)
            {
                sb.AddRange(OriginLocation.RenderToLook(Actor));
            }
            else
            {
                var lookTarget = (ILookable)Subject;
                sb.AddRange(lookTarget.RenderToLook(Actor));
            }

            var messagingObject = new MessageCluster(sb, new string[] { "$A$ looks at you." }, new string[] { }, new string[] { "$A$ looks around the room." }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, (IEntity)Subject, null, OriginLocation, null);
        }
示例#12
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var topic = (IHelpful)Subject;
            var sb    = GetHelpHeader(topic);

            sb = sb.Concat(topic.RenderHelpBody()).ToList();

            //If it's a command render the syntax help at the bottom
            if (topic.GetType().GetInterfaces().Contains(typeof(ICommand)))
            {
                var subject = (ICommand)topic;
                sb.Add(string.Empty);
                sb = sb.Concat(subject.RenderSyntaxHelp()).ToList();
            }

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { }, new string[] { });

            messagingObject.ExecuteMessaging(Actor, null, null, null, null);
        }
示例#13
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb    = new List <string>();
            var thing = (IEntity)Subject;
            var place = (IContains)Target;
            var actor = (IContains)Actor;

            actor.MoveFrom(thing);
            place.MoveInto(thing);

            sb.Add("You put $S$ in the $T$.");

            var toActor = new Message(MessagingType.Visible, new Occurrence()
            {
                Strength = 1
            })
            {
                Override = sb
            };

            var toOrigin = new Message(MessagingType.Visible, new Occurrence()
            {
                Strength = 30
            })
            {
                Override = new string[] { "$A$ puts $S$ in the $T$." }
            };

            var messagingObject = new MessageCluster(toActor)
            {
                ToOrigin = new List <IMessage> {
                    toOrigin
                }
            };

            messagingObject.ExecuteMessaging(Actor, thing, place, OriginLocation.CurrentLocation, null);
        }
示例#14
0
 /// <summary>
 /// News up an entity with its backing data
 /// </summary>
 /// <param name="backingStore">the backing data</param>
 public Pathway(IPathwayData backingStore)
 {
     Enter        = new MessageCluster();
     DataTemplate = backingStore;
     GetFromWorldOrSpawn();
 }
示例#15
0
 /// <summary>
 /// News up an empty entity
 /// </summary>
 public Pathway()
 {
     Enter = new MessageCluster();
 }