using Kryz.CharacterStats.Examples; using UnityEngine; public class BlockInterceptor : BrokerInterceptor { float percentStatMitigation; float finalValue; float reducedDamage; protected override void Awake() { base.Awake(); broker.OnIncomingDamage.Subscribe(HandleBlockMitigation, GameConstants.BrokerEventPriority.Block); } protected void HandleBlockMitigation(DamageArgs args) { if (args.currentValue >= 0) return; BlockArgs blockArgs = new BlockArgs() { user = user, blockedSuccessfully = false }; if(HasBlocked()) { Debug.Log("Blocked!"); percentStatMitigation = MathHelpers.NormalizePercentageDecimal(stats.GetStat("blockeffectiveness").Value); percentStatMitigation = Mathf.Clamp(percentStatMitigation, 0, GameConstants.CharacterStatsBalancing.MaximumPercentDamageReductionFromBlock); reducedDamage = args.currentValue * percentStatMitigation; finalValue += Mathf.Abs(reducedDamage); if (finalValue > 0) //avoid damage ultra mitigated turning into healing finalValue = 0; blockArgs.blockedSuccessfully = true; args.currentValue = finalValue; } broker.OnBlock.Invoke(blockArgs); } protected bool HasBlocked() { return MathHelpers.RollChancePercent(stats.GetStat("blockchance").Value); } }