public static void InflictDamage( GameObject victim, Object inflictor, float damage, DamageKind kind, List <SurfaceContact> contacts = null ) { if (damage == 0) { return; } float influence = DamageReceiver.GetInfluence(victim, kind); if (influence != 0) { damage *= influence; var damageData = new DamageMessageData( inflictor, damage, DamageKind.Collision, contacts ); victim.SendMessage(DamageMessageData.MessageName, damageData, SendMessageOptions.DontRequireReceiver); } }
void OnDamage(DamageMessageData data) { if (!enabled) { return; } float actualHealth = HealthComponent.ActualHealth; if (data.Damage >= LoseControlWhenDamagedAbove || actualHealth <= 0) { Movement.IncreaseControlLossTimer(MediumControlLossDuration); soundPlayer.PlayVariation(MediumHitSounds); TurnManager.Singleton.RequestFinishCurrentTurn(PlayerOwnedObject, 0); if (actualHealth <= 0) { TurnManager.Singleton.DrawAttention(gameObject, AttentionPriority.Death); } CameraEvents.LostControl.Restart(); } else { Movement.IncreaseControlLossTimer(LowControlLossDuration); soundPlayer.PlayVariation(LowHitSounds); } TurnManager.Singleton.DrawAttention(gameObject, AttentionPriority.HealthChanged); }
protected bool SendDamageMessage(GameObject gameObject, float damage, List <SurfaceContact> contacts) { var data = new DamageMessageData(this, damage, Kind, contacts); gameObject.SendMessage(DamageMessageData.MessageName, data, SendMessageOptions.DontRequireReceiver); return(data.ApplyDamageEffect); }
private void ProcessQueueItem(DamageMessageData damageData) { float oldHealth = Health; Health -= damageData.Damage; TotalDamageReceived += damageData.Damage; if (!AllowNegativeValues && Health < 0) { Health = 0; } var messageData = new DamageAccountedMessageData(damageData, oldHealth, Health); SendMessage(DamageAccountedMessageData.MessageName, messageData, SendMessageOptions.DontRequireReceiver); }
void OnDamage(DamageMessageData data) { if (!enabled) { return; } if (Mathf.Abs(data.Damage) < MinChangeToAccount) { return; } print("OnDamage, " + this + " received damage: " + data.Damage + ", inflictor: " + data.Inflictor); if (ChangeImmediately) { ProcessQueueItem(data); } else { DamageQueue.Enqueue(data); } }
public DamageAccountedMessageData(DamageMessageData damageData, float oldHealth, float newHealth) { this.DamageData = damageData; this.OldHealth = oldHealth; this.NewHealth = newHealth; }