add support for buying commodities

this now impacts influence since Update 10
This commit is contained in:
Florian Stinglmayr 2022-01-26 09:58:23 +01:00
parent afa4866dbe
commit d17137c123
6 changed files with 125 additions and 5 deletions

69
BGS/BuyCargo.cs Normal file
View File

@ -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<MarketBuyEntry>().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<MarketBuyEntry>().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();
}
/// <summary>
/// Selling resources to a market only helps the controlling faction
/// </summary>
public override bool OnlyControllingFaction => true;
}
}

View File

@ -221,6 +221,24 @@ namespace EliteBGS.BGS {
return builder.ToString();
}
private string BuildMarketBuy(Objective objective) {
BuyCargo[] buys = objective.LogEntries.OfType<BuyCargo>().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);

View File

@ -271,6 +271,24 @@ namespace EliteBGS.BGS {
return builder.ToString();
}
private string BuildMarketBuy(Objective objective) {
BuyCargo[] buys = objective.LogEntries.OfType<BuyCargo>().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);

View File

@ -61,7 +61,7 @@ namespace EliteBGS.BGS {
List<Entry> relevant = entries.Where(x => IsRelevant(x)).ToList();
Dictionary<int, MissionAcceptedEntry> acceptedMissions = new Dictionary<int, MissionAcceptedEntry>();
Dictionary<string, int> buyCost = new Dictionary<string, int>();
Dictionary<string, long> buyCost = new Dictionary<string, long>();
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) {

View File

@ -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() { }

View File

@ -87,6 +87,7 @@
<Compile Include="BGS\InfluenceSupport.cs" />
<Compile Include="BGS\MissionFailed.cs" />
<Compile Include="BGS\NonaDiscordLog.cs" />
<Compile Include="BGS\BuyCargo.cs" />
<Compile Include="BGS\SellCargo.cs" />
<Compile Include="BGS\SellMicroResources.cs" />
<Compile Include="BGS\FactionKillBonds.cs" />