Skip to content

Commit fcbb93f

Browse files
committed
Merge branch 'combat_simulator' into scout_villages
2 parents 0e629f5 + 64549dd commit fcbb93f

36 files changed

+1533
-321
lines changed

TbsCore/Database/DbRepository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,4 @@ private static DbAccount ConvertAcc(Account acc) =>
8484
JsonData = JsonConvert.SerializeObject(acc)
8585
};
8686
}
87-
88-
//public class RawAcc
89-
//{
90-
// public string Username { get; set; }
91-
// public string Server { get; set; }
92-
//}
9387
}

TbsCore/Helpers/Classificator.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,5 +518,32 @@ public enum BuildingType
518518
General,
519519
AutoUpgradeResFields
520520
}
521+
522+
public enum ReportType
523+
{
524+
TruceReport, // iReport0
525+
AttackNoLosses, // iReport1 - Won as attacker without losses, Green sword
526+
AttackSomeLosses, // iReport2 - Won as attacker with losses
527+
AttackAllLosses, // iReport3 - Lost as attacker with losses
528+
DeffendNoLosses, // iReport4
529+
DeffendSomeLosses, // iReport5
530+
DeffendAllLosses, // iReport6
531+
DeffendNoDeff, // iReport7
532+
Reinforcement, // iReport8 - Reinforcement
533+
Unknown9, // 9
534+
Unknown10, // 9
535+
WoodDelivery, // iReport11 - Wood Delivery
536+
ClayDelivery, // iReport12 - Clay Delivery
537+
IronDelivery, // iReport13 - Iron Delivery
538+
CropDelivery, // iReport14 - Crop Delivery
539+
ScoutNoLosses, // iReport15 - Won scouting as attacker
540+
ScoutSomeLosses, // iReport16 - Won scouting as attacker but defender found out
541+
ScoutAllLosses, // iReport17 - Lost scouting as attacker
542+
ScoutingDeffended, // iReport18
543+
ScoutingPartlyDeffended, // iReport19
544+
AnimalsCaught, // iReport20
545+
AdventureReport, // iReport21
546+
NewVillage, // iReport22 - Settlers founded a new village
547+
}
521548
}
522549
}

