philipcass/uClicker

Bug in ApplyBuildingPerks

SnaiperoG3D opened this issue · 0 comments

This method logic always multiply current currency amount instead of multiply only current building amount. For example we have B1(building 1) - 10 amount, B2 - 10 and B - 10 and upgrade perk to have x2 to each only individualy, as it present in sample scene project. And lets say each building gives 1 rabbit per sec, which means we should have 10 * 2 + 10 * 2 + 10 * 2 = 60 income, but we not. Income will be 140, cuz this method do next: (0 + 10) * 2 = 20, then (20 + 10) * 2 = 60, then (60 + 10) * 2 = 140.

There is a fix

        private void ApplyBuildingPerks(Currency currency, ref float totalAmount)
        {
            float buildingAmount;
            foreach (KeyValuePair<Building, int> kvp in State.EarnedBuildings)
            {
                buildingAmount = 0f;
                Building building = kvp.Key;
                if (building.YieldAmount.Currency != currency)
                {
                    continue;
                }

                int buildingCount = kvp.Value;
                buildingAmount += building.YieldAmount.Amount * buildingCount;

                foreach (Upgrade upgrade in State.EarnedUpgrades)
                {
                    foreach (UpgradePerk upgradePerk in upgrade.UpgradePerk)
                    {
                        if (upgradePerk.TargetBuilding != building)
                        {
                            continue;
                        }

                        switch (upgradePerk.Operation)
                        {
                            case Operation.Add:
                                buildingAmount += upgradePerk.Amount;
                                break;
                            case Operation.Multiply:
                                buildingAmount *= upgradePerk.Amount;
                                break;
                        }
                    }
                }
                totalAmount += buildingAmount;
            }
        }