-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEveOrder.cs
161 lines (146 loc) · 4.67 KB
/
EveOrder.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
155
156
157
158
159
160
161
/*
* ---------------------------------------
* User: duketwo
* Date: 16.12.2013
* Time: 00:16
*
* ---------------------------------------
*/
using System;
using System.Collections.Generic;
namespace EveModel
{
/// <summary>
/// Description of EveOrder.
/// </summary>
///
public enum OrderRange
{
Station,
SolarSystem,
Constellation,
Region
}
public class EveOrder : EveObject
{
//public long? BookmarkId { get; private set; }
public int? Jumps { get; set; }
public int? SolarSystemId { get; set; }
public int? RegionId { get; set; }
public int? StationId { get; set; }
public int? Duration { get; set; }
public DateTime IssuedOn { get; set; }
public bool IsBid { get; set; }
public int? MinimumVolume { get; set; }
public int? VolumeEntered { get; set; }
public long? OrderId { get; set; }
public OrderRange Range { get; set; }
public int? RangeAbsolute { get; set; }
public int? TypeId { get; set; }
public int? VolumeRemaining { get; set; }
public double? Price { get; set; }
public EveOrder(IntPtr ptr, Boolean isMyOrder = false) : base()
{
PointerToObject = ptr;
if(this.IsValid) {
this.OrderId = -1L;
this.OrderId = this["orderID"].GetValueAs<long>();
this.VolumeEntered = this["volEntered"].GetValueAs<int>();
this.MinimumVolume = this["minVolume"].GetValueAs<int>(); // minVolume
this.IsBid = this["bid"].GetValueAs<bool>(); // bid
try { this.IssuedOn = new DateTime(this["issueDate"].GetValueAs<long>()).AddYears(1600); } catch (Exception) {} // issued
this.Duration = this["duration"].GetValueAs<int>(); // duration
this.StationId = this["stationID"].GetValueAs<int>(); // stationID
this.RegionId = this["regionID"].GetValueAs<int>(); // regionID
this.SolarSystemId = this["solarSystemID"].GetValueAs<int>(); // solarSystemID
if(!isMyOrder) this.Jumps = this["jumps"].GetValueAs<int>();// jumps
this.Price = this["price"].GetValueAs<double>(); // price
this.VolumeRemaining = this["volRemaining"].GetValueAs<int>(); // volRemaining
this.TypeId = this["typeID"].GetValueAs<int>(); // typeID
int tmpRange = this["range"].GetValueAs<int>();
if(tmpRange == 0) {
this.Range = OrderRange.SolarSystem;
} else {
if(tmpRange == 4) {
this.Range = OrderRange.Constellation;
} else {
if(tmpRange == 32767) {
this.Range = OrderRange.Region;
} else {
if(tmpRange == -1) {
this.Range = OrderRange.Station;
} else {
this.RangeAbsolute = tmpRange;
}
}
}
}
} else {
Frame.Log("eveorder not valid");
}
}
private Dictionary<long?,DateTime> _lastOrderIdModified;
private Dictionary<long?,DateTime> LastOrderIdModified {
get{
if(_lastOrderIdModified == null)
_lastOrderIdModified = new Dictionary<long?, DateTime>();
return _lastOrderIdModified;
}
set {
_lastOrderIdModified = value;
}
}
public bool CancelOrder(){
bool result= false;
if (this.OrderId == -1L || !this.IsValid)
{
Frame.Log("Trying to cancel an invalid order");
result = false;
}
else
{
if(CanBeModified) {
LastOrderIdModified.Remove(this.OrderId);
result = Frame.Client.MarketQuote.CallMethod("CancelOrder", new object[] { this.OrderId,this.RegionId }, true).GetValueAs<bool>();
IssuedOn = DateTime.UtcNow;
} else {
Frame.Log("[CancelOrder] Can't be modified < 5 minutes");
}
}
return result;
}
public bool CanBeModified{
get {
if(!LastOrderIdModified.ContainsKey(this.OrderId)){
return DateTime.UtcNow >= (this.IssuedOn.AddMinutes(5));
}
else {
return DateTime.UtcNow >= (this.IssuedOn.AddMinutes(5)) &&(LastOrderIdModified[this.OrderId].AddMinutes(5) < DateTime.UtcNow);
}
}
}
public bool ModifyOrder(double? newPrice)
{
bool result= false;
if (this.OrderId == -1L || !this.IsValid || newPrice == null || this.StationId != Frame.Client.Session.StationId){
Frame.Log("[ModifyOrder] Trying to modify an invalid order || newPrice == null || this.StationId != Frame.Client.Session.StationId");
result = false;
}
else
{
if(CanBeModified) {
LastOrderIdModified[this.OrderId] = DateTime.UtcNow;
result = Frame.Client.MarketQuote.CallMethod("ModifyOrder", new object[] { this,newPrice }, true).GetValueAs<bool>();
IssuedOn = DateTime.UtcNow;
} else {
Frame.Log("[ModifyOrder] can't be modified < 5 minutes");
}
}
return result;
}
public bool Buy(int quantity)
{
return Frame.Client.MarketQuote.CallMethod("BuyStuff", new object[]{this.StationId,this.TypeId,this.Price,quantity,(int)-1},true).GetValueAs<bool>();
}
}
}