Exemplo n.º 1
0
    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);
        }
    }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
0
    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);
    }
Exemplo n.º 5
0
    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);
        }
    }
Exemplo n.º 6
0
 public DamageAccountedMessageData(DamageMessageData damageData, float oldHealth, float newHealth)
 {
     this.DamageData = damageData;
     this.OldHealth  = oldHealth;
     this.NewHealth  = newHealth;
 }