Juice sell price
This commit is contained in:
@@ -132,8 +132,8 @@ function register_storage(ctx: ServerContext) {
|
||||
return menu_type;
|
||||
}
|
||||
|
||||
// a shipping bin, like stardew valley's: a chest that every morning at 06:00 sells everything in it with a
|
||||
// base_sell_value, and pays for it in as few coins as it can
|
||||
// a shipping bin, like stardew valley's: a chest that every morning at 06:00 sells everything in it with a sell
|
||||
// value, and pays for it in as few coins as it can
|
||||
|
||||
const COINS = [
|
||||
"bworld:cobalt_coin",
|
||||
@@ -165,7 +165,7 @@ function register_shipping_bin(ctx: ServerContext, storage_menu: ReturnType<type
|
||||
let total = 0;
|
||||
for (let slot = 0; slot < container.size; slot++) {
|
||||
const item = container.get(slot);
|
||||
const value = item && ctx.items.sell_value(item.id);
|
||||
const value = item && ctx.items.sell_value(item.id, item.data);
|
||||
if (value === undefined) continue;
|
||||
total += value * item!.count;
|
||||
container.set(slot, undefined);
|
||||
|
||||
@@ -154,13 +154,18 @@ export interface JuicerTank {
|
||||
amount: number;
|
||||
}
|
||||
|
||||
// what juice sells for, as a multiple of what the items pressed to make it sell for
|
||||
export const JUICE_VALUE = 1.2;
|
||||
|
||||
// juice is one fluid for every fruit, like create's potion fluid: which fruit sits in its data, { item }. it's named
|
||||
// after that item, "Strawberry Juice", in the color its bworld:juiceable says
|
||||
// after that item, "Strawberry Juice", in the color its bworld:juiceable says, and sells for JUICE_VALUE times the
|
||||
// items it took
|
||||
function register_juice(ctx: SharedContext) {
|
||||
const item_of = (data: unknown) => {
|
||||
const item = (data as { item?: unknown } | undefined)?.item;
|
||||
return typeof item === "string" && ctx.items.exists(item) ? item : undefined;
|
||||
};
|
||||
const juiceable = (item: string) => ctx.items.components(item)["bworld:juiceable"] as JuiceableParams | undefined;
|
||||
ctx.fluids.register("bworld:juice", {
|
||||
name(data) {
|
||||
const item = item_of(data);
|
||||
@@ -168,7 +173,14 @@ function register_juice(ctx: SharedContext) {
|
||||
},
|
||||
color(data) {
|
||||
const item = item_of(data);
|
||||
return item && (ctx.items.components(item)["bworld:juiceable"] as JuiceableParams | undefined)?.color;
|
||||
return item && juiceable(item)?.color;
|
||||
},
|
||||
sell_value(data) {
|
||||
const item = item_of(data);
|
||||
if (!item) return undefined;
|
||||
const juice = juiceable(item)?.juice;
|
||||
const value = ctx.items.sell_value(item);
|
||||
return juice && value !== undefined ? JUICE_VALUE * value * 1000 / juice : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user