Skip to content

Commit 77f2dd8

Browse files
committed
feat: simple list challenges mode
1 parent 17288ad commit 77f2dd8

3 files changed

Lines changed: 170 additions & 2 deletions

File tree

DataTool/DataModels/Challenge.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#nullable enable
2+
using System.Linq;
3+
using DataTool.Helper;
4+
using TankLib;
5+
using TankLib.STU.Types;
6+
7+
namespace DataTool.DataModels;
8+
9+
public class Challenge {
10+
public teResourceGUID GUID { get; set; }
11+
public string? Name { get; set; }
12+
public string? Description { get; set; }
13+
14+
public GenericGUIDValue? Hero { get; set; }
15+
public teResourceGUID? IconGUID { get; set; }
16+
public teResourceGUID? SeasonGUID { get; set; }
17+
public teResourceGUID? CelebrationGUID { get; set; }
18+
public teResourceGUID? CategoryGUID { get; set; }
19+
public teResourceGUID? SubCategoryGUID { get; set; }
20+
21+
public UnlockLite? RequiredUnlock { get; set; }
22+
public UnlockLite?[]? Rewards { get; set; }
23+
public ChallengePrerequisites? Prerequisites { get; set; }
24+
25+
public Challenge(STU_F9392C2B stu, ulong key = default) {
26+
Init(stu, key);
27+
}
28+
29+
public void Init(STU_F9392C2B stu, ulong key = default) {
30+
GUID = (teResourceGUID) key;
31+
Name = IO.GetString(stu.m_name);
32+
Description = IO.GetString(stu.m_description);
33+
IconGUID = stu.m_544A6A4F;
34+
CelebrationGUID = stu.m_B44A42A0;
35+
SeasonGUID = stu.m_29E273F8;
36+
CategoryGUID = stu.m_5E4619AF?.m_id;
37+
SubCategoryGUID = stu.m_CAF37A9E?.m_id;
38+
Hero = stu.m_hero != null ? new GenericGUIDValue(stu.m_hero, HeroVM.GetName(stu.m_hero)) : null;
39+
40+
if (stu.m_41A13472 != null) {
41+
RequiredUnlock = Unlock.Load(stu.m_41A13472)?.ToLiteUnlock();
42+
}
43+
44+
if (stu.m_DEB2CEFA != null) {
45+
Rewards = stu.m_DEB2CEFA.m_unlocks?.Select(x => Unlock.Load(x)?.ToLiteUnlock()).Where(x => x != null).ToArray();
46+
}
47+
48+
if (stu.m_481F944B != null) {
49+
Prerequisites = new ChallengePrerequisites {
50+
ChallengeGUIDs = stu.m_481F944B.m_FB667EC7?.Select(x => x.m_A236519D?.GUID).Where(x => x != null).ToArray() ?? [],
51+
RequiredCount = (int) stu.m_481F944B.m_amount,
52+
};
53+
}
54+
}
55+
56+
public static Challenge? Load(ulong guid) {
57+
var stu = STUHelper.GetInstance<STU_F9392C2B>(guid);
58+
if (stu == null) return null;
59+
return new Challenge(stu, guid);
60+
}
61+
62+
public ChallengeLite ToLite() {
63+
return ChallengeLite.FromChallenge(this);
64+
}
65+
66+
public class ChallengePrerequisites {
67+
public teResourceGUID?[]? ChallengeGUIDs { get; set; }
68+
public int RequiredCount { get; set; }
69+
}
70+
}
71+
72+
public class ChallengeLite {
73+
public teResourceGUID? GUID { get; set; }
74+
public string? Name { get; set; }
75+
public string? Description { get; set; }
76+
77+
public static ChallengeLite FromChallenge(Challenge challenge) {
78+
return new ChallengeLite {
79+
GUID = challenge.GUID,
80+
Name = challenge.Name,
81+
Description = challenge.Description
82+
};
83+
}
84+
}

DataTool/DataModels/Unlock.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,34 @@ public UnlockLite ToLiteUnlock() {
269269
}
270270

