예제 #1
0
 public MoveAction(Mode mode, int byAmount, ToTarget toTarget, int targetId, PlaceTypeTarget targetType, MovementType movementType)
 {
     this.mode         = mode;
     this.byAmount     = byAmount;
     this.toTarget     = toTarget;
     this.targetId     = targetId;
     this.targetType   = targetType;
     this.movementType = movementType;
 }
예제 #2
0
        /// <summary>
        /// Executes the messaging, sending messages using WriteTo on all relevant entities
        /// </summary>
        /// <param name="Actor">The acting entity</param>
        /// <param name="Subject">The command's subject entity</param>
        /// <param name="Target">The command's target entity</param>
        /// <param name="OriginLocation">The location the acting entity acted in</param>
        /// <param name="DestinationLocation">The location the command is targetting</param>
        public void ExecuteMessaging(IEntity Actor, IEntity Subject, IEntity Target, IEntity OriginLocation, IEntity DestinationLocation)
        {
            var entities = new Dictionary <MessagingTargetType, IEntity[]>();

            entities.Add(MessagingTargetType.Actor, new IEntity[] { Actor });
            entities.Add(MessagingTargetType.Subject, new IEntity[] { Subject });
            entities.Add(MessagingTargetType.Target, new IEntity[] { Target });
            entities.Add(MessagingTargetType.OriginLocation, new IEntity[] { OriginLocation });
            entities.Add(MessagingTargetType.DestinationLocation, new IEntity[] { DestinationLocation });

            if (Actor != null && ToActor.Any(str => !string.IsNullOrWhiteSpace(str)))
            {
                Actor.WriteTo(TranslateOutput(ToActor, entities));
            }

            if (Subject != null && ToSubject.Any(str => !string.IsNullOrWhiteSpace(str)))
            {
                Subject.WriteTo(TranslateOutput(ToSubject, entities));
            }

            if (Target != null && ToTarget.Any(str => !string.IsNullOrWhiteSpace(str)))
            {
                Target.WriteTo(TranslateOutput(ToTarget, entities));
            }

            if (OriginLocation != null && ToOrigin.Any(str => !string.IsNullOrWhiteSpace(str)))
            {
                var oLoc          = (IContains)OriginLocation;
                var validContents = oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target));

                //Message dudes in the location, including non-person entities since they might have triggers
                foreach (var dude in validContents)
                {
                    dude.WriteTo(TranslateOutput(ToOrigin, entities));
                }
            }

            if (DestinationLocation != null && ToDestination.Any(str => !string.IsNullOrWhiteSpace(str)))
            {
                var oLoc = (IContains)DestinationLocation;

                //Message dudes in the location, including non-person entities since they might have triggers
                foreach (var dude in oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target)))
                {
                    dude.WriteTo(TranslateOutput(ToDestination, entities));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Get the string version of all the contained messages
        /// </summary>
        /// <param name="target">The entity type to select the messages of</param>
        /// <returns>Everything unpacked</returns>
        public string Unpack(TargetEntity target, LexicalContext overridingContext = null)
        {
            switch (target)
            {
            case TargetEntity.Destination:
                return(string.Join(" ", ToDestination.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Origin:
                return(string.Join(" ", ToOrigin.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Subject:
                return(string.Join(" ", ToSubject.Select(msg => msg.Describe(overridingContext))));

            case TargetEntity.Target:
                return(string.Join(" ", ToTarget.Select(msg => msg.Describe(overridingContext))));
            }

            return(string.Join(" ", ToActor.Select(msg => msg.Describe(overridingContext))));
        }
예제 #4
0
        /// <summary>
        /// Executes the messaging, sending messages using WriteTo on all relevant entities
        /// </summary>
        /// <param name="Actor">The acting entity</param>
        /// <param name="Subject">The command's subject entity</param>
        /// <param name="Target">The command's target entity</param>
        /// <param name="OriginLocation">The location the acting entity acted in</param>
        /// <param name="DestinationLocation">The location the command is targetting</param>
        public void ExecuteMessaging(IEntity Actor, IEntity Subject, IEntity Target, IEntity OriginLocation, IEntity DestinationLocation)
        {
            Dictionary <MessagingTargetType, IEntity[]> entities = new Dictionary <MessagingTargetType, IEntity[]>
            {
                { MessagingTargetType.Actor, new IEntity[] { Actor } },
                { MessagingTargetType.Subject, new IEntity[] { Subject } },
                { MessagingTargetType.Target, new IEntity[] { Target } },
                { MessagingTargetType.OriginLocation, new IEntity[] { OriginLocation } },
                { MessagingTargetType.DestinationLocation, new IEntity[] { DestinationLocation } }
            };

            if (Actor != null && ToActor.Any())
            {
                if (ToActor.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str)))
                {
                    Actor.WriteTo(TranslateOutput(ToActor.Select(msg => msg.Override), entities));
                }
                else
                {
                    Actor.WriteTo(TranslateOutput(ToActor.Select(msg => msg.Describe()), entities));
                }
            }

            if (Subject != null && ToSubject.Any())
            {
                if (ToSubject.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str)))
                {
                    Subject.WriteTo(TranslateOutput(ToSubject.Select(msg => msg.Override), entities));
                }
                else
                {
                    Subject.WriteTo(TranslateOutput(ToSubject.Select(msg => msg.Describe()), entities));
                }
            }

            if (Target != null && ToTarget.Any())
            {
                ILanguage language = Target.IsPlayer() ? ((IPlayer)Target).Template <IPlayerTemplate>().Account.Config.UILanguage : null;
                if (ToTarget.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str)))
                {
                    Target.WriteTo(TranslateOutput(ToTarget.Select(msg => msg.Override), entities));
                }
                else
                {
                    Target.WriteTo(TranslateOutput(ToTarget.Select(msg => msg.Describe()), entities));
                }
            }

            //TODO: origin and destination are areas of effect on their surrounding areas
            if (OriginLocation != null && ToOrigin.Any())
            {
                IContains             oLoc          = (IContains)OriginLocation;
                IEnumerable <IEntity> validContents = oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target));

                //Message dudes in the location, including non-person entities since they might have triggers
                foreach (IEntity dude in validContents)
                {
                    if (ToOrigin.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str)))
                    {
                        dude.WriteTo(TranslateOutput(ToOrigin.Select(msg => msg.Override), entities));
                    }
                    else
                    {
                        dude.WriteTo(TranslateOutput(ToOrigin.Select(msg => msg.Describe()), entities));
                    }
                }
            }

            if (DestinationLocation != null && ToDestination.Any())
            {
                IContains oLoc = (IContains)DestinationLocation;

                //Message dudes in the location, including non-person entities since they might have triggers
                foreach (IEntity dude in oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target)))
                {
                    if (ToDestination.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str)))
                    {
                        dude.WriteTo(TranslateOutput(ToDestination.Select(msg => msg.Override), entities));
                    }
                    else
                    {
                        dude.WriteTo(TranslateOutput(ToDestination.Select(msg => msg.Describe()), entities));
                    }
                }
            }
        }
