Skip to content

Commit

Permalink
🚧 Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Nov 16, 2023
1 parent d34a5d3 commit 9e4c483
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
<ProjectReference Include="..\BD.WTTS.Client.Avalonia\BD.WTTS.Client.Avalonia.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
53 changes: 53 additions & 0 deletions src/BD.WTTS.Client.Plugins.SteamIdleCard/Models/IdleApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using BD.SteamClient.Models;
using BD.SteamClient.Models.Idle;

namespace BD.WTTS.Models;

public class IdleApp : ReactiveObject
{
public SteamApp App { get; }

public Badge Badge { get; }

public uint AppId
{
get
{
return App.AppId;
}

set
{
App.AppId = value;
this.RaisePropertyChanged();
}
}

public string? AppName
{
get
{
return App.Name;
}

set
{
App.Name = value;
this.RaisePropertyChanged();
}
}

public string? Tags
{
get
{
return $"剩余掉落卡片:{Badge.CardsRemaining} | 游玩时间:{Badge.HoursPlayed}";
}
}

public IdleApp(Badge badge)
{
Badge = badge;
App = new SteamApp(badge.AppId) { Name = badge.AppName };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BD.SteamClient.Models.Idle;
using BD.SteamClient.Services;
using BD.WTTS.UI.Views.Pages;
using System;
using System.Linq;

namespace BD.WTTS.UI.ViewModels;
Expand Down Expand Up @@ -151,7 +152,7 @@ await IWindowManager.Instance.ShowTaskDialogAsync(vm, Strings.Steam_Login,

private void ChangeRunTxt()
{
var count = IdleGameList.Count(x => x.Process != null);
var count = IdleGameList.Count(x => x.App.Process != null);
RuningCountTxt = Strings.Idle_RuningCount.Format(count, IdleGameList.Count);
RunState = count > 0;
}
Expand All @@ -161,14 +162,14 @@ private async Task SteamAppsSort()
try
{
IEnumerable<Badge> badges;
if (IdleSequentital == IdleSequentital.Mostvalue)
{
(UserIdleInfo, badges) = await IdleCard.GetBadgesAsync(SteamConnectService.Current.CurrentSteamUser!.SteamId64.ToString(), true);
}
else
{
(UserIdleInfo, badges) = await IdleCard.GetBadgesAsync(SteamConnectService.Current.CurrentSteamUser!.SteamId64.ToString());
}
//if (IdleSequentital == IdleSequentital.Mostvalue)
//{
(UserIdleInfo, badges) = await IdleCard.GetBadgesAsync(SteamConnectService.Current.CurrentSteamUser!.SteamId64.ToString(), true);
//}
//else
//{
// (UserIdleInfo, badges) = await IdleCard.GetBadgesAsync(SteamConnectService.Current.CurrentSteamUser!.SteamId64.ToString());
//}

Badges.Clear();
TotalCardsRemaining = 0;
Expand All @@ -189,13 +190,13 @@ private async Task SteamAppsSort()
return;
}

var apps = Enumerable.Empty<SteamApp>();
var apps = Enumerable.Empty<IdleApp>();
apps = IdleSequentital switch
{
IdleSequentital.LeastCards => Badges.OrderBy(o => o.CardsRemaining).Select(s => new SteamApp(s.AppId) { Name = s.AppName }),
IdleSequentital.Mostcards => Badges.OrderByDescending(o => o.CardsRemaining).Select(s => new SteamApp(s.AppId) { Name = s.AppName }),
IdleSequentital.Mostvalue => Badges.OrderByDescending(o => o.RegularAvgPrice).Select(s => new SteamApp(s.AppId) { Name = s.AppName }),
_ => Badges.Select(s => new SteamApp(s.AppId) { Name = s.AppName }),
IdleSequentital.LeastCards => Badges.OrderBy(o => o.CardsRemaining).Select(s => new IdleApp(s)),
IdleSequentital.Mostcards => Badges.OrderByDescending(o => o.CardsRemaining).Select(s => new IdleApp(s)),
IdleSequentital.Mostvalue => Badges.OrderByDescending(o => o.RegularAvgPrice).Select(s => new IdleApp(s)),
_ => Badges.Select(s => new IdleApp(s)),
};

//不应该使用 SteamConnectService 的 apps
Expand Down Expand Up @@ -233,7 +234,7 @@ private void StartIdle()
{
if (IdleRule == IdleRule.OneThenMany)
{
var canIdles = Badges.Where(z => z.MinutesPlayed / 60 >= MinRunTime).Select(s => s.AppId);
var canIdles = Badges.Where(z => z.HoursPlayed >= MinRunTime).Select(s => s.AppId);
var multi = IdleGameList.Where(x => canIdles.Contains(x.AppId));
if (multi.Count() >= 1)
{
Expand All @@ -248,7 +249,7 @@ private void StartIdle()
}
else
{
var canIdles = Badges.Where(z => z.MinutesPlayed / 60 < MinRunTime).Select(s => s.AppId);
var canIdles = Badges.Where(z => z.HoursPlayed < MinRunTime).Select(s => s.AppId);
var multi = IdleGameList.Where(x => canIdles.Contains(x.AppId));
if (multi.Count() >= 2)
{
Expand Down Expand Up @@ -279,13 +280,13 @@ private void RunNextIdle()
/// 单独运行游戏
/// </summary>
/// <param name="item"></param>
private void StartSoloIdle(SteamApp item)
private void StartSoloIdle(IdleApp item)
{
SteamConnectService.Current.RuningSteamApps.TryGetValue(item.AppId, out var runState);
if (runState == null)
{
item.StartSteamAppProcess();
SteamConnectService.Current.RuningSteamApps.TryAdd(item.AppId, item);
item.App.StartSteamAppProcess();
SteamConnectService.Current.RuningSteamApps.TryAdd(item.AppId, item.App);
}
else
{
Expand All @@ -295,7 +296,7 @@ private void StartSoloIdle(SteamApp item)
}
else
{
item.Process = runState.Process;
item.App.Process = runState.Process;
}
}
}
Expand All @@ -309,14 +310,14 @@ private void StartMultipleIdle()
if (badge == null)
continue;

if (badge.MinutesPlayed / 60 >= MinRunTime)
StopSoloIdle(item);
if (badge.HoursPlayed >= MinRunTime)
StopSoloIdle(item.App);

if (badge.MinutesPlayed / 60 < MinRunTime && IdleGameList.Count(x => x.Process != null) < MaxIdleCount)
if (badge.HoursPlayed < MinRunTime && IdleGameList.Count(x => x.App.Process != null) < MaxIdleCount)
StartSoloIdle(item);
}

if (!IdleGameList.Any(x => x.Process != null))
if (!IdleGameList.Any(x => x.App.Process != null))
StartIdle();

}
Expand All @@ -333,12 +334,12 @@ private void StopIdle()
{
runState.Process?.KillEntireProcessTree();
SteamConnectService.Current.RuningSteamApps.TryRemove(item.AppId, out var remove);
item.Process = null;
item.App.Process = null;
}
else
{
item.Process = null;
SteamConnectService.Current.RuningSteamApps.TryAdd(item.AppId, item);
item.App.Process = null;
SteamConnectService.Current.RuningSteamApps.TryAdd(item.AppId, item.App);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public sealed partial class IdleCardPageViewModel
/// 正在挂卡游戏
/// </summary>
[Reactive]
public ObservableCollection<SteamApp> IdleGameList { get; set; } = new();
public ObservableCollection<IdleApp> IdleGameList { get; set; } = new();

/// <summary>
/// 用户徽章和卡片数据
/// </summary>
[Reactive]
public ObservableCollection<Badge> Badges { get; set; } = new();

[Reactive]
public TimeSpan IdleTime { get; set; }

[Reactive]
public int TotalCardsRemaining { get; set; }

Expand All @@ -52,7 +55,7 @@ public sealed partial class IdleCardPageViewModel
/// 当前挂卡游戏
/// </summary>
[Reactive]
public SteamApp? CurrentIdle { get; set; }
public IdleApp? CurrentIdle { get; set; }

/// <summary>
/// 挂卡规则
Expand Down
Loading

0 comments on commit 9e4c483

Please sign in to comment.