Beyond_Beyaan.Planet.SetOutputAmount C# (CSharp) Метод

SetOutputAmount() публичный Метод

public SetOutputAmount ( OUTPUT_TYPE outputType, int amount, bool forceChange ) : void
outputType OUTPUT_TYPE
amount int
forceChange bool
Результат void
        public void SetOutputAmount(OUTPUT_TYPE outputType, int amount, bool forceChange)
        {
            if (forceChange)
            {
                //First, try and change it without forcing it
                SetOutputAmount(outputType, amount, false);
                switch (outputType)
                {
                    case OUTPUT_TYPE.CONSTRUCTION:
                        {
                            if (ConstructionAmount == amount)
                            {
                                //Success
                                return;
                            }
                        } break;
                    case OUTPUT_TYPE.DEFENSE:
                        {
                            if (DefenseAmount == amount)
                            {
                                //Success
                                return;
                            }
                        }
                        break;
                    case OUTPUT_TYPE.ENVIRONMENT:
                        {
                            if (EnvironmentAmount == amount)
                            {
                                //Success
                                return;
                            }
                        }
                        break;
                    case OUTPUT_TYPE.INFRASTRUCTURE:
                        {
                            if (InfrastructureAmount == amount)
                            {
                                //Success
                                return;
                            }
                        }
                        break;
                    case OUTPUT_TYPE.RESEARCH:
                        {
                            if (ResearchAmount == amount)
                            {
                                //Success
                                return;
                            }
                        }
                        break;
                }
            }

            int remainingPercentile = 100;
            if (InfrastructureLocked && !forceChange)
            {
                remainingPercentile -= InfrastructureAmount;
            }
            if (EnvironmentLocked && !forceChange)
            {
                remainingPercentile -= EnvironmentAmount;
            }
            if (DefenseLocked && !forceChange)
            {
                remainingPercentile -= DefenseAmount;
            }
            if (ConstructionLocked && !forceChange)
            {
                remainingPercentile -= ConstructionAmount;
            }
            if (ResearchLocked && !forceChange)
            {
                remainingPercentile -= ResearchAmount;
            }

            //if the player set the slider to or beyond the allowed percentile, all other sliders are set to 0
            if (amount >= remainingPercentile)
            {
                //set all sliders to 0, and change amount to remainingPercentile
                if (!InfrastructureLocked)
                {
                    InfrastructureAmount = 0;
                }
                if (!EnvironmentLocked)
                {
                    EnvironmentAmount = 0;
                }
                if (!DefenseLocked)
                {
                    DefenseAmount = 0;
                }
                if (!ResearchLocked)
                {
                    ResearchAmount = 0;
                }
                if (!ConstructionLocked)
                {
                    ConstructionAmount = 0;
                }
                amount = remainingPercentile;
            }

            //Now scale
            int totalPointsExcludingSelectedType = GetPointsExcludingSelectedTypeAndLockedTypes(outputType);
            switch (outputType)
            {
                case OUTPUT_TYPE.INFRASTRUCTURE:
                    {
                        InfrastructureAmount = amount;
                        remainingPercentile -= InfrastructureAmount;
                    } break;
                case OUTPUT_TYPE.ENVIRONMENT:
                    {
                        EnvironmentAmount = amount;
                        remainingPercentile -= EnvironmentAmount;
                    } break;
                case OUTPUT_TYPE.DEFENSE:
                    {
                        DefenseAmount = amount;
                        remainingPercentile -= DefenseAmount;
                    } break;
                case OUTPUT_TYPE.CONSTRUCTION:
                    {
                        ConstructionAmount = amount;
                        remainingPercentile -= ConstructionAmount;
                    } break;
                case OUTPUT_TYPE.RESEARCH:
                    {
                        ResearchAmount = amount;
                        remainingPercentile -= ResearchAmount;
                    } break;
            }
            if (remainingPercentile < totalPointsExcludingSelectedType)
            {
                int amountToDeduct = totalPointsExcludingSelectedType - remainingPercentile;
                int prevValue;
                if ((!ResearchLocked || forceChange) && outputType != OUTPUT_TYPE.RESEARCH)
                {
                    prevValue = ResearchAmount;
                    ResearchAmount -= (ResearchAmount >= amountToDeduct ? amountToDeduct : ResearchAmount);
                    amountToDeduct -= (prevValue - ResearchAmount);
                }
                if (amountToDeduct > 0)
                {
                    if ((!ConstructionLocked || forceChange) && outputType != OUTPUT_TYPE.CONSTRUCTION)
                    {
                        prevValue = ConstructionAmount;
                        ConstructionAmount -= (ConstructionAmount >= amountToDeduct ? amountToDeduct : ConstructionAmount);
                        amountToDeduct -= (prevValue - ConstructionAmount);
                    }
                }
                if (amountToDeduct > 0)
                {
                    if ((!DefenseLocked || forceChange) && outputType != OUTPUT_TYPE.DEFENSE)
                    {
                        prevValue = DefenseAmount;
                        DefenseAmount -= (DefenseAmount >= amountToDeduct ? amountToDeduct : DefenseAmount);
                        amountToDeduct -= (prevValue - DefenseAmount);
                    }
                }
                if (amountToDeduct > 0)
                {
                    if ((!InfrastructureLocked || forceChange) && outputType != OUTPUT_TYPE.INFRASTRUCTURE)
                    {
                        prevValue = InfrastructureAmount;
                        InfrastructureAmount -= (InfrastructureAmount >= amountToDeduct ? amountToDeduct : InfrastructureAmount);
                        amountToDeduct -= (prevValue - InfrastructureAmount);
                    }
                }
                if (amountToDeduct > 0)
                {
                    if ((!EnvironmentLocked || forceChange) && outputType != OUTPUT_TYPE.ENVIRONMENT)
                    {
                        prevValue = EnvironmentAmount;
                        EnvironmentAmount -= (EnvironmentAmount >= amountToDeduct ? amountToDeduct : EnvironmentAmount);
                        amountToDeduct -= (prevValue - EnvironmentAmount);
                    }
                }
            }
            if (remainingPercentile > totalPointsExcludingSelectedType) //excess points needed to allocate
            {
                int amountToAdd = remainingPercentile - totalPointsExcludingSelectedType;
                if (!InfrastructureLocked && outputType != OUTPUT_TYPE.INFRASTRUCTURE)
                {
                    InfrastructureAmount += amountToAdd;
                    amountToAdd = 0;
                }
                if (amountToAdd > 0)
                {
                    if (!EnvironmentLocked && outputType != OUTPUT_TYPE.ENVIRONMENT)
                    {
                        EnvironmentAmount += amountToAdd;
                        amountToAdd = 0;
                    }
                }
                if (amountToAdd > 0)
                {
                    if (!DefenseLocked && outputType != OUTPUT_TYPE.DEFENSE)
                    {
                        DefenseAmount += amountToAdd;
                        amountToAdd = 0;
                    }
                }
                if (amountToAdd > 0)
                {
                    if (!ResearchLocked && outputType != OUTPUT_TYPE.RESEARCH)
                    {
                        ResearchAmount += amountToAdd;
                        amountToAdd = 0;
                    }
                }
                if (amountToAdd > 0)
                {
                    if (!ConstructionLocked && outputType != OUTPUT_TYPE.CONSTRUCTION)
                    {
                        ConstructionAmount += amountToAdd;
                        amountToAdd = 0;
                    }
                }
                if (amountToAdd > 0) //All other sliders has been locked, allocate the remaining points back to this output
                {
                    switch (outputType)
                    {
                        case OUTPUT_TYPE.INFRASTRUCTURE:
                                {
                                    InfrastructureAmount += amountToAdd;
                                    break;
                                }
                        case OUTPUT_TYPE.RESEARCH:
                                {
                                    ResearchAmount += amountToAdd;
                                    break;
                                }
                        case OUTPUT_TYPE.ENVIRONMENT:
                                {
                                    EnvironmentAmount += amountToAdd;
                                    break;
                                }
                        case OUTPUT_TYPE.DEFENSE:
                                {
                                    DefenseAmount += amountToAdd;
                                    break;
                                }
                        case OUTPUT_TYPE.CONSTRUCTION:
                                {
                                    ConstructionAmount += amountToAdd;
                                    break;
                                }
                    }
                }
            }

            UpdateOutputs();
        }