Exemplo n.º 1
0
    public void ApplyDamage(float amount)
    {
        Vital shield = GetVital(VitalType.ShieldPoints);
        Vital hull   = GetVital(VitalType.HullPoints);

        if (hull.current <= 0f)
        {
            return;
        }

        if (shield.current >= amount)
        {
            shield.Update(-amount);
        }
        else if (shield.current > 0)
        {
            amount -= shield.current;

            shield.Update(-shield.current);
            hull.Update(-amount);
        }
        else
        {
            hull.Update(-amount);
        }

        OnVitalChanged?.Invoke(VitalType.ShieldPoints, shield.inPercent);
        OnVitalChanged?.Invoke(VitalType.HullPoints, hull.inPercent);
    }
Exemplo n.º 2
0
    void OnVitalChange(VitalType v, float current)
    {
        OnVitalChanged?.Invoke(v, current);

        //hook in audio here
        if (v == VitalType.HullPoints && current <= 0f)
        {
            OnShipDestroyed();
        }
    }
Exemplo n.º 3
0
    public void Update(int amount)
    {
        this.current += amount;

        if (this.current < 0)
        {
            this.current = 0;
        }
        else if (this.current > _getMax())
        {
            this.current = _getMax();
        }

        OnVitalChanged?.Invoke(type, amount);
    }
Exemplo n.º 4
0
    public void SetCurrent(int current)
    {
        //cache old
        int change = current - this.current;

        this.current = current;

        if (this.current < 0)
        {
            this.current = 0;
        }
        else if (this.current > _getMax())
        {
            this.current = _getMax();
        }

        OnVitalChanged?.Invoke(type, change);
    }