示例#1
0
        void RewardPlayer(BasePlayer player, double amount, double multiplier = 1, string reason = null, bool isWelcomeReward = false)
        {
            if (amount > 0)
            {
                amount = amount * multiplier;

                if (options.UseEconomicsPlugin)
                {
                    Economics?.Call("Deposit", player.UserIDString, amount);
                }
                if (options.UseServerRewardsPlugin)
                {
                    ServerRewards?.Call("AddPoints", player.userID, (int)amount);
                }
                if (!isWelcomeReward)
                {
                    SendChatMessage(player, reason == null ? Lang("ActivityReward", player.UserIDString, amount) : Lang("KillReward", player.UserIDString, amount, reason), Lang("Prefix"));
                    LogToFile(Name, $"[{DateTime.Now}] " + player.displayName + " got " + amount + " for " + (reason == null ? "activity" : "killing " + reason), this);
                    if (options.PrintToConsole)
                    {
                        Puts(player.displayName + " got " + amount + " for " + (reason == null ? "activity" : "killing " + reason));
                    }
                }
                else
                {
                    SendChatMessage(player, Lang("WelcomeReward", player.UserIDString, amount), Lang("Prefix"));
                    LogToFile(Name, $"[{DateTime.Now}] " + player.displayName + " got " + amount + " as a welcome reward", this);
                    if (options.PrintToConsole)
                    {
                        Puts(player.displayName + " got " + amount + " as a welcome reward");
                    }
                }
            }
        }
        /// <summary>
        /// Withdraws the specified player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="vehicleSettings">The vehicle settings.</param>
        /// <returns></returns>
        private bool Withdraw(BasePlayer player, VehicleSettings vehicleSettings)
        {
            bool result = false;
            var  item   = ItemManager.FindItemDefinition(_itemsNeededToBuyVehicles);

            if (Economics != null && _useEconomics)
            {
                result = Economics.Call <bool>("Withdraw", player.userID, Convert.ToDouble(vehicleSettings.price));
            }
            else if (ServerRewards != null && _useServerRewards)
            {
                result = ServerRewards.Call <bool>("TakePoints", player.userID, Convert.ToDouble(vehicleSettings.price));
            }
            else if (item != null && player.inventory.GetAmount(item.itemid) >= vehicleSettings.price)
            {
                player.inventory.Take(null, item.itemid, vehicleSettings.price);
                result = true;
            }

            if (result)
            {
                SendReply(player, string.Format(Msg("vehiclePurchased", player.UserIDString), vehicleSettings.name));
                return(true);
            }
            else
            {
                SendReply(player, Msg("noMoney", player.UserIDString));
                return(false);
            }
        }
示例#3
0
 private void TryGiveRP(IPlayer player, int amount)
 {
     if (ServerRewards.Call <bool>("AddPoints", player.Id, amount))
     {
         data.Players.Add(player.Id);
     }
 }
        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (!useBarrels || info?.Initiator == null)
            {
                return;
            }

            if (!entity.ShortPrefabName.StartsWith("loot-barrel") && !entity.ShortPrefabName.StartsWith("loot_barrel") && entity.ShortPrefabName != "oil_barrel")
            {
                return;
            }

            BasePlayer player = info.InitiatorPlayer;

            if (player == null || !player.IsValid())
            {
                return;
            }

            string userPermission = GetPermissionName(player);

            if (userPermission == null)
            {
                return;
            }

            // Checking for number of barrels hit
            if (!playerInfo.ContainsKey(player.UserIDString))
            {
                playerInfo.Add(player.UserIDString, 0);
            }

            if (playerInfo[player.UserIDString] == givePointsEvery - 1)
            {
                // Section that gives the player their money
                if (useEconomy && Economics)
                {
                    Economics.Call("Deposit", player.userID, Convert.ToDouble(permissionList[userPermission]));
                    if (sendNotificationMessage)
                    {
                        player.ChatMessage(string.Format(Msg("Economy Notice (Barrel)", player.UserIDString), permissionList[userPermission]));
                    }
                }
                if (useServerRewards && ServerRewards)
                {
                    ServerRewards.Call("AddPoints", player.userID, Convert.ToInt32(permissionList[userPermission]));
                    if (sendNotificationMessage)
                    {
                        player.ChatMessage(string.Format(Msg("RP Notice (Barrel)", player.UserIDString), permissionList[userPermission]));
                    }
                }
                playerInfo[player.UserIDString] = 0;
            }
            else
            {
                playerInfo[player.UserIDString]++;
            }
        }
