detect trade profit, and allow adjusting it
This commit is contained in:
@@ -7,6 +7,8 @@ namespace EliteBGS.BGS {
|
||||
public class LogEntry : IComparable<LogEntry> {
|
||||
private List<Entry> entries = new List<Entry>();
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Controlling faction of the station this entry was made/turned into.
|
||||
/// </summary>
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace EliteBGS.BGS {
|
||||
e.Is(Events.SellMicroResources) ||
|
||||
e.Is(Events.RedeemVoucher) ||
|
||||
e.Is(Events.FactionKillBond) ||
|
||||
e.Is(Events.MarketBuy) ||
|
||||
e.Is(Events.MarketSell)
|
||||
;
|
||||
}
|
||||
@@ -55,6 +56,8 @@ namespace EliteBGS.BGS {
|
||||
|
||||
Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
|
||||
|
||||
Dictionary<string, int> buyCost = new Dictionary<string, int>();
|
||||
|
||||
string current_system = null;
|
||||
string current_station = null;
|
||||
string controlling_faction = null;
|
||||
@@ -91,9 +94,9 @@ namespace EliteBGS.BGS {
|
||||
}
|
||||
} else if (e.Is(Events.MissionCompleted)) {
|
||||
var completed = e as MissionCompletedEntry;
|
||||
entry = new MissionCompleted(completed) {
|
||||
System = current_system,
|
||||
Station = current_station
|
||||
entry = new MissionCompleted(completed) {
|
||||
System = current_system,
|
||||
Station = current_station
|
||||
};
|
||||
if (completed.HumanReadableNameWasGenerated) {
|
||||
/* If the human readable name was generated, we send a log message. Because the
|
||||
@@ -149,11 +152,28 @@ namespace EliteBGS.BGS {
|
||||
};
|
||||
|
||||
entry.Entries.Add(e);
|
||||
} else if (e.Is(Events.MarketBuy)) {
|
||||
MarketBuyEntry buy = e as MarketBuyEntry;
|
||||
if (string.IsNullOrEmpty(buy.Type) || buy.BuyPrice == 0) {
|
||||
continue;
|
||||
}
|
||||
buyCost[buy.Type] = buy.BuyPrice;
|
||||
} else if (e.Is(Events.MarketSell)) {
|
||||
MarketSellEntry sell = e as MarketSellEntry;
|
||||
int 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);
|
||||
}
|
||||
|
||||
entry = new SellCargo() {
|
||||
Faction = controlling_faction,
|
||||
Station = current_station,
|
||||
System = current_system
|
||||
System = current_system,
|
||||
Profit = profit
|
||||
};
|
||||
|
||||
entry.Entries.Add(e);
|
||||
|
||||
@@ -4,6 +4,7 @@ using EDJournal;
|
||||
|
||||
namespace EliteBGS.BGS {
|
||||
public class SellCargo : LogEntry {
|
||||
public int Profit { get; set; }
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var sold = Entries.OfType<MarketSellEntry>().ToArray();
|
||||
@@ -13,11 +14,18 @@ namespace EliteBGS.BGS {
|
||||
}
|
||||
|
||||
foreach (MarketSellEntry sell in sold) {
|
||||
builder.AppendFormat("Sold {0} {1} to the {2}\n",
|
||||
builder.AppendFormat("Sold {0} {1} to the {2}",
|
||||
sell.Count,
|
||||
sell.Type,
|
||||
sell.BlackMarket ? "Black Market" : "Commodity Market"
|
||||
);
|
||||
|
||||
if (Profit != 0) {
|
||||
builder.AppendFormat(" ({0} {1})",
|
||||
Credits.FormatCredits(Profit),
|
||||
Profit < 0 ? "loss" : "profit"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString().Trim();
|
||||
|
||||
Reference in New Issue
Block a user