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