- 任务推进与结算:执行阶段按任务类型用属性权重计算进度、考虑角色/学科匹配、状态衰减与难度缩放,回合结束统一扣 Deadline、判定完成/失败并派发事件,同时记录署名贡献度 scripts/Core/GameSystems.cs - 经济结算:接收任务事件发奖惩,学术探索根据难度生成论文卡;回合结束统一扣工资并结息(经济学学科触发基础利率)scripts/Core/GameSystems.cs - 羁绊层数与效果:统计人群画像/职能分工堆叠,激活层级并聚合为全局 ModifierBundle 给数值解析器使用 scripts/Core/GameSystems.cs, scripts/Models/GameState.cs - 事件与数值解析支撑:新增领域事件与统一属性合成器,兼容羁绊/学科/特质/装备的叠加 scripts/Core/DomainEvents.cs, scripts/Core/StatResolver.cs - 回合结算入口调整:Review 阶段改由系统处理并发布回合结束事件 scripts/GameManager.cs
91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using System.Collections.Generic;
|
||
using Models;
|
||
|
||
namespace Core;
|
||
|
||
/// <summary>
|
||
/// 数值解析器(用于统一计算有效属性)
|
||
/// 设计说明:
|
||
/// 1) 只做“读+合成”,不直接修改 Model。
|
||
/// 2) 合成来源包含:羁绊、学科 Buff、特质、装备。
|
||
/// 注意事项:
|
||
/// - 规则型效果(RuleIds)暂不在此处理,由系统层扩展。
|
||
/// 未来扩展:
|
||
/// - 可引入“上下文参数”(任务类型/场景)以处理条件加成。
|
||
/// </summary>
|
||
public sealed class StatResolver
|
||
{
|
||
private readonly GameSession _session;
|
||
|
||
public StatResolver(GameSession session)
|
||
{
|
||
_session = session;
|
||
}
|
||
|
||
public float GetAttribute(UnitModel unit, AttributeType type)
|
||
{
|
||
var value = GetBaseAttribute(unit, type);
|
||
ApplyBundle(_session.State.Synergy.ActiveModifiers, type, ref value);
|
||
ApplyDiscipline(unit.Tags.DisciplineId, type, ref value);
|
||
ApplyTraits(unit.Tags.TraitIds, type, ref value);
|
||
ApplyItems(unit.Equipment.EquippedItemIds, type, ref value);
|
||
return value;
|
||
}
|
||
|
||
private float GetBaseAttribute(UnitModel unit, AttributeType type)
|
||
{
|
||
return type switch
|
||
{
|
||
AttributeType.Academic => unit.Attributes.Academic.Value,
|
||
AttributeType.Engineering => unit.Attributes.Engineering.Value,
|
||
AttributeType.Writing => unit.Attributes.Writing.Value,
|
||
AttributeType.Financial => unit.Attributes.Financial.Value,
|
||
AttributeType.Social => unit.Attributes.Social.Value,
|
||
AttributeType.Activation => unit.Attributes.Activation.Value,
|
||
_ => 0f
|
||
};
|
||
}
|
||
|
||
private void ApplyDiscipline(string disciplineId, AttributeType type, ref float value)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(disciplineId)) return;
|
||
if (!_session.Content.Disciplines.TryGetValue(disciplineId, out var discipline)) return;
|
||
ApplyBundle(discipline.Buff?.Modifiers, type, ref value);
|
||
}
|
||
|
||
private void ApplyTraits(List<string> traitIds, AttributeType type, ref float value)
|
||
{
|
||
if (traitIds == null || traitIds.Count == 0) return;
|
||
foreach (var traitId in traitIds)
|
||
{
|
||
if (_session.Content.Traits.TryGetValue(traitId, out var trait))
|
||
{
|
||
ApplyBundle(trait.Modifiers, type, ref value);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ApplyItems(List<string> itemIds, AttributeType type, ref float value)
|
||
{
|
||
if (itemIds == null || itemIds.Count == 0) return;
|
||
foreach (var itemId in itemIds)
|
||
{
|
||
if (_session.Content.Items.TryGetValue(itemId, out var item))
|
||
{
|
||
ApplyBundle(item.Effect?.Modifiers, type, ref value);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void ApplyBundle(ModifierBundle bundle, AttributeType type, ref float value)
|
||
{
|
||
if (bundle == null) return;
|
||
foreach (var modifier in bundle.AttributeModifiers)
|
||
{
|
||
if (modifier.Type != type) continue;
|
||
value = (value + modifier.Add) * modifier.Multiplier;
|
||
}
|
||
}
|
||
}
|
||
|