示例#5
0
        void RewardForPlayerKill(BasePlayer player, BasePlayer victim, double multiplier = 1)
        {
            if (rewardrates.human > 0)
            {
                bool success  = true;
                bool isFriend = false;
                if (IsFriendsLoaded)
                {
                    isFriend = (bool)Friends?.CallHook("HasFriend", player.userID, victim.userID);
                }
                if (!isFriend && IsClansLoaded)
                {
                    string pclan = (string)Clans?.CallHook("GetClanOf", player); string vclan = (string)Clans?.CallHook("GetClanOf", victim);
                    if (pclan == vclan)
                    {
                        isFriend = true;
                    }
                }
                if (!isFriend)
                {
                    var reward = rewardrates.human * multiplier;

                    if (IsEconomicsLoaded) //Eco
                    {
                        if (options.Economincs_TakeMoneyFromVictim)
                        {
                            if (!(bool)Economics?.Call("Transfer", victim.UserIDString, player.UserIDString, rewardrates.human * multiplier))
                            {
                                SendChatMessage(player, Lang("VictimNoMoney", player.UserIDString, victim.displayName), Lang("Prefix"));
                                success = false;
                            }
                        }
                        else
                        {
                            Economics?.Call("Deposit", player.UserIDString, reward);
                        }
                    }
                    if (IsServerRewardsLoaded) //ServerRewards
                    {
                        if (options.ServerRewards_TakeMoneyFromVictim)
                        {
                            ServerRewards?.Call("TakePoints", new object [] { victim.userID, rewardrates.human * multiplier });
                        }
                        ServerRewards?.Call("AddPoints", player.userID, (int)(reward));
                        success = true;
                    }
                    if (success) //Send message if transaction was successful
                    {
                        SendChatMessage(player, Lang("KillReward", player.UserIDString, rewardrates.human * multiplier, victim.displayName), Lang("Prefix"));
                        LogToFile(Name, $"[{DateTime.Now}] " + player.displayName + " got " + rewardrates.human * multiplier + " for killing " + victim.displayName, this);
                        if (options.PrintToConsole)
                        {
                            Puts(player.displayName + " got " + reward + " for killing " + victim.displayName);
                        }
                    }
                }
            }
        }
        private int GetServerRewards(ulong userId)
        {
            object checkedPoints = ServerRewards?.Call <int>("CheckPoints", userId);

            if (checkedPoints is int)
            {
                return((int)checkedPoints);
            }

            return(0);
        }
示例#7
0
        // Check balance on multiple plugins and optionally withdraw money from the player
        private bool CheckEconomy(BasePlayer player, double bypass, bool withdraw = false, bool deposit = false)
        {
            double balance    = 0;
            bool   foundmoney = false;

            // Check Economics first.  If not in use or balance low, check ServerRewards below
            if (useEconomics && Economics)
            {
                balance = (double)Economics?.CallHook("Balance", player.UserIDString);
                if (balance >= bypass)
                {
                    foundmoney = true;
                    if (withdraw == true)
                    {
                        var w = (bool)Economics?.CallHook("Withdraw", player.userID, bypass);
                        return(w);
                    }
                    else if (deposit == true)
                    {
                        var w = (bool)Economics?.CallHook("Deposit", player.userID, bypass);
                    }
                }
            }

            // No money via Economics, or plugin not in use.  Try ServerRewards.
            if (useServerRewards && ServerRewards)
            {
                object bal = ServerRewards?.Call("CheckPoints", player.userID);
                balance = Convert.ToDouble(bal);
                if (balance >= bypass && foundmoney == false)
                {
                    foundmoney = true;
                    if (withdraw == true)
                    {
                        var w = (bool)ServerRewards?.Call("TakePoints", player.userID, (int)bypass);
                        return(w);
                    }
                    else if (deposit == true)
                    {
                        var w = (bool)ServerRewards?.Call("AddPoints", player.userID, (int)bypass);
                    }
                }
            }

            // Just checking balance without withdrawal - did we find anything?
            return(foundmoney);
        }
        private void GiveCredit(BasePlayer player, string type, float amount, string gathered)
        {
            if (amount > 0)
            {
                if (config.Settings.UseEconomics && Economics)
                {
                    Economics.Call("Deposit", player.UserIDString, (double)amount);
                }
                if (config.Settings.UseServerRewards && ServerRewards)
                {
                    ServerRewards.Call("AddPoints", new object[] { player.userID, (int)amount });
                }
                if (type == "gather" && config.Settings.ShowMessagesOnGather)
                {
                    PrintToChat(player, config.Settings.PluginPrefix + " " + string.Format(Lang("ReceivedForGather", player), amount, gathered.ToLower()));
                }
                else if (type == "kill" && config.Settings.ShowMessagesOnKill)
                {
                    PrintToChat(player, config.Settings.PluginPrefix + " " + string.Format(Lang("ReceivedForKill", player), amount, gathered.ToLower()));
                }
            }
            else
            {
                amountstring = amount.ToString().Replace("-", "");
                amount       = float.Parse(amountstring);

                if (config.Settings.UseEconomics && Economics)
                {
                    Economics.Call("Withdraw", player.UserIDString, (double)amount);
                }
                if (config.Settings.UseServerRewards && ServerRewards)
                {
                    ServerRewards.Call("TakePoints", new object[] { player.userID, (int)amount });
                }

                if (type == "gather" && config.Settings.ShowMessagesOnGather)
                {
                    PrintToChat(player, config.Settings.PluginPrefix + " " + string.Format(Lang("LostForGather", player), amount, gathered.ToLower()));
                }
                else if (type == "kill" && config.Settings.ShowMessagesOnKill)
                {
                    PrintToChat(player, config.Settings.PluginPrefix + " " + string.Format(Lang("LostForKill", player), amount, gathered.ToLower()));
                }
            }
        }