271271
public STU_3021DDED GetSTU() => STU;
272+
273+
public string GetFormattedName() {
274+
var rarity = IsTraditionalUnlock ? $"{Rarity} " : "";
275+
276+
if (Name != null) {
277+
return $"{rarity}{Type} - {Name}";
278+
}
279+
280+
string? guessedName = Type switch {
281+
UnlockType.VirtualCurrency => Amount.ToString(), // can't easily get the currency type here so just show the amount
282+
UnlockType.BattlePassTierSkip => Amount.ToString(),
283+
UnlockType.BattlePassXP => Amount.ToString(),
284+
_ => null
285+
};
286+
287+
return $"{Rarity} {Type} - {guessedName ?? "UNKNOWN"}";
288+
}
272289
}
273290

274291
public class UnlockLite {
275292
public teResourceGUID GUID { get; set; }
276-
public string Name { get; set; }
293+
public string? Name { get; set; }
277294
public UnlockType Type { get; set; }
278295
public STUUnlockRarity Rarity { get; set; }
279296
public int? Amount { get; set; }
280297

298+
internal Unlock? FullUnlock { get; set; }
299+
281300
public bool ShouldSerializeAmount() => Amount != null;
282301

283302
public static UnlockLite FromUnlock(Unlock unlock) {
@@ -286,9 +305,14 @@ public static UnlockLite FromUnlock(Unlock unlock) {
286305
Name = unlock.Name,
287306
Type = unlock.Type,
288307
Rarity = unlock.Rarity,
289-
Amount = unlock.Amount
308+
Amount = unlock.Amount,
309+
FullUnlock = unlock
290310
};
291311
}
312+
313+
public string GetFormattedName() {
314+
return FullUnlock?.GetFormattedName() ?? $"{Rarity} {Type} - {Name ?? "UNKNOWN"}";
315+
}
292316
}
293317

294318
public enum UnlockType {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Collections.Generic;
2+
using DataTool.DataModels;
3+
using DataTool.Flag;
4+
using DataTool.Helper;
5+
using DataTool.JSON;
6+
using TankLib;
7+
8+
namespace DataTool.ToolLogic.List;
9+
10+
[Tool("list-challenges", Description = "List challenges", CustomFlags = typeof(ListFlags))]
11+
public class ListChallenges : JSONTool, ITool {
12+
public void Parse(ICLIFlags toolFlags) {
13+
var flags = (ListFlags) toolFlags;
14+
var data = GetData();
15+
16+
if (flags.JSON) {
17+
OutputJSON(data, flags);
18+
return;
19+
}
20+
21+
var indentLevel = new IndentHelper();
22+
foreach (var (key, challenge) in data) {
23+
Log($"{indentLevel}{challenge.Name}:");
24+
if (!flags.Simplify) {
25+
if (challenge.Description != null) {
26+
Log($"{indentLevel + 1}Description: {challenge.Description}");
27+
}
28+
29+
if (challenge.Hero != null) {
30+
Log($"{indentLevel + 1}Hero: {challenge.Hero?.Value ?? "Unknown"}");
31+
}
32+
33+
if (challenge.RequiredUnlock != null) {
34+
Log($"{indentLevel + 1}Required Unlock: {challenge.RequiredUnlock.GetFormattedName()}");
35+
}
36+
37+
if (challenge.Rewards?.Length > 0) {
38+
Log($"{indentLevel + 1}Rewards:");
39+
foreach (var reward in challenge.Rewards) {
40+
Log($"{indentLevel + 2}{reward?.GetFormattedName()}");
41+
}
42+
}
43+
44+
Log();
45+
}
46+
}
47+
}
48+
49+
public static Dictionary<teResourceGUID, Challenge> GetData() {
50+
var map = new Dictionary<teResourceGUID, Challenge>();
51+
52+
foreach (teResourceGUID guid in Program.TrackedFiles[0x157]) {
53+
var challenge = Challenge.Load(guid);
54+
if (challenge == null) continue;
55+
map.Add(guid, challenge);
56+
}
57+
58+
return map;
59+
}
60+
}

0 commit comments

Comments
 (0)