Files
SectSimulator/src/Core/GameConfig.gd
T

159 lines
7.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 游戏全局配置(Autoload 单例)。
## 启动时从 resources/game_config.cfg 读取所有可调参数,
## 其他系统通过公开变量读取,如 GameConfig.recruit_interval_years。
extends Node
## 配置文件路径(res:// 开发期可改,导出后只读)。
const CONFIG_PATH := "res://resources/game_config.cfg"
# —— 招募系统(对应 cfg 的 [recruitment] 节)——
## 当前难度档位(对应下方各难度节,如 "normal"/"hard")。
var difficulty := "normal"
## 开局候选人数。
var opening_applicant_count := 5
## 开局必须选满数。
var opening_pick_count := 3
## 定期招募间隔(游戏年,1 年 = 360 天)。
## 注意:cfg 文件不随导出打包(未知扩展名),导出版使用此默认值——与 cfg 保持同步。
var recruit_interval_years := 12.0
## 定期弹窗候选人数。
var recruit_applicant_count := 3
## 天灵根概率(仅天骄资质中再掷一次)。
var heavenly_root_chance := 0.5
## 灵根数量权重(按根数-1 索引:1根~5根,和=100 即百分比概率)。
var root_count_weights: Array[int] = [20, 20, 20, 20, 20]
# —— 修炼系统(对应 cfg 的 [cultivation] 节)——
## 基础修炼速度(修为/游戏日)。
var cultivation_base_speed := 10.0
## 宗门灵气浓度(修炼速度系数,D6 建筑系统接入后动态化)。
var qi_concentration := 1.0
## 资质修炼倍率(按下品/中品/上品/天骄索引)。
var aptitude_speed: Array[float] = [0.6, 1.0, 1.5, 2.0]
## 天灵根额外修炼速度倍率。
var heavenly_bonus := 1.5
## 各瓶颈层突破成功率(与 bottleneck_levels 一一对应:升4层/7层/10层/13层)。
var bottleneck_chances: Array[float] = [0.85, 0.8, 0.75, 0.6]
## 练气期各层升级所需修为(练气 1→2 到 12→13,共 12 项)。
var level_thresholds: Array[float] = [100.0, 200.0, 350.0, 550.0, 800.0, 1100.0, 1500.0, 2000.0, 2600.0, 3300.0, 4100.0, 5000.0]
## 瓶颈目标层(升到这些层需突破判定)。
var bottleneck_levels: Array[int] = [4, 7, 10, 13]
# —— UI 通用(对应 cfg 的 [ui] 节)——
## HUD 字体大小(导出版用默认值,与 cfg 保持同步)。
var hud_font_size := 24
# —— 建筑系统(对应 cfg 的 [building] 节)——
## 开局赠送灵石(新游戏发放)。
var starting_spirit_stones := 500
## 开局赠送灵米(新游戏发放)。
var starting_food := 100
## 建筑等级上限。
var building_max_level := 10
## 各建筑参数表(键 = 建筑类型名,值 = {cost, output, upgrade_cost_x, upgrade_output_x})。
var building_params: Dictionary = {
"mine": {"cost": 200, "output": 10, "upgrade_cost_x": 2.0, "upgrade_output_x": 1.5},
"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],
"hard": [60, 30, 8, 2],
}
func _ready() -> void:
_load_config()
## 读取配置文件;缺失的项保持代码默认值,不会报错。
func _load_config() -> void:
var cfg := ConfigFile.new()
var err := cfg.load(CONFIG_PATH)
if err != OK:
push_warning("GameConfig: 配置文件不存在,使用默认值")
return
difficulty = cfg.get_value("recruitment", "difficulty", difficulty)
opening_applicant_count = cfg.get_value("recruitment", "opening_applicant_count", opening_applicant_count)
opening_pick_count = cfg.get_value("recruitment", "opening_pick_count", opening_pick_count)
recruit_interval_years = cfg.get_value("recruitment", "recruit_interval_years", recruit_interval_years)
recruit_applicant_count = cfg.get_value("recruitment", "recruit_applicant_count", recruit_applicant_count)
heavenly_root_chance = cfg.get_value("recruitment", "heavenly_root_chance", heavenly_root_chance)
var root_raw: Variant = cfg.get_value("recruitment", "root_count_weights", [])
if root_raw is Array and root_raw.size() == root_count_weights.size():
var arr_roots: Array[int] = []
for w in root_raw:
arr_roots.append(int(w))
root_count_weights = arr_roots
# 修炼系统
cultivation_base_speed = cfg.get_value("cultivation", "base_speed", cultivation_base_speed)
qi_concentration = cfg.get_value("cultivation", "qi_concentration", qi_concentration)
heavenly_bonus = cfg.get_value("cultivation", "heavenly_bonus", heavenly_bonus)
var bc_raw: Variant = cfg.get_value("cultivation", "breakthrough_chances", [])
if bc_raw is Array and bc_raw.size() == bottleneck_chances.size():
var arr_bc: Array[float] = []
for v in bc_raw:
arr_bc.append(float(v))
bottleneck_chances = arr_bc
var th_raw: Variant = cfg.get_value("cultivation", "level_thresholds", [])
if th_raw is Array and th_raw.size() == level_thresholds.size():
var arr_th: Array[float] = []
for v in th_raw:
arr_th.append(float(v))
level_thresholds = arr_th
var bn_raw: Variant = cfg.get_value("cultivation", "bottleneck_levels", [])
if bn_raw is Array and bn_raw.size() == bottleneck_levels.size():
var arr_bn: Array[int] = []
for v in bn_raw:
arr_bn.append(int(v))
bottleneck_levels = arr_bn
# UI 通用
hud_font_size = cfg.get_value("ui", "hud_font_size", hud_font_size)
# 建筑系统
starting_spirit_stones = cfg.get_value("building", "starting_spirit_stones", starting_spirit_stones)
starting_food = cfg.get_value("building", "starting_food", starting_food)
building_max_level = cfg.get_value("building", "max_level", building_max_level)
for key in building_params.keys():
var p: Dictionary = building_params[key]
building_params[key] = {
"cost": cfg.get_value("building_" + key, "cost", p["cost"]),
"output": cfg.get_value("building_" + key, "output", p["output"]),
"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] = []
for v in apt_raw:
arr.append(float(v))
aptitude_speed = arr
# 逐档读取难度权重(INI 数组字面量,如 [45, 35, 15, 5]
for key in aptitude_weights_by_difficulty.keys():
var raw: Variant = cfg.get_value("recruitment_" + key, "aptitude_weights", [])
if raw is Array and raw.size() > 0:
var arr: Array[int] = []
for w in raw:
arr.append(int(w))
aptitude_weights_by_difficulty[key] = arr
## 当前难度下的资质权重(下品/中品/上品/天骄)。
func get_aptitude_weights() -> Array[int]:
var raw: Array = aptitude_weights_by_difficulty.get(difficulty, aptitude_weights_by_difficulty["normal"])
var result: Array[int] = []
for w in raw:
result.append(int(w))
return result