示例#9
0
        void AddPoints(IPlayer player, int amount)
        {
            object multiplier = GetRewardMultiplier(player);

            if (multiplier == null)
            {
                multiplier = 1f;
            }
            amount = Convert.ToInt32(Math.Floor(amount * (float)multiplier));
            if (amount == 0)
            {
                amount = 1;
            }

            string currency = Msg("currencyNameEco", player.Id);

            #if RUST
            if (ServerRewards && configData.RewardSystem.RewardPlugins.Rust.ServerRewards)
            {
                ServerRewards?.Call("AddPoints", ulong.Parse(player.Id), amount);
                currency = Msg("currencyNameRP", player.Id);
            }

            if (Economics && configData.RewardSystem.RewardPlugins.Rust.Economics)
            {
                Economics?.Call("Deposit", player.Id, (double)amount);
            }
            #endif

            #if HURTWORLD
            if (Economy && configData.RewardSystem.RewardPlugins.Hurtworld.Economy)
            {
                Economy?.Call("AddMoney", player.Object as PlayerSession, (double)amount);
            }
            #endif
            if (UEconomics && configData.RewardSystem.RewardPlugins.Universal.UEconomics)
            {
                UEconomics?.Call("Deposit", player.Id, amount);
            }

            if (configData.RewardSystem.SendDepositMessage)
            {
                player.Reply(string.Format(Msg("depositMsg", player.Id), amount, currency));
            }
        }
示例#10
0
        private bool CanBuyStrike(BasePlayer player, StrikeType type)
        {
            Dictionary <string, int> costToBuy = type == StrikeType.Strike ? configData.Buy.StrikeCost : configData.Buy.SquadCost;

            foreach (var item in costToBuy)
            {
                if (item.Key == "RP")
                {
                    if (ServerRewards)
                    {
                        if ((int)ServerRewards.Call("CheckPoints", player.userID) < item.Value)
                        {
                            SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, item.Key));
                            Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
                            return(false);
                        }
                    }
                }
                if (item.Key == "Economics")
                {
                    if (Economics)
                    {
                        if ((double)Economics.Call("GetPlayerMoney", player.userID) < item.Value)
                        {
                            SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, item.Key));
                            Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
                            return(false);
                        }
                    }
                }
                if (shortnameToId.ContainsKey(item.Key))
                {
                    if (player.inventory.GetAmount(shortnameToId[item.Key]) < item.Value)
                    {
                        SendReply(player, string.Format(msg("buyItem", player.UserIDString), item.Value, shortnameToDn[item.Key]));
                        Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.denied.prefab", player.transform.position);
                        return(false);
                    }
                }
            }
            Effect.server.Run("assets/prefabs/locks/keypad/effects/lock.code.updated.prefab", player.transform.position);
            return(true);
        }
示例#11
0
        public bool TakeMoney(BasePlayer player, double amount)
        {
            if (useEconomics)
            {
                if (Economics == null)
                {
                    Send(player, GetMessage("NoEconomics")); return(false);
                }

                bool canBuy = (bool)Economics.CallHook("Withdraw", player.userID, amount);

                if (canBuy)
                {
                    return(true);
                }
                else
                {
                    Send(player, GetMessage("NoMoney"));
                    return(false);
                }
            }
            else if (useServerRewards)
            {
                if (Economics == null)
                {
                    Send(player, GetMessage("NoServerRewards")); return(false);
                }

                bool canBuy = (bool)ServerRewards?.Call("TakePoints", player.userID, Convert.ToInt32(amount));

                if (canBuy)
                {
                    return(true);
                }
                else
                {
                    Send(player, GetMessage("NoMoney"));
                    return(false);
                }
            }

            return(false);
        }
        private void OnLootEntity(BasePlayer player, BaseEntity entity)
        {
            if (!useCrates)
            {
                return;
            }

            if (!entity.ShortPrefabName.Contains("crate_") && entity.ShortPrefabName != "heli_crate")
            {
                return;
            }

            if (crateCache.Contains(entity.net.ID))
            {
                return;
            }

            crateCache.Add(entity.net.ID);
            string userPermission = GetPermissionName(player);

            if (userPermission == null)
            {
                return;
            }

            if (useEconomy && Economics)
            {
                Economics.Call("Deposit", player.userID, Convert.ToDouble(permissionList[userPermission]));
                if (sendNotificationMessage)
                {
                    player.ChatMessage(string.Format(Msg("Economy Notice (Crate)", player.UserIDString), permissionList[userPermission]));
                }
            }
            if (useServerRewards)
            {
                ServerRewards.Call("AddPoints", player.userID, Convert.ToInt32(permissionList[userPermission]));
                if (sendNotificationMessage)
                {
                    player.ChatMessage(string.Format(Msg("RP Notice (Crate)", player.UserIDString), permissionList[userPermission]));
                }
            }
        }
示例#13
0
        private void StealPoints(BasePlayer victim, BasePlayer attacker)
        {
            var chance = random.NextDouble() * (config.MaxChancePoints / 100f);

            // ServerRewards plugin support - http://oxidemod.org/plugins/serverrewards.1751/
            if (ServerRewards != null)
            {
                var balance = ServerRewards.Call("CheckPoints", victim.userID) ?? 0;
                var points  = Math.Floor((int)balance * chance);

                if (points > 0)
                {
                    ServerRewards.Call("TakePoints", victim.userID, points);
                    ServerRewards.Call("AddPoints", attacker.userID, points);
                    Player.Reply(attacker, Lang("StolePoints", attacker.UserIDString, points, victim.displayName));
                }
                else
                {
                    Player.Reply(attacker, Lang("StoleNothing", attacker.UserIDString, victim.displayName));
                }
            }
        }
