Created EndRaidResultExtensions
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using SPTarkov.Server.Core.Models.Eft.Match;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
|
||||
namespace SPTarkov.Server.Core.Extensions
|
||||
{
|
||||
public static class EndRaidResultExtensions
|
||||
{
|
||||
private static HashSet<ExitStatus> deathStates = [ExitStatus.KILLED, ExitStatus.MISSINGINACTION, ExitStatus.LEFT];
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if player survives. run through will return false
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if survived </returns>
|
||||
public static bool IsPlayerSurvived(this EndRaidResult results)
|
||||
{
|
||||
return results.Result == ExitStatus.SURVIVED;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the player dead after a raid - dead = anything other than "survived" / "runner"
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if dead </returns>
|
||||
public static bool IsPlayerDead(this EndRaidResult results)
|
||||
{
|
||||
return deathStates.Contains(results.Result.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Has the player moved from one map to another
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if players transferred </returns>
|
||||
public static bool IsMapToMapTransfer(this EndRaidResult results)
|
||||
{
|
||||
return results.Result == ExitStatus.TRANSIT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Was extract by car
|
||||
/// </summary>
|
||||
/// <param name="requestResults">Result object from completed raid</param>
|
||||
/// <param name="carExtracts">Car extract names</param>
|
||||
/// <returns> True if extract was by car </returns>
|
||||
public static bool TookCarExtract(this EndRaidResult? requestResults, HashSet<string> carExtracts)
|
||||
{
|
||||
// exit name is undefined on death
|
||||
if (string.IsNullOrEmpty(requestResults?.ExitName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (requestResults.ExitName.ToLowerInvariant().Contains("v-ex"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return carExtracts.Contains(requestResults.ExitName.Trim());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raid exit was via coop extract
|
||||
/// </summary>
|
||||
/// <param name="raidResult">Result object from completed raid</param>
|
||||
/// <param name="coopExtracts"></param>
|
||||
/// <returns>True when exit was coop extract</returns>
|
||||
public static bool TookCoopExtract(this EndRaidResult? raidResult, HashSet<string> coopExtracts)
|
||||
{
|
||||
return raidResult?.ExitName is not null && coopExtracts.Contains(raidResult.ExitName.Trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,9 +332,9 @@ public class LocationLifecycleService(
|
||||
|
||||
var locationName = serverDetails[0].ToLowerInvariant();
|
||||
var isPmc = serverDetails[1].ToLowerInvariant().Contains("pmc");
|
||||
var isDead = IsPlayerDead(request.Results);
|
||||
var isTransfer = IsMapToMapTransfer(request.Results);
|
||||
var isSurvived = IsPlayerSurvived(request.Results);
|
||||
var isDead = request.Results.IsPlayerDead();
|
||||
var isTransfer = request.Results.IsMapToMapTransfer();
|
||||
var isSurvived = request.Results.IsPlayerSurvived();
|
||||
|
||||
// Handle items transferred via BTR or transit to player mailbox
|
||||
btrDeliveryService.HandleItemTransferEvent(sessionId, request);
|
||||
@@ -360,13 +360,13 @@ public class LocationLifecycleService(
|
||||
HandlePostRaidPmc(sessionId, fullProfile, scavProfile, isDead, isSurvived, isTransfer, request, locationName);
|
||||
|
||||
// Handle car extracts
|
||||
if (TookCarExtract(request.Results))
|
||||
if (request.Results.TookCarExtract(_inRaidConfig.CarExtracts))
|
||||
{
|
||||
HandleCarExtract(request.Results.ExitName, pmcProfile, sessionId);
|
||||
}
|
||||
|
||||
// Handle coop exit
|
||||
if (TookCoopExtract(request.Results) && _traderConfig.Fence.CoopExtractGift.SendGift)
|
||||
if (request.Results.TookCoopExtract(_inRaidConfig.CoopExtracts) && _traderConfig.Fence.CoopExtractGift.SendGift)
|
||||
{
|
||||
HandleCoopExtract(sessionId, pmcProfile, request.Results.ExitName);
|
||||
SendCoopTakenFenceMessage(sessionId);
|
||||
@@ -403,37 +403,6 @@ public class LocationLifecycleService(
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Was extract by car
|
||||
/// </summary>
|
||||
/// <param name="requestResults">Result object from completed raid</param>
|
||||
/// <returns> True if extract was by car </returns>
|
||||
protected bool TookCarExtract(EndRaidResult? requestResults)
|
||||
{
|
||||
// exit name is undefined on death
|
||||
if (string.IsNullOrEmpty(requestResults?.ExitName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (requestResults.ExitName.ToLowerInvariant().Contains("v-ex"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _inRaidConfig.CarExtracts.Contains(requestResults.ExitName.Trim());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raid exit was via coop extract
|
||||
/// </summary>
|
||||
/// <param name="raidResult">Result object from completed raid</param>
|
||||
/// <returns>True when exit was coop extract</returns>
|
||||
protected bool TookCoopExtract(EndRaidResult? raidResult)
|
||||
{
|
||||
return raidResult?.ExitName is not null && ExtractTakenWasCoop(raidResult.ExitName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle when a player extracts using a car - Add rep to fence
|
||||
/// </summary>
|
||||
@@ -525,22 +494,6 @@ public class LocationLifecycleService(
|
||||
return Math.Round(newFenceStanding, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Did player take a COOP extract
|
||||
/// </summary>
|
||||
/// <param name="extractName"> Name of extract player took </param>
|
||||
/// <returns> True if coop extract </returns>
|
||||
protected bool ExtractTakenWasCoop(string? extractName)
|
||||
{
|
||||
// No extract name, not a coop extract
|
||||
if (extractName is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _inRaidConfig.CoopExtracts.Contains(extractName.Trim());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform post-raid profile changes
|
||||
/// </summary>
|
||||
@@ -604,7 +557,7 @@ public class LocationLifecycleService(
|
||||
scavProfile.TradersInfo[Traders.FENCE].Standing = Math.Clamp(postRaidFenceData.Standing.Value, fenceMin, fenceMax);
|
||||
|
||||
// Successful extract as scav, give some rep
|
||||
if (IsPlayerSurvived(request.Results) && scavProfile.TradersInfo[Traders.FENCE].Standing < fenceMax)
|
||||
if (request.Results.IsPlayerSurvived() && scavProfile.TradersInfo[Traders.FENCE].Standing < fenceMax)
|
||||
{
|
||||
scavProfile.TradersInfo[Traders.FENCE].Standing += _inRaidConfig.ScavExtractStandingGain;
|
||||
}
|
||||
@@ -1033,37 +986,6 @@ public class LocationLifecycleService(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if player survives. run through will return false
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if survived </returns>
|
||||
protected bool IsPlayerSurvived(EndRaidResult results)
|
||||
{
|
||||
return results.Result == ExitStatus.SURVIVED;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the player dead after a raid - dead = anything other than "survived" / "runner"
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if dead </returns>
|
||||
protected bool IsPlayerDead(EndRaidResult results)
|
||||
{
|
||||
var deathEnums = new List<ExitStatus> { ExitStatus.KILLED, ExitStatus.MISSINGINACTION, ExitStatus.LEFT };
|
||||
return deathEnums.Contains(results.Result.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Has the player moved from one map to another
|
||||
/// </summary>
|
||||
/// <param name="results"> Post raid request </param>
|
||||
/// <returns> True if players transferred </returns>
|
||||
protected bool IsMapToMapTransfer(EndRaidResult results)
|
||||
{
|
||||
return results.Result == ExitStatus.TRANSIT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the skill points earned in a raid to 0, ready for next raid
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user