respect vendor offer seed for innate damage

This commit is contained in:
Sainan 2025-04-01 13:58:15 +02:00
parent ac2de14674
commit 5b1d4cdd3e
3 changed files with 43 additions and 15 deletions

View File

@ -69,7 +69,7 @@ import { addStartingGear } from "@/src/controllers/api/giveStartingGearControlle
import { addQuestKey, completeQuest } from "@/src/services/questService"; import { addQuestKey, completeQuest } from "@/src/services/questService";
import { handleBundleAcqusition } from "./purchaseService"; import { handleBundleAcqusition } from "./purchaseService";
import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json"; import libraryDailyTasks from "@/static/fixed_responses/libraryDailyTasks.json";
import { getRandomElement, getRandomInt } from "./rngService"; import { getRandomElement, getRandomInt, SRng } from "./rngService";
import { createMessage } from "./inboxService"; import { createMessage } from "./inboxService";
export const createInventory = async ( export const createInventory = async (
@ -230,7 +230,8 @@ export const addItem = async (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
typeName: string, typeName: string,
quantity: number = 1, quantity: number = 1,
premiumPurchase: boolean = false premiumPurchase: boolean = false,
seed?: bigint
): Promise<IInventoryChanges> => { ): Promise<IInventoryChanges> => {
// Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments. // Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments.
if (typeName in ExportBundles) { if (typeName in ExportBundles) {
@ -380,12 +381,11 @@ export const addItem = async (
defaultOverwrites.Features = EquipmentFeatures.DOUBLE_CAPACITY; defaultOverwrites.Features = EquipmentFeatures.DOUBLE_CAPACITY;
} }
if (weapon.maxLevelCap == 40 && typeName.indexOf("BallasSword") == -1) { if (weapon.maxLevelCap == 40 && typeName.indexOf("BallasSword") == -1) {
defaultOverwrites.UpgradeType = "/Lotus/Weapons/Grineer/KuvaLich/Upgrades/InnateDamageRandomMod"; if (!seed) {
defaultOverwrites.UpgradeFingerprint = JSON.stringify({ seed = BigInt(Math.round(Math.random() * Number.MAX_SAFE_INTEGER));
compat: typeName, }
buffs: [ const rng = new SRng(seed);
{ const tag = rng.randomElement([
Tag: getRandomElement([
"InnateElectricityDamage", "InnateElectricityDamage",
"InnateFreezeDamage", "InnateFreezeDamage",
"InnateHeatDamage", "InnateHeatDamage",
@ -393,8 +393,19 @@ export const addItem = async (
"InnateMagDamage", "InnateMagDamage",
"InnateRadDamage", "InnateRadDamage",
"InnateToxinDamage" "InnateToxinDamage"
]), ]);
Value: Math.trunc(Math.random() * 0x40000000) const WeaponUpgradeValueAttenuationExponent = 2.25;
let value = Math.pow(rng.randomFloat(), WeaponUpgradeValueAttenuationExponent);
if (value >= 0.941428) {
value = 1;
}
defaultOverwrites.UpgradeType = "/Lotus/Weapons/Grineer/KuvaLich/Upgrades/InnateDamageRandomMod";
defaultOverwrites.UpgradeFingerprint = JSON.stringify({
compat: typeName,
buffs: [
{
Tag: tag,
Value: Math.trunc(value * 0x40000000)
} }
] ]
}); });

View File

@ -51,6 +51,7 @@ export const handlePurchase = async (
logger.debug("purchase request", purchaseRequest); logger.debug("purchase request", purchaseRequest);
const prePurchaseInventoryChanges: IInventoryChanges = {}; const prePurchaseInventoryChanges: IInventoryChanges = {};
let seed: bigint | undefined;
if (purchaseRequest.PurchaseParams.Source == 7) { if (purchaseRequest.PurchaseParams.Source == 7) {
const rawManifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!); const rawManifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
if (rawManifest) { if (rawManifest) {
@ -74,6 +75,9 @@ export const handlePurchase = async (
prePurchaseInventoryChanges prePurchaseInventoryChanges
); );
} }
if (offer.LocTagRandSeed !== undefined) {
seed = BigInt(offer.LocTagRandSeed);
}
if (!config.noVendorPurchaseLimits && ItemId) { if (!config.noVendorPurchaseLimits && ItemId) {
inventory.RecentVendorPurchases ??= []; inventory.RecentVendorPurchases ??= [];
let vendorPurchases = inventory.RecentVendorPurchases.find( let vendorPurchases = inventory.RecentVendorPurchases.find(
@ -136,7 +140,10 @@ export const handlePurchase = async (
const purchaseResponse = await handleStoreItemAcquisition( const purchaseResponse = await handleStoreItemAcquisition(
purchaseRequest.PurchaseParams.StoreItem, purchaseRequest.PurchaseParams.StoreItem,
inventory, inventory,
purchaseRequest.PurchaseParams.Quantity purchaseRequest.PurchaseParams.Quantity,
undefined,
undefined,
seed
); );
combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges); combineInventoryChanges(purchaseResponse.InventoryChanges, prePurchaseInventoryChanges);
@ -324,7 +331,8 @@ export const handleStoreItemAcquisition = async (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
quantity: number = 1, quantity: number = 1,
durability: TRarity = "COMMON", durability: TRarity = "COMMON",
ignorePurchaseQuantity: boolean = false ignorePurchaseQuantity: boolean = false,
seed?: bigint
): Promise<IPurchaseResponse> => { ): Promise<IPurchaseResponse> => {
let purchaseResponse = { let purchaseResponse = {
InventoryChanges: {} InventoryChanges: {}
@ -345,7 +353,7 @@ export const handleStoreItemAcquisition = async (
} }
switch (storeCategory) { switch (storeCategory) {
default: { default: {
purchaseResponse = { InventoryChanges: await addItem(inventory, internalName, quantity, true) }; purchaseResponse = { InventoryChanges: await addItem(inventory, internalName, quantity, true, seed) };
break; break;
} }
case "Types": case "Types":

View File

@ -127,4 +127,13 @@ export class SRng {
} }
return min; return min;
} }
randomElement<T>(arr: T[]): T {
return arr[this.randomInt(0, arr.length - 1)];
}
randomFloat(): number {
this.state = (0x5851f42d4c957f2dn * this.state + 0x14057b7ef767814fn) & 0xffffffffffffffffn;
return (Number(this.state >> 38n) & 0xffffff) * 0.000000059604645;
}
} }