Skip to content

Commit 0dd664c

Browse files
authored
Merge pull request #165 from Erol444/release/2.2.0
Release 2.2.0 **Changelog**: - Add auto-improve troops (works for both servers but TTWars is a better use case because of zero second upgrade). Read docs [here](https://tbs-docs.readthedocs.io/en/latest/improve.html) - Redesign Village>Setting tab and add a checkbox to refresh setting to enable or disable - Fix after first sleep, TBS wants to work 24/24 - Fix TBS use gold upgrade even with residence and similar building - Fix TBS forgot to check the prerequisite building before build - Fix TBS didn't know Travian forced to log out after a few inactive hours If you like my work, you can donate to me through [ko-fi.com/vinaghost](ko-fi.com/vinaghost)
2 parents 308231f + 4b41e3a commit 0dd664c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2054
-428
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
${{needs.version.outputs.changelog}}
102102
Discord:
103103
runs-on: ubuntu-latest
104-
needs: release
104+
needs: [release, version]
105105
steps:
106106
- name: Ping @everyone
107107
run: |

MainCore/AppDbContext.cs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using MainCore.Models.Database;
1+
using MainCore.Enums;
2+
using MainCore.Helper;
3+
using MainCore.Models.Database;
24
using Microsoft.EntityFrameworkCore;
5+
using System.Collections.Generic;
36
using System.Linq;
47

58
namespace MainCore
@@ -204,6 +207,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
204207
});
205208

206209
#endregion Farm settings
210+
211+
#region Village troops
212+
213+
modelBuilder.Entity<VillageTroops>(entity =>
214+
{
215+
entity.ToTable("VillagesTroops");
216+
entity.HasKey(e => new { e.VillageId, e.Id })
217+
.HasName("PK_VILLAGESTROOPS");
218+
});
219+
220+
#endregion Village troops
207221
}
208222

209223
public void AddAccount(int accountId)
@@ -266,6 +280,22 @@ public void AddVillage(int villageId)
266280
//VillagesBuildings
267281
}
268282

283+
public void AddTroop(int villageId, TribeEnums tribe)
284+
{
285+
var troops = tribe.GetTroops();
286+
for (int i = 0; i < troops.Count; i++)
287+
{
288+
var level = -1;
289+
if (i == 0) level = 0;
290+
VillagesTroops.Add(new VillageTroops
291+
{
292+
Id = (int)troops[i],
293+
VillageId = villageId,
294+
Level = level,
295+
});
296+
}
297+
}
298+
269299
public void AddFarm(int farmId)
270300
{
271301
FarmsSettings.Add(new FarmSetting
@@ -377,6 +407,30 @@ public void UpdateDatabase()
377407
});
378408
}
379409
}
410+
411+
if (!VillagesTroops.Any())
412+
{
413+
foreach (var account in Accounts)
414+
{
415+
var tribe = AccountsInfo.Find(account.Id).Tribe;
416+
var troops = tribe.GetTroops();
417+
var villages = Villages.Where(x => x.AccountId == account.Id).ToList();
418+
foreach (var village in villages)
419+
{
420+
for (int i = 0; i < troops.Count; i++)
421+
{
422+
var level = -1;
423+
if (i == 0) level = 0;
424+
VillagesTroops.Add(new VillageTroops
425+
{
426+
Id = (int)troops[i],
427+
VillageId = village.Id,
428+
Level = level,
429+
});
430+
}
431+
}
432+
}
433+
}
380434
}
381435

382436
public void DeleteAccount(int accountId)
@@ -428,6 +482,8 @@ public void DeleteVillage(int villageId)
428482
VillagesQueueBuildings.RemoveRange(queue);
429483
var buildings = VillagesBuildings.Where(x => x.VillageId == villageId);
430484
VillagesBuildings.RemoveRange(buildings);
485+
var troops = VillagesTroops.Where(x => x.VillageId == villageId);
486+
VillagesTroops.RemoveRange(troops);
431487

