using System.Text; using System.Text.Json.Serialization; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Model { public class DecisionPoints { /// /// 所用的游戏平衡常数 /// [JsonIgnore] public EquilibriumConstant GameplayEquilibriumConstant { get; set; } = General.GameplayEquilibriumConstant; /// /// 当前决策点 /// public int CurrentDecisionPoints { get; set; } = General.GameplayEquilibriumConstant.InitialDecisionPoints; /// /// 决策点上限 /// public int MaxDecisionPoints { get; set; } = General.GameplayEquilibriumConstant.InitialDecisionPoints; /// /// 每回合决策点补充数量 /// public int RecoverDecisionPointsPerRound { get; set; } = General.GameplayEquilibriumConstant.RecoverDecisionPointsPerRound; /// /// 本回合已补充的决策点 /// public int DecisionPointsRecovery { get; set; } = 0; /// /// 是否释放过勇气指令 /// public bool CourageCommandSkill { get; set; } = false; /// /// 记录本回合已使用的行动类型和次数 /// public Dictionary ActionTypes { get; } = []; /// /// 记录本回合行动的硬直时间 /// public List ActionsHardnessTime { get; } = []; /// /// 本回合已进行的行动次数 /// public int ActionsTaken { get; set; } = 0; /// /// 本回合已使用的决策点 /// public int DecisionPointsCost { get; set; } = 0; /// /// 临时全能决策点配额加成 /// public int TempActionQuotaAllRound => _tempActionQuotaAllRound.Values.Sum(); /// /// 临时普通攻击决策点配额加成 /// public int TempActionQuotaNormalAttack => _tempActionQuotaNormalAttack.Values.Sum(); /// /// 临时爆发技决策点配额加成 /// public int TempActionQuotaSuperSkill => _tempActionQuotaSuperSkill.Values.Sum(); /// /// 临时战技决策点配额加成 /// public int TempActionQuotaSkill => _tempActionQuotaSkill.Values.Sum(); /// /// 临时使用物品决策点配额加成 /// public int TempActionQuotaItem => _tempActionQuotaItem.Values.Sum(); /// /// 临时其他决策点配额加成 /// public int TempActionQuotaOther => _tempActionQuotaOther.Values.Sum(); // 回合内的临时决策点配额加成 private readonly Dictionary _tempActionQuotaAllRound = []; private readonly Dictionary _tempActionQuotaNormalAttack = []; private readonly Dictionary _tempActionQuotaSuperSkill = []; private readonly Dictionary _tempActionQuotaSkill = []; private readonly Dictionary _tempActionQuotaItem = []; private readonly Dictionary _tempActionQuotaOther = []; /// /// 获取决策点配额 /// /// /// public int this[CharacterActionType type] { get { return type switch { CharacterActionType.NormalAttack => GameplayEquilibriumConstant.ActionQuotaNormalAttack + TempActionQuotaNormalAttack + TempActionQuotaAllRound, CharacterActionType.CastSuperSkill => GameplayEquilibriumConstant.ActionQuotaSuperSkill + TempActionQuotaSuperSkill + TempActionQuotaAllRound, CharacterActionType.CastSkill => GameplayEquilibriumConstant.ActionQuotaSkill + TempActionQuotaSkill + TempActionQuotaAllRound, CharacterActionType.PreCastSkill => GameplayEquilibriumConstant.ActionQuotaMagic, CharacterActionType.UseItem => GameplayEquilibriumConstant.ActionQuotaItem + TempActionQuotaItem + TempActionQuotaAllRound, _ => GameplayEquilibriumConstant.ActionQuotaOther + TempActionQuotaOther + TempActionQuotaAllRound, }; } } /// /// 添加临时决策点配额 [ 回合结束时清除 ] /// /// /// /// public void AddTempActionQuota(Effect effect, CharacterActionType? type = null, int add = 1) { Dictionary dict = type switch { null => _tempActionQuotaAllRound, CharacterActionType.NormalAttack => _tempActionQuotaNormalAttack, CharacterActionType.CastSkill => _tempActionQuotaSkill, CharacterActionType.CastSuperSkill => _tempActionQuotaSuperSkill, CharacterActionType.UseItem => _tempActionQuotaItem, _ => _tempActionQuotaOther }; dict[effect] = dict.GetValueOrDefault(effect) + add; } /// /// 清除临时决策点配额 /// public void ClearTempActionQuota() { _tempActionQuotaAllRound.Clear(); _tempActionQuotaNormalAttack.Clear(); _tempActionQuotaSuperSkill.Clear(); _tempActionQuotaSkill.Clear(); _tempActionQuotaItem.Clear(); _tempActionQuotaOther.Clear(); } /// /// 累计行动类型和次数 /// /// /// /// public void AddActionType(CharacterActionType type, Skill? skill = null, bool addActionTaken = true) { if (addActionTaken) ActionsTaken++; if (!ActionTypes.TryAdd(type, 1)) { ActionTypes[type]++; } DecisionPointsCost += GetActionPointCost(type, skill); } /// /// 判断行动类型是否达到配额 /// /// public bool CheckActionTypeQuota(CharacterActionType type) { if (ActionTypes.TryGetValue(type, out int times)) { return times < this[type]; } return true; } /// /// 获取决策点消耗 /// /// /// /// public int GetActionPointCost(CharacterActionType type, Skill? skill = null) { return type switch { CharacterActionType.NormalAttack => GameplayEquilibriumConstant.DecisionPointsCostNormalAttack, CharacterActionType.PreCastSkill when skill?.SkillType == SkillType.SuperSkill => GameplayEquilibriumConstant.DecisionPointsCostSuperSkill, CharacterActionType.PreCastSkill when skill?.SkillType == SkillType.Skill => GameplayEquilibriumConstant.DecisionPointsCostSkill, CharacterActionType.PreCastSkill when skill?.SkillType == SkillType.Magic => GameplayEquilibriumConstant.DecisionPointsCostMagic, CharacterActionType.UseItem => GameplayEquilibriumConstant.DecisionPointsCostItem, CharacterActionType.CastSuperSkill => GameplayEquilibriumConstant.DecisionPointsCostSuperSkillOutOfTurn, // 回合外使用爆发技 _ => GameplayEquilibriumConstant.DecisionPointsCostOther }; } /// /// 获取当前决策点信息 /// /// public string GetDecisionPointsInfo() { StringBuilder builder = new(); builder.AppendLine($"===[ 决策点信息 ]==="); builder.AppendLine($"当前决策点:{CurrentDecisionPoints} / {MaxDecisionPoints}"); builder.AppendLine($"普通攻击决策点配额:{this[CharacterActionType.NormalAttack] - ActionTypes.GetValueOrDefault(CharacterActionType.NormalAttack)} / {this[CharacterActionType.NormalAttack]}"); builder.AppendLine($"战技决策点配额:{this[CharacterActionType.CastSkill] - ActionTypes.GetValueOrDefault(CharacterActionType.CastSkill)} / {this[CharacterActionType.CastSkill]}"); builder.AppendLine($"魔法决策点配额:{this[CharacterActionType.PreCastSkill] - ActionTypes.GetValueOrDefault(CharacterActionType.PreCastSkill)} / {this[CharacterActionType.PreCastSkill]}"); builder.AppendLine($"爆发技决策点配额:{this[CharacterActionType.CastSuperSkill] - ActionTypes.GetValueOrDefault(CharacterActionType.CastSuperSkill)} / {this[CharacterActionType.CastSuperSkill]}"); builder.AppendLine($"使用物品决策点配额:{this[CharacterActionType.UseItem] - ActionTypes.GetValueOrDefault(CharacterActionType.UseItem)} / {this[CharacterActionType.UseItem]}"); if (_tempActionQuotaAllRound.Count > 0) { builder.AppendLine($"全能决策点配额:你拥有以下全能决策点配额加成并已自动计入每个行动决策所需的配额中。"); builder.AppendLine(string.Join("\r\n", _tempActionQuotaAllRound.Select(kv => $"{kv.Key.Name}:{kv.Value}"))); } return builder.ToString(); } } }