Juice sell price
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import type { FluidRules } from "./fluids.ts";
|
||||
import type { FluidVariant } from "./mod_api/shared.ts";
|
||||
import { is_object } from "./schema.ts";
|
||||
import { same_data } from "./utils.ts";
|
||||
@@ -40,6 +41,18 @@ export function contained_fluid(id: string, data?: unknown): FluidVariant | unde
|
||||
return fluid as unknown as FluidVariant;
|
||||
}
|
||||
|
||||
// what one of a stack sells for: its item's base_sell_value, and a full fluid container's fluid on top, rounded up.
|
||||
// undefined when neither has a value, so it can't be sold
|
||||
export function sell_value(id: string, data: unknown, fluids: FluidRules): number | undefined {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
const fluid = contained_fluid(id, data);
|
||||
const per_bucket = fluid && fluids.sell_value(fluid);
|
||||
if (per_bucket === undefined) return item?.base_sell_value;
|
||||
const value = per_bucket * item!.fluid_container!.capacity / 1000;
|
||||
// so float error doesn't round 18.000000000000004 up to 19
|
||||
return (item!.base_sell_value ?? 0) + Math.ceil(value - 1e-9);
|
||||
}
|
||||
|
||||
export class ItemStack<T = unknown | undefined> {
|
||||
type_id: string;
|
||||
amount: number;
|
||||
|
||||
Reference in New Issue
Block a user