432488
var village = Villages.Find(villageId);
433489
Villages.Remove(village);
@@ -441,6 +497,23 @@ public void DeleteFarm(int farmId)
441497
Farms.Remove(farm);
442498
}
443499

500+
public void AddVersionInfo()
501+
{
502+
Database.ExecuteSqlRaw("CREATE TABLE \"VersionInfo\" (\"Version\" INTEGER NOT NULL, \"AppliedOn\" DATETIME, \"Description\" TEXT)");
503+
504+
var migrations = new List<KeyValuePair<long, string>>()
505+
{
506+
KeyValuePair.Create(202209131759,"Farming"),
507+
KeyValuePair.Create(202210061322,"NPCMigrations"),
508+
KeyValuePair.Create(202210162304,"TroopsMigrations"),
509+
KeyValuePair.Create(202210181120,"UpgradeTroopMigrations"),
510+
};
511+
foreach (var migration in migrations)
512+
{
513+
Database.ExecuteSqlRaw($"INSERT INTO VersionInfo (Version, Description) VALUES ('{migration.Key}','{migration.Value}')");
514+
}
515+
}
516+
444517
public DbSet<Account> Accounts { get; set; }
445518
public DbSet<AccountInfo> AccountsInfo { get; set; }
446519
public DbSet<Access> Accesses { get; set; }
@@ -458,5 +531,6 @@ public void DeleteFarm(int farmId)
458531
public DbSet<VillageProduction> VillagesProduction { get; set; }
459532
public DbSet<Farm> Farms { get; set; }
460533
public DbSet<FarmSetting> FarmsSettings { get; set; }
534+
public DbSet<VillageTroops> VillagesTroops { get; set; }
461535
}
462536
}

MainCore/Enums/TroopEnums.cs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
namespace MainCore.Enums
2+
{
3+
public enum TroopEnums
4+
{
5+
None,
6+
7+
//Romans//,
8+
Legionnaire,
9+
10+
Praetorian,
11+
Imperian,
12+
EquitesLegati,
13+
EquitesImperatoris,
14+
EquitesCaesaris,
15+
RomanRam,
16+
RomanCatapult,
17+
RomanChief,
18+
RomanSettler,
19+
20+
//Teutons//,
21+
Clubswinger,
22+
23+
Spearman,
24+
Axeman,
25+
Scout,
26+
Paladin,
27+
TeutonicKnight,
28+
TeutonRam,
29+
TeutonCatapult,
30+
TeutonChief,
31+
TeutonSettler,
32+
33+
//Gauls//,
34+
Phalanx,
35+
36+
Swordsman,
37+
Pathfinder,
38+
TheutatesThunder,
39+
Druidrider,
40+
Haeduan,
41+
GaulRam,
42+
GaulCatapult,
43+
GaulChief,
44+
GaulSettler,
45+
46+
//Nature//,
47+
Rat,
48+
49+
Spider,
50+
Snake,
51+
Bat,
52+
WildBoar,
53+
Wolf,
54+
Bear,
55+
Crocodile,
56+
Tiger,
57+
Elephant,
58+
59+
//Natars//,
60+
Pikeman,
61+
62+
ThornedWarrior,
63+
Guardsman,
64+
BirdsOfPrey,
65+
Axerider,
66+
NatarianKnight,
67+
Warelephant,
68+
Ballista,
69+
NatarianEmperor,
70+
Settler,
71+
72+
//Egyptians//,
73+
SlaveMilitia,
74+
75+
AshWarden,
76+
KhopeshWarrior,
77+
SopduExplorer,
78+
AnhurGuard,
79+
ReshephChariot,
80+
EgyptianRam,
81+
EgyptianCatapult,
82+
EgyptianChief,
83+
EgyptianSettler,
84+
85+
//Huns//,
86+
Mercenary,
87+
88+
Bowman,
89+
Spotter,
90+
SteppeRider,
91+
Marksman,
92+
Marauder,
93+
HunRam,
94+
HunCatapult,
95+
HunChief,
96+
HunSettler,
97+
98+
//Hero
99+
Hero
100+
}
101+
}

0 commit comments

Comments
 (0)