Skip to content

Commit 96a43a1

Browse files
authored
Release 2.5.0 (#211)
- Re-desgin Farming tab UI (time setting works now) - Remove TTWars from auto build system (you will need to compile it in local and fix parser system yourself because of TTWars's UI changes) (why I (VINAGHOST) don't fix ? I don't play on TTWars and since no donations for that, i prefer on Official version)
1 parent 4f516f9 commit 96a43a1

File tree

16 files changed

+227
-341
lines changed

16 files changed

+227
-341
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
strategy:
1111
matrix:
12-
server: [TRAVIAN_OFFICIAL, TTWARS]
12+
server: [TRAVIAN_OFFICIAL]
1313
runs-on: windows-2019
1414
steps:
1515
- name: Setup dotnet

.github/workflows/hotfix.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
needs: version
5050
strategy:
5151
matrix:
52-
server: [TRAVIAN_OFFICIAL, TTWARS]
52+
server: [TRAVIAN_OFFICIAL]
5353
steps:
5454
- name: Setup dotnet
5555
uses: actions/setup-dotnet@v2
@@ -84,15 +84,14 @@ jobs:
8484
- name: Archive release
8585
run: |
8686
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" ../; cd ..
87-
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
8887
8988
- name: Create release
9089
uses: ncipollo/release-action@v1
9190
with:
9291
name: TBS-${{needs.version.outputs.version}}
9392
tag: ${{needs.version.outputs.version}}
9493
commit: master
95-
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
94+
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip"
9695
token: ${{ secrets.GITHUB_TOKEN }}
9796
body: |
9897
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
@@ -124,7 +123,7 @@ jobs:
124123
needs: release
125124
strategy:
126125
matrix:
127-
server: [TRAVIAN_OFFICIAL, TTWARS]
126+
server: [TRAVIAN_OFFICIAL]
128127
steps:
129128
- name: Delete artifact
130129
uses: geekyeggo/delete-artifact@v1

.github/workflows/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
needs: version
4949
strategy:
5050
matrix:
51-
server: [TRAVIAN_OFFICIAL, TTWARS]
51+
server: [TRAVIAN_OFFICIAL]
5252
steps:
5353
- name: Setup dotnet
5454
uses: actions/setup-dotnet@v2
@@ -83,7 +83,6 @@ jobs:
8383
- name: Archive release
8484
run: |
8585
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial.zip" ../; cd ..
86-
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
8786
8887
- name: Create release
8988
uses: ncipollo/release-action@v1
@@ -122,7 +121,7 @@ jobs:
122121
needs: release
123122
strategy:
124123
matrix:
125-
server: [TRAVIAN_OFFICIAL, TTWARS]
124+
server: [TRAVIAN_OFFICIAL]
126125
steps:
127126
- name: Delete artifact
128127
uses: geekyeggo/delete-artifact@v1

MainCore/Services/Implementations/TaskManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private void Loop(int index)
159159
else
160160
{
161161
var result = poliResult.Result;
162+
if (result is null) result = poliResult.FinalHandledResult;
162163
if (result.IsFailed)
163164
{
164165
task.Stage = TaskStage.Waiting;

MainCore/Tasks/Update/UpdateInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FluentResults;
22
using MainCore.Enums;
3+
using MainCore.Errors;
34
using MainCore.Models.Database;
45
using ModuleCore.Parser;
56
using Splat;
@@ -26,6 +27,7 @@ public UpdateInfo(int accountId, CancellationToken cancellationToken = default)
2627

2728
public override Result Execute()
2829
{
30+
if (CancellationToken.IsCancellationRequested) return Result.Fail(new Cancel());
2931
UpdateAccountInfo();
3032
UpdateVillageList();
3133
UpdateHeroInfo();

WPFUI/AppBoostrapper.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using WPFUI.ViewModels.Tabs;
1010
using WPFUI.ViewModels.Tabs.Villages;
1111
using WPFUI.ViewModels.Uc.BuildView;
12-
using WPFUI.ViewModels.Uc.FarmingView;
1312
using WPFUI.ViewModels.Uc.MainView;
1413

1514
namespace WPFUI
@@ -73,10 +72,6 @@ public static IServiceCollection ConfigureUcViewModel(this IServiceCollection se
7372
services.AddSingleton<MainButtonPanelViewModel>();
7473
services.AddSingleton<AccountListViewModel>();
7574

76-
// farming view
77-
services.AddSingleton<FarmListViewModel>();
78-
services.AddSingleton<FarmContentViewModel>();
79-
8075
// build view
8176
services.AddSingleton<BuildingListViewModel>();
8277
services.AddSingleton<CurrentBuildingListViewModel>();

WPFUI/ViewModels/Tabs/FarmingViewModel.cs

Lines changed: 170 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
1-
using MainCore.Tasks.Attack;
1+
using DynamicData;
2+
using DynamicData.Kernel;
3+
using MainCore.Tasks.Attack;
4+
using MainCore.Tasks.Update;
25
using ReactiveUI;
36
using System;
7+
using System.Collections.ObjectModel;
8+
using System.Drawing;
49
using System.Linq;
510
using System.Reactive;
11+
using System.Reactive.Concurrency;
12+
using System.Reactive.Linq;
613
using System.Threading.Tasks;
714
using System.Windows;
15+
using WPFUI.Models;
816
using WPFUI.ViewModels.Abstract;
917

1018
namespace WPFUI.ViewModels.Tabs
1119
{
1220
public class FarmingViewModel : AccountTabBaseViewModel
1321
{
22+
public ReactiveCommand<Unit, Unit> StartCommand { get; }
23+
public ReactiveCommand<Unit, Unit> StopCommand { get; }
24+
public ReactiveCommand<Unit, Unit> SaveCommand { get; }
25+
public ReactiveCommand<ListBoxItem, Unit> LoadCommand { get; }
26+
public ReactiveCommand<Unit, Unit> ActiveCommand { get; }
27+
public ReactiveCommand<Unit, Unit> RefreshCommand { get; }
28+
1429
public FarmingViewModel()
1530
{
1631
StartCommand = ReactiveCommand.CreateFromTask(StartTask);
1732
StopCommand = ReactiveCommand.CreateFromTask(StopTask);
33+
34+
SaveCommand = ReactiveCommand.CreateFromTask(SaveData);
35+
LoadCommand = ReactiveCommand.Create<ListBoxItem>(LoadFarm);
36+
37+
ActiveCommand = ReactiveCommand.CreateFromTask(ActiveTask, this.WhenAnyValue(vm => vm.CurrentFarm).Select(x => x is not null));
38+
RefreshCommand = ReactiveCommand.CreateFromTask(RefreshTask);
39+
40+
this.WhenAnyValue(vm => vm.CurrentFarm).BindTo(_selectorViewModel, vm => vm.Farm);
41+
this.WhenAnyValue(vm => vm.CurrentFarm).InvokeCommand(LoadCommand);
42+
_eventManager.FarmListUpdate += OnFarmListUpdate;
1843
}
1944

2045
private async Task StartTask()
@@ -61,11 +86,152 @@ await Task.Run(() =>
6186
MessageBox.Show("Removed send farm task from queue");
6287
}
6388

64-
protected override void Init(int id)
89+
public async Task SaveData()
6590
{
91+
if (CurrentFarm is null) return;
92+
_waitingWindow.Show("Saving ...");
93+
await Task.Run(() =>
94+
{
95+
using var context = _contextFactory.CreateDbContext();
96+
var settings = context.AccountsSettings.Find(_selectorViewModel.Account.Id);
97+
settings.FarmIntervalMin = Interval - DiffInterval;
98+
if (settings.FarmIntervalMin < 0) settings.FarmIntervalMin = 0;
99+
settings.FarmIntervalMax = Interval + DiffInterval;
100+
context.Update(settings);
101+
context.SaveChanges();
102+
});
103+
_waitingWindow.Close();
104+
MessageBox.Show("Saved");
66105
}
67106

68-
public ReactiveCommand<Unit, Unit> StartCommand { get; }
69-
public ReactiveCommand<Unit, Unit> StopCommand { get; }
107+
public void LoadFarm(ListBoxItem farm)
108+
{
109+
if (farm is null)
110+
{
111+
ContentButton = "=====================";
112+
}
113+
else
114+
{
115+
using var context = _contextFactory.CreateDbContext();
116+
var setting = context.FarmsSettings.Find(farm.Id);
117+
ContentButton = setting.IsActive ? "Deactive" : "Active";
118+
}
119+
}
120+
121+
public async Task ActiveTask()
122+
{
123+
if (CurrentFarm is null) return;
124+
_waitingWindow.Show("Processing ...");
125+
var active = true;
126+
await Task.Run(() =>
127+
{
128+
using var context = _contextFactory.CreateDbContext();
129+
var setting = context.FarmsSettings.Find(CurrentFarm.Id);
130+
setting.IsActive = !setting.IsActive;
131+
active = setting.IsActive;
132+
context.Update(setting);
133+
context.SaveChanges();
134+
});
135+
_waitingWindow.Close();
136+
MessageBox.Show("Done");
137+
CurrentFarm.Color = active ? Color.ForestGreen.ToMediaColor() : Color.Red.ToMediaColor();
138+
ContentButton = active ? "Deactive" : "Active";
139+
}
140+
141+
private Task RefreshTask()
142+
{
143+
var accountId = _selectorViewModel.Account.Id;
144+
var tasks = _taskManager.GetList(accountId).OfType<UpdateFarmList>();
145+
if (!tasks.Any())
146+
{
147+
_taskManager.Add(accountId, new UpdateFarmList(accountId));
148+
}
149+
else
150+
{
151+
var updateFarmList = tasks.First();
152+
updateFarmList.ExecuteAt = DateTime.Now;
153+
_taskManager.Update(accountId);
154+
}
155+
return Task.CompletedTask;
156+
}
157+
158+
private void OnFarmListUpdate(int accountId)
159+
{
160+
if (!IsActive) return;
161+
if (AccountId != accountId) return;
162+
163+
LoadData(accountId);
164+
}
165+
166+
private void LoadData(int id)
167+
{
168+
using var context = _contextFactory.CreateDbContext();
169+
var farms = context.Farms
170+
.Where(x => x.AccountId == id)
171+
.AsList()
172+
.Select(farm =>
173+
{
174+
var farmSetting = context.FarmsSettings.Find(farm.Id);
175+
var color = farmSetting.IsActive ? Color.ForestGreen.ToMediaColor() : Color.Red.ToMediaColor();
176+
return new ListBoxItem(farm.Id, farm.Name, color);
177+
}).ToList();
178+
179+
var settings = context.AccountsSettings.Find(_selectorViewModel.Account.Id);
180+
181+
RxApp.MainThreadScheduler.Schedule(() =>
182+
{
183+
FarmList.Clear();
184+
FarmList.AddRange(farms);
185+
if (farms.Any())
186+
{
187+
CurrentFarm = FarmList[0];
188+
}
189+
else
190+
{
191+
CurrentFarm = null;
192+
}
193+
194+
Interval = (settings.FarmIntervalMax + settings.FarmIntervalMin) / 2;
195+
DiffInterval = (settings.FarmIntervalMax - settings.FarmIntervalMin) / 2;
196+
});
197+
}
198+
199+
protected override void Init(int accountId)
200+
{
201+
LoadData(accountId);
202+
}
203+
204+
private int _interval;
205+
206+
public int Interval
207+
{
208+
get => _interval;
209+
set => this.RaiseAndSetIfChanged(ref _interval, value);
210+
}
211+
212+
private int _diffInterval;
213+
214+
public int DiffInterval
215+
{
216+
get => _diffInterval;
217+
set => this.RaiseAndSetIfChanged(ref _diffInterval, value);
218+
}
219+
220+
private string _contentButton;
221+
222+
public string ContentButton
223+
{
224+
get => _contentButton;
225+
set => this.RaiseAndSetIfChanged(ref _contentButton, value);
226+
}
227+
228+
public ObservableCollection<ListBoxItem> FarmList { get; } = new();
229+
private ListBoxItem _currentFarm;
230+
231+
public ListBoxItem CurrentFarm
232+
{
233+
get => _currentFarm;
234+
set => this.RaiseAndSetIfChanged(ref _currentFarm, value);
235+
}
70236
}
71237
}

0 commit comments

Comments
 (0)