using System; using Cielonos.MainGame.Characters; using SLSUtilities.General; using UnityEngine; namespace Cielonos.MainGame { public partial class ReactionSubmodule : AttackAreaSubmoduleBase { public ReactionSubmodule(AttackAreaBase owner) : base(owner) { SetBlock(); SetDodge(); SetReflection(); } } public partial class ReactionSubmodule { public bool canBeBlocked; public bool canBreakBlock; public bool hasPerfectWindowTime; public bool hasPerfectBlock; public Action generalBlockAction; public Action normalBlockAction; public Action perfectBlockAction; public Action breakBlockAction; public AttackAreaBase SetBlock(bool canBeBlocked = true, bool hasPerfectBlock = true, bool canBreakBlock = false) { this.canBeBlocked = canBeBlocked; this.hasPerfectBlock = hasPerfectBlock; this.hasPerfectWindowTime = true; this.canBreakBlock = canBreakBlock; return attackArea; } public AttackAreaBase SetBlockActions(Action generalBlockAction = null, Action breakBlockAction = null) { this.generalBlockAction = generalBlockAction; this.breakBlockAction = breakBlockAction; return attackArea; } public AttackAreaBase SetBlockActions(Action normalBlockAction, Action perfectBlockAction, Action breakBlockAction) { this.normalBlockAction = normalBlockAction; this.perfectBlockAction = perfectBlockAction; this.breakBlockAction = breakBlockAction; return attackArea; } public bool CheckBlock(CharacterBase blocker, CharacterBase attacker, Vector3 hitPosition) { BlockSubmodule characterBlockSm = blocker?.reactionSc?.blockSm; if (characterBlockSm == null) return false; if (characterBlockSm.isBlocking) { /*if (canBeBlocked) { }*/ BlockSource firstBlockSource; if (hasPerfectBlock && (!hasPerfectWindowTime || owner.timeSm.enablingTimer <= 0.2f) && characterBlockSm.isPerfectBlocking) { firstBlockSource = characterBlockSm.blockSources.Find(source => source.perfectBlockType >= attackArea.attackSm.attackValue.breakthroughType && source.isDuringPerfectBlock); if (firstBlockSource != null) { firstBlockSource.PerfectBlock(attackArea, hitPosition); generalBlockAction?.Invoke(blocker); perfectBlockAction?.Invoke(blocker); blocker.eventSm.onBlockSuccess.Invoke(attackArea, firstBlockSource); blocker.eventSm.onPerfectBlockSuccess.Invoke(attackArea, firstBlockSource); return true; } } else { firstBlockSource = characterBlockSm.blockSources.Find(source => source.normalBlockType >= attackArea.attackSm.attackValue.breakthroughType); if (firstBlockSource != null) { firstBlockSource.NormalBlock(attackArea, hitPosition); generalBlockAction?.Invoke(blocker); normalBlockAction?.Invoke(blocker); blocker.eventSm.onBlockSuccess.Invoke(attackArea, firstBlockSource); blocker.eventSm.onNormalBlockSuccess.Invoke(attackArea, firstBlockSource); return true; } } //格挡被突破 breakBlockAction?.Invoke(blocker); return false; } return false; } } public partial class ReactionSubmodule { public bool canBeDodged; public bool canBreakDodge; public bool hasPerfectDodge; public Action normalDodgeAction; public Action perfectDodgeAction; public Action breakDodgeAction; public AttackAreaBase SetDodge(bool canBeDodged = true, bool hasPerfectDodge = true, bool canBreakDodge = false) { this.canBeDodged = canBeDodged; this.hasPerfectDodge = hasPerfectDodge; this.canBreakDodge = canBreakDodge; return attackArea; } public AttackAreaBase SetDodgeActions(Action normalDodgeAction = null, Action perfectDodgeAction = null, Action breakDodgeAction = null) { this.normalDodgeAction = normalDodgeAction; this.perfectDodgeAction = perfectDodgeAction; this.breakDodgeAction = breakDodgeAction; return attackArea; } public bool CheckDodge(CharacterBase dodger) { DodgeSubmodule characterDodgeSm = dodger?.reactionSc?.dodgeSm; if (characterDodgeSm == null) return false; if (characterDodgeSm.isDodging) { if (canBeDodged) { DodgeSource firstDodgeSource; if (hasPerfectDodge && owner.timeSm.enablingTimer <= 0.2f && characterDodgeSm.isPerfectDodging) { firstDodgeSource = characterDodgeSm.dodgeSources.Find(source => source.isDuringPerfectDodge); firstDodgeSource.PerfectDodge(); perfectDodgeAction?.Invoke(dodger); // 触发完美闪避成功事件 dodger.eventSm.onPerfectDodgeSuccess.Invoke(owner, firstDodgeSource); } else { firstDodgeSource = characterDodgeSm.dodgeSources[0]; firstDodgeSource.NormalDodge(); normalDodgeAction?.Invoke(dodger); // 触发普通闪避成功事件 dodger.eventSm.onNormalDodgeSuccess.Invoke(owner, firstDodgeSource); } return true; } if (canBreakDodge) { breakDodgeAction?.Invoke(dodger); return false; } } return false; } } public partial class ReactionSubmodule { public bool canBeReflected; public AttackAreaBase SetReflection(bool canBeReflected = false) { this.canBeReflected = canBeReflected; return attackArea; } public bool CheckReflection(CharacterBase reflector) { ReflectionSubmodule characterReflectionSm = reflector?.reactionSc?.reflectionSm; if (characterReflectionSm == null) return false; if (characterReflectionSm.isReflecting) { if (canBeReflected) { foreach (ReflectionSource source in characterReflectionSm.reflectionSources) { if (source.condition == null || source.condition(attackArea)) { source.onReflection(attackArea); return true; } } } } return false; } } }