示例#14
0
        private void GivePlayerRewards(BasePlayer player, RewardInfo rewardInfo)
        {
            if (rewardInfo.econAmount > 0 && Economics)
            {
                Economics?.Call("Deposit", player.UserIDString, (double)rewardInfo.econAmount);
            }

            if (rewardInfo.rpAmount > 0 && ServerRewards)
            {
                ServerRewards?.Call("AddPoints", player.userID, rewardInfo.rpAmount);
            }

            if (rewardInfo.rewardItems.Count > 0)
            {
                foreach (RewardInfo.ItemData itemData in rewardInfo.rewardItems)
                {
                    Item item = CreateItem(itemData);
                    player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
                }
            }

            SendReply(player, msg("reward_claimed", player.userID));
        }
示例#15
0
        private void BuyStrike(BasePlayer player, StrikeType type)
        {
            Dictionary <string, int> costToBuy = type == StrikeType.Strike ? configData.Buy.StrikeCost : configData.Buy.SquadCost;

            foreach (var item in costToBuy)
            {
                if (item.Key == "RP")
                {
                    if (ServerRewards)
                    {
                        ServerRewards.Call("TakePoints", player.userID, item.Value);
                    }
                }
                if (item.Key == "Economics")
                {
                    if (Economics)
                    {
                        Economics.Call("Withdraw", player.userID, (double)item.Value);
                    }
                }
                if (shortnameToId.ContainsKey(item.Key))
                {
                    player.inventory.Take(null, shortnameToId[item.Key], item.Value);
                }
            }
            if (type == StrikeType.Strike)
            {
                CallStrike(player.transform.position);
                SendReply(player, string.Format(msg("strikeConfirmed", player.UserIDString), player.transform.position));
            }
            else
            {
                CallSquad(player.transform.position);
                SendReply(player, string.Format(msg("squadConfirmed", player.UserIDString), player.transform.position));
            }
        }
        private object OnItemAction(Item item, string action)
        {
            if (action != "crush")
            {
                return(null);
            }
            if (item.info.shortname != "skull.human")
            {
                return(null);
            }
            string skullName = null;

            if (item.name != null)
            {
                skullName = item.name.Substring(10, item.name.Length - 11);
            }
            if (string.IsNullOrEmpty(skullName))
            {
                return(DecideReturn(item));
            }

            BasePlayer ownerPlayer = item.GetOwnerPlayer();

            if (ownerPlayer == null)
            {
                if (nullCrusherMessage)
                {
                    rust.BroadcastChat(null, string.Format(msg("Null Crusher"), skullName));
                }
                return(DecideReturn(item));
            }
            if (ownerPlayer.displayName == skullName)
            {
                if (ownCrusherMessage)
                {
                    rust.BroadcastChat(null, string.Format(msg("Crushed own skull"), ownerPlayer.displayName));
                }
                return(DecideReturn(item));
            }

            BasePlayer skullOwner = BasePlayer.Find(skullName);

            if (skullOwner)
            {
                if (friendsSupport || clansSupport || teamsSupport)
                {
                    if (IsTeamed(ownerPlayer, skullOwner))
                    {
                        return(DecideReturn(item));
                    }
                }
            }

            if (!cacheDic.ContainsKey(ownerPlayer.UserIDString))
            {
                cacheDic.Add(ownerPlayer.UserIDString, 0);
            }
            cacheDic[ownerPlayer.UserIDString]++;
            if (useEconomy)
            {
                if (Economics)
                {
                    if (sendNotificaitionMessage)
                    {
                        ownerPlayer.ChatMessage(string.Format(msg("Economy Notice", ownerPlayer.UserIDString), moneyPerSkullCrush));
                    }
                    Economics.CallHook("Deposit", ownerPlayer.userID, moneyPerSkullCrush);
                }
            }
            if (useServerRewards)
            {
                if (ServerRewards)
                {
                    if (sendNotificaitionMessage)
                    {
                        ownerPlayer.ChatMessage(string.Format(msg("ServerRewards Notice", ownerPlayer.UserIDString), RPPerSkullCrush));
                    }
                    ServerRewards.Call("AddPoints", ownerPlayer.userID, RPPerSkullCrush);
                }
            }
            if (normalCrusherMessage)
            {
                rust.BroadcastChat(null, string.Format(msg("Default Crush Message"), skullName, ownerPlayer.displayName));
            }
            return(DecideReturn(item));
        }
