Refactored InraidHelper

This commit is contained in:
Dev 2024-06-12 20:42:29 +01:00
parent 1caff10d35
commit 4e311da111
2 changed files with 74 additions and 65 deletions

View File

@ -177,7 +177,7 @@ export class InraidController
serverPmcProfile.InsuredItems, serverPmcProfile.InsuredItems,
postRaidRequest.profile.Inventory.fastPanel, postRaidRequest.profile.Inventory.fastPanel,
); );
this.inRaidHelper.addUpdToMoneyFromRaid(postRaidRequest.profile.Inventory.items); this.inRaidHelper.addStackCountToMoneyFromRaid(postRaidRequest.profile.Inventory.items);
// Purge profile of equipment/container items // Purge profile of equipment/container items
this.inRaidHelper.setInventory(sessionID, serverPmcProfile, postRaidRequest.profile); this.inRaidHelper.setInventory(sessionID, serverPmcProfile, postRaidRequest.profile);
@ -276,7 +276,7 @@ export class InraidController
this.updatePmcHealthPostRaid(postRaidSaveRequest, pmcData); this.updatePmcHealthPostRaid(postRaidSaveRequest, pmcData);
this.inRaidHelper.deleteInventory(pmcData, sessionID); this.inRaidHelper.deleteInventory(pmcData, sessionID);
if (this.inRaidHelper.removeQuestItemsOnDeath()) if (this.inRaidHelper.shouldQuestItemsBeRemovedOnDeath())
{ {
// Find and remove the completed condition from profile if player died, otherwise quest is stuck in limbo // Find and remove the completed condition from profile if player died, otherwise quest is stuck in limbo
// and quest items cannot be picked up again // and quest items cannot be picked up again
@ -386,7 +386,7 @@ export class InraidController
); );
// Some items from client profile don't have upd objects when they're single stack items // Some items from client profile don't have upd objects when they're single stack items
this.inRaidHelper.addUpdToMoneyFromRaid(postRaidRequest.profile.Inventory.items); this.inRaidHelper.addStackCountToMoneyFromRaid(postRaidRequest.profile.Inventory.items);
// Reset hp/regenerate loot // Reset hp/regenerate loot
this.handlePostRaidPlayerScavProcess(serverScavProfile, sessionID, postRaidRequest, serverPmcProfile, isDead); this.handlePostRaidPlayerScavProcess(serverScavProfile, sessionID, postRaidRequest, serverPmcProfile, isDead);

View File

