2023-03-03 19:25:33 +00:00
|
|
|
|
/* ProfileInfo.cs
|
|
|
|
|
* License: NCSA Open Source License
|
|
|
|
|
*
|
2024-07-21 13:15:27 +01:00
|
|
|
|
* Copyright: SPT
|
2023-03-03 19:25:33 +00:00
|
|
|
|
* AUTHORS:
|
|
|
|
|
* waffle.lord
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
using SPT.Launcher.Helpers;
|
|
|
|
|
using SPT.Launcher.MiniCommon;
|
|
|
|
|
using SPT.Launcher.Models.SPT;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.IO;
|
2024-09-02 07:53:58 +00:00
|
|
|
|
using SPT.Launcher.Utilities;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
namespace SPT.Launcher.Models.Launcher
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
public class ProfileInfo : NotifyPropertyChangedBase
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _username;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string Username
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _username;
|
|
|
|
|
set => SetProperty(ref _username, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _nickname;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string Nickname
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _nickname;
|
|
|
|
|
set => SetProperty(ref _nickname, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _sideImage;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string SideImage
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _sideImage;
|
|
|
|
|
set => SetProperty(ref _sideImage, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _side;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string Side
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _side;
|
|
|
|
|
set => SetProperty(ref _side, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private string _level;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public string Level
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _level;
|
|
|
|
|
set => SetProperty(ref _level, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _XPLevelProgress;
|
|
|
|
|
public int XPLevelProgress
|
|
|
|
|
{
|
|
|
|
|
get => _XPLevelProgress;
|
2024-09-02 07:53:58 +00:00
|
|
|
|
set => SetProperty(ref _XPLevelProgress, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private long _currentXP;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public long CurrentExp
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _currentXP;
|
|
|
|
|
set => SetProperty(ref _currentXP, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private long _remainingExp;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public long RemainingExp
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _remainingExp;
|
|
|
|
|
set => SetProperty(ref _remainingExp, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private long _nextLvlExp;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public long NextLvlExp
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _nextLvlExp;
|
|
|
|
|
set => SetProperty(ref _nextLvlExp, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private bool _hasData;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public bool HasData
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _hasData;
|
|
|
|
|
set => SetProperty(ref _hasData, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string MismatchMessage => VersionMismatch ? LocalizationProvider.Instance.profile_version_mismath : null;
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private bool _versionMismatch;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
public bool VersionMismatch
|
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _versionMismatch;
|
|
|
|
|
set => SetProperty(ref _versionMismatch, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private SPTData _spt;
|
2024-05-21 20:15:19 +01:00
|
|
|
|
public SPTData SPT
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
get => _spt;
|
|
|
|
|
set => SetProperty(ref _spt, value);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
public void UpdateDisplayedProfile(ProfileInfo pInfo)
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
if (pInfo.Side == null || string.IsNullOrWhiteSpace(pInfo.Side) || pInfo.Side == "unknown") return;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
|
|
|
|
HasData = true;
|
2024-09-02 07:53:58 +00:00
|
|
|
|
Nickname = pInfo.Nickname;
|
|
|
|
|
Side = pInfo.Side;
|
|
|
|
|
SideImage = pInfo.SideImage;
|
|
|
|
|
Level = pInfo.Level;
|
|
|
|
|
CurrentExp = pInfo.CurrentExp;
|
|
|
|
|
NextLvlExp = pInfo.NextLvlExp;
|
|
|
|
|
RemainingExp = pInfo.RemainingExp;
|
|
|
|
|
XPLevelProgress = pInfo.XPLevelProgress;
|
|
|
|
|
|
|
|
|
|
SPT = pInfo.SPT;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-21 20:15:19 +01:00
|
|
|
|
/// Checks if the SPT versions are compatible (non-major changes)
|
2023-03-03 19:25:33 +00:00
|
|
|
|
/// </summary>
|
2024-09-02 07:53:58 +00:00
|
|
|
|
/// <param name="currentVersion"></param>
|
|
|
|
|
/// <param name="expectedVersion"></param>
|
2023-03-03 19:25:33 +00:00
|
|
|
|
/// <returns></returns>
|
2024-09-02 07:53:58 +00:00
|
|
|
|
private bool CompareVersions(string currentVersion, string expectedVersion)
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-09-02 07:53:58 +00:00
|
|
|
|
if (expectedVersion == "") return false;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
var v1 = new SPTVersion(currentVersion);
|
|
|
|
|
var v2 = new SPTVersion(expectedVersion);
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
|
|
|
|
// check 'X'.x.x
|
|
|
|
|
if (v1.Major != v2.Major) return false;
|
|
|
|
|
|
|
|
|
|
// check x.'X'.x
|
|
|
|
|
if(v1.Minor != v2.Minor) return false;
|
|
|
|
|
|
|
|
|
|
//otherwise probably good
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProfileInfo(ServerProfileInfo serverProfileInfo)
|
|
|
|
|
{
|
|
|
|
|
Username = serverProfileInfo.username;
|
|
|
|
|
Nickname = serverProfileInfo.nickname;
|
|
|
|
|
Side = serverProfileInfo.side;
|
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
SPT = serverProfileInfo.SPTData;
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
2024-05-21 20:15:19 +01:00
|
|
|
|
if (SPT != null)
|
2023-03-03 19:25:33 +00:00
|
|
|
|
{
|
2024-05-21 20:15:19 +01:00
|
|
|
|
VersionMismatch = !CompareVersions(SPT.version, ServerManager.GetVersion());
|
2023-03-03 19:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SideImage = Path.Combine(ImageRequest.ImageCacheFolder, $"side_{Side.ToLower()}.png");
|
|
|
|
|
|
2024-09-02 07:53:58 +00:00
|
|
|
|
HasData = Side != null && !string.IsNullOrWhiteSpace(Side) && Side != "unknown";
|
2023-03-03 19:25:33 +00:00
|
|
|
|
|
|
|
|
|
Level = serverProfileInfo.currlvl.ToString();
|
|
|
|
|
CurrentExp = serverProfileInfo.currexp;
|
|
|
|
|
|
|
|
|
|
//check if player is max level
|
|
|
|
|
if (Level == serverProfileInfo.maxlvl.ToString())
|
|
|
|
|
{
|
|
|
|
|
NextLvlExp = 0;
|
|
|
|
|
XPLevelProgress = 100;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NextLvlExp = serverProfileInfo.nextlvl;
|
|
|
|
|
RemainingExp = NextLvlExp - CurrentExp;
|
|
|
|
|
|
|
|
|
|
long currentLvlTotal = NextLvlExp - serverProfileInfo.prevexp;
|
|
|
|
|
|
|
|
|
|
XPLevelProgress = (int)Math.Floor((((double)currentLvlTotal) - RemainingExp) / currentLvlTotal * 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|