Fixed quest items not being transferred from client to server profile

Cleaned up `setInventory()`
This commit is contained in:
Dev 2024-11-02 09:59:37 +00:00
parent 9b17a9b350
commit a8c6432d28

View File

@ -64,7 +64,7 @@ export class InRaidHelper {
// Store insurance (as removeItem() removes insured items) // Store insurance (as removeItem() removes insured items)
const insured = this.cloner.clone(serverProfile.InsuredItems); const insured = this.cloner.clone(serverProfile.InsuredItems);
// Remove possible equipped items from before the raid // Remove equipped items from before the raid
this.inventoryHelper.removeItem(serverProfile, serverProfile.Inventory.equipment, sessionID); this.inventoryHelper.removeItem(serverProfile, serverProfile.Inventory.equipment, sessionID);
// Get all items that have a parent of `serverProfile.Inventory.equipment` (All items player had on them at end of raid) // Get all items that have a parent of `serverProfile.Inventory.equipment` (All items player had on them at end of raid)
@ -73,45 +73,73 @@ export class InRaidHelper {
postRaidProfile.Inventory.equipment, postRaidProfile.Inventory.equipment,
); );
// Get all items that have a parent of `serverProfile.Inventory.questRaidItems` (Quest items player had on them at end of raid)
const postRaidQuestItems = this.itemHelper.findAndReturnChildrenAsItems(
postRaidProfile.Inventory.items,
postRaidProfile.Inventory.questRaidItems,
);
// Handle Removing of FIR status if player did not survive + not transferring // Handle Removing of FIR status if player did not survive + not transferring
// Do after above filtering code to reduce work done // Do after above filtering code to reduce work done
if (!isSurvived && !isTransfer && !this.inRaidConfig.alwaysKeepFoundInRaidonRaidEnd) { if (!isSurvived && !isTransfer && !this.inRaidConfig.alwaysKeepFoundInRaidonRaidEnd) {
const dbItems = this.databaseService.getItems(); this.removeFiRStatusFromCertainItems(postRaidProfile.Inventory.items);
const itemsToRemovePropertyFrom = postRaidProfile.Inventory.items.filter((item) => {
// Has upd object + upd.SpawnedInSession property + not a quest item
return (
item.upd?.SpawnedInSession &&
!dbItems[item._tpl]._props.QuestItem &&
!(
this.inRaidConfig.keepFiRSecureContainerOnDeath &&
this.itemHelper.itemIsInsideContainer(item, "SecuredContainer", postRaidProfile.Inventory.items)
)
);
});
this.itemHelper.removeSpawnedInSessionPropertyFromItems(itemsToRemovePropertyFrom);
} }
// Add items from client profile into server profile // Add items from client profile into server profile
for (const item of postRaidInventoryItems) { this.addItemsToInventory(postRaidInventoryItems, serverProfile.Inventory.items);
// Try to find index of item to determine if we should add or replace
const existingItemIndex = serverProfile.Inventory.items.findIndex( // Add quest items from client profile into server profile
(inventoryItem) => inventoryItem._id === item._id, this.addItemsToInventory(postRaidQuestItems, serverProfile.Inventory.items);
);
if (existingItemIndex === -1) {
// Not found, add
serverProfile.Inventory.items.push(item);
} else {
// Replace item with one from client
postRaidProfile.Inventory.items.splice(existingItemIndex, 1, item);
}
}
serverProfile.Inventory.fastPanel = postRaidProfile.Inventory.fastPanel; // Quick access items bar serverProfile.Inventory.fastPanel = postRaidProfile.Inventory.fastPanel; // Quick access items bar
serverProfile.InsuredItems = insured; serverProfile.InsuredItems = insured;
} }
/**
* Remove FiR status from items
* @param items Items to process
*/
protected removeFiRStatusFromCertainItems(items: IItem[]): void {
const dbItems = this.databaseService.getItems();
const itemsToRemovePropertyFrom = items.filter((item) => {
// Has upd object + upd.SpawnedInSession property + not a quest item
return (
item.upd?.SpawnedInSession &&
!dbItems[item._tpl]._props.QuestItem &&
!(
this.inRaidConfig.keepFiRSecureContainerOnDeath &&
this.itemHelper.itemIsInsideContainer(item, "SecuredContainer", items)
)
);
});
for (const item of itemsToRemovePropertyFrom) {
delete item.upd.SpawnedInSession;
}
}
/**
* Add items from one parameter into another
* @param itemsToAdd Items we want to add
* @param serverInventoryItems Location to add items to
*/
protected addItemsToInventory(itemsToAdd: IItem[], serverInventoryItems: IItem[]): void {
for (const itemToAdd of itemsToAdd) {
// Try to find index of item to determine if we should add or replace
const existingItemIndex = serverInventoryItems.findIndex(
(inventoryItem) => inventoryItem._id === itemToAdd._id,
);
if (existingItemIndex === -1) {
// Not found, add
serverInventoryItems.push(itemToAdd);
} else {
// Replace item with one from client
serverInventoryItems.splice(existingItemIndex, 1, itemToAdd);
}
}
}
/** /**
* Clear PMC inventory of all items except those that are exempt * Clear PMC inventory of all items except those that are exempt
* Used post-raid to remove items after death * Used post-raid to remove items after death