implement a summary line
For Pony's bot, implement a summary line that just shows the highlights of the log
This commit is contained in:
		
							parent
							
								
									3c1abe5e8c
								
							
						
					
					
						commit
						5120c7991f
					
				| @ -34,4 +34,16 @@ public class Credits { | ||||
| 
 | ||||
|         return string.Format("{0} CR", amount.ToString("N", format)); | ||||
|     } | ||||
| 
 | ||||
|     public static string FormatMillions(long amount) { | ||||
|         double millions = (amount / 1000000.0); | ||||
| 
 | ||||
|         if (amount >= 100000) { | ||||
|             return string.Format("{0:0.0}M", millions); | ||||
|         } else if (amount >= 10000) { | ||||
|             return string.Format("{0:0.00}M", millions); | ||||
|         } | ||||
| 
 | ||||
|         return ""; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -24,6 +24,31 @@ public class DiscordLogGenerator { | ||||
|         new SearchAndRescueFormat(), | ||||
|     }; | ||||
| 
 | ||||
|     protected virtual string GenerateSummary(Objective objective) { | ||||
|         StringBuilder sb = new StringBuilder(); | ||||
| 
 | ||||
|         foreach (var formatter in formatters) { | ||||
|             string summary = ""; | ||||
| 
 | ||||
|             try { | ||||
|                 summary = formatter.GenerateSummary(objective); | ||||
|             } catch (NotImplementedException) { | ||||
|             } | ||||
| 
 | ||||
|             if (string.IsNullOrEmpty(summary)) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             if (sb.Length > 0) { | ||||
|                 sb.Append(", "); | ||||
|             } | ||||
| 
 | ||||
|             sb.Append(summary); | ||||
|         } | ||||
| 
 | ||||
|         return sb.ToString(); | ||||
|     } | ||||
| 
 | ||||
|     protected virtual string GenerateHeader() { | ||||
|         return ""; | ||||
|     } | ||||
| @ -50,8 +75,13 @@ public class DiscordLogGenerator { | ||||
|                 .Count() | ||||
|                 ; | ||||
| 
 | ||||
|         string summary = GenerateSummary(objective); | ||||
| 
 | ||||
|         log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy")); | ||||
|         log.AppendFormat("**Target:** {0}\n", location); | ||||
|         if (!string.IsNullOrEmpty(summary)) { | ||||
|             log.AppendFormat("**Summary**: {0}\n", summary); | ||||
|         } | ||||
|         if (legacycount > 0) { | ||||
|             log.AppendFormat("**Warning:** Some actions were performed on ED Legacy\n"); | ||||
|         } | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Windows.Documents; | ||||
| using EDPlayerJournal; | ||||
| using EDPlayerJournal.BGS; | ||||
| 
 | ||||
| @ -53,4 +54,15 @@ public class CargoSoldFormatter : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         SellCargo[] sold = objective.EnabledOfType<SellCargo>().ToArray(); | ||||
|         long totalProfit = sold.Sum(x => x.Profit); | ||||
| 
 | ||||
|         if (totalProfit >= 100000) { | ||||
|             return string.Format("Trade: {0}", Credits.FormatMillions(totalProfit)); | ||||
|         } | ||||
| 
 | ||||
|         return ""; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -19,4 +19,15 @@ public class CartographicsFormat : LogFormatter { | ||||
|                              pages, Credits.FormatCredits(sum) | ||||
|                              ); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         Cartographics[] sold = objective.EnabledOfType<Cartographics>().ToArray(); | ||||
|         long totalProfit = sold.Sum(x => x.TotalSum); | ||||
| 
 | ||||
|         if (totalProfit >= 100000) { | ||||
|             return string.Format("Explo: {0}", Credits.FormatMillions(totalProfit)); | ||||
|         } | ||||
| 
 | ||||
|         return ""; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -43,4 +43,48 @@ class CombatZoneFormat : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString().Trim(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         var logs = objective | ||||
|             .EnabledOfType<CombatZone>() | ||||
|             .GroupBy(x => new { x.Type, x.Grade }) | ||||
|             .ToDictionary(x => x.Key, x => x.ToList()) | ||||
|             ; | ||||
|         StringBuilder builder = new StringBuilder(); | ||||
| 
 | ||||
|         if (logs == null || logs.Count() <= 0) { | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         foreach (var log in logs) { | ||||
|             int optionals = log.Value | ||||
|                                 .Sum(x => x.OptionalObjectivesCompleted) | ||||
|                                 ; | ||||
|             if (builder.Length > 0) { | ||||
|                 builder.Append(", "); | ||||
|             } | ||||
|             if (!string.IsNullOrEmpty(log.Key.Grade)) { | ||||
|                 string grade = log.Key.Grade.Substring(0, 1); | ||||
|                 if (log.Key.Grade == CombatZones.DifficultyVeryHigh) { | ||||
|                     grade = "VH"; | ||||
|                 } | ||||
|                 builder.AppendFormat("CZ: {0}x{1}{2}", | ||||
|                     log.Value.Count, | ||||
|                     log.Key.Grade.Substring(0, 1), | ||||
|                     log.Key.Type.Substring(0, 1) | ||||
|                     ); | ||||
|             } else { | ||||
|                 builder.AppendFormat("CZ: {0}x?{1}", | ||||
|                     log.Value.Count, | ||||
|                     log.Key.Type.Substring(0, 1) | ||||
|                     ); | ||||
|             } | ||||
| 
 | ||||
|             if (optionals > 0) { | ||||
|                 builder.AppendFormat("+ {0} OPTS", optionals); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return builder.ToString().Trim(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using EDPlayerJournal.Entries; | ||||
| using EDPlayerJournal.BGS; | ||||
| 
 | ||||
| namespace EliteBGS.LogGenerator; | ||||
| @ -31,4 +30,30 @@ public class FailedMissionFormat : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString().Trim(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         var missions = objective.EnabledOfType<MissionFailed>(); | ||||
| 
 | ||||
|         if (missions.Count <= 0) { | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         StringBuilder sb = new(); | ||||
| 
 | ||||
|         int onFootFails = missions.Where(x => x.Mission.IsOnFoot).Count(); | ||||
|         int shipFails = missions.Where(x => !x.Mission.IsOnFoot).Count(); | ||||
| 
 | ||||
|         if (onFootFails > 0) { | ||||
|             sb.AppendFormat("Fails: {0} Ground", onFootFails); | ||||
|         } | ||||
| 
 | ||||
|         if (shipFails > 0) { | ||||
|             if (sb.Length> 0) { | ||||
|                 sb.Append(", "); | ||||
|             } | ||||
|             sb.AppendFormat("{0} Ship", shipFails); | ||||
|         } | ||||
| 
 | ||||
|         return sb.ToString(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -25,4 +25,8 @@ public class GenericFormat<Type> : LogFormatter where Type : Transaction { | ||||
| 
 | ||||
|         return builder.ToString(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         throw new System.NotImplementedException(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -2,4 +2,5 @@ | ||||
| 
 | ||||
| public interface LogFormatter { | ||||
|     string GenerateLog(Objective objective); | ||||
|     string GenerateSummary(Objective objective); | ||||
| } | ||||
|  | ||||
| @ -16,4 +16,8 @@ public class MicroResourcesFormat : LogFormatter { | ||||
|         return string.Format("Sold {0} worth of Micro Resources\n", | ||||
|             Credits.FormatCredits(sum)); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         return ""; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -76,4 +76,21 @@ public class MissionFormat : LogFormatter { | ||||
| 
 | ||||
|         return output.ToString().Trim(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         long influence = objective | ||||
|             .EnabledOfType<MissionCompleted>() | ||||
|             .Sum(x => x.Influence.Length) | ||||
|             ; | ||||
|         long support = objective | ||||
|             .EnabledOfType<InfluenceSupport>() | ||||
|             .Sum(x => x.Influence.Length) | ||||
|             ; | ||||
| 
 | ||||
|         if (influence + support <= 0) { | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         return string.Format("INF: {0}", influence + support); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -45,4 +45,18 @@ public class MurderFormat : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         long murders = objective | ||||
|             .EnabledOfType<FoulMurder>() | ||||
|             .Where(x => x.CrimeType == CrimeTypes.Murder || x.CrimeType == CrimeTypes.OnFootMurder) | ||||
|             .Count() | ||||
|             ; | ||||
| 
 | ||||
|         if (murders <= 0) { | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         return string.Format("Kills: {0}", murders); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -29,4 +29,30 @@ public class ThargoidFormatter : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         List<ThargoidKill> kills = objective.EnabledOfType<ThargoidKill>().ToList(); | ||||
| 
 | ||||
|         if (kills.Count == 0 ) { | ||||
|             return ""; | ||||
|         } | ||||
| 
 | ||||
|         int scouts = kills.Where(x => x.ThargoidType == ThargoidVessel.Scout).Count(); | ||||
|         int interceptors = kills.Count - scouts; | ||||
| 
 | ||||
|         StringBuilder builder = new StringBuilder(); | ||||
| 
 | ||||
|         builder.Append("AX: "); | ||||
|         if (interceptors > 0) { | ||||
|             builder.AppendFormat("{0} INT", interceptors); | ||||
|         } | ||||
|         if (scouts > 0) { | ||||
|             if (builder.Length> 0) { | ||||
|                 builder.Append(", "); | ||||
|             } | ||||
|             builder.AppendFormat("{0} SCT", scouts); | ||||
|         } | ||||
| 
 | ||||
|         return builder.ToString(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -25,4 +25,32 @@ public class VoucherFormat : LogFormatter { | ||||
| 
 | ||||
|         return builder.ToString().Trim(); | ||||
|     } | ||||
| 
 | ||||
|     public string GenerateSummary(Objective objective) { | ||||
|         long bounties = objective | ||||
|             .EnabledOfType<Vouchers>() | ||||
|             .Where(x => x.Type == "Bounty") | ||||
|             .Sum(x => x.TotalSum) | ||||
|             ; | ||||
|         long bonds = objective | ||||
|             .EnabledOfType<Vouchers>() | ||||
|             .Where(x => x.Type == "Combat Bond") | ||||
|             .Sum(x => x.TotalSum) | ||||
|             ; | ||||
| 
 | ||||
|         StringBuilder sb = new(); | ||||
| 
 | ||||
|         if (bounties > 0) { | ||||
|             sb.AppendFormat("Bounties: {0}", Credits.FormatMillions(bounties)); | ||||
|         } | ||||
| 
 | ||||
|         if (bonds > 0) { | ||||
|             if (sb.Length > 0) { | ||||
|                 sb.Append(", "); | ||||
|             } | ||||
|             sb.AppendFormat("Bonds: {0}", Credits.FormatMillions(bonds)); | ||||
|         } | ||||
| 
 | ||||
|         return sb.ToString(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -12,9 +12,7 @@ using EDPlayerJournal.Entries; | ||||
| using EliteBGS.BGS; | ||||
| using EliteBGS.Util; | ||||
| using System.Globalization; | ||||
| using System.Windows.Forms; | ||||
| using System.Windows.Controls.Primitives; | ||||
| using ControlzEx.Theming; | ||||
| using MahApps.Metro.Controls; | ||||
| using ControlzEx.Theming; | ||||
| using System.Windows.Media; | ||||
|  | ||||
| @ -51,7 +51,12 @@ public class NonaDiscordLog : DiscordLogGenerator { | ||||
|                     .Count() | ||||
|                     ; | ||||
| 
 | ||||
|         string summary = GenerateSummary(objective); | ||||
| 
 | ||||
|         log.AppendFormat(":globe_with_meridians: `Target:` {0}\n", location); | ||||
|         if (!string.IsNullOrEmpty(summary)) { | ||||
|             log.AppendFormat(":scroll: `Summary:` {0}\n", summary); | ||||
|         } | ||||
|         if (legacycount > 0) { | ||||
|             log.Append(":rotating_light: `Warning`: Some actions were done in E:D Legacy\n"); | ||||
|         } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user