Exemplo n.º 1
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                LevelInfo.OutputBackups(p, p.level.MapName); return;
            }

            string[] args      = message.ToLower().SplitSpaces();
            string   mapArg    = args.Length > 1 ? args[0] : p.level.MapName;
            string   backupArg = args.Length > 1 ? args[1] : args[0];

            string path;

            if (backupArg == currentFlag)
            {
                path = LevelInfo.MapPath(mapArg);
                if (!LevelInfo.MapExists(mapArg))
                {
                    if (Directory.Exists(LevelInfo.BackupBasePath(mapArg)))
                    {
                        p.Message("&WLevel \"{0}\" does not currently exist, &Showever:", mapArg);
                        LevelInfo.OutputBackups(p, mapArg);
                    }
                    else
                    {
                        p.Message("&WLevel \"{0}\" does not exist and no backups could be found.", mapArg);
                    }
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(LevelInfo.BackupBasePath(mapArg)))
                {
                    p.Message("Level \"{0}\" has no backups.", mapArg); return;
                }
                if (backupArg == latestFlag)
                {
                    int latest = LevelInfo.LatestBackup(mapArg);
                    if (latest == 0)
                    {
                        p.Message("&WLevel \"{0}\" does not have any numbered backups, " +
                                  "so the latest backup could not be determined.", mapArg);
                        return;
                    }
                    backupArg = latest.ToString();
                }
                path = LevelInfo.BackupFilePath(mapArg, backupArg);
            }
            if (!File.Exists(path))
            {
                p.Message("Backup \"{0}\" for {1} could not be found.", backupArg, mapArg); return;
            }

            string formattedMuseumName;

            if (backupArg == currentFlag)
            {
                formattedMuseumName = "&cMuseum &S(" + mapArg + ")";
            }
            else
            {
                formattedMuseumName = "&cMuseum &S(" + mapArg + " " + backupArg + ")";
            }

            if (p.level.name.CaselessEq(formattedMuseumName))
            {
                p.Message("You are already in this museum."); return;
            }
            if (Interlocked.CompareExchange(ref p.LoadingMuseum, 1, 0) == 1)
            {
                p.Message("You are already loading a museum level."); return;
            }

            try {
                Level lvl = LevelActions.LoadMuseum(p, formattedMuseumName, mapArg, path);
                PlayerActions.ChangeMap(p, lvl);
            } finally {
                Interlocked.Exchange(ref p.LoadingMuseum, 0);
            }
        }