feat: 口粮消耗与饥饿减半([food] 配置驱动)

This commit is contained in:
2026-08-09 16:19:01 +08:00
parent b85d7ef991
commit 00c4495bca
5 changed files with 45 additions and 7 deletions
+5 -5
View File
@@ -2,7 +2,7 @@
> 对应开发计划表 D6(8/8):① 灵石矿场景 ② 建造→产出 ③ 升级。交付标准:建筑产资源,升级加速。
> 本文档只描述设计,不包含代码。
> 状态:步骤 14、6 已实现(食物资源/HUD 灵米/开局赠送/建筑参数配置/Building+BuildingManager/BuildingsPanel+资源按钮+暂停恢复),步骤 5(口粮/饥饿/离宗)待实现
> 状态:步骤 1–6 已实现(食物资源/HUD 灵米/开局赠送/建筑参数配置/Building+BuildingManager/BuildingsPanel/口粮消耗+饥饿减半),步骤 5 的离宗部分待接入
---
@@ -161,12 +161,12 @@ hunger_threshold_days=30 ; 断粮累计天数上限(达到即离宗)
| 改动 | `src/Sect/buildings/Building.gd`type/level + 价格产出计算,运行时读配置);`src/Sect/BuildingManager.gd`(建造/升级/每日产出/`buildings_changed` 信号);`project.godot` 注册 Autoload |
| 验证 | ✅ 建造扣费入列、每日产出进 SectManager、升级后产出提升(10→15)、灵石不足拒绝 |
### 步骤 5:口粮消耗 + 饥饿惩罚 + 断粮离宗
### 步骤 5:口粮消耗 + 饥饿惩罚 + 断粮离宗 🟡(前两部分已实现,离宗待接入)
| 项 | 内容 |
|----|------|
| 改动 | `Disciple.gd``hunger_days``CultivationManager.gd` 每日先结算口粮(消耗→饥饿→离宗),`_gain_exp` 乘饥饿倍率 |
| 验证 | 模拟 40 天断粮:饥饿累计、修炼减半、第 30 天离宗、日志可见;恢复食物后清零 |
| 改动 | `Disciple.gd``hunger_days``CultivationManager.gd` 每日先结算口粮(消耗→饥饿累计),`_gain_exp` 乘饥饿倍率 |
| 验证 | ✅ 模拟:充足 30 天食物精确扣减、饥饿清零;断粮 5 天饥饿=5、修为增量精确减半(10→5/日);恢复后清零。离宗(≥阈值移除)待接入 |
### 步骤 6BuildingsPanel UI + "资源"按钮接线 ✅
@@ -195,7 +195,7 @@ hunger_threshold_days=30 ; 断粮累计天数上限(达到即离宗)
- [x] 升级建筑后产出提升(升级倍率生效),价格按倍率递增
- [x] 灵石不足时建造/升级按钮禁用
- [x] 等级达到上限后不可再升级
- [ ] 练气弟子每日消耗食物;断粮后饥饿天数累计、修炼速度减半
- [x] 练气弟子每日消耗食物;断粮后饥饿天数累计、修炼速度减半
- [ ] 断粮累计 30 天弟子离宗(名录移除 + 日志)
- [ ] 食物恢复充足后饥饿清零
- [ ] 建筑/饥饿数据为纯数据(可序列化,D8 存档接入)
+5
View File
@@ -47,3 +47,8 @@ cost=100 ; 建造价(灵石)
output=5 ; 日产出(灵米)
upgrade_cost_x=2.0 ; 升级价格倍率
upgrade_output_x=1.5 ; 升级产出倍率
[food] ; 口粮与生存
consumption_per_disciple=1 ; 练气弟子人均日消耗灵米
hunger_speed_multiplier=0.5 ; 饥饿期间修炼速度倍率
hunger_threshold_days=30 ; 断粮累计天数上限(达到即离宗,待接入)
+22 -2
View File
@@ -12,14 +12,32 @@ func _ready() -> void:
# 每日推进时结算全体已入宗弟子的修为与境界
TimeSystem.day_passed.connect(_on_day_passed)
## 每日结算:仅结算已入宗名录(候选池不修炼)。
## 每日结算:先扣口粮,再结算已入宗弟子的修为与境界(候选池不修炼)。
func _on_day_passed(_year: int, _month: int, _day: int) -> void:
_settle_food()
for d in DiscipleManager.disciples:
_gain_exp(d)
_check_breakthrough(d)
## 每日口粮结算:练气弟子人均消耗灵米(筑基+辟谷豁免)。
## 食物充足 → 扣减并饥饿清零;食物不足 → 归零并全员饥饿天数 +1。
func _settle_food() -> void:
var eaters: Array[Disciple] = []
for d in DiscipleManager.disciples:
if d.realm_index == 0:
eaters.append(d)
var need := eaters.size() * GameConfig.food_consumption_per_disciple
if SectManager.food >= need:
SectManager.remove_food(need)
for d in eaters:
d.hunger_days = 0
return
SectManager.remove_food(SectManager.food)
for d in eaters:
d.hunger_days += 1
## 按公式累计一日修为。
## 速度 = 基础速度 × 资质倍率 × 灵根容量 × 天灵根加成 × 灵气浓度
## 速度 = 基础速度 × 资质倍率 × 灵根容量 × 天灵根加成 × 灵气浓度 × 饥饿倍率
## 练气圆满(13 层)后修为封顶,不再增长。
## @param d: 已入宗弟子
func _gain_exp(d: Disciple) -> void:
@@ -32,6 +50,8 @@ func _gain_exp(d: Disciple) -> void:
if d.is_heavenly:
speed *= GameConfig.heavenly_bonus
speed *= GameConfig.qi_concentration
if d.hunger_days > 0:
speed *= GameConfig.hunger_speed_multiplier
d.cultivation_exp += speed
## 突破判定:修为满当前层门槛时推进境界。
+1
View File
@@ -29,6 +29,7 @@ var join_day: int = 0 # 入宗日
var realm_index: int = 0 # 大境界索引(0=练气)
var sub_realm_index: int = 0 # 小境界索引(练气层数-1
var cultivation_exp: float = 0.0 # 修为(float 可积累小数,D5 每日结算)
var hunger_days: int = 0 # 断粮累计天数(≥阈值离宗,方案 B)
# —— 辅助函数:把数据翻译成给人看的文本 ——
func get_aptitude_name() -> String:
+12
View File
@@ -56,6 +56,14 @@ var building_params: Dictionary = {
"field": {"cost": 100, "output": 5, "upgrade_cost_x": 2.0, "upgrade_output_x": 1.5},
}
# —— 口粮与生存(对应 cfg 的 [food] 节)——
## 练气弟子人均日消耗灵米。
var food_consumption_per_disciple := 1
## 饥饿期间修炼速度倍率。
var hunger_speed_multiplier := 0.5
## 断粮累计天数上限(达到即离宗)。
var hunger_threshold_days := 30
## 各难度资质权重表(键 = 难度档位,值 = 下品/中品/上品/天骄 权重)。
var aptitude_weights_by_difficulty: Dictionary = {
"normal": [45, 35, 15, 5],
@@ -121,6 +129,10 @@ func _load_config() -> void:
"upgrade_cost_x": cfg.get_value("building_" + key, "upgrade_cost_x", p["upgrade_cost_x"]),
"upgrade_output_x": cfg.get_value("building_" + key, "upgrade_output_x", p["upgrade_output_x"]),
}
# 口粮与生存
food_consumption_per_disciple = cfg.get_value("food", "consumption_per_disciple", food_consumption_per_disciple)
hunger_speed_multiplier = cfg.get_value("food", "hunger_speed_multiplier", hunger_speed_multiplier)
hunger_threshold_days = cfg.get_value("food", "hunger_threshold_days", hunger_threshold_days)
var apt_raw: Variant = cfg.get_value("cultivation", "aptitude_speed", [])
if apt_raw is Array and apt_raw.size() == aptitude_speed.size():
var arr: Array[float] = []