예제 #5
0
        private async void CoreCommand(string Line)
        {
            NextSeg(ref Line, out string Cmd);
            Cmd = Cmd.ToLower();

            List <string> Options = new List <string>();

            NextSeg(ref Line, out string Target);
            while (!string.IsNullOrEmpty(Target) && Target[0] == '-')
            {
                Options.Add(Target);
                NextSeg(ref Line, out Target);
            }

            string p;

            try
            {
                p = ResolvePath(cwd + Target);
            }
            catch (Exception ex)
            {
                ResponseError(ex.Message);
                return;
            }

            switch (Cmd)
            {
            case "ls":

                if (Shared.Storage.FileExists(p))
                {
                    ResponseCommand(Target);
                    return;
                }

                p = p + "/";
                if (Shared.Storage.DirExist(p))
                {
                    string Lines = string.Join("/\n", Shared.Storage.ListDirs(p));
                    if (!string.IsNullOrEmpty(Lines))
                    {
                        ResponseCommand(Lines + "/", "");
                    }

                    Lines = string.Join("\n", Shared.Storage.ListFiles(p));
                    if (!string.IsNullOrEmpty(Lines))
                    {
                        ResponseCommand(Lines, "");
                    }

                    ResponseCommand("", "");
                }
                else
                {
                    if (Target == "")
                    {
                        ResponseError("ls: cannot open directory '.': No such file or directory");
                    }
                    else
                    {
                        ResponseError("ls: cannot access '" + Target + "': No such file or directory");
                    }
                }
                return;

            case "mv":
                if (NextSeg(ref Line, out string ToTarget))
                {
                    try
                    {
                        string pt = ResolvePath(cwd + ToTarget);

                        if (pt == p)
                        {
                            ResponseError($"mv: '{Target}' and '{Target}' are the same file");
                        }
                        else if (pt.IndexOf(p) == 0)
                        {
                            ResponseError($"mv: cannot move '{Target}' to a subdirectory of itself, '{ToTarget}'");
                        }
                        else if (Shared.Storage.DirExist(p))
                        {
                            if (Shared.Storage.FileExists(pt))
                            {
                                ResponseError($"mv: cannot overwrite non-directory '{ToTarget}' with directory '{Target}'");
                            }
                            else if (Shared.Storage.DirExist(pt))
                            {
                                Shared.Storage.MoveDir(p, pt + "/" + Path.GetFileName(p));
                            }
                            else
                            {
                                Shared.Storage.MoveDir(p, pt);
                            }
                        }
                        else if (Shared.Storage.FileExists(p))
                        {
                            if (Shared.Storage.DirExist(pt))
                            {
                                Shared.Storage.MoveFile(p, pt + "/" + Path.GetFileName(p));
                            }
                            else if (ToTarget.EndsWith("/"))
                            {
                                ResponseError($"mv: cannot move '{Target}' to '{ToTarget}': No such file or directory");
                            }
                            else
                            {
                                Shared.Storage.MoveFile(p, pt);
                            }
                        }
                        else
                        {
                            ResponseError($"mv: cannot stat '{Target}': No such file or directory");
                        }
                    }
                    catch (Exception ex)
                    {
                        ResponseError(ex.Message);
                    }
                }