This commit is contained in:
CWXDEV 2024-01-12 22:00:02 +00:00
commit 04564d7e76
3 changed files with 99 additions and 52 deletions

View File

@ -116,6 +116,18 @@
"min": 0.05, "min": 0.05,
"max": 1 "max": 1
}, },
"644120aa86ffbe10ee032b6f": {
"_name": "ARMOR_PLATE",
"conditionChance": 0.6,
"min": 0.3,
"max": 1
},
"65649eb40bf0ed77b8044453": {
"_name": "BUILT_IN_INSERTS",
"conditionChance": 0.3,
"min": 0.1,
"max": 1
},
"57bef4c42459772e8d35a53b": { "57bef4c42459772e8d35a53b": {
"_name": "ARMORED_EQUIPMENT", "_name": "ARMORED_EQUIPMENT",
"conditionChance": 0.6, "conditionChance": 0.6,

View File

@ -60,7 +60,7 @@ export class RagfairAssortGenerator
protected generateRagfairAssortItems(): Item[] protected generateRagfairAssortItems(): Item[]
{ {
const results: Item[] = []; const results: Item[] = [];
const items = this.itemHelper.getItems(); const items = this.itemHelper.getItems().filter(item => item._type !== "Node");
const weaponPresets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly) const weaponPresets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
? this.getDefaultPresets() ? this.getDefaultPresets()
@ -73,18 +73,16 @@ export class RagfairAssortGenerator
BaseClasses.INVENTORY, BaseClasses.INVENTORY,
BaseClasses.STATIONARY_CONTAINER, BaseClasses.STATIONARY_CONTAINER,
BaseClasses.POCKETS, BaseClasses.POCKETS,
BaseClasses.BUILT_IN_INSERTS BaseClasses.BUILT_IN_INSERTS,
BaseClasses.ARMOR,
BaseClasses.VEST,
BaseClasses.HEADWEAR,
]; ];
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
const seasonalItemTplBlacklist = this.seasonalEventService.getInactiveSeasonalEventItems(); const seasonalItemTplBlacklist = this.seasonalEventService.getInactiveSeasonalEventItems();
for (const item of items) for (const item of items)
{ {
if (item._type === "Node")
{
continue;
}
if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes)) if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes))
{ {
continue; continue;
@ -103,7 +101,7 @@ export class RagfairAssortGenerator
for (const weapon of weaponPresets) for (const weapon of weaponPresets)
{ {
results.push(this.createRagfairAssortItem(weapon._items[0]._tpl, weapon._id)); // preset id must be passed thruogh to ensure flea shows presets results.push(this.createRagfairAssortItem(weapon._items[0]._tpl, weapon._id)); // Preset id must be passed through to ensure flea shows presets
} }
return results; return results;

View File

@ -380,25 +380,25 @@ export class RagfairOfferGenerator
/** /**
* Create one flea offer for a specific item * Create one flea offer for a specific item
* @param items Item to create offer for * @param itemWithChildren Item to create offer for
* @param isPreset Is item a weapon preset * @param isPreset Is item a weapon preset
* @param itemDetails raw db item details * @param itemDetails raw db item details
* @returns Item array * @returns Item array
*/ */
protected async createSingleOfferForItem( protected async createSingleOfferForItem(
items: Item[], itemWithChildren: Item[],
isPreset: boolean, isPreset: boolean,
itemDetails: [boolean, ITemplateItem], itemDetails: [boolean, ITemplateItem],
): Promise<void> ): Promise<void>
{ {
// Set stack size to random value // Set stack size to random value
items[0].upd.StackObjectsCount = this.ragfairServerHelper.calculateDynamicStackCount(items[0]._tpl, isPreset); itemWithChildren[0].upd.StackObjectsCount = this.ragfairServerHelper.calculateDynamicStackCount(itemWithChildren[0]._tpl, isPreset);
const isBarterOffer = this.randomUtil.getChance100(this.ragfairConfig.dynamic.barter.chancePercent); const isBarterOffer = this.randomUtil.getChance100(this.ragfairConfig.dynamic.barter.chancePercent);
const isPackOffer = this.randomUtil.getChance100(this.ragfairConfig.dynamic.pack.chancePercent) const isPackOffer = this.randomUtil.getChance100(this.ragfairConfig.dynamic.pack.chancePercent)
&& !isBarterOffer && !isBarterOffer
&& items.length === 1 && itemWithChildren.length === 1
&& this.itemHelper.isOfBaseclasses(items[0]._tpl, this.ragfairConfig.dynamic.pack.itemTypeWhitelist); && this.itemHelper.isOfBaseclasses(itemWithChildren[0]._tpl, this.ragfairConfig.dynamic.pack.itemTypeWhitelist);
const randomUserId = this.hashUtil.generate(); const randomUserId = this.hashUtil.generate();
let barterScheme: IBarterScheme[]; let barterScheme: IBarterScheme[];
@ -409,28 +409,28 @@ export class RagfairOfferGenerator
this.ragfairConfig.dynamic.pack.itemCountMin, this.ragfairConfig.dynamic.pack.itemCountMin,
this.ragfairConfig.dynamic.pack.itemCountMax, this.ragfairConfig.dynamic.pack.itemCountMax,
); );
items[0].upd.StackObjectsCount = stackSize; itemWithChildren[0].upd.StackObjectsCount = stackSize;
// Don't randomise pack items // Don't randomise pack items
barterScheme = this.createCurrencyBarterScheme(items, isPackOffer, stackSize); barterScheme = this.createCurrencyBarterScheme(itemWithChildren, isPackOffer, stackSize);
} }
else if (isBarterOffer) else if (isBarterOffer)
{ {
// Apply randomised properties // Apply randomised properties
items = this.randomiseItemUpdProperties(randomUserId, items, itemDetails[1]); itemWithChildren = this.randomiseItemUpdProperties(randomUserId, itemWithChildren, itemDetails[1]);
barterScheme = this.createBarterBarterScheme(items); barterScheme = this.createBarterBarterScheme(itemWithChildren);
} }
else else
{ {
// Apply randomised properties // Apply randomised properties
items = this.randomiseItemUpdProperties(randomUserId, items, itemDetails[1]); itemWithChildren = this.randomiseItemUpdProperties(randomUserId, itemWithChildren, itemDetails[1]);
barterScheme = this.createCurrencyBarterScheme(items, isPackOffer); barterScheme = this.createCurrencyBarterScheme(itemWithChildren, isPackOffer);
} }
const offer = this.createFleaOffer( const offer = this.createFleaOffer(
randomUserId, randomUserId,
this.timeUtil.getTimestamp(), this.timeUtil.getTimestamp(),
items, itemWithChildren,
barterScheme, barterScheme,
1, 1,
isPreset || isPackOffer, isPreset || isPackOffer,
@ -542,7 +542,7 @@ export class RagfairOfferGenerator
// Roll random chance to randomise item condition // Roll random chance to randomise item condition
if (this.randomUtil.getChance100(this.ragfairConfig.dynamic.condition[parentId].conditionChance * 100)) if (this.randomUtil.getChance100(this.ragfairConfig.dynamic.condition[parentId].conditionChance * 100))
{ {
this.randomiseItemCondition(parentId, itemWithMods[0], itemDetails); this.randomiseItemCondition(parentId, itemWithMods, itemDetails);
} }
} }
@ -572,62 +572,63 @@ export class RagfairOfferGenerator
/** /**
* Alter an items condition based on its item base type * Alter an items condition based on its item base type
* @param conditionSettingsId also the parentId of item being altered * @param conditionSettingsId also the parentId of item being altered
* @param item Item to adjust condition details of * @param itemWithMods Item to adjust condition details of
* @param itemDetails db item details of first item in array * @param itemDetails db item details of first item in array
*/ */
protected randomiseItemCondition(conditionSettingsId: string, item: Item, itemDetails: ITemplateItem): void protected randomiseItemCondition(conditionSettingsId: string, itemWithMods: Item[], itemDetails: ITemplateItem): void
{ {
const rootItem = itemWithMods[0];
const itemConditionValues = this.ragfairConfig.dynamic.condition[conditionSettingsId];
const multiplier = this.randomUtil.getFloat( const multiplier = this.randomUtil.getFloat(
this.ragfairConfig.dynamic.condition[conditionSettingsId].min, itemConditionValues.min,
this.ragfairConfig.dynamic.condition[conditionSettingsId].max, itemConditionValues.max,
); );
// Armor or weapons // Randomise armor
if (item.upd.Repairable) if (this.itemHelper.armorItemCanHoldMods(rootItem._tpl))
{ {
// Randomise non-0 class armor this.randomiseArmorDurabilityValues(itemWithMods);
if (itemDetails._props.armorClass && <number>itemDetails._props.armorClass >= 1)
{
this.randomiseDurabilityValues(item, multiplier);
}
// Randomise Weapons
if (this.itemHelper.isOfBaseclass(itemDetails._id, BaseClasses.WEAPON))
{
this.randomiseDurabilityValues(item, multiplier);
}
return; return;
} }
if (item.upd.MedKit) // Randomise Weapons
if (this.itemHelper.isOfBaseclass(itemDetails._id, BaseClasses.WEAPON))
{
this.randomiseWeaponDurabilityValues(itemWithMods[0], multiplier);
return;
}
if (rootItem.upd.MedKit)
{ {
// randomize health // randomize health
item.upd.MedKit.HpResource = Math.round(item.upd.MedKit.HpResource * multiplier) || 1; rootItem.upd.MedKit.HpResource = Math.round(rootItem.upd.MedKit.HpResource * multiplier) || 1;
return; return;
} }
if (item.upd.Key && itemDetails._props.MaximumNumberOfUsage > 1) if (rootItem.upd.Key && itemDetails._props.MaximumNumberOfUsage > 1)
{ {
// randomize key uses // randomize key uses
item.upd.Key.NumberOfUsages = Math.round(itemDetails._props.MaximumNumberOfUsage * (1 - multiplier)) || 0; rootItem.upd.Key.NumberOfUsages = Math.round(itemDetails._props.MaximumNumberOfUsage * (1 - multiplier)) || 0;
return; return;
} }
if (item.upd.FoodDrink) if (rootItem.upd.FoodDrink)
{ {
// randomize food/drink value // randomize food/drink value
item.upd.FoodDrink.HpPercent = Math.round(itemDetails._props.MaxResource * multiplier) || 1; rootItem.upd.FoodDrink.HpPercent = Math.round(itemDetails._props.MaxResource * multiplier) || 1;
return; return;
} }
if (item.upd.RepairKit) if (rootItem.upd.RepairKit)
{ {
// randomize repair kit (armor/weapon) uses // randomize repair kit (armor/weapon) uses
item.upd.RepairKit.Resource = Math.round(itemDetails._props.MaxRepairResource * multiplier) || 1; rootItem.upd.RepairKit.Resource = Math.round(itemDetails._props.MaxRepairResource * multiplier) || 1;
return; return;
} }
@ -636,7 +637,7 @@ export class RagfairOfferGenerator
{ {
const totalCapacity = itemDetails._props.MaxResource; const totalCapacity = itemDetails._props.MaxResource;
const remainingFuel = Math.round(totalCapacity * multiplier); const remainingFuel = Math.round(totalCapacity * multiplier);
item.upd.Resource = { UnitsConsumed: totalCapacity - remainingFuel, Value: remainingFuel }; rootItem.upd.Resource = { UnitsConsumed: totalCapacity - remainingFuel, Value: remainingFuel };
} }
} }
@ -645,7 +646,7 @@ export class RagfairOfferGenerator
* @param item item (weapon/armor) to adjust * @param item item (weapon/armor) to adjust
* @param multiplier Value to multiple durability by * @param multiplier Value to multiple durability by
*/ */
protected randomiseDurabilityValues(item: Item, multiplier: number): void protected randomiseWeaponDurabilityValues(item: Item, multiplier: number): void
{ {
item.upd.Repairable.Durability = Math.round(item.upd.Repairable.Durability * multiplier) || 1; item.upd.Repairable.Durability = Math.round(item.upd.Repairable.Durability * multiplier) || 1;
@ -665,10 +666,46 @@ export class RagfairOfferGenerator
tempMaxDurability = item.upd.Repairable.Durability; tempMaxDurability = item.upd.Repairable.Durability;
} }
// after clamping, finally assign to the item's properties // after clamping, assign to the item's properties
item.upd.Repairable.MaxDurability = tempMaxDurability; item.upd.Repairable.MaxDurability = tempMaxDurability;
} }
protected randomiseArmorDurabilityValues(armorWithMods: Item[]): void
{
const childMultiplerValues = {};
for (const item of armorWithMods)
{
const itemDbDetails = this.itemHelper.getItem(item._tpl)[1];
if ((parseInt(<string>itemDbDetails._props.armorClass)) > 0)
{
if (!item.upd)
{
item.upd = {};
}
// Store mod types durabiltiy multiplier for later use in current/max durability value calculation
if (!childMultiplerValues[itemDbDetails._parent])
{
childMultiplerValues[itemDbDetails._parent] = Math.round(this.randomUtil.getFloat(
this.ragfairConfig.dynamic.condition[itemDbDetails._parent].min,
this.ragfairConfig.dynamic.condition[itemDbDetails._parent].max,
));
}
const maxDurability = Math.round(
this.randomUtil.getFloat(itemDbDetails._props.MaxDurability * this.randomUtil.getFloat(childMultiplerValues[itemDbDetails._parent], 1), itemDbDetails._props.MaxDurability),
);
item.upd.Repairable = {
Durability: Math.round(itemDbDetails._props.MaxDurability * childMultiplerValues[itemDbDetails._parent]) || 1,
MaxDurability: maxDurability
};
const x = 2;
}
}
}
/** /**
* Add missing conditions to an item if needed * Add missing conditions to an item if needed
* Durabiltiy for repairable items * Durabiltiy for repairable items
@ -790,15 +827,15 @@ export class RagfairOfferGenerator
/** /**
* Create a random currency-based barter scheme for an array of items * Create a random currency-based barter scheme for an array of items
* @param offerItems Items on offer * @param offerWithChildren Items on offer
* @param isPackOffer Is the barter scheme being created for a pack offer * @param isPackOffer Is the barter scheme being created for a pack offer
* @param multipler What to multiply the resulting price by * @param multipler What to multiply the resulting price by
* @returns Barter scheme for offer * @returns Barter scheme for offer
*/ */
protected createCurrencyBarterScheme(offerItems: Item[], isPackOffer: boolean, multipler = 1): IBarterScheme[] protected createCurrencyBarterScheme(offerWithChildren: Item[], isPackOffer: boolean, multipler = 1): IBarterScheme[]
{ {
const currency = this.ragfairServerHelper.getDynamicOfferCurrency(); const currency = this.ragfairServerHelper.getDynamicOfferCurrency();
const price = this.ragfairPriceService.getDynamicOfferPriceForOffer(offerItems, currency, isPackOffer) const price = this.ragfairPriceService.getDynamicOfferPriceForOffer(offerWithChildren, currency, isPackOffer)
* multipler; * multipler;
return [{ count: price, _tpl: currency }]; return [{ count: price, _tpl: currency }];