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
+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] = []