Пример #1
0
        /// <summary>
        /// Calculate the tax rate
        /// </summary>
        /// <param name="privlidge"></param>
        /// <returns></returns>
        private double CalculateTaxRate(BuildingPrivlidge privlidge)
        {
            BuildingPrivlidge.UpkeepBracket[] upkeepBrackets = new List <BuildingPrivlidge.UpkeepBracket>()
            {
                new BuildingPrivlidge.UpkeepBracket(ConVar.Decay.bracket_0_blockcount, ConVar.Decay.bracket_0_costfraction),
                new BuildingPrivlidge.UpkeepBracket(ConVar.Decay.bracket_1_blockcount, ConVar.Decay.bracket_1_costfraction),
                new BuildingPrivlidge.UpkeepBracket(ConVar.Decay.bracket_2_blockcount, ConVar.Decay.bracket_2_costfraction),
                new BuildingPrivlidge.UpkeepBracket(ConVar.Decay.bracket_3_blockcount, ConVar.Decay.bracket_3_costfraction)
            }.ToArray();

            BuildingManager.Building building = privlidge.GetBuilding();
            if (building == null || !building.HasBuildingBlocks())
            {
                return(ConVar.Decay.bracket_0_costfraction);
            }
            int count = building.buildingBlocks.Count;
            int a     = count;

            for (int index = 0; index < upkeepBrackets.Length; ++index)
            {
                BuildingPrivlidge.UpkeepBracket upkeepBracket = upkeepBrackets[index];
                upkeepBracket.blocksTaxPaid = 0.0f;
                if (a > 0)
                {
                    int num = index != upkeepBrackets.Length - 1 ? Mathf.Min(a, upkeepBrackets[index].objectsUpTo) : a;
                    a -= num;
                    upkeepBracket.blocksTaxPaid = num * upkeepBracket.fraction;
                }
            }
            float num1 = 0.0f;

            for (int index = 0; index < upkeepBrackets.Length; ++index)
            {
                BuildingPrivlidge.UpkeepBracket upkeepBracket = upkeepBrackets[index];
                if (upkeepBracket.blocksTaxPaid > 0.0)
                {
                    num1 += upkeepBracket.blocksTaxPaid;
                }
                else
                {
                    break;
                }
            }
            return(Math.Ceiling((num1 / count) * 100));
        }
    public float CalculateBuildingTaxRate()
    {
        BuildingManager.Building building = base.GetBuilding();
        if (building == null)
        {
            return(ConVar.Decay.bracket_0_costfraction);
        }
        if (!building.HasBuildingBlocks())
        {
            return(ConVar.Decay.bracket_0_costfraction);
        }
        int count = building.buildingBlocks.Count;
        int num   = count;

        for (int i = 0; i < (int)BuildingPrivlidge.upkeepBrackets.Length; i++)
        {
            BuildingPrivlidge.UpkeepBracket upkeepBracket = BuildingPrivlidge.upkeepBrackets[i];
            upkeepBracket.blocksTaxPaid = 0f;
            if (num > 0)
            {
                int num1 = 0;
                num1 = (i != (int)BuildingPrivlidge.upkeepBrackets.Length - 1 ? Mathf.Min(num, BuildingPrivlidge.upkeepBrackets[i].objectsUpTo) : num);
                num -= num1;
                upkeepBracket.blocksTaxPaid = (float)num1 * upkeepBracket.fraction;
            }
        }
        float single = 0f;

        for (int j = 0; j < (int)BuildingPrivlidge.upkeepBrackets.Length; j++)
        {
            BuildingPrivlidge.UpkeepBracket upkeepBracket1 = BuildingPrivlidge.upkeepBrackets[j];
            if (upkeepBracket1.blocksTaxPaid <= 0f)
            {
                break;
            }
            single += upkeepBracket1.blocksTaxPaid;
        }
        single /= (float)count;
        return(single);
    }
    public float CalculateBuildingTaxRate()
    {
        BuildingManager.Building building = this.GetBuilding();
        if (building == null || !building.HasBuildingBlocks())
        {
            return(ConVar.Decay.bracket_0_costfraction);
        }
        int count = building.buildingBlocks.get_Count();
        int num1  = count;

        for (int index = 0; index < BuildingPrivlidge.upkeepBrackets.Length; ++index)
        {
            BuildingPrivlidge.UpkeepBracket upkeepBracket = BuildingPrivlidge.upkeepBrackets[index];
            upkeepBracket.blocksTaxPaid = 0.0f;
            if (num1 > 0)
            {
                int num2 = index != BuildingPrivlidge.upkeepBrackets.Length - 1 ? Mathf.Min(num1, BuildingPrivlidge.upkeepBrackets[index].objectsUpTo) : num1;
                num1 -= num2;
                upkeepBracket.blocksTaxPaid = (float)num2 * upkeepBracket.fraction;
            }
        }
        float num3 = 0.0f;

        for (int index = 0; index < BuildingPrivlidge.upkeepBrackets.Length; ++index)
        {
            BuildingPrivlidge.UpkeepBracket upkeepBracket = BuildingPrivlidge.upkeepBrackets[index];
            if ((double)upkeepBracket.blocksTaxPaid > 0.0)
            {
                num3 += upkeepBracket.blocksTaxPaid;
            }
            else
            {
                break;
            }
        }
        return(num3 / (float)count);
    }