/// <summary> /// Use the alignment to see if adding damage is a valid action /// </summary> /// <param name="damageAddition"> /// The damage to add /// </param> /// <param name="damageAlignment"> /// The alignment of the other combatant /// </param> /// <param name="output"> /// The output data if there is damage taken /// </param> /// <returns> /// <value>true if this instance added damage</value> /// <value>false if this instance was already dead, or the alignment did not allow the damage</value> /// </returns> public bool CheckDamage(int damageAddition, IAlignmentProvider damageAlignment, Vector3 hitPosition, out HitInfo output) { var info = new DamageChangeInfo { alignment = damageAlignment, damageable = this, newDamage = CurrentDamage, oldDamage = CurrentDamage }; output = new HitInfo { damageChangeInfo = info, damagePoint = hitPosition }; if (damageAlignment == null || AlignmentProvider == null) { return(false); } bool canDamage = damageAlignment.CanHarm(AlignmentProvider); //if (!IsAlive || !canDamage) if (IsAlive == false || canDamage == false) { return(false); } AddDamage(+damageAddition, output); SafelyDoAction(Damaged, output); return(true); }
/// <summary> /// Use the alignment to see if taking damage is a valid action /// </summary> /// <param name="damage"> /// The damage to take /// </param> /// <param name="damageAlignment"> /// The alignment of the other combatant /// </param> /// <param name="output"> /// The output data if there is damage taken /// </param> /// <returns> /// <value>true if this instance took damage</value> /// <value>false if this instance was already dead, or the alignment did not allow the damage</value> /// </returns> public bool TakeDamage(float damage, IAlignmentProvider damageAlignment, out HealthChangeInfo output) { output = new HealthChangeInfo { damageAlignment = damageAlignment, damageable = this, newHealth = currentHealth, oldHealth = currentHealth }; bool canDamage = damageAlignment == null || alignmentProvider == null || damageAlignment.CanHarm(alignmentProvider); if (isDead || !canDamage) { return(false); } ChangeHealth(-damage, output); SafelyDoAction(damaged, output); if (isDead) { SafelyDoAction(died, output); } return(true); }
/// <summary> /// 伤害 /// </summary> public bool Damage(float damageValue, Vector3 damagePoint, IAlignmentProvider alignment) { // We don't want to enable this state if the FSM is dead //GotHitState gotHitState = GetState<GotHitState>(); //if ( gotHitState != null && gotHitState.CanGetHit(this) ) //{ //SubtractHealthValue(totalDamage); //if ( gotHitState.CoolDownFinished() ) //{ // ChangeActiveState(gotHitState); //} //} if (alignment.CanHarm(this.configuration.alignmentProvider)) { this.TakeDamage(damageValue, damagePoint, alignment); } else { Debug.Log("不可伤害,因为是友方单位"); } return(this.isDead); }
protected virtual bool IsLegalTarget(Transform targetable, SearchType searchType) { if (targetable == null) { return(false); } if (targetable.GetComponent <Targetable>() == null) { return(false); } bool isLegalTarget = true; IAlignmentProvider targetAlignment = targetable.GetComponent <Targetable>().configuration.alignmentProvider; IAlignmentProvider selfAlignment = alignment.GetInterface(); if (searchType == SearchType.All) { isLegalTarget = true; } else if (searchType == SearchType.Enemy) { isLegalTarget = selfAlignment == null || targetAlignment == null || selfAlignment.CanHarm(targetAlignment); } else if (searchType == SearchType.Friend) { isLegalTarget = selfAlignment == null || targetAlignment == null || selfAlignment.IsFriend(targetAlignment); } return(isLegalTarget); }
// Find out whether the found target is in the opponent alignment. protected virtual bool IsTargetableValid(Targetable targetable) { if (targetable == null || alignment == null) { return(false); } bool canDamage = alignment.CanHarm(targetable.configuration.alignmentProvider); return(canDamage); }
public virtual void TakeDamage(float damage, IAlignmentProvider damageAlignment, out bool output) { float effectivDamage = damage * (1 - resistance); bool canDamage = damageAlignment == null || alignmentProvider == null || damageAlignment.CanHarm(alignmentProvider); if (isDead || !canDamage) { output = false; return; } ChangeHealth(-effectivDamage); output = true; if (isDead) { died(); } }
public bool CanKnockback(IAlignmentProvider attackerAlignment) { var returnVal = attackerAlignment.CanHarm(configuration.AlignmentProvider); return(returnVal); }