示例#17
0
        private object OnPlayerDeath(BasePlayer player, HitInfo hitInfo)
        {
            if (player == null || player.IsNpc)
            {
                return(null);
            }
            if (permission.UserHasPermission(player.UserIDString, PERMISSION_BLOCKED))
            {
                return(null);
            }

            bool preventDeath = false;
            int  costOfLife   = int.MaxValue;

            if (config.UseRaidableBases)
            {
                if (RaidableBases != null && RaidableBases.IsLoaded)
                {
                    if (RaidableBases.Call <bool>("EventTerritory", player.transform.position))
                    {
                        return(null);
                    }
                }
            }
            if (data.activatedIDs.Contains(player.UserIDString))
            {
                config.perms.ForEach(p =>
                {
                    if (permission.UserHasPermission(player.UserIDString, p.Permission))
                    {
                        preventDeath = true;
                        if (p.Cost < costOfLife)
                        {
                            costOfLife = p.Cost;
                        }
                    }
                });
                if (!preventDeath)
                {
                    return(null);               //Player does not have permission so exit
                }
                if (config.UseServerRewards)
                {
                    if (ServerRewards == null || !ServerRewards.IsLoaded)
                    {//Server Rewards enabled but not present. Log error and return
                        Message("ServerRewardsNull", player.IPlayer);
                        Logger("ServerRewardsNull");
                        return(null);
                    }
                    if (costOfLife > 0)
                    {//object object CheckPoints(ulong ID) // Returns int, or null if no data is saved
                        var rp = ServerRewards.Call("CheckPoints", player.userID);
                        if ((rp is int?(int)rp : 0) >= costOfLife)
                        {
                            ServerRewards.Call("TakePoints", player.UserIDString, costOfLife);
                        }
                        else
                        {
                            Message("CantAfford", player.IPlayer);
                            Logger("DiedCouldntAfford", player.IPlayer);
                            return(null); //Player can't afford so exit
                        }
                    }
                    Message("SavedYourLifeCost", player.IPlayer, costOfLife);
                    Logger("SavedLife", player.IPlayer, costOfLife);
                }
                else //Not using ServerRewards
                {
                    Message("SavedYourLife", player.IPlayer);
                    Logger("ServerRewardsInactiveSavedLife", player.IPlayer);
                }
                player.health = 100f;
                if (player.IsWounded())
                {
                    player.StopWounded();
                }
                return(true);
            }
            Logger("DiedNotActive", player.IPlayer);
            return(null); //Life Support not activated for this player so exit
        }
