Fixed quest items not being transferred from client to server profile
Cleaned up `setInventory()`
This commit is contained in:
parent
9b17a9b350
commit
a8c6432d28
@ -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,43 +73,71 @@ 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) {
|
||||||
|
this.removeFiRStatusFromCertainItems(postRaidProfile.Inventory.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add items from client profile into server profile
|
||||||
|
this.addItemsToInventory(postRaidInventoryItems, serverProfile.Inventory.items);
|
||||||
|
|
||||||
|
// Add quest items from client profile into server profile
|
||||||
|
this.addItemsToInventory(postRaidQuestItems, serverProfile.Inventory.items);
|
||||||
|
|
||||||
|
serverProfile.Inventory.fastPanel = postRaidProfile.Inventory.fastPanel; // Quick access items bar
|
||||||
|
serverProfile.InsuredItems = insured;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove FiR status from items
|
||||||
|
* @param items Items to process
|
||||||
|
*/
|
||||||
|
protected removeFiRStatusFromCertainItems(items: IItem[]): void {
|
||||||
const dbItems = this.databaseService.getItems();
|
const dbItems = this.databaseService.getItems();
|
||||||
|
|
||||||
const itemsToRemovePropertyFrom = postRaidProfile.Inventory.items.filter((item) => {
|
const itemsToRemovePropertyFrom = items.filter((item) => {
|
||||||
// Has upd object + upd.SpawnedInSession property + not a quest item
|
// Has upd object + upd.SpawnedInSession property + not a quest item
|
||||||
return (
|
return (
|
||||||
item.upd?.SpawnedInSession &&
|
item.upd?.SpawnedInSession &&
|
||||||
!dbItems[item._tpl]._props.QuestItem &&
|
!dbItems[item._tpl]._props.QuestItem &&
|
||||||
!(
|
!(
|
||||||
this.inRaidConfig.keepFiRSecureContainerOnDeath &&
|
this.inRaidConfig.keepFiRSecureContainerOnDeath &&
|
||||||
this.itemHelper.itemIsInsideContainer(item, "SecuredContainer", postRaidProfile.Inventory.items)
|
this.itemHelper.itemIsInsideContainer(item, "SecuredContainer", items)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.itemHelper.removeSpawnedInSessionPropertyFromItems(itemsToRemovePropertyFrom);
|
for (const item of itemsToRemovePropertyFrom) {
|
||||||
|
delete item.upd.SpawnedInSession;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add items from client profile into server profile
|
/**
|
||||||
for (const item of postRaidInventoryItems) {
|
* 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
|
// Try to find index of item to determine if we should add or replace
|
||||||
const existingItemIndex = serverProfile.Inventory.items.findIndex(
|
const existingItemIndex = serverInventoryItems.findIndex(
|
||||||
(inventoryItem) => inventoryItem._id === item._id,
|
(inventoryItem) => inventoryItem._id === itemToAdd._id,
|
||||||
);
|
);
|
||||||
if (existingItemIndex === -1) {
|
if (existingItemIndex === -1) {
|
||||||
// Not found, add
|
// Not found, add
|
||||||
serverProfile.Inventory.items.push(item);
|
serverInventoryItems.push(itemToAdd);
|
||||||
} else {
|
} else {
|
||||||
// Replace item with one from client
|
// Replace item with one from client
|
||||||
postRaidProfile.Inventory.items.splice(existingItemIndex, 1, item);
|
serverInventoryItems.splice(existingItemIndex, 1, itemToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serverProfile.Inventory.fastPanel = postRaidProfile.Inventory.fastPanel; // Quick access items bar
|
|
||||||
serverProfile.InsuredItems = insured;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user