TbsCore/Helpers/HeroHelper.cs

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public static Village GetHeroHomeVillage(Account acc) =>
4343
/// <param name="acc">Account</param>
4444
public static void AutoEquipHero(Account acc)
4545
{
46-
foreach (Classificator.HeroItemCategory category
47-
in (Classificator.HeroItemCategory[])Enum.GetValues(typeof(Classificator.HeroItemCategory)))
46+
foreach (HeroItemCategory category
47+
in (HeroItemCategory[])Enum.GetValues(typeof(HeroItemCategory)))
4848
{
49-
if (category == Classificator.HeroItemCategory.Others) continue; // Don't equip into hero bag
49+
if (category == HeroItemCategory.Others) continue; // Don't equip into hero bag
5050
int currentTier = 0;
5151
if (acc.Hero.Equipt.TryGetValue(category, out var item))
5252
{
@@ -66,7 +66,7 @@ public static void AutoEquipHero(Account acc)
6666
acc.Tasks.Add(new HeroEquip()
6767
{
6868
ExecuteAt = DateTime.Now,
69-
Items = new List<(Classificator.HeroItemEnum, int)>()
69+
Items = new List<(HeroItemEnum, int)>()
7070
{
7171
(equipWith.Item, 0)
7272
}
@@ -80,35 +80,74 @@ public static void AutoEquipHero(Account acc)
8080
/// </summary>
8181
/// <param name="item">Hero item enum</param>
8282
/// <returns>Hero item (category, name, tier)</returns>
83-
public static (Classificator.HeroItemCategory, string, int) ParseHeroItem(Classificator.HeroItemEnum item)
83+
public static (HeroItemCategory, string, int) ParseHeroItem(HeroItemEnum item)
8484
{
8585
var attr = item.ToString().Split('_');
8686

87-
Enum.TryParse(attr[0], out Classificator.HeroItemCategory category);
87+
Enum.TryParse(attr[0], out HeroItemCategory category);
8888
string name = attr[1];
8989
int tier = int.Parse(attr[2]);
9090

9191
return (category, name, tier);
9292
}
9393

94+
/// <summary>
95+
/// Parses hero weapon
96+
/// </summary>
97+
/// <param name="item">Hero item</param>
98+
/// <returns>(Troop boost, boost)</returns>
99+
public static (TroopsEnum, int) ParseWeapon(HeroItemEnum item)
100+
{
101+
var (_, name, tier) = ParseHeroItem(item);
102+
if(Enum.TryParse(name, out TroopsEnum troop))
103+
{
104+
return (troop, GetWeaponBoost(troop, tier));
105+
}
106+
return (TroopsEnum.None, 0);
107+
}
108+
109+
public static int GetArmorStrength(string name)
110+
{
111+
switch (name)
112+
{
113+
case "Breastplate": return 500;
114+
case "Segmented": return 250;
115+
default: return 0;
116+
}
117+
}
118+
119+
public static int GetArmorDmgReduce(string name, int tier)
120+
{
121+
switch (name)
122+
{
123+
case "Scale": return 2 + 2 * tier;
124+
case "Segmented": return 2 + tier;
125+
default: return 0;
126+
}
127+
}
128+
129+
private static int GetWeaponBoost(TroopsEnum troop, int tier)
130+
{
131+
var upkeep = TroopsData.GetTroopUpkeep(troop);
132+
return (tier + 2) * upkeep;
133+
}
134+
94135
/// <summary>
95136
/// Gets the tier of the hero item
96137
/// </summary>
97138
/// <param name="item">HeroItem</param>
98139
/// <returns>Tier</returns>
99-
public static int GetHeroItemTier(Classificator.HeroItemEnum item)
140+
public static int GetHeroItemTier(HeroItemEnum item)
100141
{
101142
var (_, _, itemTier) = ParseHeroItem(item);
102143
return itemTier;
103144
}
104-
105-
public static string GetHeroItemName(Classificator.HeroItemEnum item)
145+
public static string GetHeroItemName(HeroItemEnum item)
106146
{
107147
var (_, name, _) = ParseHeroItem(item);
108148
return name;
109149
}
110-
111-
public static Classificator.HeroItemCategory GetHeroItemCategory(Classificator.HeroItemEnum item)
150+
public static HeroItemCategory GetHeroItemCategory(HeroItemEnum item)
112151
{
113152
var (category, _, _) = ParseHeroItem(item);
114153
return category;
@@ -129,7 +168,7 @@ public static void ParseHeroPage(Account acc)
129168

130169
if (acc.Hero.Settings.AutoEquip)
131170
{
132-
HeroHelper.AutoEquipHero(acc);
171+
AutoEquipHero(acc);
133172
}
134173
}
135174

@@ -140,11 +179,10 @@ public static void UpdateHeroVillage(Account acc)
140179

141180
switch (acc.AccInfo.ServerVersion)
142181
{
143-
case Classificator.ServerVersionEnum.T4_4:
182+
case ServerVersionEnum.T4_4:
144183
acc.Hero.HomeVillageId = hrefId ?? 0;
145184
return;
146-
147-
case Classificator.ServerVersionEnum.T4_5:
185+
case ServerVersionEnum.T4_5:
148186
// Convert from coordinates id -> coordinates -> villageId
149187
var coordinates = MapHelper.CoordinatesFromKid(hrefId ?? 0, acc);
150188
var vill = acc.Villages.FirstOrDefault(x => x.Coordinates.Equals(coordinates));
@@ -159,10 +197,10 @@ public static long[] GetHeroResources(Account acc)
159197
var heroItems = acc.Hero.Items;
160198
return new long[]
161199
{
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
200+
heroItems.FirstOrDefault(x => x.Item == HeroItemEnum.Others_Wood_0)?.Count ?? 0,
201+
heroItems.FirstOrDefault(x => x.Item == HeroItemEnum.Others_Clay_0)?.Count ?? 0,
202+
heroItems.FirstOrDefault(x => x.Item == HeroItemEnum.Others_Iron_0)?.Count ?? 0,
203+
heroItems.FirstOrDefault(x => x.Item == HeroItemEnum.Others_Crop_0)?.Count ?? 0
166204
};
167205
}
168206

@@ -172,21 +210,21 @@ public static long[] GetHeroResources(Account acc)
172210
/// <param name="acc">Account</param>
173211
/// <param name="troop">Troop to train</param>
174212
/// <returns>Whether to switch helmets first</returns>
175-
public static bool SwitchHelmet(Account acc, Village trainVill, Classificator.BuildingEnum building, TrainTroops task)
213+
public static bool SwitchHelmet(Account acc, Village trainVill, BuildingEnum building, TrainTroops task)
176214
{
177215
if (!acc.Hero.Settings.AutoSwitchHelmets) return false;
178216

179217
// In T4.5, helmet will only have effect in hero home village
180218
// In TTWars, helmets have acc-wide effect
181219
// TODO: for T4.5, add auto-move hero feature (for helmet effect purposes)
182220
if (GetHeroHomeVillage(acc) != trainVill &&
183-
acc.AccInfo.ServerVersion != Classificator.ServerVersionEnum.T4_4) return false;
221+
acc.AccInfo.ServerVersion != ServerVersionEnum.T4_4) return false;
184222

185223
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";
224+
if (building == BuildingEnum.Barracks ||
225+
building == BuildingEnum.GreatBarracks) type = "Infantry";
226+
if (building == BuildingEnum.Stable ||
227+
building == BuildingEnum.GreatStable) type = "Cavalry";
190228

191229
// No helmet helps us for training in workshop
192230
if (string.IsNullOrEmpty(type)) return false;
@@ -199,7 +237,7 @@ public static bool SwitchHelmet(Account acc, Village trainVill, Classificator.Bu
199237

200238
var (equipCategory, equipName, equipTier) = ParseHeroItem(equipWith.Item);
201239

202-
if (acc.Hero.Equipt.TryGetValue(Classificator.HeroItemCategory.Helmet, out var equiped))
240+
if (acc.Hero.Equipt.TryGetValue(HeroItemCategory.Helmet, out var equiped))
203241
{
204242
var (category, name, tier) = ParseHeroItem(equiped);
205243
if (name == type &&

TbsCore/Helpers/ObjectHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using System.Runtime.InteropServices;
66
using TbsCore.Models.AccModels;
7+
using TbsCore.Models.World;
78

89
namespace TbsCore.Helpers
910
{

TbsCore/Helpers/TroopsHelper.cs

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,13 @@ namespace TbsCore.Helpers
1515
{
1616
public static class TroopsHelper
1717
{
18-
public static BuildingEnum GetTroopBuilding(TroopsEnum t, bool great)
18+
internal static TroopsEnum TroopFromInt(Account acc, int num) =>
19+
TroopFromInt(acc.AccInfo.Tribe ?? TribeEnum.Any, num);
20+
internal static TroopsEnum TroopFromInt(TribeEnum tribe, int num) =>
21+
(TroopsEnum)TroopIntFromInt(tribe, num);
22+
internal static int TroopIntFromInt(TribeEnum tribe, int num)
1923
{
20-
switch (t)
21-
{
22-
case TroopsEnum.Legionnaire:
23-
case TroopsEnum.Praetorian:
24-
case TroopsEnum.Imperian:
25-
case TroopsEnum.Clubswinger:
26-
case TroopsEnum.Spearman:
27-
case TroopsEnum.Axeman:
28-
case TroopsEnum.Scout:
29-
case TroopsEnum.Phalanx:
30-
case TroopsEnum.Swordsman:
31-
case TroopsEnum.SlaveMilitia:
32-
case TroopsEnum.AshWarden:
33-
case TroopsEnum.KhopeshWarrior:
34-
case TroopsEnum.Mercenary:
35-
case TroopsEnum.Bowman:
36-
if (great) return BuildingEnum.GreatBarracks;
37-
return BuildingEnum.Barracks;
38-
39-
case TroopsEnum.EquitesLegati:
40-
case TroopsEnum.EquitesImperatoris:
41-
case TroopsEnum.EquitesCaesaris:
42-
case TroopsEnum.Paladin:
43-
case TroopsEnum.TeutonicKnight:
44-
case TroopsEnum.Pathfinder:
45-
case TroopsEnum.TheutatesThunder:
46-
case TroopsEnum.Druidrider:
47-
case TroopsEnum.Haeduan:
48-
case TroopsEnum.SopduExplorer:
49-
case TroopsEnum.AnhurGuard:
50-
case TroopsEnum.ReshephChariot:
51-
case TroopsEnum.Spotter:
52-
case TroopsEnum.SteppeRider:
53-
case TroopsEnum.Marksman:
54-
case TroopsEnum.Marauder:
55-
if (great) return BuildingEnum.GreatStable;
56-
return BuildingEnum.Stable;
57-
58-
case TroopsEnum.RomanRam:
59-
case TroopsEnum.RomanCatapult:
60-
case TroopsEnum.TeutonCatapult:
61-
case TroopsEnum.TeutonRam:
62-
case TroopsEnum.GaulRam:
63-
case TroopsEnum.GaulCatapult:
64-
case TroopsEnum.EgyptianCatapult:
65-
case TroopsEnum.EgyptianRam:
66-
case TroopsEnum.HunCatapult:
67-
case TroopsEnum.HunRam:
68-
return BuildingEnum.Workshop;
69-
70-
default:
71-
return BuildingEnum.Site; //idk, should have error handling
72-
}
73-
}
74-
75-
internal static TroopsEnum TroopFromInt(Account acc, int num)
76-
{
77-
return (TroopsEnum)(num + 1 + (((int)acc.AccInfo.Tribe - 1) * 10));
24+
return num + 1 + (((int)tribe - 1) * 10);
7825
}
7926

8027
/// <summary>
@@ -88,11 +35,11 @@ internal static TroopsEnum TroopFromInt(Account acc, int num)
8835
internal static long TroopsToFill(Account acc, Village vill, TroopsEnum troop, bool great)
8936
{
9037
var troopCost = TroopCost.GetResourceCost(troop, great);
91-
var trainTime = TroopCost.GetTrainingTime(acc, vill, troop, great);
38+
var trainTime = TroopsData.GetTrainingTime(acc, vill, troop, great);
9239

9340
//how many troops we want to train
9441
// Take into account how many troop are already training
95-
var trainBuilding = TroopsHelper.GetTroopBuilding(troop, great);
42+
var trainBuilding = TroopsData.GetTroopBuilding(troop, great);
9643
var trainingTime = TroopsHelper.GetTrainingTimeForBuilding(trainBuilding, vill);
9744

9845
var currentlyTrainingHours = (trainingTime - DateTime.Now).TotalHours;
@@ -102,12 +49,20 @@ internal static long TroopsToFill(Account acc, Village vill, TroopsEnum troop, b
10249
return (long)Math.Ceiling(fillForHours / trainTime.TotalHours);
10350
}
10451

105-
public static DateTime TrainingDuration(HtmlAgilityPack.HtmlDocument html)
52+
public static DateTime TrainingDuration(HtmlDocument html)
10653
{
10754
var training = TroopsParser.GetTroopsCurrentlyTraining(html);
10855
return (training.Count == 0 ? DateTime.MinValue : training.Last().FinishTraining);
10956
}
11057

58+
public static List<TroopsEnum> AvailableTroops(TribeEnum tribe)
59+
{
60+
var ret = new List<TroopsEnum>();
61+
int troopsEnum = ((int)tribe - 1) * 10;
62+
for (var i = troopsEnum + 1; i < troopsEnum + 11; i++) ret.Add((TroopsEnum)i);
63+
return ret;
64+
}
65+
11166
/// <summary>
11267
/// Will (re)start troop training for all buildings (barracks,stable,gs...)
11368
/// </summary>
@@ -379,8 +334,8 @@ public static long GetTroopsUpkeep(Account acc, int[] troops)
379334
long upkeep = 0;
380335
for (int i = 0; i < 10; i++)
381336
{
382-
var troop = TroopsHelper.TroopFromInt(acc, i);
383-
upkeep += troops[i] * TroopSpeed.GetTroopUpkeep(troop);
337+
var troop = TroopFromInt(acc, i);
338+
upkeep += troops[i] * TroopsData.GetTroopUpkeep(troop);
384339
}
385340
return upkeep;
386341
}

TbsCore/Helpers/VillageHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public static int GetVillageIdFromName(string name, Account acc)
5151
public static string VillageType(Village vill)
5252
{
5353
string type = "";
54-
type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.Woodcutter).ToString();
55-
type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.ClayPit).ToString();
56-
type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.IronMine).ToString();
57-
type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.Cropland).ToString();
54+
type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.Woodcutter).ToString();
55+
type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.ClayPit).ToString();
56+
type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.IronMine).ToString();
57+
type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.Cropland).ToString();
5858
if (type == "11115") type = "15c";
5959
return type;
6060
}
6161

62-
public static string BuildingTypeToString(Classificator.BuildingEnum building) => EnumStrToString(building.ToString());
62+
public static string BuildingTypeToString(BuildingEnum building) => EnumStrToString(building.ToString());
6363

6464
public static string EnumStrToString(string str)
6565
{

0 commit comments

Comments
 (0)