Exemplo n.º 1
0
        /// <summary>
        /// Exports the plan under a text format.
        /// </summary>
        /// <param name="planToExport"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static string ExportAsText(Plan planToExport, PlanExportSettings settings)
        {
            var plan = new PlanScratchpad(planToExport.Character, planToExport);

            plan.Sort(planToExport.SortingPreferences);
            plan.UpdateStatistics();

            var builder    = new StringBuilder();
            var timeFormat = DescriptiveTextOptions.FullText | DescriptiveTextOptions.IncludeCommas | DescriptiveTextOptions.SpaceText;
            var character  = (Character)plan.Character;

            // Initialize constants
            string lineFeed  = "";
            string boldStart = "";
            string boldEnd   = "";

            switch (settings.Markup)
            {
            default:
                break;

            case MarkupType.Forum:
                boldStart = "[b]";
                boldEnd   = "[/b]";
                break;

            case MarkupType.Html:
                lineFeed  = "<br />";
                boldStart = "<b>";
                boldEnd   = "</b>";
                break;
            }

            // Header
            if (settings.IncludeHeader)
            {
                builder.Append(boldStart);
                if (settings.ShoppingList)
                {
                    builder.Append("Shopping list for ").Append(character.Name);
                }
                else
                {
                    builder.Append("Skill plan for ").Append(character.Name);
                }
                builder.Append(boldEnd);
                builder.AppendLine(lineFeed);
                builder.AppendLine(lineFeed);
            }

            // Scroll through entries
            int      index   = 0;
            DateTime endTime = DateTime.Now;

            foreach (PlanEntry entry in plan)
            {
                // Remapping point
                if (!settings.ShoppingList && entry.Remapping != null)
                {
                    builder.Append("***").Append(entry.Remapping.ToString()).Append("***");
                    builder.AppendLine(lineFeed);
                }

                // Skip is we're only build a shopping list
                bool shoppingListCandidate = !(entry.CharacterSkill.IsKnown || entry.Level != 1 || entry.CharacterSkill.IsOwned);
                if (settings.ShoppingList && !shoppingListCandidate)
                {
                    continue;
                }

                // Entry's index
                index++;
                if (settings.EntryNumber)
                {
                    builder.Append(index.ToString()).Append(". ");
                }

                // Name
                builder.Append(boldStart);

                if (settings.Markup == MarkupType.Html)
                {
                    builder.Append("<a href=\"\" onclick=\"CCPEVE.showInfo(").Append(entry.Skill.ID.ToString()).Append(")\">");
                }
                builder.Append(entry.Skill.Name);
                if (settings.Markup == MarkupType.Html)
                {
                    builder.Append("</a>");
                }

                if (!settings.ShoppingList)
                {
                    builder.Append(' ').Append(Skill.GetRomanForInt(entry.Level));
                }

                builder.Append(boldEnd);

                // Training time
                if (settings.EntryTrainingTimes || settings.EntryStartDate || settings.EntryFinishDate || (settings.EntryCost && shoppingListCandidate))
                {
                    builder.Append(" (");
                    bool needComma = false;

                    // Training time
                    if (settings.EntryTrainingTimes)
                    {
                        needComma = true;
                        builder.Append(Skill.TimeSpanToDescriptiveText(entry.TrainingTime, timeFormat));
                    }

                    // Training start date
                    if (settings.EntryStartDate)
                    {
                        if (needComma)
                        {
                            builder.Append("; ");
                        }
                        needComma = true;

                        builder.Append("Start: ").Append(entry.StartTime.ToString());
                    }

                    // Training end date
                    if (settings.EntryFinishDate)
                    {
                        if (needComma)
                        {
                            builder.Append("; ");
                        }
                        needComma = true;

                        builder.Append("Finish: ").Append(entry.EndTime.ToString());
                    }

                    // Skill cost
                    if (settings.EntryCost && shoppingListCandidate)
                    {
                        if (needComma)
                        {
                            builder.Append("; ");
                        }
                        needComma = true;

                        builder.Append(entry.Skill.FormattedCost + " ISK");
                    }

                    builder.Append(')');
                }
                builder.AppendLine(lineFeed);

                // End time
                endTime = entry.EndTime;
            }

            // Footer
            if (settings.FooterCount || settings.FooterTotalTime || settings.FooterDate || settings.FooterCost)
            {
                builder.AppendLine(lineFeed);
                bool needComma = false;

                // Skills count
                if (settings.FooterCount)
                {
                    builder.Append(boldStart).Append(index.ToString()).Append(boldEnd);
                    builder.Append((index == 1 ? " skill" : " skills"));
                    needComma = true;
                }

                // Plan's training duration
                if (settings.FooterTotalTime)
                {
                    if (needComma)
                    {
                        builder.Append("; ");
                    }
                    needComma = true;

                    builder.Append("Total time: ");
                    builder.Append(boldStart);
                    builder.Append(Skill.TimeSpanToDescriptiveText(plan.GetTotalTime(null, true), timeFormat));
                    builder.Append(boldEnd);
                }

                // End training date
                if (settings.FooterDate)
                {
                    if (needComma)
                    {
                        builder.Append("; ");
                    }
                    needComma = true;

                    builder.Append("Completion: ");
                    builder.Append(boldStart).Append(endTime.ToString()).Append(boldEnd);
                }

                // Total books cost
                if (settings.FooterCost)
                {
                    if (needComma)
                    {
                        builder.Append("; ");
                    }
                    needComma = true;

                    builder.Append("Cost: ");
                    builder.Append(boldStart);
                    builder.Append((plan.TotalBooksCost == 0 ? "0 ISK" : String.Format("{0:0,0,0} ISK", plan.TotalBooksCost)));
                    builder.Append(boldEnd);
                }

                // Warning about skill costs
                builder.AppendLine(lineFeed);
                if (settings.FooterCost || settings.EntryCost)
                {
                    builder.Append("N.B. Skill costs are based on CCP's database and are indicative only");
                    builder.AppendLine(lineFeed);
                }
            }

            // Returns the text representation.
            return(builder.ToString());
        }