This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource parser.linq
459 lines (434 loc) · 18.9 KB
/
resource parser.linq
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<Query Kind="Program">
<NuGetReference>Humanizer</NuGetReference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Humanizer</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
</Query>
void Main()
{
var json = File.ReadAllText(@"D:\Code\LinqPad Queries\Gaming\AF\res\23_cache_json$f0170aad834e758c8de1f3455e70ad5c919569007.bin");
var data = JObject.Parse(json);
data.ToObject().Dump("RawData", 0);
// JsonHelper.GetCommonClassDefinition(data["MissionTypes"])
// .Dump(0);
// data["MissionTypes"].ToDictionary()
// .Values
// //.SelectMany(x => x["eliteTechs"] as JArray)
// .Cast<JObject>().SelectMany(x => x.Properties())
// .Select(x => new { x.Name, Value = JsonConvert.SerializeObject(x.Value) })
// .Distinct()
// .ToLookup(x => x.Name, x => (string)x.Value)
// .ToDictionary(x => x.Key, x => x.AsEnumerable())
// .Dump(0);
var resources = JsonConvert.DeserializeObject<Resources>(json).Dump("Parsed Object", 0);
ResourcesHelper.DebugTimedMissions(resources);
}
// Define other methods and classes here
public class Resources
{
public Dictionary<string, ImageData> Images { get; set; }
//public Dictionary<string, EffectData> Effects { get; set; }
public Dictionary<string, DropData> Drops { get; set; }
public Dictionary<string, EngineData> Engines { get; set; }
public Dictionary<string, WeaponData> Weapons { get; set; }
public Dictionary<string, ShipData> Ships { get; set; }
public Dictionary<string, CommodityData> Commodities { get; set; }
[JsonProperty(PropertyName = "MissionTypes")]
public Dictionary<string, MissionData> Missions { get; set; }
public Dictionary<string, DailyMissionData> DailyMissions { get; set; }
public abstract class BigDBObject
{
public string Key { get; set; }
public string Table { get; set; }
}
public class ImageData
{
public string Key { get; set; }
public string Table { get; set; }
public string FileName { get; set; }
public string TextureName { get; set; }
public double Scale { get; set; }
public bool Mirror { get; set; }
public ImageType Type { get; set; }
public bool Animate { get; set; }
public bool AnimateOnStart { get; set; }
public int AnimationDelay { get; set; }
public int AnimationCellHeight { get; set; }
public int AnimatonStrips { get; set; }
public int AnimationCells { get; set; }
public int AnimationCellWidth { get; set; }
public int Volume { get; set; }
public int AnimationStrips { get; set; }
public enum ImageType { Ships, TechIcons, Projectiles, Music, Drops, Commodities, Spawners, Artifacts, Specials, Bodies, Boss, Crew, Effects, SolarSystems, SolarSystem }
}
public class DropData
{
public string Key { get; set; }
public string Name { get; set; }
public string Table { get; set; } // "Drops"
public string Type { get; set; } // {drop, mission, explore}
public bool Crate { get; set; }
public double Chance { get; set; }
public List<DropTableItem> DropItems { get; set; }
public double ArtifactChance { get; set; }
public int ArtifactAmount { get; set; }
public int ArtifactLevel { get; set; }
public int FluxMin { get; set; }
public int FluxMax { get; set; }
public int XpMin { get; set; }
public int XpMax { get; set; }
public int Reputation { get; set; }
public class DropTableItem
{
public string Table { get; set; }
public string Item { get; set; }
public double Chance { get; set; }
public int Min { get; set; }
public int Max { get; set; }
}
}
public class CommodityData
{
public string Key { get; set; }
public string Table { get; set; }
public string Name { get; set; }
public CommodityType Type { get; set; }
public int Size { get; set; }
public int SellValue { get; set; }
public string Bitmap { get; set; }
public List<RecycleItemData> RecycleItems { get; set; }
public enum CommodityType { SpaceJunk, Mineral }
public class RecycleItemData
{
public string Item { get; set; }
public int Min { get; set; }
public int Max { get; set; }
public double Chance { get; set; }
}
}
public class EngineData
{
public string Key { get; set; }
public string Table { get; set; }
public string Name { get; set; }
public int Speed { get; set; }
public double Acceleration { get; set; }
public double RotationSpeed { get; set; }
// public string RibbonTexture { get; set; }
// public int IdleThrustFinishColor { get; set; }
// public int RibbonThickness { get; set; }
// public int IdleThrustStartColor { get; set; }
// public bool UseEffects { get; set; }
// public bool ChangeIdleThrustColors { get; set; }
// public int ThrustStartColor { get; set; }
// public bool ChangeThrustColors { get; set; }
// public double RibbonAlpha { get; set; }
// public bool RibbonTrail { get; set; }
// public bool Dual { get; set; }
// public string IdleEffect { get; set; }
// public int RibbonColor { get; set; }
// public int ThrustFinishColor { get; set; }
// public string Effect { get; set; }
// public double RibbonSpeed { get; set; }
// public string Sound { get; set; }
// public int DualDistance { get; set; }
}
public class WeaponData
{
public string Key { get; set; }
public string Table { get; set; }
public string Name { get; set; }
public string TechIcon { get; set; }
public string Description { get; set; }
public int DescriptionRefire { get; set; }
public int DescriptionDifficulty { get; set; }
public int DescriptionHeat { get; set; }
public int DescriptionDmg { get; set; }
public int DescriptionRange { get; set; }
public string Projectile { get; set; }
public int Speed { get; set; }
//public List<object> EliteTechs { get; set; } TODO
public bool IsMissileWeapon { get; set; }
public bool MultiSideFire { get; set; }
public int Dot { get; set; }
public WeaponDebuffType DebuffType { get; set; }
public int DotDuration { get; set; }
public string Sound { get; set; }
//public ??? TechLevels { get; set; } TODO
public bool HasTechTree { get; set; }
public WeaponDamageType DamageType { get; set; }
public WeaponType Type { get; set; }
public int MaxProjectiles { get; set; }
public int MultiOffset { get; set; }
public int NumberOfHits { get; set; }
public bool MultiSpreadStart { get; set; }
public int MultiNrOfP { get; set; }
public int Radius { get; set; }
public int HealthVamp { get; set; }
public bool RandomAngle { get; set; }
public int PositionXVariance { get; set; }
public int EnergyDepleteTime { get; set; }
public bool TriggerMeleeAnimation { get; set; }
public bool HasSpecialFunction { get; set; }
public int TwinOffset { get; set; }
public int PvpMod { get; set; }
public WeaponDamageType DotDamageType { get; set; }
public int Dmg { get; set; }
public double AngleVariance { get; set; }
public int PositionOffset { get; set; }
public string DotEffect { get; set; }
public bool HasChargeUp { get; set; }
public bool Simultaneous { get; set; }
public int PvpModDot { get; set; }
public int BurstDelay { get; set; }
public double AimArc { get; set; }
public int Range { get; set; }
public int Ttl { get; set; }
public bool UseShipSystem { get; set; }
public int HeatCost { get; set; }
public double Acceleration { get; set; }
public bool Global { get; set; }
public double Friction { get; set; }
public double RotationSpeed { get; set; }
public int ShieldVamp { get; set; }
public bool NoRandomSpeed { get; set; }
public int MultiAngleOffset { get; set; }
public string FireSound { get; set; }
public int PositionVariance { get; set; }
public int Burst { get; set; }
public int ReloadTime { get; set; }
public bool Twin { get; set; }
public bool FireBackwards { get; set; }
public int MaxChargeDuration { get; set; }
public string FireEffect { get; set; }
public bool Cluster { get; set; }
public bool HasSpecialBonus { get; set; }
public string Enemy { get; set; }
public int MaxPets { get; set; }
public int EnemyHpBonus { get; set; }
public int ChargeUpBonusDmg { get; set; }
public int PositionOffsetY { get; set; }
public int ChargeUp { get; set; }
public int IncInterval { get; set; }
public bool Homing { get; set; }
public int Overheat { get; set; }
public string HitEffect { get; set; }
public int DmgInterval { get; set; }
public string HitSound { get; set; }
public int GlowColor { get; set; }
public int Beams { get; set; }
public int BeamColor { get; set; }
public double BeamThickness { get; set; }
public double BeamAmplitude { get; set; }
public double BeamAlpha { get; set; }
public double BeamNodes { get; set; }
public int NrTargets { get; set; }
public int IncOverheat { get; set; }
public bool Teleport { get; set; }
public int SpecialBonusPercentage { get; set; }
public string SpecialCondition { get; set; }
public enum WeaponType { Projectile, Blaster, SmartGun, PetSpawner, Beam, Teleport, Cloak }
public enum WeaponDebuffType { None = -1, DOT = 0, StackingDOT = 1, Bomb = 2, ReduceArmor = 3, Burn = 4, DisableRegen = 5, DisableHeal = 6, ReduceDamange = 7, ReduceKineticRes = 8, ReduceEnegyRes = 9, ReduceCorrosiveRes = 10 }
public enum WeaponDamageType { Kinetic, Energy, Corrosive, KineticEnergy, CorrosiveKinetic, Unknown, Heal, EnergyKinetic, AllThree, None, EnergyCorrosive }
}
public class ShipData
{
public string ExplosionSound { get; set; }
public string ExplosionEffect { get; set; }
public string Hp { get; set; }
public string CollisionRadius { get; set; }
public string Armor { get; set; }
public string Name { get; set; }
public string WeaponPosY { get; set; }
public string Key { get; set; }
public string EnginePosX { get; set; }
public string ShieldRegen { get; set; }
public string WeaponPosX { get; set; }
public string ShieldHp { get; set; }
public string Table { get; set; }
public string BlendModeAdd { get; set; }
public string Type { get; set; }
public string EnginePosY { get; set; }
public string Bitmap { get; set; }
public string UseBitmapTint { get; set; }
public string AnimationDelay { get; set; }
public string BitmapTint { get; set; }
public string Animation { get; set; }
public string AnimationCellWidth { get; set; }
public string AnimationCellHeight { get; set; }
public string AnimationCells { get; set; }
public string HueRotation { get; set; }
}
public class MissionData : BigDBObject
{
public string Title { get; set; }
public string Label { get; set; }
public string Description { get; set; }
public string Drop { get; set; }
public int Expires { get; set; }
public List<string> AddedBodies { get; set; }
public int MinLvl { get; set; }
public int MaxLvl { get; set; }
public MissionMajorType MajorType { get; set; }
public int Value { get; set; }
public bool Available { get; set; }
public MissionType Type { get; set; }
public string Item { get; set; }
public string NextMission { get; set; }
public string CompleteDescription { get; set; }
public List<string> AddedEnemies { get; set; }
public MissionSubtype Subtype { get; set; }
public bool MustBeInorder { get; set; }
public int NrAreas { get; set; }
public bool Proofread { get; set; }
public bool PoliceMission { get; set; }
public bool PirateMission { get; set; }
public string Solarsystem { get; set; }
public string Spawner { get; set; }
public string Bitmap { get; set; }
public List<object> AddedSystems { get; set; }
public int ReqLvl { get; set; }
public int TargetLvlReq { get; set; }
public bool TargetsNeutral { get; set; }
public bool TargetsPolice { get; set; }
public bool TargetsPirate { get; set; }
public string RewardKey { get; set; }
public string NextMissionPolice { get; set; }
public string NextMissionPirate { get; set; }
public string Body { get; set; }
public enum MissionMajorType { Time, Static, PvpChain }
public enum MissionType { Pickup, Kill, Transport, Recycle, Level, Explore }
public enum MissionSubtype { Ship, Boss, Frenzy, Reputation, Spawner, Player, PvpStart }
}
public class DailyMissionData : BigDBObject
{
public string Name { get; set; }
public string Description { get; set; }
[JsonConverter(typeof(SnakeCaseEnumConverter))]
public DailyMissionType Type { get; set; }
public int Level { get; set; }
public string Bitmap { get; set; }
public List<string> Reward { get; set; }
public DailyMissionTarget Targets { get; set; }
public class DailyMissionTarget
{
public bool Any { get; set; }
public string Type { get; set; }
public string Planet { get; set; }
public List<string> Enemies { get; set; }
public string SolarSystem { get; set; }
public int Count { get; set; }
public bool Distinct { get; set; }
}
public enum DailyMissionType { Kill, UpgradeTech, LandOnPlanet, Pickup, CapturePlanet, Missions, WinPvp, PlaySurvival, HealPlayer, KillDistinct }
}
}
public class ResourcesHelper
{
public static void DebugTimedMissions(Resources resources)
{
var timed = resources.Missions.Values
.Where(x => x.MajorType == UserQuery.Resources.MissionData.MissionMajorType.Time);
timed
.OrderBy(x => x.MinLvl)
.ThenBy(x => x.Expires)
.Select(x => new
{
x.Key,
Title = x.Title.Replace("[amount]", x.Value.ToString()),
Description = x.Description.Replace("[amount]", x.Value.ToString()),
x.Type,
x.Subtype,
x.MinLvl,
x.Expires
})
.Dump();
}
}
public static class JsonHelper
{
public static object ToObject(this JToken token)
{
switch (token.Type)
{
case JTokenType.Object:
return token
.Values<JProperty>()
.ToDictionary(x => x.Name, x => x.Value.ToObject());
case JTokenType.Array:
return token
.Select(Tuple.Create<JToken, int>)
.ToDictionary(x => x.Item2.ToString(), x => x.Item1.ToObject());
default:
return token.Value<object>();
}
}
public static Dictionary<string, JToken> ToDictionary(this JToken dictionaryRoot)
{
return dictionaryRoot
.Values<JProperty>()
.ToDictionary(x => x.Name, x => x.Value);
}
public static object GetCommonClassDefinition(JToken dictionaryRoot)
{
return string.Join("\n", dictionaryRoot
.Cast<JProperty>()
.ToDictionary(x => x.Name, x => (JObject)x.Value)
.Values.SelectMany(x => x.Properties())
.Select(x => x.Name)
.Distinct()
.Select(x => $"public string {x.Pascalize()} {{ get; set; }}")
);
}
}
public static class EnumerableExtensions
{
public static Dictionary<TKey, T> ToDistnctDictionary<T, TKey>(this IEnumerable<T> source, Func<T, TKey> keySelector)
{
return source.ToDistnctDictionary(keySelector, x => x);
}
public static Dictionary<TKey, TValue> ToDistnctDictionary<T, TKey, TValue>(this IEnumerable<T> source, Func<T, TKey> keySelector, Func<T, TValue> valueSelector)
{
return source
.GroupBy(keySelector)
.ToDictionary(g => g.Key, g => g.Select(valueSelector).First());
}
}
public class SnakeCaseEnumConverter : JsonConverter
{
public override bool CanConvert(Type type)
{
type = IsNullableType(type)
? Nullable.GetUnderlyingType(type)
: type;
return type.IsEnum;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
if (!IsNullableType(objectType))
throw new JsonSerializationException($"Cannot convert null value to {objectType}.");
return null;
}
var type = IsNullableType(objectType)
? Nullable.GetUnderlyingType(objectType)
: objectType;
var value = reader.Value.ToString().Pascalize();
var result = Enum.GetValues(type).Cast<Enum>()
.FirstOrDefault(x => x.ToString() == value);
if (result == null)
throw new JsonSerializationException($"Error converting value \"{reader.Value.ToString()}\" to type '{objectType}'.");
return result;
}
private bool IsNullableType(Type type)
{
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
}
}