Expanded PrestigeController implementation

This commit is contained in:
Chomp
2025-01-14 10:50:15 +00:00
parent 5256d5b88a
commit d64dc5d040
11 changed files with 147 additions and 25 deletions
+6 -3
View File
@@ -1,9 +1,10 @@
using Core.Annotations;
using Core.Annotations;
using Core.Controllers;
using Core.Helpers;
using Core.Models.Eft.Common;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.HttpResponse;
using Core.Models.Eft.Prestige;
using Core.Utils;
namespace Core.Callbacks;
@@ -48,8 +49,10 @@ public class PrestigeCallbacks
/// <param name="sessionID"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public string ObtainPrestige(string url, EmptyRequestData info, string sessionID)
public string ObtainPrestige(string url, List<ObtainPrestigeRequest> info, string sessionID)
{
return _httpResponseUtil.GetBody(_prestigeController.ObtainPrestige(sessionID, info));
_prestigeController.ObtainPrestige(sessionID, info);
return _httpResponseUtil.NullResponse();
}
}
+113 -5
View File
@@ -1,21 +1,50 @@
using Core.Annotations;
using Core.Helpers;
using Core.Models.Eft.Common;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.Inventory;
using Core.Models.Eft.Prestige;
using Core.Models.Eft.Profile;
using Core.Routers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using ILogger = Core.Models.Utils.ILogger;
namespace Core.Controllers;
[Injectable]
public class PrestigeController
{
private readonly ILogger _logger;
private readonly TimeUtil _timeUtil;
private readonly InventoryHelper _inventoryHelper;
private readonly ProfileHelper _profileHelper;
private readonly EventOutputHolder _eventOutputHolder;
private readonly CreateProfileService _createProfileService;
private DatabaseService _databaseService;
private readonly ICloner _cloner;
public PrestigeController
(
DatabaseService databaseService
ILogger logger,
TimeUtil timeUtil,
InventoryHelper inventoryHelper,
ProfileHelper profileHelper,
EventOutputHolder eventOutputHolder,
CreateProfileService createProfileService,
DatabaseService databaseService,
ICloner cloner
)
{
_logger = logger;
_timeUtil = timeUtil;
_inventoryHelper = inventoryHelper;
_profileHelper = profileHelper;
_eventOutputHolder = eventOutputHolder;
_createProfileService = createProfileService;
_databaseService = databaseService;
_cloner = cloner;
}
/// <summary>
@@ -35,12 +64,91 @@ public class PrestigeController
/// Handle /client/prestige/obtain
/// </summary>
/// <param name="sessionId"></param>
/// <param name="info"></param>
/// <param name="request"></param>
/// <returns></returns>
public object ObtainPrestige( // TODO: returns `any` in the node server, not implemented either
public void ObtainPrestige(
string sessionId,
EmptyRequestData info)
List<ObtainPrestigeRequest> request)
{
throw new NotImplementedException("Method not Implemented");
var prePrestigeProfileClone = _cloner.Clone(_profileHelper.GetFullProfile(sessionId));
var prePrestigePmc = prePrestigeProfileClone.CharacterData.PmcData;
var createRequest = new ProfileCreateRequestData {
Side = prePrestigePmc.Info.Side,
Nickname = prePrestigePmc.Info.Nickname,
HeadId = prePrestigePmc.Customization.Head,
VoiceId = _databaseService.GetTemplates().Customization.FirstOrDefault(
(customisation) => customisation.Value.Name == prePrestigePmc.Info.Voice).Value.Id,
SptForcePrestigeLevel = prePrestigeProfileClone.CharacterData.PmcData.Info.PrestigeLevel.GetValueOrDefault(0) + 1, // Current + 1
};
// Reset profile
_createProfileService.CreateProfile(sessionId, createRequest);
// Get freshly reset profile ready for editing
var newProfile = _profileHelper.GetFullProfile(sessionId);
// Skill copy
var commonSkillsToCopy = prePrestigePmc.Skills.Common;
foreach (var skillToCopy in commonSkillsToCopy) {
// Set progress to max level 20
skillToCopy.Progress = Math.Min(skillToCopy.Progress.Value, 2000);
var existingSkill = newProfile.CharacterData.PmcData.Skills.Common.FirstOrDefault((skill) => skill.Id == skillToCopy.Id);
if (existingSkill is not null)
{
existingSkill.Progress = skillToCopy.Progress;
}
else
{
newProfile.CharacterData.PmcData.Skills.Common.Add(skillToCopy);
}
}
var masteringSkillsToCopy = prePrestigePmc.Skills.Mastering;
foreach (var skillToCopy in masteringSkillsToCopy) {
// Set progress to max level 20
skillToCopy.Progress = Math.Min(skillToCopy.Progress.Value, 2000);
var existingSkill = newProfile.CharacterData.PmcData.Skills.Mastering.FirstOrDefault(
(skill) => skill.Id == skillToCopy.Id);
if (existingSkill is not null)
{
existingSkill.Progress = skillToCopy.Progress;
}
else
{
newProfile.CharacterData.PmcData.Skills.Mastering.Add(skillToCopy);
}
}
var indexToGet = Math.Min(createRequest.SptForcePrestigeLevel.Value - 1, 1); // Index starts at 0
var rewards = _databaseService.GetTemplates().Prestige.Elements[indexToGet].Rewards;
AddPrestigeRewardsToProfile(sessionId, newProfile, rewards);
// Copy transferred items
foreach (var transferRequest in request) {
var item = prePrestigePmc.Inventory.Items.FirstOrDefault((item) => item.Id == transferRequest.Id);
var addItemRequest = new AddItemDirectRequest {
ItemWithModsToAdd = [item],
FoundInRaid = item.Upd?.SpawnedInSession,
UseSortingTable = false,
Callback = null,
};
_inventoryHelper.AddItemToStash(
sessionId,
addItemRequest,
newProfile.CharacterData.PmcData,
_eventOutputHolder.GetOutput(sessionId));
}
// Add "Prestigious" achievement
if (!newProfile.PlayerAchievements.ContainsKey("676091c0f457869a94017a23"))
{
newProfile.PlayerAchievements.Add("676091c0f457869a94017a23", _timeUtil.GetTimeStamp());
}
}
private void AddPrestigeRewardsToProfile(string sessionId, SptProfile newProfile, IEnumerable<QuestReward> rewards)
{
_logger.Error("NOT IMPLEMENTED AddPrestigeRewardsToProfile()");
}
}
+1 -1
View File
@@ -305,7 +305,7 @@ public class PlayerScavGenerator
{
return new()
{
Common = new(new(), new()),
Common = new(),
Mastering = new (),
Points = 0
};
+3 -3
View File
@@ -445,7 +445,7 @@ public class ProfileHelper
if (profileSkills == null)
return false;
var profileSkill = profileSkills.Dictionary.FirstOrDefault(s => s.Value.Id == skill.ToString()).Value;
var profileSkill = profileSkills.FirstOrDefault(s => s.Id == skill.ToString());
if (profileSkill == null)
{
_logger.Error(_localisationService.GetText("quest-no_skill_found", skill));
@@ -479,7 +479,7 @@ public class ProfileHelper
return;
}
var profileSkill = profileSkills.Dictionary.FirstOrDefault(s => s.Value.Id == skill.ToString()).Value;
var profileSkill = profileSkills.FirstOrDefault(s => s.Id == skill.ToString());
if (profileSkill == null)
{
_logger.Error(_localisationService.GetText("quest-no_skill_found", skill));
@@ -508,7 +508,7 @@ public class ProfileHelper
/// <returns>Common skill object from desired profile</returns>
public Common? GetSkillFromProfile(PmcData pmcData, SkillTypes skill)
{
var skillToReturn = pmcData?.Skills?.Common.List.FirstOrDefault(s => s.Id == skill.ToString());
var skillToReturn = pmcData?.Skills?.Common.FirstOrDefault(s => s.Id == skill.ToString());
if (skillToReturn == null)
_logger.Warning($"Profile {pmcData.SessionId} does not have a skill named: {skill.ToString()}");
+7 -6
View File
@@ -184,7 +184,7 @@ public class Info
[JsonPropertyName("isMigratedSkills")]
public bool? IsMigratedSkills { get; set; }
public double? PrestigeLevel { get; set; }
public int? PrestigeLevel { get; set; }
}
public class BotInfoSettings
@@ -291,17 +291,18 @@ public class BotBaseInventory
public class BaseJsonSkills
{
public Dictionary<string, Common>? Common { get; set; }
public Dictionary<string, Mastering>? Mastering { get; set; }
public List<Common>? Common { get; set; }
public List<Mastering>? Mastering { get; set; }
public double? Points { get; set; }
}
public class Skills
{
public DictionaryOrList<string, Common>? Common { get; set; }
public List<Common>? Common { get; set; }
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public Dictionary<string, Mastering>? Mastering { get; set; }
public List<Mastering>? Mastering { get; set; }
public double? Points { get; set; }
}
+8 -2
View File
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Core.Models.Common;
using Core.Utils.Json.Converters;
@@ -35,7 +34,7 @@ public class BotType
public List<string>? LastNames { get; set; }
[JsonPropertyName("skills")]
public Skills? BotSkills { get; set; }
public BotDbSkills? BotSkills { get; set; }
}
public class Appearance
@@ -370,3 +369,10 @@ public class ItemPools
public Dictionary<string, double>? SpecialLoot { get; set; }
public Dictionary<string, double>? TacticalVest { get; set; }
}
public class BotDbSkills
{
public Dictionary<string, MinMax>? Common { get; set; }
public Dictionary<string, MinMax>? Mastering { get; set; }
}
@@ -16,4 +16,7 @@ public class ProfileCreateRequestData : IRequestData
[JsonPropertyName("voiceId")]
public string? VoiceId { get; set; }
[JsonPropertyName("sptForcePrestigeLevel")]
public int? SptForcePrestigeLevel { get; set; }
}
+1 -1
View File
@@ -42,7 +42,7 @@ public class SptProfile
/** Achievements earned by player */
[JsonPropertyName("achievements")]
public Dictionary<string, int>? PlayerAchievements { get; set; }
public Dictionary<string, long>? PlayerAchievements { get; set; }
/** List of friend profile IDs */
[JsonPropertyName("friends")]
+1 -1
View File
@@ -63,7 +63,7 @@ public class EventOutputHolder
Items = new ItemChanges(){ NewItems = [], ChangedItems = [], DeletedItems = []},
Production = new Dictionary<string, Productive>(),
Improvements = new Dictionary<string, HideoutImprovement>(),
Skills = new Skills{ Common = new DictionaryOrList<string, Common>(null, []), Mastering = new Dictionary<string, Mastering>(), Points = 0},
Skills = new Skills{ Common = [], Mastering = [], Points = 0},
Health = _cloner.Clone(pmcProfile.Health),
TraderRelations = new Dictionary<string, TraderData>(),
RecipeUnlocked = {},
+3 -2
View File
@@ -1,7 +1,8 @@
using Core.Annotations;
using Core.Annotations;
using Core.Callbacks;
using Core.DI;
using Core.Models.Eft.Common;
using Core.Models.Eft.Prestige;
using Core.Utils;
namespace Core.Routers.Static;
@@ -32,7 +33,7 @@ public class PrestigeStaticRouter : StaticRouter
info,
sessionID,
output
) => _presetCallbacks.ObtainPrestige(url, info as EmptyRequestData, sessionID))
) => _presetCallbacks.ObtainPrestige(url, info as List<ObtainPrestigeRequest>, sessionID))
]
)
{
+1 -1
View File
@@ -457,7 +457,7 @@ public class ProfileFixerService
{
var skills = pmcProfile.Skills.Common;
foreach (var skill in skills.List
foreach (var skill in skills
.Where(skill => skill.Progress > 5100))
{
skill.Progress = 5100;