示例#18
0
        private void cmdBounty(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, "bounty.use"))
            {
                SendReply(player, msg("no_permission", player.userID));
                return;
            }

            if (args.Length == 0)
            {
                SendReply(player, string.Format(msg("title", player.userID), Title, Version));
                if (configData.Rewards.AllowItems)
                {
                    SendReply(player, msg("help1", player.userID));
                }
                if (configData.Rewards.AllowServerRewards && ServerRewards)
                {
                    SendReply(player, msg("help2", player.userID));
                }
                if (configData.Rewards.AllowEconomics && Economics)
                {
                    SendReply(player, msg("help3", player.userID));
                }
                SendReply(player, msg("help4", player.userID));
                SendReply(player, msg("help5", player.userID));
                SendReply(player, msg("help6", player.userID));
                SendReply(player, msg("help7", player.userID));
                SendReply(player, msg("help8", player.userID));

                if (player.IsAdmin || permission.UserHasPermission(player.UserIDString, "bounty.admin"))
                {
                    SendReply(player, msg("help9", player.userID));
                }

                return;
            }

            switch (args[0].ToLower())
            {
            case "add":
            {
                if (args.Length < 3)
                {
                    SendReply(player, msg("invalid_syntax", player.userID));
                    return;
                }

                List <BasePlayer> players = FindPlayer(args[2]);
                if (players.Count == 0)
                {
                    SendReply(player, msg("no_player_found", player.userID));
                    return;
                }
                if (players.Count > 1)
                {
                    SendReply(player, msg("multiple_players_found", player.userID));
                    return;
                }

                BasePlayer targetPlayer = players[0];
                if (targetPlayer == null)
                {
                    SendReply(player, msg("no_player_found", player.userID));
                    return;
                }

                if (targetPlayer == player)
                {
                    SendReply(player, msg("cant_bounty_self", player.userID));
                    return;
                }

                PlayerData playerData;
                if (!storedData.players.TryGetValue(targetPlayer.userID, out playerData))
                {
                    playerData = new PlayerData(targetPlayer.displayName);

                    storedData.players.Add(targetPlayer.userID, playerData);
                }

                if (playerData.activeBounties.Find(x => x.initiatorId == player.userID) != null)
                {
                    SendReply(player, msg("has_active_bounty", player.userID));
                    return;
                }

                switch (args[1].ToLower())
                {
                case "items":
                    SpawnItemContainer(player);

                    if (bountyCreator.ContainsKey(player.userID))
                    {
                        bountyCreator[player.userID] = targetPlayer.userID;
                    }
                    else
                    {
                        bountyCreator.Add(player.userID, targetPlayer.userID);
                    }
                    return;

                case "rp":
                    if (!configData.Rewards.AllowServerRewards || !ServerRewards || args.Length != 4)
                    {
                        SendReply(player, msg("invalid_syntax", player.userID));
                        return;
                    }

                    int rpAmount;
                    if (!int.TryParse(args[3], out rpAmount))
                    {
                        SendReply(player, msg("no_value_entered", player.userID));
                        return;
                    }

                    int availableRp = (int)ServerRewards?.Call("CheckPoints", player.userID);

                    if (availableRp < rpAmount || !(bool)ServerRewards?.Call("TakePoints", player.userID, rpAmount))
                    {
                        SendReply(player, msg("not_enough_rp", player.userID));
                        return;
                    }

                    CreateNewBounty(player, targetPlayer.userID, rpAmount, 0, null);
                    return;

                case "eco":
                    if (!configData.Rewards.AllowEconomics || !Economics || args.Length != 4)
                    {
                        SendReply(player, msg("invalid_syntax", player.userID));
                        return;
                    }

                    int ecoAmount;
                    if (!int.TryParse(args[3], out ecoAmount))
                    {
                        SendReply(player, msg("no_value_entered", player.userID));
                        return;
                    }

                    double availableEco = (double)Economics?.Call("Balance", player.UserIDString);

                    if (availableEco < ecoAmount || !(bool)Economics?.Call("Withdraw", player.UserIDString, (double)ecoAmount))
                    {
                        SendReply(player, msg("not_enough_eco", player.userID));
                        return;
                    }

                    CreateNewBounty(player, targetPlayer.userID, 0, ecoAmount, null);
                    return;

                default:
                    SendReply(player, msg("invalid_syntax", player.userID));
                    return;
                }
            }

            case "cancel":
            {
                if (args.Length < 2)
                {
                    SendReply(player, msg("invalid_syntax", player.userID));
                    return;
                }

                IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]);
                if (targetPlayer == null)
                {
                    SendReply(player, msg("no_player_found", player.userID));
                    return;
                }

                CancelBounty(player, targetPlayer);
            }
                return;

            case "claim":
            {
                PlayerData playerData;
                if (!storedData.players.TryGetValue(player.userID, out playerData) || playerData.unclaimedRewards.Count == 0)
                {
                    SendReply(player, msg("no_rewards_pending", player.userID));
                    return;
                }

                if (args.Length < 2)
                {
                    SendReply(player, msg("help10", player.userID));
                    foreach (int rewardId in playerData.unclaimedRewards)
                    {
                        RewardInfo rewardInfo = storedData.rewards[rewardId];
                        string     reward     = string.Empty;
                        if (rewardInfo.rewardItems.Count > 1)
                        {
                            for (int i = 0; i < rewardInfo.rewardItems.Count; i++)
                            {
                                RewardInfo.ItemData itemData = rewardInfo.rewardItems.ElementAt(i);
                                reward += (string.Format(msg("reward_item", player.userID), itemData.amount, idToDisplayName[itemData.itemid]) + (i < rewardInfo.rewardItems.Count - 1 ? ", " : ""));
                            }
                        }
                        else
                        {
                            reward = rewardInfo.econAmount > 0 ? string.Format(msg("reward_econ", player.userID), rewardInfo.econAmount) : string.Format(msg("reward_rp", player.userID), rewardInfo.rpAmount);
                        }

                        SendReply(player, string.Format(msg("reward_info", player.userID), rewardId, reward));
                    }
                }
                else
                {
                    int rewardId;
                    if (!int.TryParse(args[1], out rewardId) || !playerData.unclaimedRewards.Contains(rewardId))
                    {
                        SendReply(player, msg("invalid_reward_id", player.userID));
                        return;
                    }

                    RewardInfo rewardInfo = storedData.rewards[rewardId];
                    GivePlayerRewards(player, rewardInfo);
                    storedData.rewards.Remove(rewardId);
                    playerData.unclaimedRewards.Remove(rewardId);
                }
            }
                return;

            case "view":
            {
                if (args.Length < 2)
                {
                    SendReply(player, msg("invalid_syntax", player.userID));
                    return;
                }

                IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]);
                if (targetPlayer == null)
                {
                    SendReply(player, msg("no_player_found", player.userID));
                    return;
                }

                PlayerData playerData;
                if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0)
                {
                    SendReply(player, msg("no_active_bounties", player.userID));
                    return;
                }

                SendReply(player, string.Format(msg("player_has_bounties", player.userID), targetPlayer.Name, playerData.activeBounties.Count));
                foreach (var bounty in playerData.activeBounties)
                {
                    RewardInfo rewardInfo = storedData.rewards[bounty.rewardId];
                    string     reward     = string.Empty;
                    if (rewardInfo.rewardItems.Count > 1)
                    {
                        for (int i = 0; i < rewardInfo.rewardItems.Count; i++)
                        {
                            RewardInfo.ItemData itemData = rewardInfo.rewardItems.ElementAt(i);
                            reward += (string.Format(msg("reward_item", player.userID), itemData.amount, idToDisplayName[itemData.itemid]) + (i < rewardInfo.rewardItems.Count - 1 ? ", " : ""));
                        }
                    }
                    else
                    {
                        reward = rewardInfo.econAmount > 0 ? string.Format(msg("reward_econ", player.userID), rewardInfo.econAmount) : string.Format(msg("reward_rp", player.userID), rewardInfo.rpAmount);
                    }

                    SendReply(player, string.Format(msg("bounty_info", player.userID), bounty.initiatorName, FormatTime(CurrentTime() - bounty.initiatedTime), reward));
                }
            }
                return;

            case "top":
                IEnumerable <PlayerData> top10Hunters = storedData.players.Values.OrderByDescending(x => x.bountiesClaimed).Take(10);
                string hunterMessage = msg("top_hunters", player.userID);

                foreach (PlayerData playerData in top10Hunters)
                {
                    hunterMessage += string.Format(msg("top_hunter_entry", player.userID), playerData.displayName, playerData.bountiesClaimed);
                }

                SendReply(player, hunterMessage);
                return;

            case "wanted":
                IEnumerable <PlayerData> top10Hunted = storedData.players.Values.OrderByDescending(x => x.totalWantedTime + x.GetCurrentWantedTime()).Take(10);
                string wantedMessage = msg("top_wanted", player.userID);

                foreach (PlayerData playerData in top10Hunted)
                {
                    wantedMessage += string.Format(msg("top_wanted_entry", player.userID), playerData.displayName, FormatTime(playerData.totalWantedTime + playerData.GetCurrentWantedTime()), playerData.totalBounties);
                }

                SendReply(player, wantedMessage);
                return;

            case "clear":
            {
                if (args.Length < 2)
                {
                    SendReply(player, msg("invalid_syntax", player.userID));
                    return;
                }

                IPlayer targetPlayer = covalence.Players.FindPlayer(args[1]);
                if (targetPlayer == null)
                {
                    SendReply(player, msg("no_player_found", player.userID));
                    return;
                }

                PlayerData playerData;
                if (!storedData.players.TryGetValue(ulong.Parse(targetPlayer.Id), out playerData) || playerData.activeBounties.Count == 0)
                {
                    SendReply(player, msg("no_active_bounties", player.userID));
                    return;
                }

                foreach (var bounty in playerData.activeBounties)
                {
                    storedData.rewards.Remove(bounty.rewardId);
                }
                playerData.activeBounties.Clear();

                SendReply(player, string.Format(msg("bounties_cleared", player.userID), targetPlayer.Name));
            }
                return;

            default:
                SendReply(player, msg("invalid_syntax", player.userID));
                break;
            }
        }
