コード例 #1
0
    public int GetRepairCost(BuildingHealth health)
    {
        int healthLost   = health.MaxHealth - health.CurrentHealth;
        int buildingCost = health.GetComponent <BuildingInfo>().BaseCost;

        foreach (RepairConfig config in RepairCosts)
        {
            if (healthLost * config.HealthDenominator < health.MaxHealth * config.HealthNumerator)
            {
                return(buildingCost * config.CostNumerator / config.CostDenominator);
            }
        }
        Debug.LogError("Unexpected branch in GetRepairCost");
        Debug.LogError($"Building health {health.CurrentHealth} max health {health.MaxHealth} health lost {healthLost}");
        Debug.LogError("Defaulting to full cost");
        return(buildingCost);
    }
コード例 #2
0
    public int GetHealthUpgradeCost(BuildingHealth health)
    {
        int baseCost = health.GetComponent <BuildingInfo>().BaseCost;

        switch (health.HealthUpgradeLevel)
        {
        case 0:
            return(baseCost / 4);

        case 1:
            return(baseCost / 3);

        default:
            Debug.LogError("Unexpected branch in GetUpgradeCost");
            Debug.LogError($"Building health level {health.HealthUpgradeLevel}");
            return(baseCost);
        }
    }