using System; using System.Collections.Generic; using System.Linq; using Continentis.MainGame.Card; using SLSUtilities.General; using UnityEngine; namespace Continentis.MainGame.Character { public partial class RecordSubmodule : SubmoduleBase { public int currentRound; public int currentAction; public List actionRecords; /// /// 记录角色本回合被攻击的次数(含闪避)。 /// 每次 onGetAttacked 触发时自增,每次 DispatchRoundStart 时归零。 /// 可被卡牌(如"不屈")用于判断"本回合是否被攻击过"。 /// public int attacksReceivedThisRound; public RecordSubmodule(CharacterBase owner) : base(owner) { actionRecords = new List(); // 自动挂钩:每次被攻击时计数 owner.eventSubmodule.onGetAttacked.InsertByPriority( "RecordSubmodule_AttackCount", new PrioritizedAction((attacker, result) => { attacksReceivedThisRound++; })); // 自动挂钩:回合开始时重计 owner.eventSubmodule.onRoundStart.InsertByPriority( "RecordSubmodule_ResetAttackCount", new PrioritizedAction(() => { attacksReceivedThisRound = 0; })); } public void SetAction(int round, int actionIndex) { currentRound = round; currentAction = actionIndex; actionRecords.Add(new ActionRecord(round, actionIndex, new List())); } /// /// 返回本回合是否已被攻击过至少一次。 /// public bool WasAttackedThisRound => attacksReceivedThisRound > 0; } public partial class RecordSubmodule { public void RecordCardPlay(CardInstance card) { if (actionRecords.Count == 0) { Debug.LogWarning("No action record to add card play to."); return; } ActionRecord currentRecord = actionRecords[actionRecords.Count - 1]; currentRecord.cardsPlayed.Add(card); Debug.Log($"在回合 {currentRecord.round} 行动 {currentRecord.actionIndex} 中记录了卡牌 {card.contentSubmodule.cardName} 的使用。"); } } public partial class RecordSubmodule { public ActionRecord GetRecord(int round, int actionIndex) { return actionRecords.FirstOrDefault(record => record.round == round && record.actionIndex == actionIndex); } public List GetLastActionsRecords(int count) { return actionRecords.Skip(Mathf.Max(0, actionRecords.Count - count)).ToList(); } public List GetLastRoundsRecords(int roundCount) { int minRound = Mathf.Max(0, currentRound - roundCount + 1); return actionRecords.Where(record => record.round >= minRound).ToList(); } } [Serializable] public class ActionRecord { public int round; public int actionIndex; public List cardsPlayed; public ActionRecord(int round, int actionIndex, List cardsPlayed) { this.round = round; this.actionIndex = actionIndex; this.cardsPlayed = cardsPlayed; } } }