Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.9 kB
0
Indexable
Never
        public static float GetPrice(CharacterType characterType)
        {
            float pricePurchaseFinal = 0;

            int thresholdCount = _thresholdIndex + 1;

#if PRINT_FORMULA
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"Price for {characterType} with threshold index = {_thresholdIndex}");
#endif

            for (int i = 0; i < thresholdCount; i++)
            {
#if PRINT_FORMULA
                sb.AppendLine($"Step {i + 1}:");
#endif

                float amount = FactoryCharacter.pricePurchase.GetClamp(i) * DataCharacter.GetPurchaseCount(characterType, i) + (i == 0 ? FactoryCharacter.priceBase : 0.0f);

#if PRINT_FORMULA
                if (i == 0)
                {
                    sb.AppendLine($"amount = {FactoryCharacter.pricePurchase.GetClamp(i)} * n{i} + price base");
                    sb.AppendLine($"amount = {FactoryCharacter.pricePurchase.GetClamp(i)} * {DataCharacter.GetPurchaseCount(characterType, i)} + {FactoryCharacter.priceBase} = {amount}");
                }
                else
                {
                    sb.AppendLine($"amount = {FactoryCharacter.pricePurchase.GetClamp(i)} * n{i}");
                    sb.AppendLine($"amount = {FactoryCharacter.pricePurchase.GetClamp(i)} * {DataCharacter.GetPurchaseCount(characterType, i)} = {amount}");
                }
#endif

                if (i == thresholdCount - 2)
                {
#if PRINT_FORMULA
                    sb.AppendLine($"final = (final + amount) * (threshold multiple)");
                    sb.AppendLine($"final = ({pricePurchaseFinal} + {amount}) * {FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple} = {(pricePurchaseFinal + amount) * FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple}");
#endif
                    pricePurchaseFinal = (pricePurchaseFinal + amount) * FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple;
                    continue;
                }
                else if (i < thresholdCount - 1)
                {
#if PRINT_FORMULA
                    sb.AppendLine($"amount = amount * threshold multiple");
                    sb.AppendLine($"amount = {amount} * {FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple} = {amount * FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple}");
#endif
                    amount *= FactoryCharacter.priceThreshold.GetClamp(i + 1).multiple;
                }

#if PRINT_FORMULA
                sb.AppendLine("final = final + amount");
                sb.AppendLine($"final = {pricePurchaseFinal} + {amount} = {pricePurchaseFinal + amount}");
#endif

                pricePurchaseFinal += amount;
            }

#if PRINT_FORMULA
            BDebug.Log(sb.ToString());
#endif

            return pricePurchaseFinal;
        }