feat: 建筑面板——资源按钮入口+建造升级产出(D6 核心)
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
## 建筑管理器(Autoload 单例)。
|
||||
## 负责建筑建造/升级与每日产出结算,产出直接进入 SectManager 资源。
|
||||
## 本期每种建筑至多一座(面板按类型一行展示);多实例留待后续扩展。
|
||||
extends Node
|
||||
|
||||
## 建筑列表变化时发出(建造/升级/重置)。
|
||||
signal buildings_changed
|
||||
|
||||
## 宗门建筑列表。
|
||||
var buildings: Array[Building] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# 每日推进时结算各建筑产出
|
||||
TimeSystem.day_passed.connect(_on_day_passed)
|
||||
|
||||
## 建造建筑:检查灵石足够 → 扣费入列。
|
||||
## 同类型已存在时拒绝(本期一座一型)。
|
||||
## @param type: 建筑种类
|
||||
## @return 是否建造成功
|
||||
func build(type: Building.Type) -> bool:
|
||||
if _find(type) != null:
|
||||
return false
|
||||
var b := Building.new()
|
||||
b.type = type
|
||||
if SectManager.spirit_stones < b.get_build_cost():
|
||||
return false
|
||||
SectManager.remove_spirit_stones(b.get_build_cost())
|
||||
buildings.append(b)
|
||||
buildings_changed.emit()
|
||||
return true
|
||||
|
||||
## 升级建筑:检查灵石足够 → 扣费提升等级。
|
||||
## @param b: 要升级的建筑
|
||||
## @return 是否升级成功
|
||||
func upgrade(b: Building) -> bool:
|
||||
if b.is_max_level() or SectManager.spirit_stones < b.get_upgrade_cost():
|
||||
return false
|
||||
SectManager.remove_spirit_stones(b.get_upgrade_cost())
|
||||
b.level += 1
|
||||
buildings_changed.emit()
|
||||
return true
|
||||
|
||||
## 清空建筑列表(新游戏开局调用)。
|
||||
func reset() -> void:
|
||||
buildings.clear()
|
||||
buildings_changed.emit()
|
||||
|
||||
## 每日结算:各建筑产出进入 SectManager 对应资源。
|
||||
func _on_day_passed(_year: int, _month: int, _day: int) -> void:
|
||||
for b in buildings:
|
||||
match b.type:
|
||||
Building.Type.MINE:
|
||||
SectManager.add_spirit_stones(b.get_output())
|
||||
Building.Type.FIELD:
|
||||
SectManager.add_food(b.get_output())
|
||||
|
||||
## 查找指定类型的建筑,不存在返回 null。
|
||||
func _find(type: Building.Type) -> Building:
|
||||
for b in buildings:
|
||||
if b.type == type:
|
||||
return b
|
||||
return null
|
||||
Reference in New Issue
Block a user