예제 #1
0
    public WeaponDamageRange CalculateDamageRange(WeaponProperties weapon, float accuracy, FiringZone.Face face, float targetShield, float priorShieldDamage = 0)
    {
        WeaponDamageRange damageRange = new WeaponDamageRange();

        damage.AddModifier(properties.Profile[(int)face]);
        // target has a shield - need to factor in each weapon types effectiveness
        if (targetShield - priorShieldDamage > 0)
        {
            // a list going from most effective to least effective against shields
            foreach (var shieldPriority in DamageTypeEffect.SHIELD_PRIORITY_LIST)
            {
                Vector2Int range = weapon.Damage[shieldPriority];
                // TODO add modifiers of effect
                // THIS IS PROBLEM AREA
                // TODO doing targetDamage.shieldRange.x is being conservative
                // doing targetDamage.shieldRange.y would be greedy
                if (damageRange.shieldRange.x >= targetShield - priorShieldDamage)
                {
                    damage.BaseValue         = range.x;
                    damageRange.hullRange.x += damage.Value * DamageTypeEffect.HullEffect(shieldPriority);
                    damage.BaseValue         = range.y;
                    damageRange.hullRange.y += damage.Value * DamageTypeEffect.HullEffect(shieldPriority);
                }
                // else if (damageRange.shieldRange.y >= targetShield - targetDamage.shieldRange.x)
                // {
                //     damage.BaseValue = range.x;
                //     damageRange.shieldRange.x += damage.Value;
                //     damage.BaseValue = range.y;
                //     damageRange.hullRange.y += damage.Value;
                // }
                else
                {
                    damage.BaseValue           = range.x;
                    damageRange.shieldRange.x += damage.Value * DamageTypeEffect.ShieldEffect(shieldPriority);
                    damage.BaseValue           = range.y;
                    damageRange.shieldRange.y += damage.Value * DamageTypeEffect.ShieldEffect(shieldPriority);
                }
            }
            damageRange *= accuracy;
            damageRange.shieldRange.x = Mathf.Clamp(damageRange.shieldRange.x, 0, targetShield);
            damageRange.shieldRange.y = Mathf.Clamp(damageRange.shieldRange.y, 0, targetShield);
        }
        else
        {
            // if the target has no shield it is simply hull damage
            // hull damage of a weapon can be precomputed and cached with effectivenesses
            damage.BaseValue        = weapon.HullDamage.x;
            damageRange.hullRange.x = damage.Value;
            damage.BaseValue        = weapon.HullDamage.y;
            damageRange.hullRange.y = damage.Value;
            damageRange            *= accuracy;
        }
        damage.RemoveModifier(properties.Profile[(int)face]);
        return(damageRange);
    }
예제 #2
0
    protected override void OnEnable()
    {
        base.OnEnable();
        var types = Enum.GetValues(typeof(DamageType));

        Damage = new Dictionary <DamageType, Vector2Int>(types.Length);
        Vector2 dmg = Vector2Int.zero;

        for (int i = 0; i < types.Length; i++)
        {
            var type = (DamageType)types.GetValue(i);
            Damage.Add(type, damage[i]);
            dmg += new Vector2(damage[i].x, damage[i].y) * DamageTypeEffect.HullEffect(type);
        }
        hullDamage = new Vector2Int((int)dmg.x, (int)dmg.y);
    }