diff --git a/BGS/BuyCargo.cs b/BGS/BuyCargo.cs new file mode 100644 index 0000000..c78bb1e --- /dev/null +++ b/BGS/BuyCargo.cs @@ -0,0 +1,69 @@ +using System.Text; +using System.Linq; +using EDJournal; + +namespace EliteBGS.BGS { + public class BuyCargo : LogEntry { + public BuyCargo() { } + + public BuyCargo(MarketBuyEntry e) { + Entries.Add(e); + } + + public string Cargo { + get { + string cargo; + var sell = Entries.OfType().First(); + + if (!string.IsNullOrEmpty(sell.TypeLocalised)) { + cargo = sell.TypeLocalised; + } else { + cargo = sell.Type; + if (cargo.Length >= 2) { + cargo = cargo[0].ToString().ToUpper() + cargo.Substring(1); + } + } + + return cargo; + } + } + + public long Amount { + get { return Entries.OfType().Sum(x => x.Count); } + } + + public override int CompareTo(LogEntry other) { + if (other == null || other.GetType() != typeof(BuyCargo)) { + return -1; + } + + BuyCargo buycargo = other as BuyCargo; + if (buycargo.Cargo == Cargo && + buycargo.System == System && buycargo.Faction == Faction) { + return 0; + } + + return -1; + } + + public override string ToString() { + StringBuilder builder = new StringBuilder(); + + if (Entries.Count <= 0) { + return builder.ToString(); + } + + builder.AppendFormat("Bought {0} {1} at the Commodity Market", + Amount, + Cargo + ); + + return builder.ToString().Trim(); + } + + /// + /// Selling resources to a market only helps the controlling faction + /// + public override bool OnlyControllingFaction => true; + } +} diff --git a/BGS/GenericDiscordLog.cs b/BGS/GenericDiscordLog.cs index 96e265a..0d06747 100644 --- a/BGS/GenericDiscordLog.cs +++ b/BGS/GenericDiscordLog.cs @@ -221,6 +221,24 @@ namespace EliteBGS.BGS { return builder.ToString(); } + private string BuildMarketBuy(Objective objective) { + BuyCargo[] buys = objective.LogEntries.OfType().ToArray(); + StringBuilder builder = new StringBuilder(); + + if (buys.Length <= 0) { + return ""; + } + + foreach (BuyCargo buy in buys) { + builder.Append(buy.ToString()); + builder.Append("\n"); + } + + builder.Append("\n"); + + return builder.ToString(); + } + public string GenerateDiscordLog(Report report) { StringBuilder log = new StringBuilder(); @@ -265,6 +283,9 @@ namespace EliteBGS.BGS { var micro = BuildMicroResourcesSold(objective); entries.Append(micro); + var buy = BuildMarketBuy(objective); + entries.Append(buy); + var sold = BuildCargoSold(objective); entries.Append(sold); diff --git a/BGS/NonaDiscordLog.cs b/BGS/NonaDiscordLog.cs index 2a86d93..5fbd3d4 100644 --- a/BGS/NonaDiscordLog.cs +++ b/BGS/NonaDiscordLog.cs @@ -271,6 +271,24 @@ namespace EliteBGS.BGS { return builder.ToString(); } + private string BuildMarketBuy(Objective objective) { + BuyCargo[] buys = objective.LogEntries.OfType().ToArray(); + StringBuilder builder = new StringBuilder(); + + if (buys.Length <= 0) { + return ""; + } + + foreach (BuyCargo buy in buys) { + builder.Append(buy.ToString()); + builder.Append("\n"); + } + + builder.Append("\n"); + + return builder.ToString(); + } + public string GenerateDiscordLog(Report report) { StringBuilder log = new StringBuilder(); @@ -314,6 +332,9 @@ namespace EliteBGS.BGS { var micro = BuildMicroResourcesSold(objective); entries.Append(micro); + var buy = BuildMarketBuy(objective); + entries.Append(buy); + var sold = BuildCargoSold(objective); entries.Append(sold); diff --git a/BGS/Report.cs b/BGS/Report.cs index 6a09a97..e0b8aaa 100644 --- a/BGS/Report.cs +++ b/BGS/Report.cs @@ -61,7 +61,7 @@ namespace EliteBGS.BGS { List relevant = entries.Where(x => IsRelevant(x)).ToList(); Dictionary acceptedMissions = new Dictionary(); - Dictionary buyCost = new Dictionary(); + Dictionary buyCost = new Dictionary(); string current_system = null; string current_station = null; @@ -206,15 +206,23 @@ namespace EliteBGS.BGS { continue; } buyCost[buy.Type] = buy.BuyPrice; + + results.Add(new BuyCargo(buy) { + Faction = controlling_faction, + Station = current_station, + System = current_system, + }); + + collate = true; } else if (e.Is(Events.MarketSell)) { MarketSellEntry sell = e as MarketSellEntry; - int profit = 0; + long profit = 0; if (!buyCost.ContainsKey(sell.Type)) { OnLog?.Invoke("Could not find buy order for the given commodity. Please adjust profit manually."); } else { - int avg = buyCost[sell.Type]; - profit = sell.TotalSale - (avg * sell.Count); + long avg = buyCost[sell.Type]; + profit = (long)sell.TotalSale - (avg * sell.Count); } results.Add(new SellCargo(e as MarketSellEntry) { diff --git a/BGS/SellCargo.cs b/BGS/SellCargo.cs index 45fb841..7b4038f 100644 --- a/BGS/SellCargo.cs +++ b/BGS/SellCargo.cs @@ -4,7 +4,7 @@ using EDJournal; namespace EliteBGS.BGS { public class SellCargo : LogEntry { - public int Profit { get; set; } + public long Profit { get; set; } public SellCargo() { } diff --git a/EliteBGS.csproj b/EliteBGS.csproj index 211a1f5..fdc87ce 100644 --- a/EliteBGS.csproj +++ b/EliteBGS.csproj @@ -87,6 +87,7 @@ +