Иконка ресурса

FREE Economics : 0.4.3 0.4.3

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using ConVar;
using Facepunch.Extend;
using Network;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Economics","Baks","0.4.3")]
    public class Economics : RustPlugin
    {
        #region var

        [PluginReference] private Plugin ImageLibrary,RustStore,GameStore,BroadcastSystem;

        private string path = "Economics/";
        string _defaultCurrency;
        

        #endregion

        #region config

        class Money
        {
            [JsonProperty("Название валюты")]
            public string Name;
            [JsonProperty("Виртуальная/физическая(true/false)")]
            public bool Vitrual;
            [JsonProperty("Максимальное кол-во")]
            public float Max;
            [JsonProperty("Может быть отрицательным")]
            public bool Negative;
            [JsonProperty("Картинка")]
            public string Img;
            [JsonProperty("skinId(Если физическая)")]
            public ulong SkinId;
            [JsonProperty("Начальный бонус")]
            public int StartAmount = 1000;
            [JsonProperty("Сбрасывать после вайпа?(true/false)")]
            public bool WipeOnNewSave = false;
        }

        class FarmPoints
        {
            [JsonProperty("Настройка валюты за руду")]
            public OreGather Ore;
            [JsonProperty("Настройки валюты за дерево")]
            public WoodGather Wood;
            [JsonProperty("Настройки валюты за убийство")]
            public KillPoints KP;
            [JsonProperty("Настройки валюты за время")]
            public TimePoints TimePoints;
        }

        class OreGather
        {
            [JsonProperty("Валюта за добычу серы")]
            public double SulfurOreGather;
            [JsonProperty("Валюта за добычу железа")]
            public double MetalOreGather;
            [JsonProperty("Валюта за добычу камня")]
            public double StoneOreGather;
            
            [JsonProperty("Валюта за бонус серы")]
            public double SulfurOreBonus;
            [JsonProperty("Валюта за бонус железа")]
            public double MetalOreBonus;
            [JsonProperty("Валюта за бонус камня")]
            public double StoneOreBonus;
        }

        class WoodGather
        {
            [JsonProperty("Валюта за добычу дерева")]
            public double Gather;
            [JsonProperty("Валюта за бонус дерева")]
            public double Bonus;

        }

        class KillPoints
        {
            [JsonProperty("Валюта за убийство NPC")]
            public double Npc;
            [JsonProperty("Валюта за убийство Животного")]
            public double Animal;
            [JsonProperty("Валюта за убийство Игрока")]
            public double Player;
            [JsonProperty("Валюта за убийство Танка")]
            public double Tank = 5;
            [JsonProperty("Валюта за убийство Вертолета")]
            public double Heli = 5;
            [JsonProperty("Валюта за убийство Чинука")]
            public double Ch47 = 5;
        }

        class TimePoints
        {
            [JsonProperty("Как часто давать валюту за время(секунды)")]
            public short Time = 60;
            [JsonProperty("Количество валюты за время")]
            public double Amount = 1;
        }

        class LootPoints
        {
            [JsonProperty("Валюта за разрушение бочки")]
            public double Barrel = 0;
            [JsonProperty("Валюта за открытие залоченого контейнера")]
            public double LockedContainer = 0;
            [JsonProperty("Валюта за собирательство")]
            public double PickUp = 0;
        }
        
        internal class GameStores
        {
            [JsonProperty("API Магазина(GameStores)")]
            public string GameStoreAPIStore;
            [JsonProperty("ID Магазина(GameStores)")]
            public string GameStoreIDStore;
            [JsonProperty("Сообщение в магазин при выдаче баланса(GameStores)")]
            public string GameStoresMessage;
        }

        class StoreApi
        {
            [JsonProperty("Использовать магазин?(0-отключено/1-MoscowOVH/2-GameStores)")]
            public int UseStore = 0;

            [JsonProperty("Настройка  GameStore(Если вы используете GameStore)")]
            public GameStores GameStore;
        }
        
        static Configuration config = new Configuration();

        class Configuration
        {
            [JsonProperty("Валюты")] 
            public List<Money> Currencies;
            [JsonProperty("Настройка  валют")]
            public Dictionary<string, FarmPoints> Settings;

            [JsonProperty("Использовать GUI(true/false)")]
            public bool UseUI = true;
            
            [JsonProperty("Настройка  MoscowOVH/GameStore")]
            public Dictionary<string, FarmPoints> GameStore;
            


            public static Configuration GetNewConfiguration()
            {
                return new Configuration
                {
                    Currencies = new List<Money>
                    {
                        new Money
                        {
                            Name = "Basic",
                            Negative = false,
                            Max = 10000,
                            StartAmount = 1000,
                            Vitrual = true,
                            Img = "https://i.ibb.co/qJkjy4t/testLogo.png",
                            SkinId = 0,
                            WipeOnNewSave = true
                        },
                        new Money
                        {
                            Name = "Additional",
                            Negative = true,
                            Max = 10000,
                            StartAmount = 1000,
                            Vitrual = true,
                            Img = "https://i.ibb.co/qJkjy4t/testLogo.png",
                            SkinId = 0,
                            WipeOnNewSave = true
                        }
                        
                    },
                    Settings = new Dictionary<string, FarmPoints>
                    {
                        ["Basic"] = new FarmPoints
                        {
                            KP = new KillPoints
                            {
                                Animal = 1,
                                Npc = 2,
                                Player = 3
                            },
                            Ore = new OreGather
                            {
                                MetalOreBonus = 1,
                                StoneOreBonus =  1,
                                SulfurOreBonus = 3,
                                MetalOreGather = 1,
                                StoneOreGather =  1,
                                SulfurOreGather = 3,
                            },
                            Wood = new WoodGather
                            {
                                Bonus = 1,
                                Gather = 2
                            },
                            TimePoints = new TimePoints()
                        },
                        ["Additional"] = new FarmPoints
                        {
                            KP = new KillPoints
                            {
                                Animal = 1,
                                Npc = 2,
                                Player = 3
                            },
                            Ore = new OreGather
                            {
                                MetalOreBonus = 1,
                                StoneOreBonus =  1,
                                SulfurOreBonus = 3,
                                MetalOreGather = 1,
                                StoneOreGather =  1,
                                SulfurOreGather = 3,
                            },
                            Wood = new WoodGather
                            {
                                Bonus = 1,
                                Gather = 2
                            },
                            TimePoints = new TimePoints()
                        }
                    }
                };
            }
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null) PrintWarning("NULL");
                if (config == null) LoadDefaultConfig();
            }
            catch
            {
                PrintError($"Не удалось найти конфигурацию 'oxide/config/{Name}', Создание конфига!!");
                LoadDefaultConfig();
            }

            NextTick(SaveConfig);
        }
        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
        protected override void SaveConfig() => Config.WriteObject(config);

        #endregion

        #region data
        
        Dictionary<string,Dictionary<ulong,double>>_database = new Dictionary<string, Dictionary<ulong, double>>();
        
        List<string>_currencies = new List<string>();

        void GetCurrencies()
        {
            foreach (var var in config.Currencies)
            {
                _currencies.Add(var.Name);
                PrintWarning($"Валюта {var.Name} добавлена в список валют");
            }
        }

        void GetNotExistCurrencies(List<string>currency)
        {
            foreach (var cur in currency)
            {
                if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"Economics/{cur}"))
                {
                    PrintWarning($"Не найдены данные валюты {cur}");
                    CreateCurrencyData(cur);
                }
            }
        }

        void CreateLocalDataBase()
        {
            foreach (var var in config.Currencies)
            {
                _database.Add(var.Name,new Dictionary<ulong, double>());
                _database[var.Name] =
                    Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, double>>($"Economics/{var.Name}");
                PrintWarning($"Данные валюты {var.Name} загружены");
            }
        }

        void CreatePlayerData(BasePlayer player, string currency)
        {
            ulong playerid = player.userID;
            Money cur = GetCurrnecyFromName(currency);
            if (!_database[currency].ContainsKey(playerid))
            {
                _database[currency].Add(playerid,cur.StartAmount);
                PrintWarning($"Добавлен игрок в валюту {currency} со стартовым значением {cur.StartAmount}");
            }
        }

        Money GetCurrnecyFromName(string name)
        {
            Money currency = config.Currencies.Find(p => p.Name == name);
            return currency;
        }

        void CreateCurrencyData(string name)
        {
            Interface.Oxide.DataFileSystem.WriteObject($"Economics/{name}",new Dictionary<ulong,double>());
            PrintWarning($"Создан файл для {name}");
        }

        

        string PathToName(string path)
        {
            string filename = path.Split('\\')[path.Split('\\').Length - 1];
            string[] cur = filename.Split('.');
            return cur[0];
        }

        void SaveDataBase()
        {
            foreach (var database in _database)
            {
                Interface.Oxide.DataFileSystem.WriteObject($"Economics/{database.Key}",database.Value);
                PrintWarning($"Данные {database.Key} сохранены!");
            }
        }
        
        #endregion

        #region hooks

        #region PlayerTime
        
        Dictionary<ulong,int>_playertime = new Dictionary<ulong, int>();

        void CreatePlayerTimeBonus(BasePlayer player)
        {
            if (!_playertime.ContainsKey(player.userID))
            {
                _playertime.Add(player.userID,0);
                
            }
            CheckPlayerTimer(player);
        }

        void CheckPlayerTimer(BasePlayer player)
        {
           
            if (player == null) return;
            
            if (!BasePlayer.activePlayerList.Contains(player)) return;
            if (!_playertime.ContainsKey(player.userID))
            {
                
                return;
            }
            _playertime[player.userID]++;
            
            foreach (var var in config.Settings)
            {
                if (_playertime[player.userID]>= var.Value.TimePoints.Time)
                {
                    
                    Deposit(player.UserIDString, var.Value.TimePoints.Amount);
                    _playertime[player.userID] = 0;
                }
            }

            timer.Once(1f, () => CheckPlayerTimer(player));
        }

        #endregion

        void OnPlayerDisconnected(BasePlayer player, string reason)
        {
            _playertime.Remove(player.userID);
        }

        void NoticePlayer(BasePlayer player,double amount,string currency = null)
        {
            string text;
            string title;
            if (currency == null)
            {
               text = $"Вы получили {amount} {_defaultCurrency}";
               title = _defaultCurrency;
            }
            else
            {
                text = $"Вы получили {amount} {currency}";
                title = currency;
            }

            BroadcastSystem.Call("SendCustonNotification",player,title,text,"assets/prefabs/deployable/vendingmachine/effects/vending-machine-purchase-human.prefab",3f);
            /*player.SendConsoleCommand("gametip.hidegametip");
            player.SendConsoleCommand("gametip.showgametip", text);
            timer.Once(3f, () => player?.SendConsoleCommand("gametip.hidegametip"));*/
        }

        void OnServerInitialized()
        {
            
            GetCurrencies();
            GetNotExistCurrencies(_currencies);
            CreateLocalDataBase();
            
            foreach (var player in BasePlayer.activePlayerList.ToList())
            {
                if (player == null) continue;
                OnPlayerConnected(player);
            }
            _defaultCurrency = config.Currencies.First().Name;
            PrintWarning($"Валюта по умолчанию: {_defaultCurrency}");
            
            timer.Once(1f, InitImages);
            
            timer.Once(120f,() =>MakeBackup());

        }

        void MakeBackup()
        {
            SaveDataBase();
            timer.Once(600f, () =>MakeBackup());
        }

        void OnPlayerConnected(BasePlayer player)
        {
            CreatePlayerTimeBonus(player);
            foreach (var var in config.Currencies)
            {
                CreatePlayerData(player,var.Name);
            }
        }

        void Unload()
        {
            SaveDataBase();
        }

        void InitImages()
        {
            foreach (var currency in config.Currencies)
            {
                ImageLibrary.Call("AddImage", currency.Img, currency.Img);
                PrintWarning($"Image - {currency.Img} loaded");
            }
        }
        
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null || info== null) return;
                if (info.InitiatorPlayer == null || info.InitiatorPlayer.userID == 0) return;
                
            
                BasePlayer player = info.InitiatorPlayer;
            if ( entity is ScientistNPC)
                foreach (var money in config.Currencies)
                {
                    Deposit(player.UserIDString, config.Settings[money.Name].KP.Npc, money.Name);
                    return;
                }
            if ( entity is BaseAnimalNPC)
                foreach (var money in config.Currencies)
                {
                    Deposit(player.UserIDString, config.Settings[money.Name].KP.Animal, money.Name);
                    return;
                }

            if ( entity is BradleyAPC)
                foreach (var money in config.Currencies)
                {
                    Deposit(player.UserIDString, config.Settings[money.Name].KP.Tank, money.Name);
                    return;
                }
            if ( entity is BaseHelicopter)
                foreach (var money in config.Currencies)
                {
                    Deposit(player.UserIDString, config.Settings[money.Name].KP.Tank, money.Name);
                    return;
                }
            if ( entity is BasePlayer)
                foreach (var money in config.Currencies)
                {
                    if (player.UserIDString == (entity as BasePlayer).UserIDString)
                    {
                        return;
                    }
                    Deposit(player.UserIDString, config.Settings[money.Name].KP.Player, money.Name);
                    return;
                }


        }

        #endregion

        #region Point Farm Hooks
        
        /*void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
        {
            if (!(entity is BasePlayer)) return;
            BasePlayer player = entity as BasePlayer;
            switch (item.info.shortname)
            {
                case "stones":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.StoneOreGather);
                    }
                    break;
                case "sulfur.ore":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.SulfurOreGather);
                    }
                    break;
                case "metal.ore":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.MetalOreGather);
                    }
                    break;
                case "wood":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Wood.Gather);
                    }
                    break;
            }
        }*/

        /*void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
        {
            switch (item.info.shortname)
            {
                case "stones":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.StoneOreBonus);
                    }
                    break;
                case "sulfur.ore":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.SulfurOreBonus);
                    }
                    break;
                case "hq.metal.ore":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Ore.MetalOreBonus);
                    }
                    break;
                case "wood":
                    foreach (var var in config.Settings)
                    {
                        Deposit(player.UserIDString, var.Value.Wood.Bonus);
                    }
                    break;
            }
        }*/

        #endregion

        #region API

        private double Balance(ulong playerId) => Balance(playerId.ToString());
        private double Balance(string playerId)
        {
            string currency = _defaultCurrency;
            if (!_database[currency].ContainsKey(Convert.ToUInt64(playerId)))
            {
                PrintWarning("Игрок не найден");
                return 0;
            }
            double balance = _database[currency][Convert.ToUInt64(playerId)];
            return balance;
        }

        private double Balance(string playerId,string currency)
        {
            /*if (currency == null)
            {
                currency = _defaultCurrency;
            }*/
            if (!_database[currency].ContainsKey(Convert.ToUInt64(playerId)))
            {
                PrintWarning("Игрок не найден");
                return 0;
            }

            double balance = _database[currency][Convert.ToUInt64(playerId)];
            return balance;
        }

        private bool SetBalance(ulong playerId, double amount) => SetBalance(playerId.ToString(), amount);
        private bool SetBalance(string playerId, double amount)
        {
            string currency = _defaultCurrency;
            if (_database[currency].ContainsKey(Convert.ToUInt64(playerId)))
            {
                _database[currency][Convert.ToUInt64(playerId)] = amount;
                PrintWarning($"Баланс {currency} игрока {BasePlayer.FindByID(Convert.ToUInt64(playerId))} изменен на {amount}");
                return true;
            }
            else
            {
                PrintError($"Игрок {playerId} не найден!");
                return false;
            }
        }

        bool SetBalance(ulong playerId, double amount, string currency) =>
            SetBalance(playerId.ToString(), amount, currency);
        private bool SetBalance(string playerId, double amount,string currency)
        {
            if (_database[currency].ContainsKey(Convert.ToUInt64(playerId)))
            {
                _database[currency][Convert.ToUInt64(playerId)] = amount;
                return true;
            }
            else
            {
                PrintError($"Игрок {playerId} не найден!");
                return false;
            }
            
        }

        private bool Deposit(string playerId, double amount, string currency)
        {
            BasePlayer player = BasePlayer.Find(playerId);
            if (player == null) return false;
            NoticePlayer(player,amount,currency);
                LogDeposit(playerId,amount,currency);
            return amount > 0 && SetBalance(playerId, amount + Balance(playerId),currency);
            
        }
        private bool Deposit(string playerId, double amount)
        {
            BasePlayer player = BasePlayer.Find(playerId);
            if (player == null) return false;
            NoticePlayer(player,amount);
            string currency = _defaultCurrency;
            LogDeposit(playerId,amount);
            return amount > 0 && SetBalance(playerId, amount + Balance(playerId),currency);
        }
        private bool Withdraw(ulong playerId, double amount) => Withdraw(playerId.ToString(), amount);
        private bool Withdraw(string playerId, double amount)
        {
            Money cur = config.Currencies.Find(p => p.Name == _defaultCurrency);
            if (cur == null)
            {
                PrintError($"Erorr to find currency - {_defaultCurrency}");
                return false;
            }
            if (amount >= 0 || cur.Negative)
            {
                double balance = Balance(playerId);
                return (balance >= amount || cur.Negative) && SetBalance(playerId, balance - amount);
            }

            return true;
        }
        private bool Withdraw(string playerId, double amount, string currency)
        {
            Money cur = config.Currencies.Find(p => p.Name == currency);
            if (cur == null)
            {
                PrintError($"Erorr to find currency - {currency}");
                return false;
            }
            if (amount >= 0 || cur.Negative)
            {
                double balance = Balance(playerId);
                return (balance >= amount || cur.Negative) && SetBalance(playerId, balance - amount);
            }

            return true;
        }

        

        string GetCurrencyURL(string name)
        {
            return config.Currencies.Find(p => p.Name == name).Img;
        }

        #region MoscowOvhApi

        bool OvhInitialized()
        {
            if (RustStore == null)
            {
                PrintError("MoscowOvh не подключен");
            }

            bool isInit = (bool) RustStore.CallHook("APIIsInitialized");
            if (isInit == null || isInit == false)
            {
                PrintError("MoscowOvh не подключен или настроен неверно");
                return false;
            }

            return true;
        }

        #endregion

        #endregion

        #region UI

        private string _layer = "BalanceUI";
        void BalanceUI(BasePlayer player)
        {
            CuiHelper.DestroyUi(player, _layer);
            if (!config.UseUI)
            {
                return;
            }
            var container = new CuiElementContainer();
            int index = 1;
            int y = 40;
            
            container.Add(new CuiPanel
            {
                Image = {Color = "0 0 0 0.3"},
                RectTransform =
                {
                    AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = $"-120 {-50*config.Currencies.Count-5}", OffsetMax = $"-5 -5"
                }
            }, "Overlay", _layer);
            foreach (var money in config.Currencies)
            {
                container.Add(new CuiPanel
                {
                    Image = {Color = "0 0 0 0"},
                    RectTransform = {AnchorMin = "1 1",AnchorMax = "1 1",OffsetMin = $"-120 {-50*index}",OffsetMax = $"-5 {-50*index+50}"}
                }, _layer,_layer + $".{index}");
                container.Add(new CuiElement
                {
                    Parent = _layer + $".{index}",
                    Name = _layer + $".{index}"+".Img",
                    Components =
                    {
                        new CuiRawImageComponent
                        {
                            Png = (string) ImageLibrary.Call("GetImage",money.Img)
                        },
                        new CuiRectTransformComponent
                        {
                            AnchorMin = "0 0",AnchorMax = "0 0",OffsetMin = "0 0",OffsetMax = "50 50"
                        }
                    }
                });
                container.Add(new CuiLabel
                {
                    Text = {Align = TextAnchor.MiddleLeft,Text = $": {_database[money.Name][player.userID]}",FontSize = 18},
                    RectTransform = {AnchorMin = "0 0",AnchorMax = "0 0",OffsetMin = "51 0",OffsetMax = "99 50"}
                }, _layer + $".{index}", _layer + $".{index}" + ".Money");
                index++;
            }

            CuiHelper.AddUi(player, container);
        }
        
        void OnPlayerDeath(BasePlayer player, HitInfo info)
        {
            CuiHelper.DestroyUi(player, _layer);
        }
        
        void OnPlayerRespawned(BasePlayer player)
        {
            BalanceUI(player);
        }

        #endregion

        #region commands

        [ChatCommand("balance")]
        void ShowPlayerBalance(BasePlayer player, string command, string[] args)
        {
            SendReply(player,Balance(player.UserIDString).ToString());
        }

        #region admin

        [ChatCommand("eco")]
        void AdminEcoCommand(BasePlayer player, string command, string[] args)
        {
            PrintWarning("Admin Command Run");
            if (!player.IsAdmin)
            {
                SendReply(player,$"Not Exist Command!");
                return;
            }
            string text = $"Admin {player} ";
            if (args.Length < 2)
            {
                SendReply(player,$"Wrong Command\n" +
                                 $"Command list:" +
                                 $"/eco set (playerid/name) (amount) - to change default balance\n" +
                                 $"/eco set (playerid/name) (amount) (currency) - to change currency balance\n" +
                                 $"/eco setme (amount) (currency) - to change your currency balance\n" +
                                 $"/eco give (playerid/name) (amount) - give balance(default) for player\n" +
                                 $"/eco give (playerid/name) (amount) (currency) - give balance for player\n" +
                                 $"/eco giveme (amount) (currency) - give balance for player\n" +
                                 $"/eco withdraw (playerid/name) (amount) - withdraw player balance(default)\n" +
                                 $"/eco withdraw (playerid/name) (amount) (currency) - withdraw player balance\n" +
                                 $"/eco withdrawme (amount) (currency) - withdraw your balance \n");
            }

            BasePlayer target = BasePlayer.Find(args[1]);
            switch (args[0])
            {
                case "set":
                    if (args.Length<3)
                    {
                        SendReply(player,$"Wrong command");
                        return;
                    }
                    
                    if (args.Length<4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "set ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        SetBalance(target.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "set ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        text += " ";
                        text += args[3];
                        LogAdminCommand(player,text);
                        SetBalance(target.UserIDString, amount,args[3]);
                        return;
                    }
                break;
                case "setme":
                    if (args.Length<3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "setme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        
                        LogAdminCommand(player,text);
                        SetBalance(player.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "setme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        SetBalance(player.UserIDString, amount,args[3]);
                        return;
                    }
                    break;
                case "withdraw":
                    
                    if (args.Length<4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "withdraw ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        Withdraw(target.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "withdraw ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        text += " ";
                        text += args[3];
                        LogAdminCommand(player,text);
                        Withdraw(target.UserIDString, amount,args[3]);
                        return;
                    }
                    break;
                case "withdrawme":
                    
                    if (args.Length<3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "withdrawme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        
                        LogAdminCommand(player,text);
                        Withdraw(player.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "withdrawme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        Withdraw(player.UserIDString, amount,args[2]);
                        return;
                    }
                    break;
                case "give":
                    if (args.Length<3)
                    {
                        SendReply(player,$"Wrong command");
                        return;
                    }
                    
                    if (args.Length<4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "give ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        Deposit(target.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 4)
                    {
                        double amount = Convert.ToDouble(args[2]);
                        text += "give ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        text += " ";
                        text += args[3];
                        LogAdminCommand(player,text);
                        Deposit(target.UserIDString, amount,args[3]);
                        return;
                    }
                    break;
                case "giveme":
                    
                    if (args.Length<3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "giveme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        
                        LogAdminCommand(player,text);
                        Deposit(player.UserIDString, amount);
                        return;
                    }

                    if (args.Length >= 3)
                    {
                        double amount = Convert.ToDouble(args[1]);
                        text += "giveme ";
                        text += args[0];
                        text += " ";
                        text += args[1];
                        text += " ";
                        text += args[2];
                        LogAdminCommand(player,text);
                        Deposit(player.UserIDString, amount,args[2]);
                        return;
                    }
                    break;
            }
        }

        [ConsoleCommand("ebalanceservadd")]
        void ServerAddBalance(ConsoleSystem.Arg arg)
        {
            if (!arg.IsServerside) return;
            if (arg.HasArgs(3))
            {
                string useid = arg.Args[0];
                int amount = arg.Args[1].ToInt();
                string currency = arg.Args[2];
                Deposit(useid, amount,currency);
                PrintWarning($"SERVER ADD BALANCE TO {useid}");
                return;
                
            }
            if (arg.HasArgs(2))
            {
                int amount = arg.Args[1].ToInt();
                string useid = arg.Args[0];
                Deposit(useid, amount);
                PrintWarning($"SERVER ADD BALANCE TO {useid}");
                return;
            }
        }

        #endregion
        /*[ChatCommand("setbalance")]
        void SetPlayerBalance(BasePlayer player, string command, string[] args)
        {
            SetBalance(player.UserIDString, Convert.ToDouble(args[0]));
        }*/

        #endregion
        

        #region log

        private string _logFile = "Economics";
        void LogDeposit(string userid, double amount, string currency)
        {
            LogToFile(_logFile,$"Added {amount} to {currency} for {userid}",this);
        }
        
        void LogDeposit(string userid, double amount)
        {
            LogToFile(_logFile,$"Added {amount} to {_defaultCurrency}(default) for {userid}",this);
        }

        void LogSetBalance(string userid, double amount, string currency)
        {
            LogToFile(_logFile,$"Set Balnce for {userid} : {amount} to {currency}",this);
        }
        
        void LogSetBalance(string userid, double amount)
        {
            LogToFile(_logFile,$"Set Balnce for {userid} : {amount} to {_defaultCurrency}(default)",this);
        }

        void LogWithdraw(string userid, double amount, string currency)
        {
            LogToFile(_logFile,$"Withdraw {amount} to {currency} for {userid}",this);
        }
        
        void LogWithdraw(string userid, double amount)
        {
            LogToFile(_logFile,$"Withdraw {amount} to {_defaultCurrency}(default) for {userid}",this);
        }

        void LogAdminCommand(BasePlayer player, string text)
        {
            LogToFile(_logFile,$"Admin:{player} - {text}",this);
        }

        #endregion
        
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок

Другие ресурсы пользователя 15FPS

Сверху