示例#19
0
        void GetReward(BasePlayer player, string s)
        {
            MessageChat(player, "Thanks", s);

            var userData = GetPlayerData(player.userID, SteamName(player));

            userData.Sites[s].Votes++;
            if (userData.Sites[s].KitsNotClaimed.Count > 0)
            {
                userData.Sites[s].KitsNotClaimed.Clear();
            }

            var getdefault = true;

            foreach (var key in Rewards.Groups.Keys)
            {
                var g = key.Split('.')[0];
                if (g == "default")
                {
                    continue;
                }
                if (permission.UserHasGroup(player.UserIDString, g))
                {
                    getdefault = false;
                    break;
                }
            }

            var           totmoney = 0;
            var           totrp    = 0;
            var           kit      = false;
            var           kiterror = false;
            List <string> commands = new List <string>();

            foreach (var g in Rewards.Groups)
            {
                if (g.Value.Count == 0)
                {
                    continue;
                }
                var args = g.Key.Split('.');
                if ((args[0] == "default" && !getdefault && !_config.AllGroupsGetDefault) ||
                    !permission.UserHasGroup(player.UserIDString, args[0]))
                {
                    continue;
                }
                if (!permission.GroupExists(args[0]))
                {
                    PrintWarning(Lang("NoGroup", null, args[0]));
                    continue;
                }
                var m = 0;
                if (args.Length <= 1 || !int.TryParse(args[1], out m))
                {
                    PrintWarning(Lang("InvalidReward", null, g.Key));
                    continue;
                }
                if (userData.Sites[s].Votes < m || (userData.Sites[s].Votes % m) != 0)
                {
                    continue;
                }

                foreach (var r in g.Value)
                {
                    switch (r.Key)
                    {
                    case "money":
                    {
                        if (!Economics)
                        {
                            break;
                        }
                        var eco = Convert.ToDouble(r.Value);
                        Economics.Call("Deposit", player.userID, eco);
                        totmoney += Convert.ToInt32(r.Value);
                        break;
                    }

                    case "rp":
                    {
                        if (!ServerRewards)
                        {
                            break;
                        }
                        var p = Convert.ToInt32(r.Value);
                        ServerRewards.Call("AddPoints", new object[] { player.userID, p });
                        totrp += Convert.ToInt32(r.Value);
                        break;
                    }

                    case "kit":
                    {
                        if (!Kits || r.Value == "")
                        {
                            break;
                        }
                        var flag = Kits?.Call("CanRedeemKit", player, r.Value, true);
                        if (flag is string || flag == null || kiterror)
                        {
                            if (!kiterror)
                            {
                                kiterror = true;
                            }
                            userData.Sites[s].KitsNotClaimed.Add(r.Value);
                        }
                        else
                        {
                            var success = Kits?.Call("GiveKit", player, r.Value);
                            if (success is string || success == null)
                            {
                                kiterror = true;
                                userData.Sites[s].KitsNotClaimed.Add(r.Value);
                            }
                            else if (!kit)
                            {
                                kit = true;
                            }
                        }
                        break;
                    }

                    default:
                    {
                        rust.RunServerCommand(r.Value.Replace("$player.id", player.UserIDString).Replace("$player.name", player.displayName));
                        if (!commands.Contains(r.Key))
                        {
                            commands.Add(r.Key);
                        }
                        break;
                    }
                    }
                }
            }

            if (totmoney > 0)
            {
                MessageChat(player, "RewardCoins", totmoney);
            }
            if (totrp > 0)
            {
                MessageChat(player, "RewardRP", totrp);
            }
            if (kiterror)
            {
                MessageChat(player, "ErrorKits");
            }
            else if (kit)
            {
                MessageChat(player, "RewardKit");
            }
            foreach (var c in commands)
            {
                MessageChat(player, "RewardCommand", c);
            }

            try
            {
                var i       = Settings[s].Interval.Split('.').Select(n => Convert.ToInt32(n)).ToArray();
                var newdate = DateTime.Now + new TimeSpan(i[0], i[1], 0, 0);
                userData.Sites[s].ExpDate = newdate.ToString();
                SaveData(Users, "VoteData");
            }
            catch
            {
                MessageChat(player, "InvalidInterval");
                var newdate = DateTime.Now + new TimeSpan(1, 0, 0, 0);
                userData.Sites[s].ExpDate = newdate.ToString();
                SaveData(Users, "VoteData");
            }
        }
