Fix compile errors

This commit is contained in:
CWX
2025-01-10 22:18:49 +00:00
parent edc11a63ee
commit b9316fee63
4 changed files with 166 additions and 119 deletions
+160 -113
View File
@@ -31,12 +31,14 @@ public class ProfileController
protected LocalisationService _localisationService;
protected SeasonalEventService _seasonalEventService;
// TODO: MailSendService mailSendService: MailSendService
protected PlayerScavGenerator _playerScavGenerator;
// TODO: EventOutputHolder eventOutputHolder: EventOutputHolder
protected TraderHelper _traderHelper;
protected DialogueHelper _dialogueHelper;
protected QuestHelper _questHelper;
// TODO: MailSendService mailSendService: MailSendService
protected PlayerScavGenerator _playerScavGenerator;
// TODO: EventOutputHolder eventOutputHolder: EventOutputHolder
protected TraderHelper _traderHelper;
protected DialogueHelper _dialogueHelper;
protected QuestHelper _questHelper;
protected ProfileHelper _profileHelper;
public ProfileController(
@@ -90,7 +92,8 @@ public class ProfileController
public MiniProfile GetMiniProfile(string sessionID)
{
var profile = _saveServer.GetProfile(sessionID);
if (profile?.CharacterData == null) {
if (profile?.CharacterData == null)
{
throw new Exception($"Unable to find character data for id: {sessionID}. Profile may be corrupt");
}
@@ -98,36 +101,39 @@ public class ProfileController
var maxlvl = _profileHelper.GetMaxLevel();
// Player hasn't completed profile creation process, send defaults
if (pmc?.Info?.Level == null) {
return new MiniProfile(){
if (pmc?.Info?.Level == null)
{
return new MiniProfile()
{
Username = profile.ProfileInfo?.UserName ?? "",
Nickname = "unknown",
Side= "unknown",
CurrentLevel= 0,
CurrentExperience= 0,
PreviousExperience= 0,
NextLevel= 0,
MaxLevel= maxlvl,
Edition= profile.ProfileInfo?.Edition ?? "",
ProfileId= profile.ProfileInfo?.ProfileId ?? "",
SptData= _profileHelper.GetDefaultSptDataObject(),
Side = "unknown",
CurrentLevel = 0,
CurrentExperience = 0,
PreviousExperience = 0,
NextLevel = 0,
MaxLevel = maxlvl,
Edition = profile.ProfileInfo?.Edition ?? "",
ProfileId = profile.ProfileInfo?.ProfileId ?? "",
SptData = _profileHelper.GetDefaultSptDataObject(),
};
}
var currlvl = pmc.Info.Level;
var nextlvl = _profileHelper.GetExperience((int)(currlvl + 1));
return new MiniProfile(){
Username= profile.ProfileInfo.UserName,
Nickname= pmc.Info.Nickname,
Side= pmc.Info.Side,
CurrentLevel= (int) (pmc.Info.Level),
CurrentExperience= (int) (pmc.Info.Experience ?? 0),
PreviousExperience= currlvl == 0 ? 0 : _profileHelper.GetExperience((int) currlvl),
NextLevel= nextlvl,
MaxLevel= maxlvl,
Edition= profile.ProfileInfo?.Edition ?? "",
ProfileId= profile.ProfileInfo?.ProfileId ?? "",
SptData= profile.SptData,
return new MiniProfile()
{
Username = profile.ProfileInfo.UserName,
Nickname = pmc.Info.Nickname,
Side = pmc.Info.Side,
CurrentLevel = (int)(pmc.Info.Level),
CurrentExperience = (int)(pmc.Info.Experience ?? 0),
PreviousExperience = currlvl == 0 ? 0 : _profileHelper.GetExperience((int)currlvl),
NextLevel = nextlvl,
MaxLevel = maxlvl,
Edition = profile.ProfileInfo?.Edition ?? "",
ProfileId = profile.ProfileInfo?.ProfileId ?? "",
SptData = profile.SptData,
};
}
@@ -175,7 +181,8 @@ public class ProfileController
UpdateInventoryEquipmentId(pmcData);
if (pmcData.UnlockedInfo == null) {
if (pmcData.UnlockedInfo == null)
{
pmcData.UnlockedInfo = new UnlockedInfo { UnlockedProductionRecipe = [] };
}
@@ -191,31 +198,34 @@ public class ProfileController
);
// Create profile
var profileDetails = new SptProfile {
ProfileInfo= account,
CharacterData= new Characters { PmcData = pmcData, ScavData = new()},
Suits= profileTemplate.Suits,
UserBuildData= profileTemplate.UserBuilds,
DialogueRecords= profileTemplate.Dialogues,
SptData= _profileHelper.GetDefaultSptDataObject(),
VitalityData= new(),
InraidData= new (),
InsuranceList= [],
TraderPurchases= new(),
PlayerAchievements= new(),
FriendProfileIds= [],
var profileDetails = new SptProfile
{
ProfileInfo = account,
CharacterData = new Characters { PmcData = pmcData, ScavData = new() },
Suits = profileTemplate.Suits,
UserBuildData = profileTemplate.UserBuilds,
DialogueRecords = profileTemplate.Dialogues,
SptData = _profileHelper.GetDefaultSptDataObject(),
VitalityData = new(),
InraidData = new(),
InsuranceList = [],
TraderPurchases = new(),
PlayerAchievements = new(),
FriendProfileIds = [],
};
_profileFixerService.CheckForAndFixPmcProfileIssues(profileDetails.CharacterData.PmcData);
_saveServer.AddProfile(profileDetails);
if (profileTemplate.Trader.SetQuestsAvailableForStart ?? false) {
if (profileTemplate.Trader.SetQuestsAvailableForStart ?? false)
{
_questHelper.AddAllQuestsToProfile(profileDetails.CharacterData.PmcData, [QuestStatusEnum.AvailableForStart]);
}
// Profile is flagged as wanting quests set to ready to hand in and collect rewards
if (profileTemplate.Trader.SetQuestsAvailableForFinish ?? false) {
if (profileTemplate.Trader.SetQuestsAvailableForFinish ?? false)
{
_questHelper.AddAllQuestsToProfile(profileDetails.CharacterData.PmcData, [
QuestStatusEnum.AvailableForStart,
QuestStatusEnum.Started,
@@ -253,13 +263,16 @@ public class ProfileController
var oldEquipmentId = pmcData.Inventory.Equipment;
pmcData.Inventory.Equipment = _hashUtil.Generate();
foreach (var item in pmcData.Inventory.Items) {
if (item.ParentId == oldEquipmentId) {
foreach (var item in pmcData.Inventory.Items)
{
if (item.ParentId == oldEquipmentId)
{
item.ParentId = pmcData.Inventory.Equipment;
continue;
}
if (item.Id == oldEquipmentId) {
if (item.Id == oldEquipmentId)
{
item.Id = pmcData.Inventory.Equipment;
}
}
@@ -272,30 +285,38 @@ public class ProfileController
*/
protected void AddMissingInternalContainersToProfile(PmcData pmcData)
{
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.HideoutCustomizationStashId)) {
pmcData.Inventory.Items.Add(new (){
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.HideoutCustomizationStashId))
{
pmcData.Inventory.Items.Add(new()
{
Id = pmcData.Inventory.HideoutCustomizationStashId,
Template = ItemTpl.HIDEOUTAREACONTAINER_CUSTOMIZATION,
Template = ItemTpl.HIDEOUTAREACONTAINER_CUSTOMIZATION,
});
}
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.SortingTable)) {
pmcData.Inventory.Items.Add(new (){
Id = pmcData.Inventory.SortingTable,
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.SortingTable))
{
pmcData.Inventory.Items.Add(new()
{
Id = pmcData.Inventory.SortingTable,
Template = ItemTpl.SORTINGTABLE_SORTING_TABLE,
});
}
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.QuestStashItems)) {
pmcData.Inventory.Items.Add(new (){
Id = pmcData.Inventory.QuestStashItems,
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.QuestStashItems))
{
pmcData.Inventory.Items.Add(new()
{
Id = pmcData.Inventory.QuestStashItems,
Template = ItemTpl.STASH_QUESTOFFLINE,
});
}
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.QuestRaidItems)) {
pmcData.Inventory.Items.Add(new (){
Id = pmcData.Inventory.QuestRaidItems,
if (!pmcData.Inventory.Items.Any((item) => item.Id == pmcData.Inventory.QuestRaidItems))
{
pmcData.Inventory.Items.Add(new()
{
Id = pmcData.Inventory.QuestRaidItems,
Template = ItemTpl.STASH_QUESTRAID,
});
}
@@ -307,9 +328,12 @@ public class ProfileController
*/
protected void DeleteProfileBySessionId(string sessionID)
{
if (_saveServer.GetProfiles().ContainsKey(sessionID)) {
if (_saveServer.GetProfiles().ContainsKey(sessionID))
{
_saveServer.DeleteProfileById(sessionID);
} else {
}
else
{
_logger.Warning(
_localisationService.GetText("profile-unable_to_find_profile_by_id_cannot_delete", sessionID)
);
@@ -329,7 +353,8 @@ public class ProfileController
ItemEventRouterResponse response
)
{
foreach (var quest in profileDetails.CharacterData.PmcData.Quests) {
foreach (var quest in profileDetails.CharacterData.PmcData.Quests)
{
var questFromDb = _questHelper.GetQuestFromDb(quest.QId, profileDetails.CharacterData.PmcData);
// Get messageId of text to send to player as text message in game
@@ -365,7 +390,8 @@ public class ProfileController
*/
protected void ResetAllTradersInProfile(string sessionId)
{
foreach (var traderId in _databaseService.GetTraders().Keys) {
foreach (var traderId in _databaseService.GetTraders().Keys)
{
_traderHelper.ResetTrader(sessionId, traderId);
}
}
@@ -386,11 +412,13 @@ public class ProfileController
*/
public string ValidateNickname(ValidateNicknameRequestData info, string sessionID)
{
if (info.Nickname.Length < 3) {
if (info.Nickname.Length < 3)
{
return "tooshort";
}
if (_profileHelper.IsNicknameTaken(info, sessionID)) {
if (_profileHelper.IsNicknameTaken(info, sessionID))
{
return "taken";
}
@@ -403,9 +431,10 @@ public class ProfileController
*/
public string ChangeNickname(ProfileChangeNicknameRequestData info, string sessionID)
{
var output = ValidateNickname(new ValidateNicknameRequestData(){Nickname = info.Nickname}, sessionID);
var output = ValidateNickname(new ValidateNicknameRequestData() { Nickname = info.Nickname }, sessionID);
if (output == "OK") {
if (output == "OK")
{
var pmcData = _profileHelper.GetPmcProfile(sessionID);
pmcData.Info.Nickname = info.Nickname;
@@ -427,17 +456,20 @@ public class ProfileController
/**
* Handle client/game/profile/search
*/
public List<SearchFriendResponse> GetFriends(SearchFriendRequestData info, string sessionID) {
public List<SearchFriendResponse> GetFriends(SearchFriendRequestData info, string sessionID)
{
// TODO: We should probably rename this method in the next client update
var result = new List<SearchFriendResponse>();
// Find any profiles with a nickname containing the entered name
var allProfiles = _saveServer.GetProfiles().Values;
foreach (var profile in allProfiles) {
foreach (var profile in allProfiles)
{
var pmcProfile = profile?.CharacterData?.PmcData;
if (!pmcProfile?.Info?.LowerNickname?.Contains(info.Nickname.ToLower()) ?? false) {
if (!pmcProfile?.Info?.LowerNickname?.Contains(info.Nickname.ToLower()) ?? false)
{
continue;
}
@@ -453,11 +485,13 @@ public class ProfileController
public GetProfileStatusResponseData GetProfileStatus(string sessionId)
{
var account = _saveServer.GetProfile(sessionId).ProfileInfo;
var response = new GetProfileStatusResponseData() {
var response = new GetProfileStatusResponseData()
{
MaxPveCountExceeded = false,
Profiles = [
new (){ ProfileId = account.ScavengerId, ProfileToken = null, Status = "Free",Sid = "", Ip = "", Port = 0 },
new (){ProfileId = account.ProfileId, ProfileToken = null, Status = "Free",Sid = "", Ip = "", Port = 0 },
Profiles =
[
new() { ProfileId = account.ScavengerId, ProfileToken = null, Status = "Free", Sid = "", Ip = "", Port = 0 },
new() { ProfileId = account.ProfileId, ProfileToken = null, Status = "Free", Sid = "", Ip = "", Port = 0 },
]
};
@@ -471,48 +505,58 @@ public class ProfileController
{
// Find the profile by the account ID, fall back to the current player if we can't find the account
var profile = _profileHelper.GetFullProfileByAccountId(request.AccountId);
if (profile?.CharacterData?.PmcData == null || profile?.CharacterData?.ScavData == null) {
if (profile?.CharacterData?.PmcData == null || profile?.CharacterData?.ScavData == null)
{
profile = _profileHelper.GetFullProfile(sessionId);
}
var playerPmc = profile.CharacterData.PmcData;
var playerScav = profile.CharacterData.ScavData;
return new GetOtherProfileResponse(){
Id= playerPmc.Id,
Aid= playerPmc.Aid as int?,
Info= {
Nickname= playerPmc.Info.Nickname,
Side= playerPmc.Info.Side,
Experience= playerPmc.Info.Experience as int?,
MemberCategory= playerPmc.Info.MemberCategory as int?,
BannedState= playerPmc.Info.BannedState,
BannedUntil= playerPmc.Info.BannedUntil,
RegistrationDate= playerPmc.Info.RegistrationDate,
return new GetOtherProfileResponse()
{
Id = playerPmc.Id,
Aid = playerPmc.Aid as int?,
Info =
{
Nickname = playerPmc.Info.Nickname,
Side = playerPmc.Info.Side,
Experience = playerPmc.Info.Experience as int?,
MemberCategory = playerPmc.Info.MemberCategory as int?,
BannedState = playerPmc.Info.BannedState,
BannedUntil = playerPmc.Info.BannedUntil,
RegistrationDate = playerPmc.Info.RegistrationDate,
},
Customization= {
Head= playerPmc.Customization.Head,
Body= playerPmc.Customization.Body,
Feet= playerPmc.Customization.Feet,
Hands= playerPmc.Customization.Hands,
Dogtag= playerPmc.Customization.DogTag,
Customization =
{
Head = playerPmc.Customization.Head,
Body = playerPmc.Customization.Body,
Feet = playerPmc.Customization.Feet,
Hands = playerPmc.Customization.Hands,
Dogtag = playerPmc.Customization.DogTag,
},
Skills= playerPmc.Skills,
Equipment= {
Id= playerPmc.Inventory.Equipment,
Items= playerPmc.Inventory.Items,
Skills = playerPmc.Skills,
Equipment =
{
Id = playerPmc.Inventory.Equipment,
Items = playerPmc.Inventory.Items,
},
Achievements= playerPmc.Achievements,
FavoriteItems= _profileHelper.GetOtherProfileFavorites(playerPmc),
PmcStats= {
Eft= {
TotalInGameTime= playerPmc.Stats.Eft.TotalInGameTime as int?,
OverAllCounters= playerPmc.Stats.Eft.OverallCounters,
Achievements = playerPmc.Achievements,
FavoriteItems = _profileHelper.GetOtherProfileFavorites(playerPmc),
PmcStats =
{
Eft =
{
TotalInGameTime = playerPmc.Stats.Eft.TotalInGameTime as int?,
OverAllCounters = playerPmc.Stats.Eft.OverallCounters,
},
},
ScavStats= {
Eft= {
TotalInGameTime= playerScav.Stats.Eft.TotalInGameTime as int?,
OverAllCounters= playerScav.Stats.Eft.OverallCounters,
ScavStats =
{
Eft =
{
TotalInGameTime = playerScav.Stats.Eft.TotalInGameTime as int?,
OverAllCounters = playerScav.Stats.Eft.OverallCounters,
}
}
};
@@ -521,18 +565,21 @@ public class ProfileController
/**
* Handle client/profile/settings
*/
public bool SetChosenProfileIcon(string sessionId, GetProfileSettingsRequest request )
public bool SetChosenProfileIcon(string sessionId, GetProfileSettingsRequest request)
{
var profileToUpdate = _profileHelper.GetPmcProfile(sessionId);
if (profileToUpdate == null) {
if (profileToUpdate == null)
{
return false;
}
if (request.MemberCategory != null) {
if (request.MemberCategory != null)
{
profileToUpdate.Info.SelectedMemberCategory = request.MemberCategory as MemberCategory?;
}
if (request.SquadInviteRestriction != null) {
if (request.SquadInviteRestriction != null)
{
profileToUpdate.Info.SquadInviteRestriction = request.SquadInviteRestriction;
}
+2 -2
View File
@@ -168,11 +168,11 @@ public class ProfileHelper
/// </summary>
/// <param name="level">Level to get xp for</param>
/// <returns>Number of xp points for level</returns>
public double? GetExperience(int level)
public int? GetExperience(int level)
{
var playerLevel = level;
var expTable = _databaseService.GetGlobals().Configuration.Exp.Level.ExperienceTable;
double? exp = null;
int? exp = null;
if (playerLevel >= expTable.Length) // make sure to not go out of bounds
playerLevel = expTable.Length - 1;
+2 -2
View File
@@ -1255,7 +1255,7 @@ public class Level
public class ExpTable
{
[JsonPropertyName("exp")]
public double? Experience { get; set; }
public int? Experience { get; set; }
}
public class LootAttempt
@@ -4347,4 +4347,4 @@ public class QuestSettings
[JsonPropertyName("GlobalRewardRepModifierQuestPvE")]
public double? GlobalRewardRepModifierQuestPvE { get; set; }
}
}
@@ -24,7 +24,7 @@ public class GetOtherProfileResponse
public OtherProfileEquipment? Equipment { get; set; }
[JsonPropertyName("achievements")]
public Dictionary<string, int>? Achievements { get; set; }
public Dictionary<string, long>? Achievements { get; set; }
[JsonPropertyName("favoriteItems")]
public List<Item>? FavoriteItems { get; set; }
@@ -100,4 +100,4 @@ public class OtherProfileSubStats
[JsonPropertyName("overAllCounters")]
public OverallCounters? OverAllCounters { get; set; }
}
}