@ -55,7 +55,7 @@ export class InRaidHelper
* Lookup quest item loss from lostOnDeath config * Lookup quest item loss from lostOnDeath config
* @returns True if items should be removed from inventory * @returns True if items should be removed from inventory
*/ */
public removeQuestItemsOnDeath(): boolean public shouldQuestItemsBeRemovedOnDeath(): boolean
{ {
return this.lostOnDeathConfig.questItems; return this.lostOnDeathConfig.questItems;
} }
@ -65,7 +65,7 @@ export class InRaidHelper
* Single stack money items have no upd object and thus no StackObjectsCount, causing issues * Single stack money items have no upd object and thus no StackObjectsCount, causing issues
* @param items Items array to check * @param items Items array to check
*/ */
public addUpdToMoneyFromRaid(items: Item[]): void public addStackCountToMoneyFromRaid(items: Item[]): void
{ {
for (const moneyItem of items.filter((item) => this.paymentHelper.isMoneyTpl(item._tpl))) for (const moneyItem of items.filter((item) => this.paymentHelper.isMoneyTpl(item._tpl)))
{ {
@ -205,12 +205,13 @@ export class InRaidHelper
): void ): void
{ {
// Only copy active quests into scav profile // Progress will later to copied over to PMC profile // Only copy active quests into scav profile // Progress will later to copied over to PMC profile
const existingActiveQuestIds = scavData.Quests?.filter((x) => x.status !== QuestStatus.AvailableForStart).map( const existingActiveQuestIds = scavData.Quests
(x) => x.qid, ?.filter((quest) => quest.status !== QuestStatus.AvailableForStart)
); .map((x) => x.qid);
if (existingActiveQuestIds) if (existingActiveQuestIds)
{ {
scavData.Quests = saveProgressRequest.profile.Quests.filter((x) => existingActiveQuestIds.includes(x.qid)); scavData.Quests = saveProgressRequest.profile.Quests
.filter((quest) => existingActiveQuestIds.includes(quest.qid));
} }
this.profileFixerService.checkForAndFixScavProfileIssues(scavData); this.profileFixerService.checkForAndFixScavProfileIssues(scavData);
@ -297,9 +298,20 @@ export class InRaidHelper
} }
// Restartable quests need special actions // Restartable quests need special actions
else if (postRaidQuestStatus === "FailRestartable") else if (postRaidQuestStatus === "FailRestartable")
{
this.handleFailRestartableQuestStatus(pmcData, postRaidProfile, postRaidQuest);
}
}
}
protected handleFailRestartableQuestStatus(
pmcData: IPmcData,
postRaidProfile: IPostRaidPmcData,
postRaidQuest: IQuestStatus): void
{ {
// Does failed quest have requirement to collect items from raid // Does failed quest have requirement to collect items from raid
const questDbData = this.questHelper.getQuestFromDb(postRaidQuest.qid, pmcData); const questDbData = this.questHelper.getQuestFromDb(postRaidQuest.qid, pmcData);
// AvailableForFinish // AvailableForFinish
const matchingAffFindConditions = questDbData.conditions.AvailableForFinish.filter( const matchingAffFindConditions = questDbData.conditions.AvailableForFinish.filter(
(condition) => condition.conditionType === "FindItem", (condition) => condition.conditionType === "FindItem",
@ -326,7 +338,7 @@ export class InRaidHelper
{ {
// Look for sessioncounter and remove it // Look for sessioncounter and remove it
const counterIndex = postRaidProfile.Stats.Eft.SessionCounters.Items.findIndex( const counterIndex = postRaidProfile.Stats.Eft.SessionCounters.Items.findIndex(
(x) => x.Key.includes(itemTpl) && x.Key.includes("LootItem"), (counter) => counter.Key.includes(itemTpl) && counter.Key.includes("LootItem"),
); );
if (counterIndex > -1) if (counterIndex > -1)
{ {
@ -344,8 +356,6 @@ export class InRaidHelper
// Clear out any completed conditions // Clear out any completed conditions
postRaidQuest.completedConditions = []; postRaidQuest.completedConditions = [];
} }
}
}
/** /**
* Take body part effects from client profile and apply to server profile * Take body part effects from client profile and apply to server profile
@ -425,10 +435,7 @@ export class InRaidHelper
*/ */
protected updateProfileAchievements(profile: IPmcData, clientAchievements: Record<string, number>): void protected updateProfileAchievements(profile: IPmcData, clientAchievements: Record<string, number>): void
{ {
if (!profile.Achievements) profile.Achievements ||= {};
{
profile.Achievements = {};
}
for (const achievementId in clientAchievements) for (const achievementId in clientAchievements)
{ {
@ -563,13 +570,14 @@ export class InRaidHelper
*/ */
protected getBaseItemsInRigPocketAndBackpack(pmcData: IPmcData): Item[] protected getBaseItemsInRigPocketAndBackpack(pmcData: IPmcData): Item[]
{ {
const rig = pmcData.Inventory.items.find((x) => x.slotId === "TacticalVest"); const items = pmcData.Inventory.items;
const pockets = pmcData.Inventory.items.find((x) => x.slotId === "Pockets"); const rig = items.find((x) => x.slotId === "TacticalVest");
const backpack = pmcData.Inventory.items.find((x) => x.slotId === "Backpack"); const pockets = items.find((x) => x.slotId === "Pockets");
const backpack = items.find((x) => x.slotId === "Backpack");
const baseItemsInRig = pmcData.Inventory.items.filter((x) => x.parentId === rig?._id); const baseItemsInRig = items.filter((x) => x.parentId === rig?._id);
const baseItemsInPockets = pmcData.Inventory.items.filter((x) => x.parentId === pockets?._id); const baseItemsInPockets = items.filter((x) => x.parentId === pockets?._id);
const baseItemsInBackpack = pmcData.Inventory.items.filter((x) => x.parentId === backpack?._id); const baseItemsInBackpack = items.filter((x) => x.parentId === backpack?._id);
return [...baseItemsInRig, ...baseItemsInPockets, ...baseItemsInBackpack]; return [...baseItemsInRig, ...baseItemsInPockets, ...baseItemsInBackpack];
} }
@ -585,7 +593,7 @@ export class InRaidHelper
// Use pocket slotId's otherwise it deletes the root pocket item. // Use pocket slotId's otherwise it deletes the root pocket item.
const pocketSlots = ["pocket1", "pocket2", "pocket3", "pocket4"]; const pocketSlots = ["pocket1", "pocket2", "pocket3", "pocket4"];
// No parentId = base inventory item, always keep // Base inventory items are always kept
if (!itemToCheck.parentId) if (!itemToCheck.parentId)
{ {
return true; return true;
@ -623,6 +631,7 @@ export class InRaidHelper
return true; return true;
} }
// All other cases item is lost
return false; return false;
} }