示例#20
0
        void CmdBuyBoat(BasePlayer player, string command, string[] args)
        {
            LisencedPlayer lisencedPlayer;

            if (args.Length == 0)
            {
                SendReply(player, Msg("helpBuyBoat", player.UserIDString));
            }
            if (args.Length >= 1)
            {
                switch (args[0].ToLower())
                {
                case "row":
                    if (!_canBuyRowBoat)
                    {
                        SendReply(player, Msg("rowBoatCannotBeBuyed", player.UserIDString));
                        break;
                    }
                    if (!_lisencedPlayer.TryGetValue(player.userID, out lisencedPlayer))
                    {
                        lisencedPlayer = new LisencedPlayer(player.userID);
                        _lisencedPlayer.Add(player.userID, lisencedPlayer);
                        if (Economics != null && _useEconomics && Economics.Call <bool>("Withdraw", player.userID, _rowBoatCost) ||
                            ServerRewards != null && _useServerRewards && ServerRewards.Call <bool>("TakePoints", player.userID, _rowBoatCost) ||
                            !_useEconomics && !_useServerRewards && Withdraw(player, _rowBoatCost))
                        {
                            lisencedPlayer.rowBoat.Buyed = true;
                            SendReply(player, Msg("boatPurchased", player.UserIDString));
                        }
                        else
                        {
                            SendReply(player, Msg("noMoney", player.UserIDString));
                        }
                    }
                    else if (!lisencedPlayer.rowBoat.Buyed)
                    {
                        if (Economics != null && _useEconomics && Economics.Call <bool>("Withdraw", player.userID, _rowBoatCost) ||
                            ServerRewards != null && _useServerRewards && ServerRewards.Call <bool>("TakePoints", player.userID, _rowBoatCost) ||
                            !_useEconomics && !_useServerRewards && Withdraw(player, _rowBoatCost))
                        {
                            lisencedPlayer.rowBoat.Buyed = true;
                            SendReply(player, Msg("boatPurchased", player.UserIDString));
                        }
                        else
                        {
                            SendReply(player, Msg("noMoney", player.UserIDString));
                        }
                    }
                    else
                    {
                        SendReply(player, Msg("boatAlreadyPurchased", player.UserIDString));
                    }
                    break;

                case "rhib":
                    if (!_canBuyRhibBoat)
                    {
                        SendReply(player, Msg("rhibCannotBeBuyed", player.UserIDString));
                        break;
                    }
                    if (!_lisencedPlayer.TryGetValue(player.userID, out lisencedPlayer))
                    {
                        lisencedPlayer = new LisencedPlayer(player.userID);
                        _lisencedPlayer.Add(player.userID, lisencedPlayer);
                        if (Economics != null && _useEconomics && Economics.Call <bool>("Withdraw", player.userID, _rhibBoatCost) ||
                            ServerRewards != null && _useServerRewards && ServerRewards.Call <bool>("TakePoints", player.userID, _rhibBoatCost) ||
                            !_useEconomics && !_useServerRewards && Withdraw(player, _rhibBoatCost))
                        {
                            lisencedPlayer.rhibBoat.Buyed = true;
                            SendReply(player, Msg("boatPurchased", player.UserIDString));
                        }
                        else
                        {
                            SendReply(player, Msg("noMoney", player.UserIDString));
                        }
                    }
                    else if (!lisencedPlayer.rhibBoat.Buyed)
                    {
                        if (Economics != null && _useEconomics && Economics.Call <bool>("Withdraw", player.userID, _rhibBoatCost) ||
                            ServerRewards != null && _useServerRewards && ServerRewards.Call <bool>("TakePoints", player.userID, _rhibBoatCost) ||
                            !_useEconomics && !_useServerRewards && Withdraw(player, _rhibBoatCost))
                        {
                            lisencedPlayer.rhibBoat.Buyed = true;
                            SendReply(player, Msg("boatPurchased", player.UserIDString));
                        }
                        else
                        {
                            SendReply(player, Msg("noMoney", player.UserIDString));
                        }
                    }
                    else
                    {
                        SendReply(player, Msg("boatAlreadyPurchased", player.UserIDString));
                    }
                    break;

                default:
                    SendReply(player, Msg("helpOptionNotFound", player.UserIDString));
                    break;
                }
            }
        }