Promotion preprod → prod : contrats/kills, factions, tech-tree, assurance payout, Fortuna Pass #1
@@ -2,6 +2,7 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Prospect.Server.Api.Services.Auth.Extensions;
|
using Prospect.Server.Api.Services.Auth.Extensions;
|
||||||
using Prospect.Server.Api.Services.CloudScript;
|
using Prospect.Server.Api.Services.CloudScript;
|
||||||
|
using Prospect.Server.Api.Services.CloudScript.Functions;
|
||||||
using Prospect.Server.Api.Services.CloudScript.Models;
|
using Prospect.Server.Api.Services.CloudScript.Models;
|
||||||
using Prospect.Server.Api.Services.UserData;
|
using Prospect.Server.Api.Services.UserData;
|
||||||
|
|
||||||
@@ -45,12 +46,14 @@ public class CompleteInventoryUpdateFunction : ICloudScriptFunction<CompleteInve
|
|||||||
private readonly ILogger<CompleteInventoryUpdateFunction> _logger;
|
private readonly ILogger<CompleteInventoryUpdateFunction> _logger;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly UserDataService _userDataService;
|
private readonly UserDataService _userDataService;
|
||||||
|
private readonly TitleDataService _titleDataService;
|
||||||
|
|
||||||
public CompleteInventoryUpdateFunction(ILogger<CompleteInventoryUpdateFunction> logger, IHttpContextAccessor httpContextAccessor, UserDataService userDataService)
|
public CompleteInventoryUpdateFunction(ILogger<CompleteInventoryUpdateFunction> logger, IHttpContextAccessor httpContextAccessor, UserDataService userDataService, TitleDataService titleDataService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_userDataService = userDataService;
|
_userDataService = userDataService;
|
||||||
|
_titleDataService = titleDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<CompleteInventoryUpdateResponse> ExecuteAsync(CompleteInventoryUpdateRequest request)
|
public async Task<CompleteInventoryUpdateResponse> ExecuteAsync(CompleteInventoryUpdateRequest request)
|
||||||
@@ -64,6 +67,42 @@ public class CompleteInventoryUpdateFunction : ICloudScriptFunction<CompleteInve
|
|||||||
var userData = await _userDataService.FindAsync(userId, userId, new List<string>{"Inventory"});
|
var userData = await _userDataService.FindAsync(userId, userId, new List<string>{"Inventory"});
|
||||||
var inventory = JsonSerializer.Deserialize<List<FYCustomItemInfo>>(userData["Inventory"].Value);
|
var inventory = JsonSerializer.Deserialize<List<FYCustomItemInfo>>(userData["Inventory"].Value);
|
||||||
|
|
||||||
|
// Insurance payout: this request also reports the end-of-match inventory, so items
|
||||||
|
// the player lost (death / left behind) arrive in ItemsToRemove. Any of those that
|
||||||
|
// were insured on deploy (EnterMatchmakingStation) are recovered back to the stash —
|
||||||
|
// the premium was already paid up-front — and the insurance is consumed (one raid).
|
||||||
|
// Recovery is only performed if the item's policy declares a positive Payout.
|
||||||
|
var recoveredInsured = new HashSet<string>();
|
||||||
|
if (request.ItemsToRemove is { Count: > 0 })
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var td = _titleDataService.Find(new List<string> { "InventoryInsurance" });
|
||||||
|
if (td.TryGetValue("InventoryInsurance", out var rawPolicies) && !string.IsNullOrEmpty(rawPolicies))
|
||||||
|
{
|
||||||
|
var policies = JsonSerializer.Deserialize<Dictionary<string, InventoryInsurancePolicy>>(rawPolicies);
|
||||||
|
foreach (var item in inventory)
|
||||||
|
{
|
||||||
|
if (!request.ItemsToRemove.Contains(item.ItemId)) continue;
|
||||||
|
if (string.IsNullOrEmpty(item.Insurance) || item.InsuranceOwnerPlayfabId != userId) continue;
|
||||||
|
if (policies == null || !policies.TryGetValue(item.Insurance, out var policy) || policy.Payout <= 0) continue;
|
||||||
|
recoveredInsured.Add(item.ItemId);
|
||||||
|
item.Insurance = ""; // consumed for this raid
|
||||||
|
item.InsuranceOwnerPlayfabId = "";
|
||||||
|
}
|
||||||
|
if (recoveredInsured.Count > 0)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Recovered {Count} insured item(s) for user {User}", recoveredInsured.Count, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Never fail the inventory commit because of insurance handling.
|
||||||
|
_logger.LogWarning(e, "Failed to process insurance payout");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Optimize
|
// TODO: Optimize
|
||||||
// TODO: Check deleted items to see if other stacks/mods were updated correctly
|
// TODO: Check deleted items to see if other stacks/mods were updated correctly
|
||||||
// Process inventory update. The player may:
|
// Process inventory update. The player may:
|
||||||
@@ -74,7 +113,8 @@ public class CompleteInventoryUpdateFunction : ICloudScriptFunction<CompleteInve
|
|||||||
// IMPORTANT: The same request is currently used to report the updated inventory in the end of match.
|
// IMPORTANT: The same request is currently used to report the updated inventory in the end of match.
|
||||||
var newInventory = new List<FYCustomItemInfo>(inventory.Count);
|
var newInventory = new List<FYCustomItemInfo>(inventory.Count);
|
||||||
foreach (var item in inventory) {
|
foreach (var item in inventory) {
|
||||||
if (!request.ItemsToRemove.Contains(item.ItemId)) {
|
// Keep items that weren't removed, plus insured items recovered above.
|
||||||
|
if (!request.ItemsToRemove.Contains(item.ItemId) || recoveredInsured.Contains(item.ItemId)) {
|
||||||
newInventory.Add(item);
|
newInventory.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -45,12 +45,14 @@ public class RequestClaimFortunaPassRewardsFunction : ICloudScriptFunction<Reque
|
|||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly UserDataService _userDataService;
|
private readonly UserDataService _userDataService;
|
||||||
private readonly TitleDataService _titleDataService;
|
private readonly TitleDataService _titleDataService;
|
||||||
|
private readonly ILogger<RequestClaimFortunaPassRewardsFunction> _logger;
|
||||||
|
|
||||||
public RequestClaimFortunaPassRewardsFunction(IHttpContextAccessor httpContextAccessor, UserDataService userDataService, TitleDataService titleDataService)
|
public RequestClaimFortunaPassRewardsFunction(IHttpContextAccessor httpContextAccessor, UserDataService userDataService, TitleDataService titleDataService, ILogger<RequestClaimFortunaPassRewardsFunction> logger)
|
||||||
{
|
{
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_userDataService = userDataService;
|
_userDataService = userDataService;
|
||||||
_titleDataService = titleDataService;
|
_titleDataService = titleDataService;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RequestClaimFortunaPassRewardsResponse> ExecuteAsync(RequestClaimFortunaPassRewardsRequest request)
|
public async Task<RequestClaimFortunaPassRewardsResponse> ExecuteAsync(RequestClaimFortunaPassRewardsRequest request)
|
||||||
@@ -96,9 +98,20 @@ public class RequestClaimFortunaPassRewardsFunction : ICloudScriptFunction<Reque
|
|||||||
{
|
{
|
||||||
// Ne pas re-créditer un palier déjà réclamé.
|
// Ne pas re-créditer un palier déjà réclamé.
|
||||||
if (claimedRewards.RewardsIDs.Contains(rewardId)) continue;
|
if (claimedRewards.RewardsIDs.Contains(rewardId)) continue;
|
||||||
claimedRewards.RewardsIDs.Add(rewardId);
|
|
||||||
|
|
||||||
if (catalog == null || !catalog.TryGetValue(rewardId, out var def) || def == null) continue;
|
if (catalog == null || !catalog.TryGetValue(rewardId, out var def) || def == null)
|
||||||
|
{
|
||||||
|
// Le catalogue des paliers est défini côté client (DataTable). On journalise
|
||||||
|
// les IDs inconnus pour pouvoir construire un vrai catalogue FortunaPass{2,3}_Rewards
|
||||||
|
// qui matche. IMPORTANT : ne PAS marquer le palier comme réclamé si on ne peut rien
|
||||||
|
// accorder — sinon il serait brûlé définitivement et inclaimable une fois le
|
||||||
|
// catalogue ajouté.
|
||||||
|
_logger.LogInformation("FortunaPass claim: aucun catalogue pour le reward '{RewardId}' (catalogue {State}) — non accordé", rewardId, catalog == null ? "absent" : "présent");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
claimedRewards.RewardsIDs.Add(rewardId);
|
||||||
|
_logger.LogInformation("FortunaPass claim: octroi reward '{RewardId}' -> {ItemId} x{Amount}", rewardId, def.ItemId, def.Amount);
|
||||||
|
|
||||||
switch (def.ItemId)
|
switch (def.ItemId)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user