Skip to content

Commit 4f8988a

Browse files
authored
Request from Kaii (#191)
* npc for warehouse * add scroll to vilalge setting * add ignore Roman tribe 's Advantage
1 parent 3efefc8 commit 4f8988a

File tree

9 files changed

+116
-27
lines changed

9 files changed

+116
-27
lines changed

MainCore/AppDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ public void AddVersionInfo()
507507
KeyValuePair.Create(202210061322,"NPCMigrations"),
508508
KeyValuePair.Create(202210162304,"TroopsMigrations"),
509509
KeyValuePair.Create(202210181120,"UpgradeTroopMigrations"),
510+
KeyValuePair.Create(202210271504,"NPCForWarhouse"),
511+
KeyValuePair.Create(2022102716038,"IgnoreRomanAdvantage"),
510512
};
511513
foreach (var migration in migrations)
512514
{

MainCore/Helper/UpgradeBuildingHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ public static PlanTask NextBuildingTask(AppDbContext context, IPlanManager planM
2727
var accountInfo = context.AccountsInfo.Find(accountId);
2828
var tribe = accountInfo.Tribe;
2929
var hasPlusAccount = accountInfo.HasPlusAccount;
30+
var setting = context.VillagesSettings.Find(villageId);
3031

3132
var maxBuild = 1;
3233
if (hasPlusAccount) maxBuild++;
33-
if (tribe == TribeEnums.Romans) maxBuild++;
34+
if (tribe == TribeEnums.Romans && !setting.IsIgnoreRomanAdvantage) maxBuild++;
3435
if (totalBuild == maxBuild)
3536
{
3637
logManager.Information(accountId, "Amount of currently building is equal with maximum building can build in same time");
3738
return null;
3839
}
3940

40-
if (tribe == TribeEnums.Romans && maxBuild - totalBuild == 1)
41+
if (tribe == TribeEnums.Romans && !setting.IsIgnoreRomanAdvantage && maxBuild - totalBuild == 1)
4142
{
4243
var numRes = currentList.Count(x => x.Type.IsResourceField());
4344
var numInfra = totalBuild - numRes;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using FluentMigrator;
2+
3+
namespace MainCore.Migrations
4+
{
5+
[Migration(202210271504)]
6+
public class NPCForWarhouse : Migration
7+
{
8+
public override void Down()
9+
{
10+
Delete
11+
.Column("IsNPCOverflow")
12+
.Column("AutoNPCWarehousePercent").FromTable("VillagesSettings");
13+
}
14+
15+
public override void Up()
16+
{
17+
Alter.Table("VillagesSettings")
18+
.AddColumn("IsNPCOverflow").AsBoolean().WithDefaultValue(false)
19+
.AddColumn("AutoNPCWarehousePercent").AsInt32().WithDefaultValue(90);
20+
}
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using FluentMigrator;
2+
3+
namespace MainCore.Migrations
4+
{
5+
[Migration(2022102716038)]
6+
public class IgnoreRomanAdvantage : Migration
7+
{
8+
public override void Down()
9+
{
10+
Delete
11+
.Column("IsIgnoreRomanAdvantage").FromTable("VillagesSettings");
12+
}
13+
14+
public override void Up()
15+
{
16+
Alter.Table("VillagesSettings")
17+
.AddColumn("IsIgnoreRomanAdvantage").AsBoolean().WithDefaultValue(false);
18+
}
19+
}
20+
}

MainCore/Models/Database/VillageSetting.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class VillageSetting
66
{
77
public int VillageId { get; set; }
88
public bool IsUseHeroRes { get; set; }
9-
9+
public bool IsIgnoreRomanAdvantage { get; set; }
1010
public bool IsInstantComplete { get; set; }
1111
public int InstantCompleteTime { get; set; }
1212

@@ -18,7 +18,9 @@ public class VillageSetting
1818
public int AutoRefreshTimeMax { get; set; }
1919

2020
public bool IsAutoNPC { get; set; }
21+
public bool IsNPCOverflow { get; set; }
2122
public int AutoNPCPercent { get; set; }
23+
public int AutoNPCWarehousePercent { get; set; }
2224
public int AutoNPCWood { get; set; }
2325
public int AutoNPCClay { get; set; }
2426
public int AutoNPCIron { get; set; }

MainCore/Tasks/Update/UpdateVillage.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ private void AutoNPC(AppDbContext context)
129129
var setting = context.VillagesSettings.Find(VillageId);
130130
if (!setting.IsAutoNPC) return;
131131
if (setting.AutoNPCPercent == 0) return;
132+
if (setting.AutoNPCWarehousePercent == 0) return;
132133

133134
var resource = context.VillagesResources.Find(VillageId);
134-
var ratio = resource.Crop * 100.0f / resource.Granary;
135-
if (ratio < setting.AutoNPCPercent) return;
135+
var ratioGranary = resource.Crop * 100.0f / resource.Granary;
136+
var maxResource = Math.Max(resource.Wood, Math.Max(resource.Clay, resource.Iron));
137+
var ratioWarehouse = maxResource * 100.0f / resource.Warehouse;
138+
if (ratioGranary < setting.AutoNPCPercent && ratioWarehouse < setting.AutoNPCWarehousePercent) return;
136139

137140
_taskManager.Add(AccountId, new NPCTask(VillageId, AccountId));
138141
}

WPFUI/Models/VillageSetting.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class VillageSetting : ReactiveObject
99
public void CopyFrom(MainCore.Models.Database.VillageSetting settings)
1010
{
1111
IsUseHeroRes = settings.IsUseHeroRes;
12+
IsIgnoreRomanAdvantage = settings.IsIgnoreRomanAdvantage;
1213
IsInstantComplete = settings.IsInstantComplete;
1314
InstantCompleteTime = settings.InstantCompleteTime.ToString();
1415
IsAdsUpgrade = settings.IsAdsUpgrade;
@@ -19,7 +20,10 @@ public void CopyFrom(MainCore.Models.Database.VillageSetting settings)
1920
AutoRefreshTimeTolerance = $"{(settings.AutoRefreshTimeMax - settings.AutoRefreshTimeMin) / 2}";
2021

2122
IsAutoNPC = settings.IsAutoNPC;
23+
IsNPCOverflow = settings.IsNPCOverflow;
24+
2225
AutoNPCPercent = settings.AutoNPCPercent.ToString();
26+
AutoNPCWarehousePercent = settings.AutoNPCWarehousePercent.ToString();
2327
AutoNPCWood = settings.AutoNPCWood.ToString();
2428
AutoNPCClay = settings.AutoNPCClay.ToString();
2529
AutoNPCIron = settings.AutoNPCIron.ToString();
@@ -32,6 +36,7 @@ public void CopyFrom(MainCore.Models.Database.VillageSetting settings)
3236
public void CopyTo(MainCore.Models.Database.VillageSetting settings)
3337
{
3438
settings.IsUseHeroRes = IsUseHeroRes;
39+
settings.IsIgnoreRomanAdvantage = IsIgnoreRomanAdvantage;
3540
settings.IsInstantComplete = IsInstantComplete;
3641
settings.InstantCompleteTime = int.Parse(InstantCompleteTime);
3742
if (settings.InstantCompleteTime < 0) settings.InstantCompleteTime = 0;
@@ -47,7 +52,9 @@ public void CopyTo(MainCore.Models.Database.VillageSetting settings)
4752
settings.AutoRefreshTimeMax = autoRefreshTime + autoRefreshTimeTolerance;
4853

4954
settings.IsAutoNPC = IsAutoNPC;
55+
settings.IsNPCOverflow = IsNPCOverflow;
5056
settings.AutoNPCPercent = int.Parse(AutoNPCPercent);
57+
settings.AutoNPCWarehousePercent = int.Parse(AutoNPCWarehousePercent);
5158
if (settings.AutoRefreshTimeMin < 4) settings.AutoRefreshTimeMin = 4;
5259
settings.AutoNPCWood = int.Parse(AutoNPCWood);
5360
settings.AutoNPCClay = int.Parse(AutoNPCClay);
@@ -117,6 +124,14 @@ public bool IsUseHeroRes
117124
set => this.RaiseAndSetIfChanged(ref _isUseHeroRes, value);
118125
}
119126

127+
private bool _isIgnoreRomanAdvantage;
128+
129+
public bool IsIgnoreRomanAdvantage
130+
{
131+
get => _isIgnoreRomanAdvantage;
132+
set => this.RaiseAndSetIfChanged(ref _isIgnoreRomanAdvantage, value);
133+
}
134+
120135
private bool _isInstantComplete;
121136

122137
public bool IsInstantComplete
@@ -181,6 +196,14 @@ public bool IsAutoNPC
181196
set => this.RaiseAndSetIfChanged(ref _isAutoNPC, value);
182197
}
183198

199+
private bool _isNPCOverflow;
200+
201+
public bool IsNPCOverflow
202+
{
203+
get => _isNPCOverflow;
204+
set => this.RaiseAndSetIfChanged(ref _isNPCOverflow, value);
205+
}
206+
184207
private string _autoNPCPercent;
185208

186209
public string AutoNPCPercent
@@ -189,6 +212,14 @@ public string AutoNPCPercent
189212
set => this.RaiseAndSetIfChanged(ref _autoNPCPercent, value);
190213
}
191214

215+
private string _autoNPCWarehousePercent;
216+
217+
public string AutoNPCWarehousePercent
218+
{
219+
get => _autoNPCWarehousePercent;
220+
set => this.RaiseAndSetIfChanged(ref _autoNPCWarehousePercent, value);
221+
}
222+
192223
private string _autoNPCWood;
193224

194225
public string AutoNPCWood

WPFUI/Views/Tabs/Villages/SettingsPage.xaml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,36 @@
2121
<Button x:Name="ExportButton" Grid.Column="1" Content="Export" FontSize="15" Margin="5,0,5,0" />
2222
<Button x:Name="SaveButton" Grid.Column="2" Content="Save" FontSize="15" FontWeight="Normal" Margin="5,0,5,0" />
2323
</Grid>
24-
25-
<StackPanel Grid.Row="1" Margin="10,0,10,0">
24+
<ScrollViewer VerticalScrollBarVisibility = "Auto" Grid.Row="1" Margin="10,0,10,0">
2625
<StackPanel>
27-
<TextBlock TextWrapping="Wrap" Text="Build settings" VerticalAlignment="Center" FontWeight="Bold" />
28-
<CheckBox x:Name="UseHeroResCheckBox" Content="Use resource from hero inventory" />
29-
<controls:CheckBoxWithInputUc x:Name="Complete" />
30-
<controls:CheckBoxWithInputUc x:Name="WatchAds" />
31-
</StackPanel>
26+
<StackPanel>
27+
<TextBlock TextWrapping="Wrap" Text="Build settings" VerticalAlignment="Center" FontWeight="Bold" />
28+
<CheckBox x:Name="UseHeroResCheckBox" Content="Use resource from hero inventory" />
29+
<CheckBox x:Name="IgnoreRomanAdvantageCheckBox" Content="Ignore Roman tribe's advantage" />
30+
<controls:CheckBoxWithInputUc x:Name="Complete" />
31+
<controls:CheckBoxWithInputUc x:Name="WatchAds" />
32+
</StackPanel>
3233

33-
<StackPanel>
34-
<TextBlock TextWrapping="Wrap" Text="Refresh settings" VerticalAlignment="Center" FontWeight="Bold" />
35-
<CheckBox x:Name="RefreshCheckBox" Content="Auto refresh village" />
36-
<controls:ToleranceUc x:Name="Refresh" />
37-
</StackPanel>
34+
<StackPanel>
35+
<TextBlock TextWrapping="Wrap" Text="Refresh settings" VerticalAlignment="Center" FontWeight="Bold" />
36+
<CheckBox x:Name="RefreshCheckBox" Content="Auto refresh village" />
37+
<controls:ToleranceUc x:Name="Refresh" />
38+
</StackPanel>
3839

39-
<StackPanel>
40-
<TextBlock TextWrapping="Wrap" Text="NPC settings" VerticalAlignment="Center" FontWeight="Bold" />
41-
<controls:CheckBoxWithInputUc x:Name="AutoNPC" />
42-
<controls:ResourcesUc x:Name="AutoNPCRatio" />
43-
</StackPanel>
40+
<StackPanel>
41+
<TextBlock TextWrapping="Wrap" Text="NPC settings" VerticalAlignment="Center" FontWeight="Bold" />
42+
<CheckBox x:Name="NPCCheckBox" Content="NPC even if after NPC resource is overflow (this may make TBS stuck)" />
43+
<controls:CheckBoxWithInputUc x:Name="AutoNPC" />
44+
<controls:CheckBoxWithInputUc x:Name="AutoNPCWarehouse" />
45+
<controls:ResourcesUc x:Name="AutoNPCRatio" />
46+
</StackPanel>
4447

45-
<StackPanel>
46-
<TextBlock TextWrapping="Wrap" Text="Troop settings" VerticalAlignment="Center" FontWeight="Bold" />
47-
<CheckBox x:Name="TroopUpgradeCheckBox" Content="Auto improve troop" />
48-
<controls:TroopsWithCheckBoxUc x:Name="TroopUpgrade" />
48+
<StackPanel>
49+
<TextBlock TextWrapping="Wrap" Text="Troop settings" VerticalAlignment="Center" FontWeight="Bold" />
50+
<CheckBox x:Name="TroopUpgradeCheckBox" Content="Auto improve troop" />
51+
<controls:TroopsWithCheckBoxUc x:Name="TroopUpgrade" />
52+
</StackPanel>
4953
</StackPanel>
50-
</StackPanel>
54+
</ScrollViewer>
5155
</Grid>
5256
</reactiveui:ReactivePage>

WPFUI/Views/Tabs/Villages/SettingsPage.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public SettingsPage()
1717
WatchAds.ViewModel = new("Using ads upgrade button when building time is longer than", "min(s)");
1818
Refresh.ViewModel = new("Refresh interval", "min(s)");
1919
AutoNPC.ViewModel = new("Auto NPC when crop is more than", "% of granary");
20+
AutoNPCWarehouse.ViewModel = new("Auto NPC when any resource is more than", "% of warehouse");
2021
AutoNPCRatio.ViewModel = new("Ratio");
2122
TroopUpgrade.ViewModel = new("Troop will be upgraded");
2223
this.WhenActivated(d =>
@@ -26,6 +27,7 @@ public SettingsPage()
2627
this.BindCommand(ViewModel, vm => vm.SaveCommand, v => v.SaveButton).DisposeWith(d);
2728

2829
this.Bind(ViewModel, vm => vm.Settings.IsUseHeroRes, v => v.UseHeroResCheckBox.IsChecked).DisposeWith(d);
30+
this.Bind(ViewModel, vm => vm.Settings.IsIgnoreRomanAdvantage, v => v.IgnoreRomanAdvantageCheckBox.IsChecked).DisposeWith(d);
2931
this.Bind(ViewModel, vm => vm.Settings.IsInstantComplete, v => v.Complete.ViewModel.IsChecked).DisposeWith(d);
3032
this.Bind(ViewModel, vm => vm.Settings.InstantCompleteTime, v => v.Complete.ViewModel.Value).DisposeWith(d);
3133
this.Bind(ViewModel, vm => vm.Settings.IsAdsUpgrade, v => v.WatchAds.ViewModel.IsChecked).DisposeWith(d);
@@ -36,7 +38,9 @@ public SettingsPage()
3638
this.Bind(ViewModel, vm => vm.Settings.AutoRefreshTimeTolerance, v => v.Refresh.ViewModel.ToleranceValue).DisposeWith(d);
3739

3840
this.Bind(ViewModel, vm => vm.Settings.IsAutoNPC, v => v.AutoNPC.ViewModel.IsChecked).DisposeWith(d);
41+
this.Bind(ViewModel, vm => vm.Settings.IsNPCOverflow, v => v.NPCCheckBox.IsChecked).DisposeWith(d);
3942
this.Bind(ViewModel, vm => vm.Settings.AutoNPCPercent, v => v.AutoNPC.ViewModel.Value).DisposeWith(d);
43+
this.Bind(ViewModel, vm => vm.Settings.AutoNPCWarehousePercent, v => v.AutoNPCWarehouse.ViewModel.Value).DisposeWith(d);
4044
this.Bind(ViewModel, vm => vm.Settings.AutoNPCWood, v => v.AutoNPCRatio.ViewModel.Wood).DisposeWith(d);
4145
this.Bind(ViewModel, vm => vm.Settings.AutoNPCClay, v => v.AutoNPCRatio.ViewModel.Clay).DisposeWith(d);
4246
this.Bind(ViewModel, vm => vm.Settings.AutoNPCIron, v => v.AutoNPCRatio.ViewModel.Iron).DisposeWith(d);

0 commit comments

Comments
 (0)