Used by the system to produce output for commands and events
Inheritance: IMessageCluster
示例#1
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);
        }
示例#2
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;

            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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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 playerDataWrapper = new PlayerData();

            //Save the player out
            playerDataWrapper.WriteOnePlayer(player);
        }
示例#8
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);
        }
示例#9
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var sb = new List<string>();

            var player = (Player)Actor;

            sb.Add("You exit this reality.");

            var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ exits this reality." }, new string[] { });

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

            var playerDataWrapper = new PlayerData();

            //Save the player out
            playerDataWrapper.WriteOnePlayer(player);
            player.CloseConnection();
        }
示例#10
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);
        }
示例#11
0
        /// <summary>
        /// Executes this command
        /// </summary>
        public override void Execute()
        {
            var newObject = (IInanimateData)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 Inanimate(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.DataTemplateName, 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);
        }
示例#12
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();
     DataTemplateId = backingStore.ID;
     GetFromWorldOrSpawn();
 }
示例#13
0
 /// <summary>
 /// News up an empty entity
 /// </summary>
 public Pathway()
 {
     Enter = new MessageCluster();
 }
示例#14
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);
        }