6
6
using TbsCore . Models . AccModels ;
7
7
using TbsCore . Models . ResourceModels ;
8
8
using TbsCore . Models . VillageModels ;
9
+ using TbsCore . TravianData ;
9
10
using TravBotSharp . Files . Parsers ;
10
11
using TravBotSharp . Files . Tasks . LowLevel ;
11
12
using static TravBotSharp . Files . Helpers . Classificator ;
@@ -43,10 +44,10 @@ public static Village GetHeroHomeVillage(Account acc) =>
43
44
/// <param name="acc">Account</param>
44
45
public static void AutoEquipHero ( Account acc )
45
46
{
46
- foreach ( Classificator . HeroItemCategory category
47
- in ( Classificator . HeroItemCategory [ ] ) Enum . GetValues ( typeof ( Classificator . HeroItemCategory ) ) )
47
+ foreach ( HeroItemCategory category
48
+ in ( HeroItemCategory [ ] ) Enum . GetValues ( typeof ( HeroItemCategory ) ) )
48
49
{
49
- if ( category == Classificator . HeroItemCategory . Others ) continue ; // Don't equip into hero bag
50
+ if ( category == HeroItemCategory . Others ) continue ; // Don't equip into hero bag
50
51
int currentTier = 0 ;
51
52
if ( acc . Hero . Equipt . TryGetValue ( category , out var item ) )
52
53
{
@@ -66,7 +67,7 @@ public static void AutoEquipHero(Account acc)
66
67
TaskExecutor . AddTaskIfNotExists ( acc , new HeroEquip ( )
67
68
{
68
69
ExecuteAt = DateTime . Now ,
69
- Items = new List < ( Classificator . HeroItemEnum , int ) > ( )
70
+ Items = new List < ( HeroItemEnum , int ) > ( )
70
71
{
71
72
( equipWith . Item , 0 )
72
73
}
@@ -80,33 +81,64 @@ public static void AutoEquipHero(Account acc)
80
81
/// </summary>
81
82
/// <param name="item">Hero item enum</param>
82
83
/// <returns>Hero item (category, name, tier)</returns>
83
- public static ( Classificator . HeroItemCategory , string , int ) ParseHeroItem ( Classificator . HeroItemEnum item )
84
+ public static ( HeroItemCategory , string , int ) ParseHeroItem ( HeroItemEnum item )
84
85
{
85
86
var attr = item . ToString ( ) . Split ( '_' ) ;
86
87
87
- Enum . TryParse ( attr [ 0 ] , out Classificator . HeroItemCategory category ) ;
88
+ Enum . TryParse ( attr [ 0 ] , out HeroItemCategory category ) ;
88
89
string name = attr [ 1 ] ;
89
90
int tier = int . Parse ( attr [ 2 ] ) ;
90
91
91
92
return ( category , name , tier ) ;
92
93
}
93
94
95
+ /// <summary>
96
+ /// Parses hero weapon
97
+ /// </summary>
98
+ /// <param name="item">Hero item</param>
99
+ /// <returns>(Troop boost, boost)</returns>
100
+ public static ( TroopsEnum , int ) ParseWeapon ( HeroItemEnum item )
101
+ {
102
+ var ( _, name , tier ) = ParseHeroItem ( item ) ;
103
+ if ( Enum . TryParse ( name , out TroopsEnum troop ) )
104
+ {
105
+ return ( troop , GetWeaponBoost ( troop , tier ) ) ;
106
+ }
107
+ return ( TroopsEnum . None , 0 ) ;
108
+ }
109
+
110
+ public static int GetArmorBaseStrength ( string name )
111
+ {
112
+ switch ( name )
113
+ {
114
+ case "Breastplate" : return 500 ;
115
+ case "Segmented" : return 250 ;
116
+ default : return 0 ;
117
+ }
118
+ }
119
+
120
+ private static int GetWeaponBoost ( TroopsEnum troop , int tier )
121
+ {
122
+ var upkeep = TroopsData . GetTroopUpkeep ( troop ) ;
123
+ return ( tier + 2 ) * upkeep ;
124
+ }
125
+
94
126
/// <summary>
95
127
/// Gets the tier of the hero item
96
128
/// </summary>
97
129
/// <param name="item">HeroItem</param>
98
130
/// <returns>Tier</returns>
99
- public static int GetHeroItemTier ( Classificator . HeroItemEnum item )
131
+ public static int GetHeroItemTier ( HeroItemEnum item )
100
132
{
101
133
var ( _, _, itemTier ) = ParseHeroItem ( item ) ;
102
134
return itemTier ;
103
135
}
104
- public static string GetHeroItemName ( Classificator . HeroItemEnum item )
136
+ public static string GetHeroItemName ( HeroItemEnum item )
105
137
{
106
138
var ( _, name , _) = ParseHeroItem ( item ) ;
107
139
return name ;
108
140
}
109
- public static Classificator . HeroItemCategory GetHeroItemCategory ( Classificator . HeroItemEnum item )
141
+ public static HeroItemCategory GetHeroItemCategory ( HeroItemEnum item )
110
142
{
111
143
var ( category , _, _) = ParseHeroItem ( item ) ;
112
144
return category ;
@@ -127,7 +159,7 @@ public static void ParseHeroPage(Account acc)
127
159
128
160
if ( acc . Hero . Settings . AutoEquip )
129
161
{
130
- HeroHelper . AutoEquipHero ( acc ) ;
162
+ AutoEquipHero ( acc ) ;
131
163
}
132
164
}
133
165
@@ -138,10 +170,10 @@ public static void UpdateHeroVillage(Account acc)
138
170
139
171
switch ( acc . AccInfo . ServerVersion )
140
172
{
141
- case Classificator . ServerVersionEnum . T4_4 :
173
+ case ServerVersionEnum . T4_4 :
142
174
acc . Hero . HomeVillageId = hrefId ?? 0 ;
143
175
return ;
144
- case Classificator . ServerVersionEnum . T4_5 :
176
+ case ServerVersionEnum . T4_5 :
145
177
// Convert from coordinates id -> coordinates -> villageId
146
178
var coordinates = MapHelper . CoordinatesFromKid ( hrefId ?? 0 , acc ) ;
147
179
var vill = acc . Villages . FirstOrDefault ( x => x . Coordinates . Equals ( coordinates ) ) ;
@@ -156,10 +188,10 @@ public static long[] GetHeroResources(Account acc)
156
188
var heroItems = acc . Hero . Items ;
157
189
return new long [ ]
158
190
{
159
- heroItems . FirstOrDefault ( x => x . Item == Classificator . HeroItemEnum . Others_Wood_0 ) ? . Count ?? 0 ,
160
- heroItems . FirstOrDefault ( x => x . Item == Classificator . HeroItemEnum . Others_Clay_0 ) ? . Count ?? 0 ,
161
- heroItems . FirstOrDefault ( x => x . Item == Classificator . HeroItemEnum . Others_Iron_0 ) ? . Count ?? 0 ,
162
- heroItems . FirstOrDefault ( x => x . Item == Classificator . HeroItemEnum . Others_Crop_0 ) ? . Count ?? 0
191
+ heroItems . FirstOrDefault ( x => x . Item == HeroItemEnum . Others_Wood_0 ) ? . Count ?? 0 ,
192
+ heroItems . FirstOrDefault ( x => x . Item == HeroItemEnum . Others_Clay_0 ) ? . Count ?? 0 ,
193
+ heroItems . FirstOrDefault ( x => x . Item == HeroItemEnum . Others_Iron_0 ) ? . Count ?? 0 ,
194
+ heroItems . FirstOrDefault ( x => x . Item == HeroItemEnum . Others_Crop_0 ) ? . Count ?? 0
163
195
} ;
164
196
}
165
197
@@ -169,21 +201,21 @@ public static long[] GetHeroResources(Account acc)
169
201
/// <param name="acc">Account</param>
170
202
/// <param name="troop">Troop to train</param>
171
203
/// <returns>Whether to switch helmets first</returns>
172
- public static bool SwitchHelmet ( Account acc , Village trainVill , Classificator . BuildingEnum building , TrainTroops task )
204
+ public static bool SwitchHelmet ( Account acc , Village trainVill , BuildingEnum building , TrainTroops task )
173
205
{
174
206
if ( ! acc . Hero . Settings . AutoSwitchHelmets ) return false ;
175
207
176
208
// In T4.5, helmet will only have effect in hero home village
177
209
// In TTWars, helmets have acc-wide effect
178
210
// TODO: for T4.5, add auto-move hero feature (for helmet effect purposes)
179
211
if ( GetHeroHomeVillage ( acc ) != trainVill &&
180
- acc . AccInfo . ServerVersion != Classificator . ServerVersionEnum . T4_4 ) return false ;
212
+ acc . AccInfo . ServerVersion != ServerVersionEnum . T4_4 ) return false ;
181
213
182
214
string type = "" ;
183
- if ( building == Classificator . BuildingEnum . Barracks ||
184
- building == Classificator . BuildingEnum . GreatBarracks ) type = "Infantry" ;
185
- if ( building == Classificator . BuildingEnum . Stable ||
186
- building == Classificator . BuildingEnum . GreatStable ) type = "Cavalry" ;
215
+ if ( building == BuildingEnum . Barracks ||
216
+ building == BuildingEnum . GreatBarracks ) type = "Infantry" ;
217
+ if ( building == BuildingEnum . Stable ||
218
+ building == BuildingEnum . GreatStable ) type = "Cavalry" ;
187
219
188
220
// No helmet helps us for training in workshop
189
221
if ( string . IsNullOrEmpty ( type ) ) return false ;
@@ -196,7 +228,7 @@ public static bool SwitchHelmet(Account acc, Village trainVill, Classificator.Bu
196
228
197
229
var ( equipCategory , equipName , equipTier ) = ParseHeroItem ( equipWith . Item ) ;
198
230
199
- if ( acc . Hero . Equipt . TryGetValue ( Classificator . HeroItemCategory . Helmet , out var equiped ) )
231
+ if ( acc . Hero . Equipt . TryGetValue ( HeroItemCategory . Helmet , out var equiped ) )
200
232
{
201
233
var ( category , name , tier ) = ParseHeroItem ( equiped ) ;
202
234
if ( name == type &&
0 commit comments