Refactored how clothing is stored and processed

`Suits` is no longer used in full profile, `customisationUnlocks` should be used
This commit is contained in:
Chomp
2025-03-28 17:54:32 +00:00
parent 09d5776f32
commit 2423a66f40
6 changed files with 40 additions and 32 deletions
@@ -128,14 +128,10 @@ public class CustomizationController(
/// <returns>true if already purchased</returns>
protected bool OutfitAlreadyPurchased(object suitId, string sessionId)
{
var suits = _saveServer.GetProfile(sessionId).Suits;
var fullProfile = _profileHelper.GetFullProfile(sessionId);
if (suits is null || suits.Count == 0)
{
return false;
}
return suits.Contains(suitId);
// Check if clothing can be found by id
return fullProfile.CustomisationUnlocks.Exists(customisation => Equals(customisation.Id, suitId));
}
/// <summary>
@@ -230,21 +230,23 @@ public class TraderHelper(
/// <summary>
/// Add a list of suit ids to a profiles suit list, no duplicates
/// </summary>
/// <param name="fullProfile">Profile to add to</param>
/// <param name="suitIds">Suit Ids to add</param>
protected void AddSuitsToProfile(SptProfile fullProfile, List<string> suitIds)
/// <param name="fullProfile">Profile to add clothing to</param>
/// <param name="clothingIds">Clothing Ids to add to profile</param>
public void AddSuitsToProfile(SptProfile fullProfile, List<string> clothingIds)
{
if (fullProfile.Suits is null)
{
fullProfile.Suits = [];
}
fullProfile.CustomisationUnlocks ??= [];
foreach (var suitId in suitIds)
// Don't add dupes
foreach (var suitId in clothingIds)
{
if (!fullProfile.Suits.Contains(suitId))
if (!fullProfile.CustomisationUnlocks.Exists((customisation) => customisation.Id == suitId))
{
fullProfile.Suits.Add(suitId);
// Clothing item doesn't exist in profile, add it
fullProfile.CustomisationUnlocks.Add(new CustomisationStorage
{
Id = suitId,
Source = CustomisationSource.UNLOCKED_IN_GAME,
Type = CustomisationType.SUITE
});
}
}
}
@@ -6,7 +6,7 @@ public record CustomisationStorage
{
// Customisation.json/itemId
[JsonPropertyName("id")]
public string? Id
public string Id
{
get;
set;
@@ -24,8 +24,9 @@ public record SptProfile
}
/// <summary>
/// Clothing purchases
/// No longer used as of 4.0.0
/// </summary>
[Obsolete("Replaced with CustomisationUnlocks")]
[JsonPropertyName("suits")]
public List<string>? Suits
{
@@ -95,6 +96,9 @@ public record SptProfile
set;
}
/// <summary>
/// Stores profile-related customisation, e.g. clothing / hideout walls / floors
/// </summary>
[JsonPropertyName("customisationUnlocks")]
public List<CustomisationStorage>? CustomisationUnlocks
{
@@ -43,10 +43,10 @@ public class CreateProfileService(
public string CreateProfile(string sessionId, ProfileCreateRequestData request)
{
var account = _cloner.Clone(_saveServer.GetProfile(sessionId));
var profileTemplate = _cloner.Clone(
var profileTemplateClone = _cloner.Clone(
_databaseService.GetProfiles()?.GetByJsonProp<ProfileSides>(account.ProfileInfo.Edition)?.GetByJsonProp<TemplateSide>(request.Side.ToLower())
);
var pmcData = profileTemplate.Character;
var pmcData = profileTemplateClone.Character;
// Delete existing profile
DeleteProfileBySessionId(sessionId);
@@ -113,9 +113,8 @@ public class CreateProfileService(
PmcData = pmcData,
ScavData = new PmcData()
},
Suits = profileTemplate.Suits,
UserBuildData = profileTemplate.UserBuilds,
DialogueRecords = profileTemplate.Dialogues,
UserBuildData = profileTemplateClone.UserBuilds,
DialogueRecords = profileTemplateClone.Dialogues,
SptData = _profileHelper.GetDefaultSptDataObject(),
VitalityData = new Vitality(),
InraidData = new Inraid(),
@@ -127,6 +126,8 @@ public class CreateProfileService(
AddCustomisationUnlocksToProfile(profileDetails);
_traderHelper.AddSuitsToProfile(profileDetails, profileTemplateClone.Suits);
_profileFixerService.CheckForAndFixPmcProfileIssues(profileDetails.CharacterData.PmcData);
if (profileDetails.CharacterData.PmcData.Achievements.Count > 0)
@@ -176,13 +177,13 @@ public class CreateProfileService(
_saveServer.AddProfile(profileDetails);
if (profileTemplate.Trader.SetQuestsAvailableForStart ?? false)
if (profileTemplateClone.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 (profileTemplateClone.Trader.SetQuestsAvailableForFinish ?? false)
{
_questHelper.AddAllQuestsToProfile(
profileDetails.CharacterData.PmcData,
@@ -650,13 +650,18 @@ public class ProfileFixerService(
}
var clothingDb = _databaseService.GetTemplates().Customization;
foreach (var suitId in fullProfile.Suits.Where(suitId => !clothingDb.ContainsKey(suitId)))
foreach (var clothingItem in fullProfile.CustomisationUnlocks.Where(customisation => customisation.Type == CustomisationType.SUITE))
{
_logger.Error(_localisationService.GetText("fixer-clothing_item_found", suitId));
if (_coreConfig.Fixes.RemoveModItemsFromProfile)
if (!clothingDb.ContainsKey(clothingItem.Id))
{
fullProfile.Suits.Remove(suitId);
_logger.Warning($"Non-default suit purchase: {suitId} removed from profile");
// Item in profile not found in db, not good
_logger.Error(_localisationService.GetText("fixer-clothing_item_found", clothingItem));
if (_coreConfig.Fixes.RemoveModItemsFromProfile)
{
fullProfile.CustomisationUnlocks.Remove(clothingItem);
_logger.Warning($"Non-default clothing purchase: {clothingItem} removed from profile");
}
}
}