예제 #1
0
        private bool TotalFundChatCommand(IcPlayer player, string command, IDATokenClass text, TextMessageEnum chatType, object data)
        {
            if (!BRFEnabled)
            {
                DA.PagePlayer(player, "Building funding is not enabled for this map.");

                return(false);
            }

            string acronym = text[1];
            MappedBuildingDefinition       mappedDefinition = FindMappedDefinition(acronym);
            ICollection <IDefinitionClass> validatedDefinitions;

            if (mappedDefinition == null || (validatedDefinitions = mappedDefinition.ValidatedDefinitions) == null)
            {
                DA.PagePlayer(player, $"No building found for acronym '{acronym}'.");

                return(false);
            }

            IScriptableGameObj destroyedBuilding = FindDestroyedBuilding(validatedDefinitions, player.PlayerType);

            if (destroyedBuilding == null)
            {
                DA.PagePlayer(player, $"No destroyed building found for acronym '{acronym}'.");

                return(false);
            }

            if (mappedDefinition.RestoreCountExceeded)
            {
                DA.PagePlayer(player, $"The maximum amount of restores per map for the {DATranslationManager.Translate(destroyedBuilding)} is exceeded.");

                return(false);
            }

            if (!buildingFunds.TryGetValue(destroyedBuilding.ID, out BuildingFund fund))
            {
                fund = new BuildingFund(mappedDefinition, destroyedBuilding.ID);
                buildingFunds.Add(destroyedBuilding.ID, fund);
            }

            float totalRestoreCost = mappedDefinition.CalculateTotalRestoreCost(Engine.GetTeamPlayerCount(player.PlayerType));

            fund.NotifyPlayerContribution(player);
            DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(totalRestoreCost + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(destroyedBuilding)}.");

            return(true);
        }
예제 #2
0
        private bool ReFundChatCommand(IcPlayer player, string command, IDATokenClass text, TextMessageEnum chatType, object data)
        {
            // Acronym for a building is specified
            if (text.Size > 0)
            {
                string acronym = text[1];
                MappedBuildingDefinition       mappedDefinition = FindMappedDefinition(acronym);
                ICollection <IDefinitionClass> validatedDefinitions;
                if (mappedDefinition == null || (validatedDefinitions = mappedDefinition.ValidatedDefinitions) == null)
                {
                    DA.PagePlayer(player, $"No building found for acronym '{acronym}'.");

                    return(false);
                }

                IScriptableGameObj destroyedBuilding = FindDestroyedBuilding(validatedDefinitions, player.PlayerType);
                if (destroyedBuilding == null)
                {
                    DA.PagePlayer(player, $"No destroyed building found for acronym '{acronym}'.");

                    return(false);
                }

                if (!buildingFunds.TryGetValue(destroyedBuilding.ID, out BuildingFund fund) || fund.Refund(player) <= 0.0f)
                {
                    DA.PagePlayer(player, $"You haven't funded the {DATranslationManager.Translate(destroyedBuilding)}.");

                    return(false);
                }

                DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(mappedDefinition.CalculateTotalRestoreCost(Engine.GetTeamPlayerCount(player.PlayerType)) + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(destroyedBuilding)}.");

                return(true);
            }
            else //  Assume they want all their money back
            {
                int playerCount = Engine.GetTeamPlayerCount(player.PlayerType);

                float totalRefundAmount = 0.0f;
                foreach (BuildingFund fund in buildingFunds.Values)
                {
                    float currentRefundAmount = fund.Refund(player);
                    if (currentRefundAmount > 0.0f)
                    {
                        totalRefundAmount += currentRefundAmount;

                        DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(fund.MappedDefinition.CalculateTotalRestoreCost(playerCount) + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(fund.BuildingObj)}.");
                    }
                }

                if (totalRefundAmount <= 0.0f)
                {
                    DA.PagePlayer(player, "You haven't funded anything.");

                    return(false);
                }

                return(true);
            }
        }
예제 #3
0
        private bool FundChatCommand(IcPlayer player, string command, IDATokenClass text, TextMessageEnum chatType, object data)
        {
            if (!BRFEnabled)
            {
                DA.PagePlayer(player, "Building funding is not enabled for this map.");

                return(false);
            }

            string acronym = text[1];
            MappedBuildingDefinition       mappedDefinition = FindMappedDefinition(acronym);
            ICollection <IDefinitionClass> validatedDefinitions;

            if (mappedDefinition == null || (validatedDefinitions = mappedDefinition.ValidatedDefinitions) == null)
            {
                DA.PagePlayer(player, $"No building found for acronym '{acronym}'.");

                return(false);
            }

            IScriptableGameObj destroyedBuilding = FindDestroyedBuilding(validatedDefinitions, player.PlayerType);

            if (destroyedBuilding == null)
            {
                DA.PagePlayer(player, $"No destroyed building found for acronym '{acronym}'.");

                return(false);
            }

            if (mappedDefinition.RestoreCountExceeded)
            {
                DA.PagePlayer(player, $"The maximum amount of restores per map for the {DATranslationManager.Translate(destroyedBuilding)} is exceeded.");

                return(false);
            }

            // First check if the player specified an amount
            float offeredFundAmount;

            if (text.Size > 1)
            {
                // Make sure to parse as int so that player can't input some weird decimal stuff
                string newFundsStr = text[2];
                if (newFundsStr == null || !int.TryParse(newFundsStr, out int parsedFundAmount) || parsedFundAmount <= 0)
                {
                    DA.PagePlayer(player, $"Invalid fund amount '{newFundsStr}'.");

                    return(false);
                }

                offeredFundAmount = parsedFundAmount;
                offeredFundAmount = Math.Min(offeredFundAmount, player.Money);
            }
            else // No amount was given, assume they want to donate everything
            {
                offeredFundAmount = player.Money;
                if (offeredFundAmount <= 0.0f)
                {
                    DA.PagePlayer(player, $"You do not have enough money to fund the '{DATranslationManager.Translate(destroyedBuilding)}'.");

                    return(false);
                }
            }

            float totalRestoreCost = mappedDefinition.CalculateTotalRestoreCost(Engine.GetTeamPlayerCount(player.PlayerType));

            // Check if we already have a fund for this building and how much is left until fully funded
            float calculatedFundAmount;

            if (buildingFunds.TryGetValue(destroyedBuilding.ID, out BuildingFund fund))
            {
                float remainingFundAmount = totalRestoreCost - fund.TotalFunds;
                calculatedFundAmount = Math.Min(remainingFundAmount, offeredFundAmount); // Do not exceed the amount required to refund
            }
            else
            {
                calculatedFundAmount = Math.Min(totalRestoreCost, offeredFundAmount); // Do not exceed the amount required to refund

                fund = new BuildingFund(mappedDefinition, destroyedBuilding.ID);
                buildingFunds.Add(destroyedBuilding.ID, fund);
            }

            // Add this player's fund to the total funds
            fund.AddFund(player, calculatedFundAmount);

            DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{player.PlayerName} deposited {(int)(calculatedFundAmount + 0.5f)} credit(s) towards the funding of the {DATranslationManager.Translate(destroyedBuilding)}.");

            // See if we have enough to restore this building
            TryRestoreBuilding(fund);

            return(true);
        }