-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathFrontierApiProfile.cs
More file actions
102 lines (86 loc) · 4.98 KB
/
FrontierApiProfile.cs
File metadata and controls
102 lines (86 loc) · 4.98 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
using Newtonsoft.Json.Linq;
using System;
namespace EddiDataDefinitions
{
/// <summary> Profile information returned by the companion app service.
/// To prevent accidentally passing incorrect information to EDDN, inputs should not include any information from EDDI data definitions. </summary>
public class FrontierApiProfile
{
/// <summary>The timestamp returned from the CAPI server</summary>
public DateTime timestamp { get; private set; }
/// <summary>The JSON object</summary>
public JObject json { get; private set; }
/// <summary>The commander</summary>
public FrontierApiCommander Cmdr { get; private set; }
/// <summary>The current starsystem</summary>
public string currentStarSystem { get; private set; }
/// <summary>The name of the last station the commander docked at</summary>
public string LastStationName { get; private set; }
/// <summary>The market id of the last station the commander docked at</summary>
public long? LastStationMarketID { get; private set; }
/// <summary>Whether this profile describes a docked commander</summary>
public bool docked { get; private set; }
/// <summary>Whether this profile describes an on-foot commander</summary>
public bool onFoot { get; set; }
/// <summary>Whether this profile describes a currently living commander</summary>
public bool alive { get; set; }
/// <summary>The contexts (i.e. "capabilities") associated with this profile </summary>
public FrontierApiContexts contexts { get; set; }
/// <summary>Create a profile given the results from a /profile call</summary>
public static FrontierApiProfile FromJson(JObject json)
{
var Profile = new FrontierApiProfile
{
json = json,
};
if (json?[nameof(timestamp)] != null)
{
Profile.timestamp = json[nameof(timestamp)].ToObject<DateTime?>() ?? DateTime.MinValue;
}
if (json?["commander"] != null)
{
var Commander = new FrontierApiCommander
{
// Caution: The "id" property here may not match the FID returned from the player journal
name = (string)json["commander"]["name"],
credits = (long)json["commander"]["credits"],
debt = (long)json["commander"]["debt"],
combatrating = CombatRating.FromRank((int?)json["commander"]["rank"]?["combat"] ?? 0),
traderating = TradeRating.FromRank((int?)json["commander"]["rank"]?["trade"] ?? 0),
explorationrating = ExplorationRating.FromRank((int?)json["commander"]["rank"]?["explore"] ?? 0),
cqcrating = CQCRating.FromRank((int?)json["commander"]["rank"]?["cqc"] ?? 0),
empirerating = EmpireRating.FromRank((int?)json["commander"]["rank"]?["empire"] ?? 0),
federationrating = FederationRating.FromRank((int?)json["commander"]["rank"]?["federation"] ?? 0),
mercenaryrating = MercenaryRating.FromRank((int?)json["commander"]["rank"]?["soldier"] ?? 0),
exobiologistrating = ExobiologistRating.FromRank((int?)json["commander"]["rank"]?["exobiologist"] ?? 0),
crimerating = (int?)json["commander"]["rank"]?["crime"] ?? 0,
servicerating = (int?)json["commander"]["rank"]?["service"] ?? 0,
powerrating = (int?)json["commander"]["rank"]?["power"] ?? 0,
squadronname = (string)json["squadron"]?["name"],
squadrontag = (string)json["squadron"]?["tag"]
};
Profile.Cmdr = Commander;
Profile.docked = (bool)json["commander"]["docked"];
Profile.onFoot = (bool)json["commander"]["onfoot"];
Profile.alive = (bool)json["commander"]["alive"];
if (json["commander"]["capabilities"] != null)
{
var contexts = new FrontierApiContexts
{
allowCobraMkIV = (bool?)json["commander"]["capabilities"]["AllowCobraMkIV"] ?? false,
hasHorizons = (bool?)json["commander"]["capabilities"]["Horizons"] ?? false,
hasOdyssey = (bool?)json["commander"]["capabilities"]["Odyssey"] ?? false
};
Profile.contexts = contexts;
}
Profile.currentStarSystem = json["lastSystem"] == null ? null : (string)json["lastSystem"]["name"];
if (json["lastStarport"] != null)
{
Profile.LastStationName = ((string)json["lastStarport"]?["name"])?.ReplaceEnd('+');
Profile.LastStationMarketID = (long?)json["lastStarport"]?["id"];
}
}
return Profile;
}
}
}