Files
SectSimulator/src/Core/GameConfig.gd
T

90 lines
3.9 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 天)。
var recruit_interval_years := 0.1
## 定期弹窗候选人数。
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
## 各难度资质权重表(键 = 难度档位,值 = 下品/中品/上品/天骄 权重)。
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 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