private void AddUnitFields(TileInfoGroupUI group, BaseUnit unit)
    {
        Damageable d = unit.GetPropertyOfType <Damageable>() as Damageable;
        Supplyable s = unit.GetPropertyOfType <Supplyable>() as Supplyable;
        CanFire    f = unit.GetAbilitieOfType <CanFire>() as CanFire;

        int health = 0;
        int ammo   = 0;
        int supply = 0;

        if (d)
        {
            health = d.Health;
        }
        if (f)
        {
            ammo = f.Settings.Ammo;
        }
        if (s)
        {
            supply = s.Supply;
        }

        group.UpdateOrAddField(_iconRef.HeartIcon, health.ToString(), 0);
        group.UpdateOrAddField(_iconRef.AmmoIcon, ammo.ToString(), 1);
        group.UpdateOrAddField(_iconRef.SupplyIcon, supply.ToString(), 2);
    }
Ejemplo n.º 2
0
    public void Confirm()
    {
        //Get references
        BaseUnit other = _entetiesManager.GetEntitieOfType <BaseUnit>(_selection.Position) as BaseUnit;

        Damageable dThis = _fireComponent.Unit.GetPropertyOfType <Damageable>() as Damageable;
        CanFire    fThis = _fireComponent;

        Damageable dOther = other.GetPropertyOfType <Damageable>() as Damageable;
        CanFire    fOther = other.GetAbilitieOfType <CanFire>() as CanFire;

        if (!(fThis && dOther))
        {
            Debug.LogWarning("Cant attck because one of units doesnt have necessary components");
            return;
        }

        // Calclulate damage
        int baseDamade = _fireComponent.Settings.DamageToBaseUnitTypeDict[fOther.Settings.Type].BaseDamage;

        float damagePercent = DamageCalculator.OriginalFormula(
            baseDamade,
            dThis.Health,
            0,
            dOther.Health
            );

        dOther.ModifyHealth(-(int)Mathf.Floor(damagePercent / 10));

        //Attack back if can
        if (fOther)
        {
            baseDamade = fOther.Settings.DamageToBaseUnitTypeDict[fThis.Settings.Type].BaseDamage;

            damagePercent = DamageCalculator.OriginalFormula(
                baseDamade,
                dOther.Health,
                0,
                dThis.Health
                );

            dThis.ModifyHealth(-(int)Mathf.Floor(damagePercent / 10));
        }


        fThis.GetComponent <BaseUnit>().ChangeState(UnitStates.Wait);
    }