Fixed location loot generator not creating unique IDs for weapons/armor child items
This commit is contained in:
parent
eef071724f
commit
1d55075f99
@ -873,13 +873,13 @@ export class LocationLootGenerator {
|
|||||||
} else {
|
} else {
|
||||||
// Also used by armors to get child mods
|
// Also used by armors to get child mods
|
||||||
// Get item + children and add into array we return
|
// Get item + children and add into array we return
|
||||||
const itemWithChildren = this.itemHelper.findAndReturnChildrenAsItems(
|
let itemWithChildren = this.itemHelper.findAndReturnChildrenAsItems(
|
||||||
spawnPoint.template.Items,
|
spawnPoint.template.Items,
|
||||||
chosenItem._id,
|
chosenItem._id,
|
||||||
);
|
);
|
||||||
|
|
||||||
// We need to reparent to ensure ids are unique
|
// Ensure all IDs are unique
|
||||||
this.reparentItemAndChildren(itemWithChildren);
|
itemWithChildren = this.itemHelper.replaceIDs(itemWithChildren);
|
||||||
|
|
||||||
itemWithMods.push(...itemWithChildren);
|
itemWithMods.push(...itemWithChildren);
|
||||||
}
|
}
|
||||||
@ -890,26 +890,6 @@ export class LocationLootGenerator {
|
|||||||
return { items: itemWithMods, width: size.width, height: size.height };
|
return { items: itemWithMods, width: size.width, height: size.height };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the _id value for base item + all children items parentid value
|
|
||||||
* @param itemWithChildren Item with mods to update
|
|
||||||
* @param newId new id to add on chidren of base item
|
|
||||||
*/
|
|
||||||
protected reparentItemAndChildren(itemWithChildren: Item[], newId = this.objectId.generate()): void {
|
|
||||||
// original id on base item
|
|
||||||
const oldId = itemWithChildren[0]._id;
|
|
||||||
|
|
||||||
// Update base item to use new id
|
|
||||||
itemWithChildren[0]._id = newId;
|
|
||||||
|
|
||||||
// Update all parentIds of items attached to base item to use new id
|
|
||||||
for (const item of itemWithChildren) {
|
|
||||||
if (item.parentId === oldId) {
|
|
||||||
item.parentId = newId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find an item in array by its _tpl, handle differently if chosenTpl is a weapon
|
* Find an item in array by its _tpl, handle differently if chosenTpl is a weapon
|
||||||
* @param items Items array to search
|
* @param items Items array to search
|
||||||
@ -977,7 +957,7 @@ export class LocationLootGenerator {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// RSP30 (62178be9d0050232da3485d9/624c0b3340357b5f566e8766/6217726288ed9f0845317459) doesnt have any default presets and kills this code below as it has no chidren to reparent
|
// RSP30 (62178be9d0050232da3485d9/624c0b3340357b5f566e8766/6217726288ed9f0845317459) doesnt have any default presets and kills this code below as it has no chidren to reparent
|
||||||
this.logger.debug(`createItem() No preset found for weapon: ${chosenTpl}`);
|
this.logger.debug(`createStaticLootItem() No preset found for weapon: ${chosenTpl}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootItem = items[0];
|
const rootItem = items[0];
|
||||||
|
@ -787,6 +787,27 @@ export class ItemHelper {
|
|||||||
return matchingItems;
|
return matchingItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the _id value for base item + all children that are children of it
|
||||||
|
* REPARENTS ROOT ITEM ID, NOTHING ELSE
|
||||||
|
* @param itemWithChildren Item with mods to update
|
||||||
|
* @param newId new id to add on chidren of base item
|
||||||
|
*/
|
||||||
|
public replaceRootItemID(itemWithChildren: Item[], newId = this.objectId.generate()): void {
|
||||||
|
// original id on base item
|
||||||
|
const oldId = itemWithChildren[0]._id;
|
||||||
|
|
||||||
|
// Update base item to use new id
|
||||||
|
itemWithChildren[0]._id = newId;
|
||||||
|
|
||||||
|
// Update all parentIds of items attached to base item to use new id
|
||||||
|
for (const item of itemWithChildren) {
|
||||||
|
if (item.parentId === oldId) {
|
||||||
|
item.parentId = newId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regenerate all GUIDs with new IDs, for the exception of special item types (e.g. quest, sorting table, etc.) This
|
* Regenerate all GUIDs with new IDs, for the exception of special item types (e.g. quest, sorting table, etc.) This
|
||||||
* function will not mutate the original items array, but will return a new array with new GUIDs.
|
* function will not mutate the original items array, but will return a new array with new GUIDs.
|
||||||
|
@ -85,6 +85,7 @@ export class LocationLifecycleService {
|
|||||||
this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION);
|
this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handle client/match/local/start */
|
||||||
public startLocalRaid(sessionId: string, request: IStartLocalRaidRequestData): IStartLocalRaidResponseData {
|
public startLocalRaid(sessionId: string, request: IStartLocalRaidRequestData): IStartLocalRaidResponseData {
|
||||||
const playerProfile = this.profileHelper.getPmcProfile(sessionId);
|
const playerProfile = this.profileHelper.getPmcProfile(sessionId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user