1. 系統概述與設計目標
系統定位與作用
數值系統是《矮人要塞》所有遊戲機制的基礎,它定義了遊戲中所有元素(生物、物品、建築等)的屬性、能力和行為規則。與其他遊戲不同,矮人要塞的數值系統強調細節和真實性,通過大量細粒度的屬性創造真實的模擬體驗,而非簡化的數值模型。
數值系統不僅僅是遊戲平衡的工具,更是創造遊戲世界真實感的核心。每個物品都有其獨特的屬性組合,每個生物都有詳細的身體狀態,每個技能都有精確的等級和經驗值。這種設計理念使得遊戲世界更加豐富和可信。
設計目標
- 細節決定真實:通過大量細節屬性創造真實的模擬體驗,而非簡化數值模型
- 多維度屬性:每個元素都有多個維度的屬性,共同決定其表現
- 動態變化:屬性不是固定值,而是會隨遊戲進程動態變化
- 歷史關聯:物品屬性與歷史事件關聯,創造獨特的敍事價值
- 技能專業化:鼓勵玩家培養專業矮人,增加策略深度
核心價值
- 真實感:詳細的屬性系統創造真實的模擬體驗
- 策略深度:多維度屬性創造豐富的策略選擇
- 敍事價值:歷史價值系統創造獨特的敍事體驗
- 重玩價值:不同的屬性組合創造不同的遊戲體驗
系統架構概覽
數值系統可以分為以下幾個核心模塊:
數值系統
├── 生物屬性模塊
│ ├── 基礎屬性
│ ├── 身體部位系統
│ ├── 健康狀態系統
│ └── 屬性成長機制
├── 物品屬性模塊
│ ├── 材料屬性系統
│ ├── 製作質量系統
│ ├── 裝飾系統
│ └── 歷史價值系統(重點)
├── 技能系統模塊
│ ├── 技能分類與層級
│ ├── 經驗積累機制
│ └── 技能影響計算
├── 戰鬥數值模塊
│ ├── 傷害計算
│ ├── 防護計算
│ └── 身體部位傷害
├── 建築數值模塊
│ ├── 建築屬性
│ ├── 材料影響
│ └── 質量系統
└── 數值計算模塊
├── 計算公式
├── 平衡設計
└── 性能優化
多維度屬性設計理念
傳統遊戲:
- 使用少量核心屬性(如攻擊力、防禦力)
- 屬性值簡單直接
- 屬性之間關係簡單
矮人要塞:
- 使用大量細粒度屬性
- 屬性值基於真實物理/化學屬性
- 屬性之間關係複雜,相互影響
設計優勢:
- 創造更真實的模擬體驗
- 支持更復雜的遊戲機制
- 產生涌現性玩法
- 增加策略深度
2. 生物屬性體系
基礎屬性
屬性類型:
力量(Strength):
- 影響:負重能力、近戰傷害、挖掘效率
- 範圍:通常 0-5000(以克為單位)
- 成長:通過負重、戰鬥、挖掘等活動提升
敏捷(Agility):
- 影響:移動速度、攻擊速度、閃避能力
- 範圍:通常 0-5000
- 成長:通過移動、戰鬥等活動提升
耐力(Endurance):
- 影響:體力上限、體力恢復速度
- 範圍:通常 0-5000
- 成長:通過體力消耗活動提升
智力(Intelligence):
- 影響:學習速度、技能上限、策略能力
- 範圍:通常 0-5000
- 成長:通過學習、研究等活動提升
意志力(Willpower):
- 影響:抵抗恐懼、抵抗痛苦、情緒穩定性
- 範圍:通常 0-5000
- 成長:通過經歷困難、克服恐懼提升
數據結構:
class CreatureAttributes:
strength: int
agility: int
endurance: int
intelligence: int
willpower: int
# 屬性上限
max_strength: int
max_agility: int
# ...
# 屬性成長
strength_growth: float
agility_growth: float
# ...
身體部位系統
身體部位結構:
- 每個生物有多個身體部位(頭、軀幹、四肢等)
- 每個部位有獨立的健康狀態
- 部位之間可能有關聯(如手臂受傷影響手部功能)
部位數據結構:
class BodyPart:
name: str
part_type: PartType # 頭部、軀幹、手臂、腿等
health: int # 健康值
max_health: int # 最大健康值
# 部位狀態
is_cut: bool # 是否被切斷
is_bruised: bool # 是否淤傷
is_broken: bool # 是否骨折
is_missing: bool # 是否缺失
# 部位功能
functions: list # 該部位的功能(如手臂可以抓取、腿可以行走)
# 關聯部位
connected_parts: list # 關聯的身體部位
部位功能影響:
- 手臂受傷影響抓取和戰鬥
- 腿受傷影響移動速度
- 頭部受傷可能影響意識和感知
- 部位缺失導致功能永久喪失
健康狀態系統
健康狀態類型:
正常(Healthy):
- 所有部位健康
- 無負面狀態
- 功能正常
受傷(Injured):
- 部分部位受傷
- 可能有疼痛、失血等狀態
- 功能受限
重創(Critical):
- 重要部位嚴重受傷
- 生命危險
- 功能嚴重受限
死亡(Dead):
- 生命值歸零或關鍵部位被摧毀
- 無法恢復
健康狀態數據結構:
class HealthStatus:
overall_health: int # 總體健康值
max_health: int # 最大健康值
# 部位健康
body_parts: dict # 身體部位字典
# 狀態效果
effects: list # 當前狀態效果(疼痛、失血、中毒等)
# 恢復狀態
recovery_rate: float # 恢復速度
recovery_blockers: list # 阻止恢復的因素
屬性計算與影響
屬性影響計算:
def calculate_effectiveness(base_value, attributes, modifiers):
# 基礎值
result = base_value
# 屬性影響
strength_modifier = attributes.strength / 1000.0
agility_modifier = attributes.agility / 1000.0
# 應用修飾符
result *= (1 + strength_modifier * modifiers.strength_factor)
result *= (1 + agility_modifier * modifiers.agility_factor)
# 應用其他修飾符
for modifier in modifiers.others:
result *= modifier
return result
屬性對行為的影響:
- 力量影響負重和傷害
- 敏捷影響速度和閃避
- 耐力影響持續活動能力
- 智力影響學習和策略
- 意志力影響情緒和抵抗
屬性成長機制
成長方式:
- 通過使用相關活動提升屬性
- 屬性有上限,受種族和個體差異影響
- 成長速度隨屬性值增加而減慢
成長算法:
def grow_attribute(attribute, activity_type, intensity):
# 計算成長量
base_growth = get_base_growth(activity_type, attribute)
intensity_factor = intensity / 100.0
# 屬性值越高,成長越慢
current_ratio = attribute.current / attribute.max
growth_multiplier = 1.0 - current_ratio * 0.5
growth = base_growth * intensity_factor * growth_multiplier
# 應用成長
attribute.current = min(attribute.current + growth, attribute.max)
設計考量:
- 屬性成長需要時間和努力
- 避免屬性無限增長
- 創造角色差異化
3. 物品屬性體系
材料屬性系統
物理屬性:
硬度(Hardness):
- 影響:抗磨損能力、切割難度
- 範圍:通常 1-100
- 示例:鑽石=100,木材=10
密度(Density):
- 影響:重量、浮力
- 範圍:通常 0.1-20(g/cm³)
- 示例:鉛=11.3,木材=0.5
熔點(Melting Point):
- 影響:冶煉温度、耐熱性
- 範圍:通常 0-5000(°C)
- 示例:鐵=1538°C,木材=300°C(燃燒)
彈性(Elasticity):
- 影響:抗衝擊能力、回彈能力
- 範圍:通常 0-1
- 示例:橡膠=0.9,石頭=0.1
化學屬性:
可燃性(Flammability):
- 影響:是否易燃、燃燒速度
- 範圍:通常 0-1
- 示例:木材=0.8,石頭=0
腐蝕性(Corrosiveness):
- 影響:是否腐蝕其他材料
- 範圍:通常 0-1
- 示例:酸=0.9,水=0.1
數據結構:
class MaterialProperties:
# 物理屬性
hardness: float
density: float
melting_point: float
elasticity: float
# 化學屬性
flammability: float
corrosiveness: float
# 其他屬性
value_multiplier: float # 價值倍數
rarity: float # 稀有度
製作質量系統
質量等級:
- 粗糙(Crude):質量 0-1,基礎物品
- 普通(Normal):質量 1-2,標準物品
- 良好(Fine):質量 2-3,優質物品
- 優秀(Superior):質量 3-4,精良物品
- 卓越(Exceptional):質量 4-5,卓越物品
- 大師(Masterwork):質量 5,大師作品
- 傳奇(Legendary):質量 5+,傳奇物品
質量影響因素:
- 製作者技能等級
- 製作者情緒狀態
- 材料質量
- 工坊質量
- 隨機因素
質量計算:
def calculate_quality(crafter_skill, material_quality, workshop_quality, mood_bonus):
# 基礎質量
base_quality = crafter_skill / 20.0 # 技能等級轉換為質量
# 材料影響
material_factor = material_quality / 2.0
# 工坊影響
workshop_factor = workshop_quality / 2.0
# 情緒加成
mood_factor = 1.0 + mood_bonus
# 計算最終質量
quality = (base_quality + material_factor + workshop_factor) * mood_factor
# 添加隨機因素
quality += random.uniform(-0.2, 0.2)
# 限制在合理範圍
quality = max(0, min(quality, 6.0))
return quality
質量對物品的影響:
- 影響物品價值
- 影響物品耐久度
- 影響物品功能效果
- 影響物品美觀度
裝飾系統
裝飾類型:
- 圖像裝飾:雕刻、繪畫等
- 材料裝飾:鑲嵌寶石、金屬等
- 文字裝飾:銘文、標記等
裝飾數據結構:
class Decoration:
decoration_type: DecorationType
material: Material # 裝飾材料
quality: float # 裝飾質量
description: str # 裝飾描述
# 裝飾主題
theme: str # 裝飾主題(如戰爭、自然、歷史等)
symbols: list # 裝飾符號
裝飾價值計算:
def calculate_decoration_value(decorations, base_value):
total_decoration_value = 0
for decoration in decorations:
# 材料價值
material_value = decoration.material.value
# 質量加成
quality_multiplier = 1.0 + decoration.quality * 0.2
# 主題加成(某些主題更受歡迎)
theme_multiplier = get_theme_multiplier(decoration.theme)
decoration_value = material_value * quality_multiplier * theme_multiplier
total_decoration_value += decoration_value
# 裝飾價值加成到基礎價值
final_value = base_value * (1.0 + total_decoration_value / base_value * 0.5)
return final_value
歷史價值系統(重點章節)
歷史價值的定義與意義
歷史價值的概念:
歷史價值是物品因與歷史事件、歷史人物或歷史時期關聯而獲得的價值。它不是物品本身的物理屬性,而是物品在歷史敍事中的意義。一個普通的鐵劍如果被傳奇英雄使用過,就會獲得巨大的歷史價值。
歷史價值的意義:
- 敍事價值:歷史價值創造獨特的敍事體驗,每個有歷史價值的物品都有自己的故事
- 遊戲價值:歷史價值影響物品的經濟價值、使用價值、收藏價值
- 沉浸感:歷史價值讓玩家感覺物品是真實歷史的一部分
- 重玩價值:不同的歷史價值創造不同的遊戲體驗
歷史事件的記錄與關聯
歷史事件類型:
- 戰鬥事件:物品在戰鬥中被使用
- 重要時刻:物品在重要歷史時刻出現
- 人物關聯:物品被重要歷史人物使用或擁有
- 文明事件:物品與文明重要事件關聯
- 傳説事件:物品與傳説、神話關聯
事件記錄數據結構:
class HistoricalEvent:
id: int
year: int
event_type: EventType
description: str
# 事件參與者
participants: list # 參與的生物、派系等
# 事件重要性
significance: float # 0-1,事件重要性
# 事件影響
effects: dict # 事件的影響
# 關聯物品
related_items: list # 與該事件關聯的物品ID
物品與事件關聯:
class ItemHistoricalRecord:
item_id: int
# 歷史事件列表
events: list # HistoricalEvent列表
# 歷史價值
historical_value: float # 計算得出的歷史價值
# 歷史描述
historical_description: str # 自動生成的歷史描述
關聯機制:
def associate_item_with_event(item, event, association_type):
# 創建關聯記錄
association = ItemEventAssociation(
item_id=item.id,
event_id=event.id,
association_type=association_type, # 使用、擁有、見證等
significance=event.significance
)
# 添加到物品歷史記錄
item.historical_record.events.append(association)
# 更新歷史價值
update_historical_value(item)
歷史價值的計算機制
基礎計算:
def calculate_historical_value(item):
base_value = 0
# 遍歷所有歷史事件
for association in item.historical_record.events:
event = get_event(association.event_id)
# 事件重要性
event_significance = event.significance
# 關聯類型權重
association_weight = get_association_weight(association.association_type)
# 使用 > 擁有 > 見證
# 時間衰減(越古老的事件價值越高,但有上限)
age_factor = calculate_age_factor(event.year, current_year)
# 參與者重要性
participant_importance = calculate_participant_importance(event.participants)
# 計算該事件貢獻的價值
event_value = (event_significance *
association_weight *
age_factor *
participant_importance)
base_value += event_value
# 歷史價值倍數(歷史價值會大幅提升物品總價值)
historical_multiplier = 1.0 + base_value * 2.0
return historical_multiplier
關聯類型權重:
ASSOCIATION_WEIGHTS = {
"used_in_battle": 1.0, # 在戰鬥中使用
"used_by_legend": 0.9, # 被傳奇人物使用
"owned_by_legend": 0.7, # 被傳奇人物擁有
"witnessed_event": 0.5, # 見證事件
"created_for_event": 0.6, # 為事件而製作
"found_at_site": 0.4 # 在歷史遺蹟中發現
}
時間衰減因子:
def calculate_age_factor(event_year, current_year):
age = current_year - event_year
# 古老物品價值更高,但有上限
if age < 10:
factor = 0.5 # 太新的事件價值較低
elif age < 100:
factor = 0.5 + (age - 10) / 90 * 0.4 # 逐漸增加
elif age < 1000:
factor = 0.9 + (age - 100) / 900 * 0.1 # 繼續增加但增速減慢
else:
factor = 1.0 # 上限
return factor
參與者重要性:
def calculate_participant_importance(participants):
total_importance = 0
for participant in participants:
# 獲取參與者的重要性(基於其歷史地位)
importance = get_participant_historical_importance(participant)
total_importance += importance
# 平均重要性,但重要參與者會顯著提升
avg_importance = total_importance / len(participants) if participants else 0
# 如果有傳奇參與者,額外加成
legend_bonus = 1.0
for participant in participants:
if is_legendary(participant):
legend_bonus += 0.5
return avg_importance * legend_bonus
歷史價值的傳承與變化
價值傳承:
- 物品的歷史價值會傳承給新制作的物品(如果使用有歷史價值的材料)
- 歷史價值會隨着物品的傳遞而累積
- 歷史價值不會因為時間而消失,只會累積
傳承機制:
def inherit_historical_value(new_item, source_items):
inherited_value = 0
for source_item in source_items:
if source_item.historical_record:
# 繼承部分歷史價值
inheritance_ratio = 0.3 # 繼承30%的歷史價值
source_value = source_item.historical_record.historical_value
inherited_value += source_value * inheritance_ratio
# 添加到新物品
if inherited_value > 0:
new_item.historical_record.inherited_value = inherited_value
update_historical_value(new_item)
價值變化:
- 新事件會增加歷史價值
- 物品損壞可能降低歷史價值
- 物品修復可能恢復部分歷史價值
變化機制:
def update_historical_value_on_event(item, new_event):
# 添加新事件
associate_item_with_event(item, new_event, "witnessed_event")
# 重新計算曆史價值
update_historical_value(item)
# 更新歷史描述
update_historical_description(item)
歷史價值對物品的影響
經濟價值影響:
def calculate_item_total_value(item):
# 基礎價值(材料、質量、裝飾)
base_value = calculate_base_value(item)
# 歷史價值倍數
historical_multiplier = item.historical_record.historical_value
# 總價值
total_value = base_value * historical_multiplier
return total_value
使用價值影響:
- 有歷史價值的物品可能獲得特殊效果
- 使用歷史物品可能提升士氣
- 歷史物品可能成為派系的象徵
收藏價值:
- 有歷史價值的物品成為收藏品
- 玩家可能專門收集歷史物品
- 歷史物品可能成為要塞的珍寶
敍事影響:
- 歷史價值創造獨特的敍事
- 每個歷史物品都有自己的故事
- 歷史物品連接當前遊戲和歷史
歷史價值的數據結構設計
完整數據結構:
class HistoricalRecord:
# 基礎信息
item_id: int
# 歷史事件關聯
events: list # ItemEventAssociation列表
# 繼承的歷史價值
inherited_value: float
# 計算得出的歷史價值
historical_value: float
# 歷史描述(自動生成)
historical_description: str
# 歷史標籤(用於快速查詢)
tags: set # 如"legendary_weapon", "battle_tested"等
# 緩存(性能優化)
value_cache: float
cache_timestamp: int
關聯數據結構:
class ItemEventAssociation:
item_id: int
event_id: int
association_type: str # 關聯類型
significance: float # 該關聯的重要性
description: str # 關聯描述
year: int # 關聯發生的年份
查詢優化:
class HistoricalValueIndex:
# 按物品ID索引
item_index: dict # item_id -> HistoricalRecord
# 按事件類型索引
event_type_index: dict # event_type -> [item_id]
# 按歷史價值排序
value_sorted_list: list # 按歷史價值排序的物品ID列表
def get_items_by_event_type(self, event_type):
return [self.item_index[item_id]
for item_id in self.event_type_index.get(event_type, [])]
def get_most_valuable_items(self, count):
return [self.item_index[item_id]
for item_id in self.value_sorted_list[:count]]
歷史價值與文明演進系統的關聯
事件來源:
- 歷史價值系統從文明演進系統獲取歷史事件
- 當前遊戲中的事件也會成為歷史事件
- 形成歷史和當前的動態交互
關聯流程:
def link_historical_value_to_civilization(item, civilization_event):
# 從文明演進系統獲取事件
historical_event = convert_civilization_event(civilization_event)
# 關聯到物品
associate_item_with_event(item, historical_event, "related_to_civilization")
# 更新歷史價值
update_historical_value(item)
雙向影響:
- 歷史事件影響物品價值
- 物品的歷史價值影響當前遊戲
- 當前遊戲中的物品可能成為未來歷史的一部分
設計考量:
- 歷史價值系統與文明演進系統緊密集成
- 創造連貫的世界觀
- 增加遊戲的敍事深度
物品屬性綜合計算
綜合價值計算:
def calculate_item_total_value(item):
# 1. 材料基礎價值
material_value = calculate_material_value(item.material, item.quantity)
# 2. 製作質量價值
quality_value = material_value * (item.quality - 1) * 0.2
# 3. 裝飾價值
decoration_value = calculate_decoration_value(item.decorations, material_value)
# 4. 歷史價值倍數
historical_multiplier = item.historical_record.historical_value
# 5. 綜合計算
base_value = material_value + quality_value + decoration_value
total_value = base_value * historical_multiplier
return total_value
屬性綜合影響:
- 所有屬性共同決定物品的表現
- 不同屬性在不同情境下重要性不同
- 屬性之間可能存在協同或衝突
4. 技能系統
技能分類與層級
技能分類:
生產技能:
- 採礦(Mining)
- 鍛造(Smithing)
- 木工(Carpentry)
- 石工(Stonecrafting)
- 烹飪(Cooking)
- 農業(Farming)
戰鬥技能:
- 近戰武器(Melee Weapons)
- 遠程武器(Ranged Weapons)
- 護甲使用(Armor Use)
- 盾牌使用(Shield Use)
其他技能:
- 醫療(Medical)
- 動物訓練(Animal Training)
- 社交(Social)
技能層級:
- 新手(Novice):0-4級
- 學徒(Apprentice):5-9級
- 熟練(Adept):10-14級
- 專家(Expert):15-19級
- 大師(Master):20級
- 傳奇(Legendary):20+級(特殊成就)
技能經驗積累機制
經驗獲取:
- 通過使用技能獲得經驗
- 經驗獲取量與使用強度相關
- 高難度任務獲得更多經驗
經驗計算:
def gain_skill_experience(dwarf, skill, task_difficulty, intensity):
# 基礎經驗
base_exp = task_difficulty * intensity
# 技能等級影響(等級越高,獲得經驗越慢)
skill_level = dwarf.skills[skill].level
level_factor = 1.0 / (1.0 + skill_level * 0.1)
# 智力影響
intelligence_factor = dwarf.attributes.intelligence / 1000.0
# 計算最終經驗
experience = base_exp * level_factor * (1.0 + intelligence_factor * 0.2)
# 添加到技能
dwarf.skills[skill].experience += experience
# 檢查是否升級
check_skill_level_up(dwarf.skills[skill])
升級機制:
def check_skill_level_up(skill):
required_exp = calculate_required_experience(skill.level + 1)
if skill.experience >= required_exp:
skill.level += 1
skill.experience -= required_exp
# 觸發升級事件
trigger_skill_level_up_event(skill)
所需經驗計算:
def calculate_required_experience(level):
# 指數增長
base_exp = 100
growth_factor = 1.5
required_exp = base_exp * (growth_factor ** level)
return required_exp
技能等級對效率和質量的影響
效率影響:
def calculate_work_efficiency(skill_level, base_time):
# 技能等級影響效率(等級越高,時間越短)
efficiency_factor = 1.0 / (1.0 + skill_level * 0.05)
actual_time = base_time * efficiency_factor
return actual_time
質量影響:
def calculate_work_quality(skill_level, base_quality):
# 技能等級影響質量
quality_bonus = skill_level * 0.1
final_quality = base_quality + quality_bonus
# 限制在合理範圍
final_quality = max(0, min(final_quality, 6.0))
return final_quality
技能專業化設計
專業化優勢:
- 專業化矮人效率更高
- 專業化矮人質量更好
- 專業化創造角色差異化
專業化機制:
def calculate_specialization_bonus(dwarf, skill):
# 計算該技能在所有技能中的佔比
total_skill_points = sum(dwarf.skills.values())
skill_ratio = dwarf.skills[skill] / total_skill_points
# 如果佔比高,獲得專業化加成
if skill_ratio > 0.3: # 30%以上
specialization_level = (skill_ratio - 0.3) / 0.7 # 0-1
bonus = specialization_level * 0.2 # 最多20%加成
return 1.0 + bonus
return 1.0
技能遺忘機制
遺忘條件:
- 長期不使用技能會遺忘
- 遺忘速度與技能等級相關(高等級技能遺忘更慢)
- 遺忘有下限(不會完全遺忘)
遺忘算法:
def process_skill_decay(dwarf, skill, time_passed):
if skill.last_used_time is None:
return
# 計算未使用時間
unused_time = current_time - skill.last_used_time
# 如果超過遺忘閾值
if unused_time > FORGET_THRESHOLD:
# 計算遺忘量
decay_rate = get_decay_rate(skill.level)
experience_loss = time_passed * decay_rate
# 應用遺忘
skill.experience = max(0, skill.experience - experience_loss)
# 檢查是否降級
check_skill_level_down(skill)
遺忘速率:
def get_decay_rate(skill_level):
# 等級越高,遺忘越慢
base_decay = 0.1
level_factor = 1.0 / (1.0 + skill_level * 0.1)
return base_decay * level_factor
5. 戰鬥數值系統
傷害計算機制
基礎傷害計算:
def calculate_damage(attacker, weapon, target, hit_location):
# 1. 基礎傷害(武器屬性)
base_damage = weapon.damage
# 2. 攻擊者力量影響
strength_modifier = attacker.attributes.strength / 1000.0
base_damage *= (1.0 + strength_modifier * 0.5)
# 3. 武器技能影響
weapon_skill = attacker.skills[weapon.skill_type].level
skill_modifier = 1.0 + weapon_skill * 0.05
base_damage *= skill_modifier
# 4. 武器質量影響
quality_modifier = 1.0 + weapon.quality * 0.1
base_damage *= quality_modifier
# 5. 護甲防護
armor_protection = calculate_armor_protection(target, hit_location)
actual_damage = base_damage * (1.0 - armor_protection)
# 6. 部位傷害調整
location_multiplier = get_location_damage_multiplier(hit_location)
final_damage = actual_damage * location_multiplier
return final_damage
武器屬性影響
武器屬性:
- 傷害值:基礎傷害
- 攻擊速度:攻擊頻率
- 攻擊範圍:攻擊距離
- 傷害類型:切割、鈍擊、穿刺等
武器數據結構:
class Weapon:
damage: float
attack_speed: float
attack_range: float
damage_type: DamageType
# 材料屬性
material: Material
# 質量
quality: float
# 歷史價值
historical_record: HistoricalRecord
護甲防護計算
護甲類型:
- 軟甲:布料、皮革,防護低但靈活
- 硬甲:金屬、石頭,防護高但笨重
- 混合甲:軟硬結合,平衡防護和靈活
防護計算:
def calculate_armor_protection(target, hit_location):
# 獲取該部位的護甲
armor = target.get_armor_at_location(hit_location)
if not armor:
return 0.0
# 基礎防護值
base_protection = armor.protection_value
# 護甲質量影響
quality_modifier = 1.0 + armor.quality * 0.1
base_protection *= quality_modifier
# 材料屬性影響
material_modifier = armor.material.get_protection_modifier()
base_protection *= material_modifier
# 限制在合理範圍(0-0.95,95%最大防護)
protection = min(0.95, base_protection)
return protection
身體部位傷害系統
部位傷害類型:
切割傷害:
- 可能造成斷肢
- 大量失血
- 功能喪失
鈍擊傷害:
- 可能造成骨折
- 內傷
- 疼痛
穿刺傷害:
- 可能穿透護甲
- 內部器官損傷
- 嚴重失血
部位傷害計算:
def apply_damage_to_location(body_part, damage, damage_type):
# 應用傷害
body_part.health -= damage
# 根據傷害類型應用特殊效果
if damage_type == "cutting":
if damage > body_part.max_health * 0.5:
# 可能斷肢
if random.random() < 0.3:
body_part.is_cut = True
body_part.functions = [] # 功能喪失
elif damage_type == "blunt":
if damage > body_part.max_health * 0.3:
# 可能骨折
if random.random() < 0.2:
body_part.is_broken = True
elif damage_type == "piercing":
# 可能造成內傷
if random.random() < 0.1:
apply_internal_injury(body_part)
戰鬥技能影響
技能對戰鬥的影響:
- 影響命中率
- 影響傷害
- 影響攻擊速度
- 影響防禦能力
技能影響計算:
def calculate_combat_effectiveness(dwarf, combat_skill):
skill_level = dwarf.skills[combat_skill].level
# 命中率加成
accuracy_bonus = skill_level * 0.02 # 每級2%
# 傷害加成
damage_bonus = skill_level * 0.03 # 每級3%
# 攻擊速度加成
speed_bonus = skill_level * 0.01 # 每級1%
return {
"accuracy": 1.0 + accuracy_bonus,
"damage": 1.0 + damage_bonus,
"speed": 1.0 + speed_bonus
}
士氣與情緒影響
士氣影響:
- 高士氣提升戰鬥力
- 低士氣降低戰鬥力
- 極端情緒可能產生特殊效果
情緒影響計算:
def calculate_morale_effect(dwarf):
morale = dwarf.morale
# 士氣影響戰鬥效果
if morale > 50:
# 高士氣加成
bonus = (morale - 50) / 50.0 * 0.2 # 最多20%加成
return 1.0 + bonus
elif morale < 50:
# 低士氣懲罰
penalty = (50 - morale) / 50.0 * 0.2 # 最多20%懲罰
return 1.0 - penalty
return 1.0
6. 建築數值系統
建築屬性
耐久度(Durability):
- 建築抵抗損壞的能力
- 受材料和質量影響
- 隨時間可能降低
支撐能力(Support Strength):
- 建築支撐上方重量的能力
- 影響多層建築設計
- 超載可能導致坍塌
防火性(Fire Resistance):
- 建築抵抗火災的能力
- 受材料影響
- 影響要塞安全
其他屬性:
- 隔熱性
- 隔音性
- 美觀度
建築數據結構:
class Building:
building_type: BuildingType
material: Material
quality: float
# 建築屬性
durability: float
support_strength: float
fire_resistance: float
# 功能屬性
functionality: dict # 建築功能相關屬性
# 裝飾
decorations: list
材料對建築屬性的影響
材料影響計算:
def calculate_building_properties(material, building_type, quality):
# 基礎屬性(基於材料)
base_durability = material.hardness * 10
base_support = material.density * material.hardness
base_fire_resistance = 1.0 - material.flammability
# 建築類型影響
type_modifiers = get_building_type_modifiers(building_type)
base_durability *= type_modifiers.durability
base_support *= type_modifiers.support
base_fire_resistance *= type_modifiers.fire_resistance
# 質量影響
quality_multiplier = 1.0 + quality * 0.1
# 最終屬性
durability = base_durability * quality_multiplier
support_strength = base_support * quality_multiplier
fire_resistance = min(1.0, base_fire_resistance * quality_multiplier)
return {
"durability": durability,
"support_strength": support_strength,
"fire_resistance": fire_resistance
}
建築質量系統
質量等級:
- 與物品質量系統類似
- 影響建築屬性和價值
- 受制作者技能影響
質量影響:
- 高質量建築更耐久
- 高質量建築更美觀
- 高質量建築提升矮人滿意度
建築功能數值
功能屬性:
- 不同建築有不同功能
- 功能屬性影響建築效果
- 功能屬性受材料和質量影響
功能計算:
def calculate_building_functionality(building):
functionality = {}
# 根據建築類型計算功能
if building.building_type == "workshop":
functionality["efficiency"] = calculate_workshop_efficiency(building)
functionality["capacity"] = calculate_workshop_capacity(building)
elif building.building_type == "bedroom":
functionality["comfort"] = calculate_bedroom_comfort(building)
functionality["prestige"] = calculate_bedroom_prestige(building)
# ...
return functionality
7. 數值計算與平衡
數值計算公式
通用計算公式:
def calculate_final_value(base_value, modifiers):
result = base_value
for modifier in modifiers:
if modifier.type == "additive":
result += modifier.value
elif modifier.type == "multiplicative":
result *= modifier.value
elif modifier.type == "exponential":
result = result ** modifier.value
return result
屬性影響公式:
def apply_attribute_modifier(base_value, attribute_value, modifier_type):
if modifier_type == "linear":
return base_value * (1.0 + attribute_value / 1000.0)
elif modifier_type == "logarithmic":
return base_value * (1.0 + math.log(1.0 + attribute_value / 100.0))
elif modifier_type == "exponential":
return base_value * (1.0 + (attribute_value / 1000.0) ** 2)
數值平衡設計
平衡原則:
- 避免數值過大或過小
- 確保不同選擇都有價值
- 避免單一最優策略
平衡調整:
def balance_value(value, min_value, max_value, target_value):
# 如果超出範圍,調整到範圍內
if value < min_value:
value = min_value
elif value > max_value:
value = max_value
# 如果偏離目標值太遠,向目標值調整
if abs(value - target_value) > target_value * 0.5:
value = target_value + (value - target_value) * 0.5
return value
數值溢出與邊界處理
溢出處理:
def safe_add(a, b, max_value=None):
result = a + b
if max_value is not None and result > max_value:
result = max_value
return result
def safe_multiply(a, b, max_value=None):
result = a * b
if max_value is not None and result > max_value:
result = max_value
return result
邊界檢查:
def clamp_value(value, min_value, max_value):
return max(min_value, min(value, max_value))
數值精度與性能優化
精度管理:
- 使用合適的數值類型(int vs float)
- 避免不必要的精度損失
- 使用定點數或整數代替浮點數(如果可能)
性能優化:
# 緩存計算結果
class ValueCache:
cache: dict
def get_cached_value(self, key, calculator):
if key in self.cache:
return self.cache[key]
value = calculator()
self.cache[key] = value
return value
def invalidate_cache(self, key):
if key in self.cache:
del self.cache[key]
8. 數值存儲與查詢
數值數據結構設計
基礎數據結構:
class NumericValue:
value: float
modifiers: list # 修飾符列表
def get_final_value(self):
result = self.value
for modifier in self.modifiers:
result = modifier.apply(result)
return result
索引結構:
class NumericIndex:
# 按類型索引
type_index: dict # type -> [object_id]
# 按值範圍索引
value_range_index: dict # (min, max) -> [object_id]
# 按屬性索引
attribute_index: dict # attribute_name -> {value: [object_id]}
數值存儲優化
壓縮存儲:
def compress_numeric_data(data):
# 使用變長編碼壓縮數值
compressed = []
for value in data:
compressed.append(encode_variable_length(value))
return compressed
增量更新:
def update_numeric_value_incremental(old_value, delta):
return old_value + delta
數值查詢機制
查詢接口:
class NumericQuery:
def by_type(self, type_name):
# 按類型查詢
pass
def by_value_range(self, min_value, max_value):
# 按值範圍查詢
pass
def by_attribute(self, attribute_name, value):
# 按屬性查詢
pass
def execute(self):
# 執行查詢
pass
查詢優化:
def optimize_query(query, index):
# 使用索引優化查詢
if query.can_use_index(index):
return index.query(query)
else:
return full_scan(query)
數值更新機制
更新策略:
- 立即更新:值變化立即反映
- 延遲更新:批量更新,提高性能
- 增量更新:只更新變化的部分
更新算法:
def update_numeric_values(objects, updates):
for obj_id, update in updates.items():
obj = get_object(obj_id)
# 應用更新
for attribute, delta in update.items():
obj.attributes[attribute] += delta
# 標記需要重新計算的值
obj.mark_dirty()
# 批量重新計算
recalculate_dirty_values()
9. 設計思路總結
細節決定真實的設計原理
核心思想:
- 通過大量細節屬性創造真實的模擬體驗
- 細節屬性之間相互影響,產生複雜行為
- 細節屬性支持涌現性玩法
實現方式:
- 定義大量細粒度屬性
- 屬性基於真實物理/化學屬性
- 屬性之間建立複雜關係
設計優勢:
- 創造更真實的遊戲世界
- 支持更復雜的遊戲機制
- 產生意外的遊戲體驗
歷史價值系統的設計創新
創新點:
- 將歷史敍事與物品屬性結合
- 歷史價值動態計算和累積
- 歷史價值影響物品的各個方面
設計意義:
- 創造獨特的敍事體驗
- 增加物品的收藏價值
- 連接歷史和當前遊戲
可借鑑性:
- 適用於需要敍事深度的遊戲
- 適用於需要收藏系統的遊戲
- 適用於需要歷史背景的遊戲
多維度屬性的優勢
優勢:
- 創造豐富的策略選擇
- 支持複雜的遊戲機制
- 產生涌現性玩法
實現要點:
- 定義多個維度的屬性
- 屬性之間建立合理關係
- 平衡不同屬性的重要性
可借鑑的設計模式
組件模式:
- 將屬性作為組件附加到對象
- 支持靈活的組合
- 便於擴展和維護
觀察者模式:
- 屬性變化時通知相關係統
- 支持解耦的事件處理
- 便於實現響應式系統
策略模式:
- 不同屬性使用不同計算策略
- 支持靈活的策略切換
- 便於平衡和調整
技術實現建議
數據結構:
- 使用高效的數據結構存儲屬性
- 使用索引優化查詢
- 使用緩存優化計算
性能優化:
- 延遲計算非關鍵屬性
- 批量更新減少開銷
- 使用對象池減少內存分配
可擴展性:
- 使用插件系統支持擴展
- 使用配置系統支持定製
- 預留擴展點支持未來功能
總結
數值系統是《矮人要塞》所有遊戲機制的基礎,它通過多維度屬性、詳細的身體部位系統、歷史價值系統等創新設計,創造了一個真實而複雜的遊戲世界。特別是歷史價值系統的設計,將歷史敍事與物品屬性完美結合,創造了獨特的遊戲體驗。
通過深入分析這個系統的設計原理和實現思路,我們可以學習到:
- 如何通過細節屬性創造真實的模擬體驗
- 如何設計歷史價值系統連接歷史和當前遊戲
- 如何管理多維度屬性的複雜度
- 如何平衡數值系統的真實性和遊戲性
- 如何優化大量數值數據的存儲和查詢
這些設計思路不僅適用於類似遊戲,也可以應用於其他需要複雜數值系統的遊戲類型。通過學習和借鑑這些設計理念,我們可以創造出更加豐富和有趣的遊戲體驗。