/// <summary> /// Called when the actor takes damage. This allows the actor to respond. /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <returns>Determines if the damage was applied</returns> public virtual bool OnDamaged(float rDamageValue, int rDamageType = 0, float rAttackAngle = 0f, Transform rBone = null) { if (!IsAlive) { return(true); } float lRemainingHealth = 0f; if (AttributeSource != null) { lRemainingHealth = AttributeSource.GetAttributeValue(HealthID) - rDamageValue; AttributeSource.SetAttributeValue(HealthID, lRemainingHealth); } if (lRemainingHealth <= 0f) { OnDeath(rDamageValue, rDamageType, rAttackAngle, rBone); } else { MotionController lMC = gameObject.GetComponent <MotionController>(); if (lMC != null) { lMC.ActivateMotion(DamagedMotion, (int)rAttackAngle); } } return(true); }
/// <summary> /// Tells the actor to die and triggers any effects or animations /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <param name="rBone">Transform that the damage it... if known</param> /// <param name="rDeathMotion">Motion to activate due to death</param> public virtual void OnKilled(IMessage rMessage) { IsAlive = false; if (AttributeSource != null && HealthID.Length > 0) { AttributeSource.SetAttributeValue(HealthID, 0f); } StartCoroutine(InternalDeath(rMessage)); }
/// <summary> /// Tells the actor to die and triggers any effects or animations /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <param name="rBone">Transform that the damage it... if known</param> public virtual void OnDeath(float rDamageValue = 0, int rDamageType = 0, float rAttackAngle = 0f, Transform rBone = null) { IsAlive = false; if (AttributeSource != null) { AttributeSource.SetAttributeValue(HealthID, 0f); } StartCoroutine(InternalDeath(rDamageValue, rDamageType, rAttackAngle, rBone)); }
/// <summary> /// Tells the actor to die and triggers any effects or animations /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <param name="rBone">Transform that the damage it... if known</param> /// <param name="rDeathMotion">Motion to activate due to death</param> public virtual void OnKilled(IMessage rMessage) { com.ootii.Utilities.Debug.Log.FileWrite(transform.name + ".OnKilled()"); IsAlive = false; if (AttributeSource != null) { AttributeSource.SetAttributeValue(HealthID, 0f); } StartCoroutine(InternalDeath(rMessage)); }
/// <summary> /// Called when the actor takes damage. This allows the actor to respond. /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <param name="rDamagedMotion">Motion to activate due to damage</param> /// <param name="rDeathMotion">Motion to activate due to death</param> /// <returns>Determines if the damage was applied</returns> public virtual bool OnDamaged(IMessage rMessage) { com.ootii.Utilities.Debug.Log.FileWrite(transform.name + ".OnDamaged()"); if (!IsAlive) { return(true); } float lRemainingHealth = 0f; if (AttributeSource != null && rMessage is CombatMessage) { lRemainingHealth = AttributeSource.GetAttributeValue(HealthID) - ((CombatMessage)rMessage).Damage; AttributeSource.SetAttributeValue(HealthID, lRemainingHealth); } if (lRemainingHealth <= 0f) { OnKilled(rMessage); } else { MotionController lMC = gameObject.GetComponent <MotionController>(); if (lMC != null) { // Send the message to the MC to let it activate //ActorMessage lMessage = ActorMessage.Allocate(); rMessage.ID = CombatMessage.MSG_DEFENDER_DAMAGED; lMC.SendMessage(rMessage); //lMC.ActivateMotion((rDamagedMotion.Length > 0 ? rDamagedMotion : DamagedMotion), (int)rAttackAngle); } else { Animator lAnimator = gameObject.GetComponent <Animator>(); if (lAnimator != null) { lAnimator.CrossFade(DamagedMotion, 0.25f); } } } return(true); }
/// <summary> /// Called when the actor takes damage. This allows the actor to respond. /// Damage Type 0 = Physical melee /// Damage Type 1 = Physical ranged /// </summary> /// <param name="rDamageValue">Amount of damage to take</param> /// <param name="rDamageType">Damage type taken</param> /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param> /// <param name="rDamagedMotion">Motion to activate due to damage</param> /// <param name="rDeathMotion">Motion to activate due to death</param> /// <returns>Determines if the damage was applied</returns> public virtual bool OnDamaged(IMessage rMessage) { if (!IsAlive) { return(true); } float lRemainingHealth = 0f; if (AttributeSource != null) { if (rMessage is DamageMessage) { lRemainingHealth = AttributeSource.GetAttributeValue(HealthID) - ((DamageMessage)rMessage).Damage; AttributeSource.SetAttributeValue(HealthID, lRemainingHealth); } } if (lRemainingHealth <= 0f) { OnKilled(rMessage); } else if (rMessage != null) { bool lPlayAnimation = true; if (rMessage is DamageMessage) { lPlayAnimation = ((DamageMessage)rMessage).AnimationEnabled; } if (lPlayAnimation) { MotionController lMotionController = gameObject.GetComponent <MotionController>(); if (lMotionController != null) { // Send the message to the MC to let it activate rMessage.ID = CombatMessage.MSG_DEFENDER_DAMAGED; lMotionController.SendMessage(rMessage); } if (!rMessage.IsHandled && DamagedMotion.Length > 0) { MotionControllerMotion lMotion = lMotionController.GetMotion(DamagedMotion); if (lMotion != null) { lMotionController.ActivateMotion(lMotion); } else { Animator lAnimator = gameObject.GetComponent <Animator>(); if (lAnimator != null) { lAnimator.CrossFade(DamagedMotion, 0.25f); } } } } } return(true); }