-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathCommodityMarketQuote.cs
More file actions
124 lines (103 loc) · 3.93 KB
/
CommodityMarketQuote.cs
File metadata and controls
124 lines (103 loc) · 3.93 KB
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
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace EddiDataDefinitions
{
[CanBeNull]
public class CommodityMarketQuote
{
// should ideally be readonly but we need to set it during JSON parsing
public CommodityDefinition definition { get; private set; }
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
if (definition == null)
{
string _name = null;
if (additionalJsonData != null)
{
if (additionalJsonData.TryGetValue("EDName", out var edName))
{
_name = (string)edName;
}
if (_name == null && (additionalJsonData?.ContainsKey("name") ?? false))
{
_name = (string)additionalJsonData?["name"];
}
}
if (_name != null)
{
definition = CommodityDefinition.FromNameOrEDName(_name);
}
}
additionalJsonData = null;
}
[JsonExtensionData]
private IDictionary<string, JToken> additionalJsonData;
public string invariantName
{
get => definition?.invariantName;
}
public string localizedName
{
get => definition?.localizedName;
}
[Utilities.PublicAPI, Obsolete("deprecated for UI usage but retained for JSON conversion from the cAPI")]
public string name
{
get => definition?.localizedName;
set
{
if (this.definition == null)
{
var newDef = CommodityDefinition.FromNameOrEDName(value);
this.definition = newDef;
}
}
}
// Per-station information (prices are usually integers but not always)
[Utilities.PublicAPI]
public decimal buyprice { get; set; }
[Utilities.PublicAPI]
public int stock { get; set; }
// StockBracket can contain the values 0, 1, 2, 3 or "" (yes, really) so we use an optional enum
public CommodityBracket? stockbracket { get; set; }
[Utilities.PublicAPI]
public decimal sellprice { get; set; }
[Utilities.PublicAPI]
public int demand { get; set; }
// DemandBracket can contain the values 0, 1, 2, 3 or "" (yes, really) so we use an optional enum
public CommodityBracket? demandbracket { get; set; }
public long? EliteID => definition?.EliteID;
[Utilities.PublicAPI, Obsolete("Please use localizedName or InvariantName")]
public string category => definition?.Category.localizedName;
// Update the definition with the new galactic average price whenever this is set.
// Fleet carriers return zero and do not display the true average price. We must disregard that information so preserve the true average price.
// The average pricing data is the only data which may reference our internal definition, and even then only to obtain an average price.
[Utilities.PublicAPI]
public decimal avgprice
{
get => definition?.avgprice ?? 0;
set
{
if (definition is null)
{
return;
}
definition.avgprice = value;
}
}
[Utilities.PublicAPI]
public bool rare => definition?.rare ?? false;
public HashSet<string> StatusFlags { get; set; }
[JsonConstructor]
public CommodityMarketQuote(CommodityDefinition definition)
{
if (definition is null) { return; }
this.definition = definition;
}
}
}