-
Notifications
You must be signed in to change notification settings - Fork 14
/
Manifest.cs
154 lines (132 loc) · 4.74 KB
/
Manifest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EliteDangerousTradingAssistant
{
public class Manifest
{
private List<Trade> trades;
private decimal capital;
private decimal cargoSlots;
private string limitingFactor;
public List<Trade> Trades
{
get { return trades; }
}
public decimal Capital
{
get { return capital; }
set { capital = value; }
}
public decimal CargoSlots
{
get { return cargoSlots; }
set { cargoSlots = value; }
}
public string LimitingFactor
{
get { return limitingFactor; }
}
public decimal Investment
{
get
{
decimal totalInvestment = 0;
foreach (Trade trade in trades)
totalInvestment += trade.UnitsBought * trade.Commodity.BuyPrice;
return totalInvestment;
}
}
public decimal Profit
{
get
{
decimal totalProfit = 0;
foreach (Trade trade in trades)
totalProfit += trade.TotalProfit;
return totalProfit;
}
}
public decimal ROI
{
get { return Investment > 0 ? Profit / Investment : 0; }
}
public DateTime OldestDate
{
get
{
DateTime oldest = DateTime.MaxValue;
foreach (Trade trade in trades)
if (trade.Commodity.LastUpdated < oldest)
oldest = trade.Commodity.LastUpdated;
return oldest;
}
}
public void AddTrade(Trade trade)
{
trades.Add(trade);
}
public Manifest()
{
trades = new List<Trade>();
}
public Manifest(Manifest copy)
{
trades = new List<Trade>();
foreach (Trade trade in copy.Trades)
this.trades.Add(new Trade(trade));
this.capital = copy.capital;
this.cargoSlots = copy.cargoSlots;
this.limitingFactor = copy.limitingFactor;
}
public void OptimizeManifest()
{
while (capital > 0 && cargoSlots > 0)
{
//Score all trades
foreach (Trade trade in trades)
trade.ScoreTrade(capital, cargoSlots);
//Remove trades with 0 score.
for (int x = 0; x < trades.Count; x++)
if (trades[x].Score <= 0 && trades[x].UnitsBought == 0)
{
trades.RemoveAt(x);
x--;
}
//Find trade with max score that has not already been used for purchase.
Trade maxScoreTrade = null;
foreach (Trade trade in trades)
if ((maxScoreTrade == null || trade.Score > maxScoreTrade.Score) && trade.UnitsBought == 0)
maxScoreTrade = trade;
//No valid trades exist to make more purchases. This manifest is done.
if (maxScoreTrade == null)
break;
//Purchase the commodity and update the available capital and cargo slots.
maxScoreTrade.UnitsBought = maxScoreTrade.AffordUnits(capital, cargoSlots);
capital = capital - (maxScoreTrade.UnitsBought * maxScoreTrade.Commodity.BuyPrice);
cargoSlots = cargoSlots - maxScoreTrade.UnitsBought;
}
for (int x = 0; x < trades.Count; x++)
if (trades[x].UnitsBought == 0)
{
trades.RemoveAt(x);
x--;
}
if (capital <= 0)
limitingFactor = "Capital. Try to earn or invest more capital for more lucrative results.";
else if (cargoSlots <= 0)
limitingFactor = "Cargo Hold. Try to expand the cargo hold or buy a larger ship for more lucrative results.";
else
limitingFactor = "Lack of Trades. Try expanding your known galaxy by adding more systems, stations, and commodities.";
}
public bool Equals(Manifest compareTo)
{
if (trades.Count != compareTo.trades.Count || capital != compareTo.Capital || cargoSlots != compareTo.cargoSlots || limitingFactor != compareTo.limitingFactor ||
Investment != compareTo.Investment || Profit != compareTo.Profit)
return false;
return true;
}
}
}