11#nullable enable
2+ using System . Linq ;
23using DataTool . Helper ;
34using TankLib ;
4- using TankLib . STU . Types ;
5+
6+ using STUTalentBase = TankLib . STU . Types . STU_DF0481B0 ;
7+ using STUTalent = TankLib . STU . Types . STU_BDDF370E ;
8+ using STUPerk = TankLib . STU . Types . STU_42B75C40 ;
59
610namespace DataTool . DataModels . Hero ;
711
812public class Talent {
913 public teResourceGUID GUID { get ; set ; }
14+ public ETalentType TalentType = ETalentType . Unknown ;
1015 public string ? Name { get ; set ; }
1116 public string ? Description { get ; set ; }
1217 public teResourceGUID TextureGUID { get ; set ; }
18+ public HeroLoadout ? Loadout ;
19+ public int MaxCount ;
20+ public int Cost ;
21+ public GenericGUIDValue ? Hero ;
22+ public GenericGUIDValue ? Rarity ;
23+ public GenericGUIDValue ? Category ;
24+
25+ public int Level ;
26+ public bool Major ;
1327
14- public Talent ( STU_BDDF370E stu , ulong key = default ) {
28+ public Talent ( STUTalentBase stu , ulong key = default ) {
1529 Init ( stu , key ) ;
1630 }
1731
18- public void Init ( STU_BDDF370E talent , ulong key = default ) {
19- GUID = ( teResourceGUID ) key ;
20- TextureGUID = talent . m_544A6A4F ;
32+ public void Init ( STUTalentBase stu , ulong key = default ) {
33+ if ( stu is STUTalent talent ) {
34+ TalentType = ETalentType . Talent ;
35+ Name = IO . GetString ( talent . m_name ) ;
36+ Description = IO . GetString ( talent . m_description ) ;
37+ TextureGUID = talent . m_544A6A4F ;
38+ MaxCount = talent . m_BBD71D14 ;
39+ Cost = talent . m_925E7392 ;
40+
41+ if ( talent . m_hero != null ) {
42+ Hero = new GenericGUIDValue ( talent . m_hero , HeroVM . GetName ( talent . m_hero ) ) ;
43+ }
44+
45+ if ( talent . m_672DA932 != null ) {
46+ Rarity = new GenericGUIDValue ( talent . m_672DA932 , IO . GetNullableGUIDName ( talent . m_672DA932 ) ) ;
47+ }
48+
49+ if ( talent . m_category ? . m_id != null ) {
50+ Category = new GenericGUIDValue ( talent . m_category . m_id , IO . GetNullableGUIDName ( talent . m_category . m_id ) ) ;
51+ }
52+
53+ if ( talent . m_loadout != null ) {
54+ var hero = FindHeroForLoadout ( talent . m_loadout ) ;
55+
56+ Loadout = new HeroLoadout {
57+ GUID = talent . m_loadout ,
58+ Name = LoadoutVM . GetName ( talent . m_loadout ) ,
59+ HeroGUID = hero ? . GUID ?? null ,
60+ HeroName = hero ? . Name ,
61+ } ;
62+ }
63+ } else if ( stu is STUPerk perk ) {
64+ TalentType = ETalentType . Perk ;
65+ if ( perk . m_loadout != null ) {
66+ var hero = FindHeroForLoadout ( perk . m_loadout ) ;
67+
68+ Loadout = new HeroLoadout {
69+ GUID = perk . m_loadout ,
70+ Name = LoadoutVM . GetName ( perk . m_loadout ) ,
71+ HeroGUID = hero ? . GUID ?? null ,
72+ HeroName = hero ? . Name ,
73+ } ;
74+ }
2175
22- Name = IO . GetString ( talent . m_name ) ? . TrimEnd ( ) ;
23- // todo: why do the names end in spaces.. it causes a double-space with the chat box in-game
24- Description = IO . GetString ( talent . m_description ) ;
76+ Name = LoadoutVM . GetName ( perk . m_loadout ) ;
77+ Level = ( int ) perk . m_4DDE5023 ;
78+ Major = perk . m_D60C9EA2 != 0 ;
79+ }
2580 }
2681
2782 public static Talent ? Load ( ulong guid ) {
28- var baseType = STUHelper . GetInstance < STU_DF0481B0 > ( guid ) ;
29- if ( baseType is not STU_BDDF370E talent ) {
30- // is a perk (or null)
31- return null ;
83+ var stu = STUHelper . GetInstance < STUTalentBase > ( guid ) ;
84+ if ( stu == null ) return null ;
85+ return new Talent ( stu , guid ) ;
86+ }
87+
88+ private static HeroVM ? FindHeroForLoadout ( teResourceGUID loadoutGuid ) {
89+ foreach ( var ( heroGuid , hero ) in Helpers . GetHeroes ( ) ) {
90+ if ( ! hero . IsHero || hero . Loadouts == null ) continue ;
91+ if ( hero . Loadouts . Any ( loadout => loadout . GUID == loadoutGuid ) ) {
92+ return hero ;
93+ }
3294 }
3395
34- return new Talent ( talent , guid ) ;
96+ return null ;
97+ }
98+
99+ public record HeroLoadout {
100+ public teResourceGUID GUID ;
101+ public string ? Name ;
102+ public teResourceGUID ? HeroGUID ;
103+ public string ? HeroName ;
104+ }
105+
106+ public enum ETalentType {
107+ Unknown = 0 ,
108+ Talent = 1 ,
109+ Perk = 2 ,
35110 }
36- }
111+ }
112+
0 commit comments