//中断可能正在执行的技能 public void Interrupt(TypeOfInterruption type) { if (!GlobalConfigComponent.Instance.networkPlayMode) { //TODO: 根据当前使用技能允许的可打断类型判定打断是否可以成功 CharacterStateComponent characterStateComponent = GetParent <Unit>().GetComponent <CharacterStateComponent>(); if (characterStateComponent.Get(SpecialStateType.UnStoppable)) { return; // 霸体状态,打断失败 } } cancelToken?.Cancel(); cancelToken = null; }
//中断可能正在执行的技能 public static void Interrupt(this ActiveSkillComponent self, TypeOfInterruption type) { //TODO: 根据当前使用技能允许的可打断类型判定打断是否可以成功 CharacterStateComponent characterStateComponent = self.GetParent <Unit>().GetComponent <CharacterStateComponent>(); if (characterStateComponent.Get(SpecialStateType.UnStoppable)) { return; // 霸体状态,打断失败 } self.cancelToken?.Cancel(); self.cancelToken = null; M2C_InterruptSkill m2c = new M2C_InterruptSkill(); m2c.Frame = Game.Scene.GetComponent <UnitStateMgrComponent>().currFrame; m2c.Id = self.GetParent <Unit>().Id; ETHotfix.MessageHelper.Broadcast(m2c); }
public static bool CalFinalDamage(long sourceUnitId, long destUnitId, DamageData skillDamageValue) { try { CharacterStateComponent unitState = UnitComponent.Instance.Get(destUnitId).GetComponent <CharacterStateComponent>(); if (unitState.Get(SpecialStateType.Die)) { return(false); } if (unitState.Get(SpecialStateType.Invincible)) { //TODO: 提示无敌状态 return(false); } NumericComponent sourceUnitNumericCom = UnitComponent.Instance.Get(sourceUnitId).GetComponent <NumericComponent>(); NumericComponent destUnitNumericCom = UnitComponent.Instance.Get(destUnitId).GetComponent <NumericComponent>(); int rateCharge = 0; //命中判定 float hitRate = sourceUnitNumericCom.GetAsFloat(NumericType.HitRate) - destUnitNumericCom.GetAsFloat(NumericType.DodgeRate); rateCharge = RandomHelper.RandomNumber(0, 100); if (rateCharge / 100.0f > hitRate) { Game.EventSystem.Run(EventIdType.AttackMissing, destUnitId); Log.Debug("Miss! 命中率 " + hitRate); return(false); } //暴击判定 //可能有技能提升效果 if (!skillDamageValue.isCritical) { float criticalRate = sourceUnitNumericCom.GetAsFloat(NumericType.CritRate); rateCharge = RandomHelper.RandomNumber(0, 100); if (rateCharge / 100.0f <= criticalRate) { //暴击判定通过 skillDamageValue.isCritical = true; } } if (skillDamageValue.isCritical) { skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * sourceUnitNumericCom.GetAsFloat(NumericType.CritDamagePct)); } NumericType resistType = NumericType.ArmorResist; if (skillDamageValue.damageType != DamageType.Physic) { resistType = NumericType.MagicResist; } skillDamageValue.damageValue = Mathf.RoundToInt(skillDamageValue.damageValue * (100.0f / (destUnitNumericCom.GetAsInt(resistType) + 100.0f))); //预防可能要考虑什么白字红字,黑字粉字等乱七八糟的情况,所以专门用一个List DamageData[] array = new DamageData[1]; array[0] = skillDamageValue; //计算最终伤害加成,减免 for (int i = 0; i < array.Length; i++) { var damage = array[i]; float finalDamagePct = 1 + sourceUnitNumericCom.GetAsFloat(NumericType.FinalDamage_AddPct) - destUnitNumericCom.GetAsFloat(NumericType.FinalDamage_ReducePct); damage.damageValue = Mathf.RoundToInt(array[i].damageValue * finalDamagePct); //限定最小伤害0 damage.damageValue = Mathf.Clamp(array[i].damageValue, 0, int.MaxValue); array[i] = damage; } //给予伤害 Game.EventSystem.Run(EventIdType.GiveDamage, destUnitId, array); //给予吸血,吸法 float xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.HP_LeechRate); if (xiQu > 0) { Game.EventSystem.Run(EventIdType.GiveHealth, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu)); } xiQu = sourceUnitNumericCom.GetAsFloat(NumericType.MP_LeechRate); if (xiQu > 0) { Game.EventSystem.Run(EventIdType.GiveMp, sourceUnitId, Mathf.RoundToInt(skillDamageValue.damageValue * xiQu)); } return(true); } catch (Exception e) { Debug.LogError(e.ToString()); return(false); } }