**注意:** 在此插件达到版本号的稳定阶段之前,不建议将其用于生产环境。在此之前也不会提供英文 Wiki。请将其视为试用版。如果在测试插件时遇到任何问题,请随时在 Discord 或 GitHub Issues 上报告。
# HyphaShop
一个高度动态、辅助脚本、高性能的商店插件。
## 特性
* 渐进式 — 高级功能是可选的
* 随机产品定价
* 随机产品数量
* 条件性产品列表
* 产品库存
* 可重复使用的产品配置 (无需重复设置)
* 产品稀有度
* 捆绑产品
* 基本属性支持 (Skull, Flag, Trim, Potion Effect, Custom Model Data)
* 自动翻译 Vanilla 项目名称
* 商店中的商人模式
* 交易日志
* 统一的基于购物车(cart)的交易
* 完全可翻译的内容
* 全面的 GUI 系统
* 类似于 JavaScript 的脚本系统
## 渐进式
如果您只需要一个简单的商店插件来销售 Vanilla 项目,可以遵循 `product/wools.yml` 中的配置示例。
所有高级功能都是完全可选的,并且在未使用时不会消耗额外的 CPU。
## 随机产品定价
添加以下配置以启用随机定价,如图片所示:
```yml
default-configs:
buy-price:
mean: 80
dev: 10
round: true
sell-price:
mean: 5
dev: 2
```

## 随机产品数量
产品数量可以接受脚本字符串作为值。它还可以根据数量自动调整价格。
```yml
default-configs:
item:
amount: 8 + nextUniform(8, 16)
buy-price:
formula: base * (1 + (Math.random() * 2 - 1) * buy_range) * product_amount
sell-price:
formula: base * (1 + (Math.random() * 2 - 1) * sell_range) * product_amount
products:
GOLD_ORE:
item:
base: gold_ore
buy-price:
context: const base = 200
sell-price:
context: const base = 70
```

## 条件性产品列表
脚本可以在插件的各种钩子上参与逻辑,包括控制是否列出产品。
```yml
default-configs:
actions:
on-before-list:
- |
const timeStr = papi("%world_time_world%").split(":");
const hours = timeStr[0];
number(hours) >= 20 || number(hours) < 6;
- total_history_bought_amount <= 64
```
## 产品库存
产品可以拥有自己的库存。 一旦库存耗尽,它们将无法再购买。
```yml
default-configs:
stock:
global:
size: 1024
replenish: true
overflow: true
inherit: true
```

## 可重复使用的产品配置
对于相似的产品(例如,羊毛的所有颜色),您可以重用默认配置。 这极大地减少了设置的复杂性。
```yml
default-configs:
item:
amount: 16
buy-price:
mean: 80
dev: 10
round: true
sell-price:
mean: 5
dev: 2
rarity: uncommon
cacheable: true
products:
LIGHT_BLUE_WOOL:
item:
base: light_blue_wool
YELLOW_WOOL:
item:
base: yellow_wool
LIME_WOOL:
item:
base: lime_wool
```

## 产品稀有度
您可以为每个产品分配稀有度级别。 这会影响随机列表的概率,也可以作为装饰。
```yml
rarities:
common:
name: "Common"
weight: 100
uncommon:
name: "Uncommon"
weight: 80
rare:
name: "Rare"
weight: 60
```
## 捆绑产品
产品可以打包成包含其他多个产品的捆绑包。
在计算捆绑包的价格时,其内容的总体价格作为上下文变量可用。
```yml
products:
WARM_COLOR_WOOL_BUNDLE:
icon:
base: barrel
amount: 1
name: "Warm toned wool bundle"
lore:
- "A bundle that contains all"
- "warm tonedwool."
buy-price:
formula: bundle_total_new * 0.8
sell-price:
disable: true
bundle-contents:
- YELLOW_WOOL
- BROWN_WOOL
- MAGIC_ORANGE_WOOL
- RED_WOOL:3
rarity: rare
```

## 基本属性支持
借助高版本的 `Data Component` 功能,该插件支持物品的基本属性。


## 自动翻译 Vanilla 项目名称
使用 `Adventure API` 的 `Translatable Component` 机制,Vanilla 项目名称会自动翻译,无需手动配置或下载语言文件。
```yml
products:
LIME_WOOL:
item:
base: lime_wool
```

## 商人模式
商店可以拥有自己的虚拟余额。 一旦余额耗尽,它们将无法再从玩家那里购买产品。
```yml
settings:
merchant:
balance: 1000
replenish: true
overflow: true
inherit: true
```

## 交易日志
每个玩家的交易都会记录在数据库中,供他们自己或服务器管理员审查。

## 基于购物车的交易
除了传统的直接购买外,玩家可以将多个产品添加到购物车并一次性购买它们。

## 全面的 GUI 系统
除了商店菜单外,您可以使用相同的 GUI 配置逻辑来创建自定义 GUI。
## 类似于 JavaScript 的脚本系统
此插件包含一个内置的脚本系统,语法类似于 JavaScript(为了函数调用而简化),提供高可配置性。