Пример #1
0
        public void AddFund(IcPlayer player, float fundAmount)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            else if (fundAmount <= 0.0f)
            {
                throw new ArgumentOutOfRangeException($"Argument '{nameof(fundAmount)}' must be > 0");
            }

            string playerName = player.PlayerName;

            if (funds.ContainsKey(playerName))
            {
                funds[playerName] += fundAmount;
            }
            else
            {
                funds.Add(playerName, fundAmount);
            }

            player.Money -= fundAmount;
            player.SetObjectDirtyBit(DirtyBit.BitOccasional, true);
        }
Пример #2
0
 public override void PlayerJoinEvent(IcPlayer player)
 {
     if (player.DAPlayer.FindObserver(nameof(RenSharpExamplePlayerObserver)) == null)
     {
         player.DAPlayer.AddObserver(new RenSharpExamplePlayerObserver());
     }
 }
Пример #3
0
        public float Refund(IcPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }

            string playerName = player.PlayerName;

            if (funds.TryGetValue(playerName, out float fundAmount))
            {
                funds.Remove(playerName);

                player.Money += fundAmount;
                player.SetObjectDirtyBit(DirtyBit.BitOccasional, true);

                DA.PagePlayer(player, $"You have been refunded {(int)fundAmount} credit(s) for the {DATranslationManager.Translate(BuildingObj)}.");

                return(fundAmount);
            }
            else
            {
                return(0.0f);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        public override bool VehicleEntryRequest(IScriptableGameObj obj, IcPlayer player, ref int seat)
        {
            if (player.PlayerType != DAVehicleManager.GetTeam(Owner))
            {
                return(false); //Prevent the enemy from stealing this vehicle.
            }

            return(true);
        }
Пример #6
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);
        }
Пример #7
0
        public void RefundAll()
        {
            foreach (var fundsPair in funds)
            {
                float playerFunds = fundsPair.Value;
                if (playerFunds > 0.0f)
                {
                    IcPlayer player = Engine.FindPlayer(fundsPair.Key);
                    if (player != null)
                    {
                        DA.PagePlayer(player, $"You have been refunded {(int)playerFunds} credit(s) for the {DATranslationManager.Translate(BuildingObj)}.");
                    }
                }
            }

            funds.Clear();
        }
Пример #8
0
        public override void PlayerJoinEvent(IcPlayer player)
        {
            PlayerClass Player = PlayersDatabase.GetPlayer(player.PlayerName);

            if (Player != null)
            {
                if (!DisableList.Contains(Player.Sound.ToLower()))
                {
                    if (Player.Delay < MinDelay && Player.Delay > MaxDelay)
                    {
                        DA.PrivateColorMessage(player, Color.Cyan, $"[Join Sounds] Server settings are changed and incompatible setting detected. Your delay has been reset to minimum. Please update your delay with \"{CmdTriggers.Split('|')[0]} delay\".");
                        Player.Delay = MinDelay;
                        PlayersDatabase.Update(player.PlayerName, Player);
                    }
                    StartTimer(player.PlayerId, FloatToTime(Player.Delay), false, new KeyValuePair <IcPlayer, PlayerClass>(player, Player));
                }
                else
                {
                    DA.PrivateColorMessage(player, Color.Cyan, $"[Join Sounds] Server settings are changed and incompatible setting detected. Your join sound is no longer available. Please update your sound with \"{CmdTriggers.Split('|')[0]} set\". Your join sound is removed.");
                    PlayersDatabase.Remove(player.PlayerName);
                }
            }
        }
Пример #9
0
 public override void RemoveWeaponEvent(IcPlayer player, IWeaponClass weapon)
 {
 }
Пример #10
0
 public override bool AddWeaponRequestEvent(IcPlayer player, IWeaponDefinitionClass weapon)
 {
     return(true);
 }
Пример #11
0
 public override void PowerUpGrantEvent(IcPlayer player, IPowerUpGameObjDef powerUp, IPowerUpGameObj powerUpObj)
 {
 }
Пример #12
0
 public override void CharacterPurchaseEvent(IcPlayer player, float cost, ISoldierGameObjDef item)
 {
 }
Пример #13
0
        public void NotifyPlayerContribution(IcPlayer player)
        {
            funds.TryGetValue(player.PlayerName, out float playerFunds);

            DA.PagePlayer(player, $"Your contribution towards restoring the {DATranslationManager.Translate(BuildingObj)} is {(int)playerFunds} credit(s).");
        }
Пример #14
0
 public override bool TeamChangeRequestEvent(IcPlayer player)
 {
     return(true);
 }
Пример #15
0
 public override bool RequestVehicleEvent(IVehicleFactoryGameObj factory, IVehicleGameObjDef vehicle, IcPlayer player, float delay)
 {
     return(true);
 }
Пример #16
0
 public override bool RefillEvent(IcPlayer player)
 {
     return(true);
 }
Пример #17
0
 public override bool SuicideEvent(IcPlayer player)
 {
     return(true);
 }
Пример #18
0
 public override void CustomPurchaseEvent(IcPlayer player, float cost, uint id)
 {
 }
Пример #19
0
 public override void PowerUpPurchaseEvent(IcPlayer player, float cost, IPowerUpGameObjDef item)
 {
 }
Пример #20
0
 public override void VehiclePurchaseEvent(IcPlayer player, float cost, IVehicleGameObjDef item)
 {
 }
Пример #21
0
 public override void ClearWeaponsEvent(IcPlayer player)
 {
 }
Пример #22
0
 public override int PowerUpPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, IPowerUpGameObjDef item)
 {
     return(-1);
 }
Пример #23
0
 public override void ChangeCharacterEvent(IcPlayer player, ISoldierGameObjDef soldier)
 {
 }
Пример #24
0
 public override bool VehicleEntryRequestEvent(IVehicleGameObj vehicle, IcPlayer player, ref int seat)
 {
     return(true);
 }
Пример #25
0
 public override void PokeEvent(IcPlayer player, IPhysicalGameObj obj)
 {
 }
Пример #26
0
 public override void VehicleExitEvent(IVehicleGameObj vehicle, IcPlayer player, int seat)
 {
 }
Пример #27
0
 public override int CharacterPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, ISoldierGameObjDef item)
 {
     return(-1);
 }
Пример #28
0
 public override bool PowerUpGrantRequestEvent(IcPlayer player, IPowerUpGameObjDef powerUp, IPowerUpGameObj powerUpObj)
 {
     return(true);
 }
Пример #29
0
 public override void TeamChangeEvent(IcPlayer player)
 {
 }
Пример #30
0
 public override int CustomPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, uint id)
 {
     return(-1);
 }