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

FREE ZNExperience : 2.0.8 2.0.8

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6

/*
 * https://github.com/DocValerian/rust-plugins
 * Copyright (C) 2022 DocValerian
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.* 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
 * GNU General Public License for more details.* 
 * You should have received a copy of the GNU General Public License
 * along with this program.If not, see <http://www.gnu.org/licenses/>.* 
 * Questions and (limited) Support can be found in our Discord: https://discord.gg/8tkBFRjg3W
 * 
 */
//Requires: Kits
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
using System.Linq;
using System;
using Network;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Libraries.Covalence;
using Newtonsoft.Json;
using System.Globalization;
using Facepunch;
namespace Oxide.Plugins {
    [Info("ZNExperience", "DocValerian", "2.0.8")]
    public class ZNExperience : RustPlugin {
        static ZNExperience Plugin;
        [PluginReference]
        private Plugin BetterChat, ServerRewards, ZNTitleManager, ImageLibrary, PlaytimeTracker, InfoAPI, ZNFarming, PrivateBuyday;
#region globalVars
        const string permUse = "znexperience.use";
        const string permAdm = "znexperience.admin";
        const string permNoLvl = "znexperience.nolevel";
        bool HasPermission(string id, string perm) => permission.UserHasPermission(id, perm);
        private Dictionary<ulong, ProfileManager> _pm = new Dictionary<ulong, ProfileManager>();
        private Dictionary<int, int> xpPerLevel = new Dictionary<int, int>();
        private Dictionary<int, int> xpAtLevel = new Dictionary<int, int>();
        private ZNSkillTree _tree;
        private List<string> allPermissions = new List<string>();
        private NumberFormatInfo nfi = new CultureInfo("en-GB", false).NumberFormat;
        private List<string> expPerms = new List<string>() {
            "znexperience.xpboost_10", "znexperience.xpboost_20", "znexperience.xpboost_30", "znexperience.xpboost_40", "znexperience.xpboost_50",
        }
        ;
        private const int PAPERID = -544317637;
#endregion
#region plugin load
        void Loaded() {
            Plugin = this;
            permission.RegisterPermission(permUse, this);
            permission.RegisterPermission(permAdm, this);
            permission.RegisterPermission(permNoLvl, this);
            foreach (string p in expPerms) {
                permission.RegisterPermission(p, this);
            }
            //storedData = new StoredData();
            storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("ZNExperience");
            expPerLevelCache();
            initSkills();
            initSkillGroups();
            SaveData(storedData);
            nfi.NumberDecimalSeparator = ",";
            nfi.NumberGroupSeparator = ".";
            nfi.NumberDecimalDigits = 0;
        }
        private void OnServerInitialized() {
            _tree = new ZNSkillTree();
            foreach (var p in BasePlayer.activePlayerList) {
                ProfileManager.Get(p.userID);
                reloadLiveUI(p);
            }
            RegisterTitles();
            ImageLibrary?.Call("ImportImageList", "xpimg", new Dictionary<string, string>() {
                ["rp_img"]
                = "http://m2v.eu/i/zn/rp1.png", ["xp_img"] = "http://m2v.eu/i/zn/xp.png"
            }
            );
        }
        void Unload() {
            foreach (var player in BasePlayer.activePlayerList) {
                OnPlayerDisconnected(player);
                killLiveUI(player);
                killUI(player);
            }
        }
#endregion
#region Config
        protected override void LoadDefaultConfig() {
            Cfg = new Configuration();
            Puts("Loaded default configuration file");
        }
        protected override void SaveConfig() => Config.WriteObject(Cfg);
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                Cfg = Config.ReadObject<Configuration>();
            }
            catch (JsonException ex) {
                Puts(ex.Message);
                PrintError("Your configuration file contains a json error, shown above.Please fix this.");
                return;
            }
            catch (Exception ex) {
                Puts(ex.Message);
                LoadDefaultConfig();
            }
            if (Cfg == null) {
                Puts("Config is null");
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        static Configuration Cfg = new Configuration();
        public class Configuration {
            [JsonProperty(PropertyName = "Settings")]
            public PluginSettings Settings = new PluginSettings();
            [JsonProperty(PropertyName = "Experience for killing")]
            public ExperienceMap xp = new ExperienceMap();
            [JsonProperty(PropertyName = "Is pvp")]
            public bool isPvp = false;
        }
        public class PluginSettings {
            public int minSP = 8;
            public int SPPerLevel = 1;
            public int apocalypseSPPerPrestige = 1;
            public int skillPointsPerPrestige = 10;
            //public int expPerLevel = 20000;
            public int baseXPPerLevel = 5000;
            public int xpGrowPerLevel = 400;
            public float xpPerPrestigeMulti = 0.1f;
            public DateTime lastApocalypse = DateTime.Now;
            public DateTime nextApocalypse = DateTime.Now;
            public int levelCap = 99;
            public string xpName = "Experience";
            public int reskillRP = 30000;
            public int buyLevelRP = 50000;
            public int buyTenLevelRP = 450000;
            public int reskillPapers = 20000;
            public float prestigeLevelBuyFactor = 0.15f;
        }
        public class ExperienceMap {
            public Dictionary<string, int> onDeath = new Dictionary<string, int>() {
                ["scientistnpc_heavy"]
                = 25, ["scientist"] = 40, ["npc_tunneldweller"] = 40, ["npc_underwaterdweller"] = 60, ["scientistnpc_roam_nvg_variant"] = 60, ["scientistnpc_junkpile_pistol"] = 40, ["scientistnpc_full_lr300"] = 60, ["scientistnpc_full_mp5"] = 60, ["scientistnpc_full_pistol"] = 60, ["scientistnpc_full_any"] = 20, ["scientistnpc_full_shotgun"] = 60, ["scientistnpc"] = 40, ["scientistnpc_oilrig"] = 30, ["scientistnpc_cargo"] = 30, ["scientistnpc_roamtethered"] = 40, ["scientistnpc_roam"] = 40, ["scientistnpc_patrol"] = 40, ["scarecrow"] = 35, ["heavyscientist"] = 40, ["heavyscientistad"] = 40, ["chicken"] = 200, ["boar"] = 40, ["wolf"] = 40, ["bear"] = 100, ["polarbear"] = 100, ["stag"] = 100, ["loot_barrel_1"] = 40, ["loot_barrel_2"] = 40, ["loot-barrel-1"] = 40, ["loot-barrel-2"] = 40, ["oil_barrel"] = 40, ["trash-pile-1"] = 40, ["roadsign1"] = 40, ["roadsign2"] = 40, ["roadsign3"] = 40, ["roadsign4"] = 40, ["roadsign5"] = 40, ["roadsign6"] = 40, ["roadsign7"] = 40, ["roadsign8"] = 40, ["roadsign9"] = 40,
            }
            ;
            public Dictionary<string, int> onLoot = new Dictionary<string, int>() {
                ["crate_normal"]
                = 50, ["crate_normal_2"] = 50, ["crate_normal_2_medical"] = 150, ["vehicle_parts"] = 50, ["crate_tools"] = 50, ["crate_underwater_advanced"] = 300, ["crate_underwater_basic"] = 150, ["crate_elite"] = 300, ["codelockedhackablecrate"] = 500, ["codelockedhackablecrate_oilrig"] = 500, ["foodbox"] = 50, ["trash-pile-1"] = 50, ["crate_mine"] = 70, ["minecart"] = 70,
            }
            ;
        }
        class StoredData {
            public Dictionary<string, ZNSkill> Skills = new Dictionary<string, ZNSkill>() {
            }
            ;
            public Dictionary<string, ZNSkillGroup> SkillGroups = new Dictionary<string, ZNSkillGroup>() {
                ["farming"]
                = new ZNSkillGroup {
                    name = "Farming Skills", description = "Skills that influence your resource farming ability", id = "farming", skillIDs = new List<string>()
                }
                , ["abilities"] = new ZNSkillGroup {
                    name = "Commands/Abilities", description = "Skills that give you extra powers", id = "abilities", skillIDs = new List<string>()
                }
                ,
            }
            ;
            public HashSet<ulong> noUIPlayers = new HashSet<ulong>();
        }
        ;
        StoredData storedData;
        private static void LoadData<T>(out T data, string filename = null) => data = Interface.Oxide.DataFileSystem.ReadObject<T>(filename ?? "ZNExperience");
        private static void SaveData<T>(T data, string filename = null) => Interface.Oxide.DataFileSystem.WriteObject(filename ?? "ZNExperience", data);
#endregion
#region Hooks
        private void OnPluginLoaded(Plugin plugin) {
            if (plugin.Title == "Better Chat") RegisterTitles();
        }
        private void OnPermissionRegistered(string name, Plugin owner) {
        }
        private void OnPluginUnloaded(Plugin plugin) {
        }
        private void OnServerSave() {
            foreach (ProfileManager pm in _pm.Values) {
                pm.SaveData();
            }
        }
        private void OnPlayerDisconnected(BasePlayer player) {
            if (_pm.ContainsKey(player.userID)) {
                ProfileManager pm = _pm[player.userID];
                pm.SaveData();
                _pm.Remove(player.userID);
            }
        }
        void OnPlayerSleepEnded(BasePlayer player) {
            if (player is NPCPlayer || player is HumanNPC || player.IsNpc) return;
            if (!_pm.ContainsKey(player.userID)) {
                _pm[player.userID] = ProfileManager.Get(player.userID);
                if (!(storedData.noUIPlayers.Contains(player.userID))) reloadLiveUI(player);
            }
        }
        private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) {
            if (entity == null || entity.IsDestroyed) return;
            if (entity == null || String.IsNullOrWhiteSpace(entity?.ShortPrefabName)) return;
            if (info == null || info.Initiator == null) return;
            if (!(info.Initiator is BasePlayer) || (info.Initiator as BasePlayer).IsNpc) return;
            BasePlayer bplayer = info?.Initiator?.ToPlayer();
            if (bplayer == null) return;
            //Puts("DEBUG: Player " + bplayer + " KILLED " + entity.ShortPrefabName);
            if (Cfg.xp.onDeath.ContainsKey(entity.ShortPrefabName)) {
                AddXp(bplayer.userID, Cfg.xp.onDeath[entity.ShortPrefabName]);
            }
        }
        void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity) {
            //Puts("DEBUG: OnLootEntityEnd " + player + " looted " + entity + " owner " + entity.OwnerID);
            if (entity == null || entity.IsDestroyed) return;
            if (entity == null || String.IsNullOrWhiteSpace(entity?.ShortPrefabName)) return;
            if (Cfg.xp.onLoot.ContainsKey(entity.ShortPrefabName)) {
                AddXp(player.userID, Cfg.xp.onLoot[entity.ShortPrefabName]);
            }
        }
        void OnItemAddedToContainer(ItemContainer container, Item item) {
            BasePlayer player = container.GetOwnerPlayer();
            if (player == null || player.IsNpc) return;
            if (item.info.shortname == "researchpaper" && !HasPermission(player.UserIDString, permAdm)) {
                if (_pm.ContainsKey(player.userID)) {
                    Item papers = player.inventory.FindItemByItemID(PAPERID);
                    // safety from overbyuing
                    if (papers == null || papers.amount < 1) {
                        return;
                    }
                    player.inventory.Take(null, PAPERID, papers.amount);
                    Puts("INFO: " + player + " auto-converted " + papers.amount + " Research Papers to XP (with multiplier)");
                    if (papers.amount >= 10000) {
                        AddXp(player.userID, papers.amount, false);
                    }
                    else {
                        AddXp(player.userID, papers.amount);
                    }
                    SendReply(player, "<color=green>ZN-XP:</color> You gained XP from looting " + papers.amount + " research papers (XP-Boosts apply!)");
                }
            }
        }
#endregion
#region Commands
        [ConsoleCommand("znexp.close")]
        private void CmdClose(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) // || !HasPermission(arg.Player().UserIDString, permUse))
            return;
            killUI(player);
        }
        [ConsoleCommand("znexp.prestige")]
        private void CmdPrestige(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) // || !HasPermission(arg.Player().UserIDString, permUse))
            return;
            float scale = arg.GetFloat(0);
            //check & Update ProfileManager
            if (_pm.ContainsKey(player.userID)) {
                _pm[player.userID].Prestige();
            }
            reloadUI(player);
        }
        [ConsoleCommand("znexp.skilldetail")]
        private void CmdOpenDetail(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) // || !HasPermission(arg.Player().UserIDString, permUse))
            return;
            string skillId = arg.GetString(0);
            //check & Update ProfileManager
            if (_pm.ContainsKey(player.userID) && storedData.Skills.ContainsKey(skillId)) {
                CuiHelper.DestroyUi(player, mainName + "_skillDetail");
                GUIskillDetailElement(player, mainName + "_skillDetail", _pm[player.userID], storedData.Skills[skillId]);
            }
        }
        [ConsoleCommand("znexp.closedetail")]
        private void CmdCloseDetail(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            CuiHelper.DestroyUi(player, mainName + "_skillDetail");
        }
        [ConsoleCommand("znexp.addskill")]
        private void CmdAddSkill(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            string skillId = arg.GetString(0);
            //check & Update ProfileManager
            if (_pm.ContainsKey(player.userID) && storedData.Skills.ContainsKey(skillId)) {
                ZNResponse r = _pm[player.userID].AddSkill(storedData.Skills[skillId]);
                if (r.success) {
                    InfoAPI.Call("ShowInfoPopup", player, r.msg);
                    reloadUI(player);
                }
                else {
                    InfoAPI.Call("ShowInfoPopup", player, r.msg, true);
                }
            }
        }
        [ConsoleCommand("znexp.prestigeunlock")]
        private void CmdPrestigeUnlock(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            string skillId = arg.GetString(0);
            //check & Update ProfileManager
            if (_pm.ContainsKey(player.userID) && storedData.Skills.ContainsKey(skillId)) {
                ZNResponse r = _pm[player.userID].PUnlock(storedData.Skills[skillId].prestigeUnlockId);
                if (r.success) {
                    InfoAPI.Call("ShowInfoPopup", player, r.msg);
                    reloadUI(player);
                }
                else {
                    InfoAPI.Call("ShowInfoPopup", player, r.msg, true);
                }
            }
        }
        [ConsoleCommand("znexp.reskillpaper")]
        private void CmdReskillPaper(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            if (_pm.ContainsKey(player.userID)) {
                Item papers = player.inventory.FindItemByItemID(PAPERID);
                ProfileManager p = _pm[player.userID];
                // safety from overbyuing
                if (papers == null || papers.amount < 1) {
                    InfoAPI.Call("ShowInfoPopup", player, "You don't have any Research Papers!", true);
                    return;
                }
                if (papers.amount < Cfg.Settings.reskillPapers) {
                    InfoAPI.Call("ShowInfoPopup", player, "It costs " + Cfg.Settings.reskillPapers + " Research Papers to use this command,\nyou only have " + papers.amount, true);
                    return;
                }
                else {
                    player.inventory.Take(null, PAPERID, Cfg.Settings.reskillPapers);
                    p.Reskill();
                    reloadUI(player);
                }
                InfoAPI.Call("ShowInfoPopup", player, "You paid " + Cfg.Settings.reskillPapers + " Research Papers.\nSkills & Unlocks reset!");
                Puts("INFO: " + player + " reset their skills for Research Papers");
            }
        }
        [ConsoleCommand("znexp.transferpapers")]
        private void CmdTransferPaper(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            if (_pm.ContainsKey(player.userID)) {
                ProfileManager p = _pm[player.userID];
                int amount = 0;
                var slots = player.inventory.FindItemsByItemID(PAPERID);
                foreach (var slot in slots) {
                    if (slot == null) {
                        continue;
                    }
                    amount += slot.amount;
                    slot.Drop(Vector3.zero, Vector3.zero);
                }
                if (amount < 1) {
                    InfoAPI.Call("ShowInfoPopup", player, "You don't have any Research Papers!", true);
                    return;
                }
                amount = (int)Math.Floor(p.xpMulti * amount);
                Puts("INFO: " + player + " converted " + amount + " Research Papers to XP (with boosts)");
                p.AddExperience(amount);
                reloadUI(player);
            }
        }
        [ConsoleCommand("znexp.closeconfirm")]
        private void CmdCloseConfirm(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            CuiHelper.DestroyUi(player, mainName + "_confirm");
        }
        [ConsoleCommand("znexp.confirm")]
        private void CmdConfirm(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            CuiHelper.DestroyUi(player, mainName + "_confirm");
            if (_pm.ContainsKey(player.userID)) {
                ProfileManager p = _pm[player.userID];
                // safety from overbyuing
                if (!p.CanReskill()) {
                    InfoAPI.Call("ShowInfoPopup", player, "You don't have anything allocated yet!", true);
                    return;
                }
                object bal = ServerRewards?.Call("CheckPoints", player.userID);
                if (bal == null) return;
                int playerRP = (int)bal;
                if (playerRP < Cfg.Settings.reskillRP) {
                    InfoAPI.Call("ShowInfoPopup", player, "It costs " + numberCandy(Cfg.Settings.reskillRP) + " RP to use this command, you only have " + playerRP, true);
                    return;
                }
                else {
                    ServerRewards?.Call("TakePoints", player.userID, Cfg.Settings.reskillRP);
                    p.Reskill();
                    reloadUI(player);
                }
                InfoAPI.Call("ShowInfoPopup", player, "You paid " + numberCandy(Cfg.Settings.reskillRP) + " RP.\nSkills & Unlocks reset!");
                Puts("INFO: " + player + " reset their skills for RP");
            }
        }
        [ConsoleCommand("znexp.reskill")]
        private void CmdReskill(ConsoleSystem.Arg arg) {
            var player = arg.Connection.player as BasePlayer;
            if (player == null) return;
            GUIconfirmElement(player, mainName + "_confirm");
        }
        [ConsoleCommand("znexp.noskillbuylevel")]
        private void CmdBuyLevel(ConsoleSystem.Arg arg) {
            return;
            //deprecated!
            /*
            var player = arg.Connection.player as BasePlayer;
            if (player == null)
                return;

            int levels = arg.GetInt(0);

            if (_pm.ContainsKey(player.userID))
            {
                ProfileManager p = _pm[player.userID];
                // safety from overbyuing

                if (p.level + levels > Cfg.Settings.levelCap)
                {
                    levels = Cfg.Settings.levelCap - p.level;
                }
                if (levels == 0)
                {
                    InfoAPI?.Call("ShowInfoPopup", player, "You must prestige first!", true);
                    return;
                }
                object bal = ServerRewards?.Call("CheckPoints", player.userID);
                if (bal == null) return;
                int playerRP = (int)bal;
                int price = (int) Math.Floor(Cfg.Settings.prestigeLevelBuyFactor * p.prestigeLevel * (levels * Cfg.Settings.buyLevelRP) + (levels * Cfg.Settings.buyLevelRP));
                if (playerRP < price)
                {
                    InfoAPI?.Call("ShowInfoPopup", player, "It costs " + price + " RP to buy " + levels + " levels, you only have " + playerRP, true);
                    return;
                }
                else
                {
                    ServerRewards?.Call("TakePoints", player.userID, price);
                    p.AddExperience(levels * Cfg.Settings.expPerLevel);
                    reloadUI(player);
                }
                SendReply(player, "<color=green>ZN-XP:</color> You paid " + price + " RP.\n" + levels + " levels added!");
                Puts("INFO: " + player + " purchased " + levels + " levels for " + price + " RP");
            }
            */
        }
        [ChatCommand("atpt")]
        void CmdAdmTest(BasePlayer player, string command, string[] args) {
            if (!HasPermission(player.UserIDString, permAdm)) return;
        }
        [ChatCommand("atxp")]
        void CmdAdmInspect(BasePlayer player, string command, string[] args) {
            if (!HasPermission(player.UserIDString, permAdm)) return;
            BasePlayer p;
            if(args.Length == 0) {
                p = player;
            }
            else {
                var findPlayers = FindPlayer(args[0]);
                if (findPlayers.Count == 0 ) {
                    SendReply(player, "No players found." );
                    return;
                }
                if (findPlayers.Count > 1 ) {
                    SendReply(player, "Multiple players found." );
                    return;
                }
                p = findPlayers[0];
            }
            ProfileManager pm = _pm[p.userID];
            if(args.Length == 2 && args[1] != null) {
                switch(args[1]) {
                    case "demote" : int levels = 0;
                    int.TryParse(args[2], out levels);
                    if (levels == 0) return;
                    pm.Demote(player, levels);
                    reloadLiveUI(p);
                    break;
                    default : break;
                }
            }
            string msg = "<color=orange>----- " + Plugin.Name + " - ADMIN /atxp -----</color>";
            msg += "\nInspecting: \t" + p.displayName + " " + pm.formatedDisplayLevel;
            msg += "\nLifetime XP:\t" + numberCandy(pm.eternalXpPoints);
            msg += "\nLevel-Up XP:\t" + (pm.xpPoints - getExpATLevel(pm.displayLevel)) + "/" + getExpForLevel(pm.displayLevel + 1) + " (" + getPercentToNextLevel(pm.displayLevel, pm.xpPoints) + "%)";
            msg += "\nSkillpoints:\t\t" + (pm.maxSkillPoints - pm.allocatedSkillPoints) + "/" + pm.maxSkillPoints;
            msg += "\nPrestige-pts:\t" + (pm.prestigeLevel - pm.prestigeUnlocks.Count()) + "/" + pm.prestigeLevel;
            msg += "\nPlaytime:\t\t" + GetPlaytimeFor(player);
            msg += "\n\n<color=green>Skills:</color>\n";
            msg += string.Join(", ", pm.playerSkills);
            msg += "\n\n<color=green>Prestige Unlocks:</color>\n";
            msg += string.Join(", ", pm.prestigeUnlocks);
            SendReply(player, msg);
        }
        [ChatCommand("pui")]
        void CmdUiToggle(BasePlayer player, string command, string[] args) {
            toggleUI(player);
        }
        [ChatCommand("p")]
        void CmdProfileMain(BasePlayer player, string command, string[] args) {
            reloadUI(player);
            return;
        }
        /*
        [ChatCommand("ll")]
        void TESTcommand(BasePlayer player, string command, string[] args)
        {
            //ProfileManager.Get(player.userID, true);
            reloadUI(player);
            return;
        }
        */
#endregion
#region API
        private int GetLevel(ulong playerId) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return 0;
            return p.level;
        }
        private int GetDisplayLevel(ulong playerId) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return 0;
            return p.displayLevel;
        }
        private string GetLevelString(ulong playerId) {
            ProfileManager p;
            if(!_pm.TryGetValue(playerId, out p)) return "";
            return p.formatedDisplayLevel;
        }
        private string GetLifetimeXPString(ulong playerId) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return "";
            return numberCandy(p.eternalXpPoints);
        }
        private Dictionary<ulong, string> GetLowLevelPlayers() {
            Dictionary<ulong, string> ret = new Dictionary<ulong, string>();
            foreach(ProfileManager p in _pm.Values) {
                if(p.displayLevel <= 10000) {
                    ret.Add(p.playerID, p.getPlayerName());
                }
            }
            ret.Add(1, "Debug PlAyA 1");
            ret.Add(2, "Debug g 23");
            ret.Add(3, "De3bug 5 6u");
            ret.Add(4, "Dedrgbug PlAyA 1");
            ret.Add(5, "Debug g 23");
            ret.Add(6, "De3bug 5 6u");
            ret.Add(7, "Debug PlAyA 1");
            ret.Add(8, "Debug g 23");
            ret.Add(9, "De3bug 5 6u");
            ret.Add(0, "Deb435tug PlAyA 1");
            ret.Add(11, "Debug g 23");
            ret.Add(12, "De3bug 5 6u");
            ret.Add(13, "Debug PlAyA 1");
            ret.Add(14, "Debug g 23");
            ret.Add(15, "De3bug 5 6u");
            ret.Add(16, "Deb erug PlAyA 1");
            ret.Add(17, "Debug g 23");
            ret.Add(18, "De3bug 5 6u");
            ret.Add(19, "Deberge ug PlAyA 1");
            ret.Add(20, "Debug g 23");
            ret.Add(21, "De3be ug 5 6u");
            return ret;
        }
        private void AddXp(ulong playerId, int amount, bool bonus = true) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return;
            if (bonus) {
                amount = (int) Math.Ceiling(p.xpMulti * amount);
                /* DEPRECATED
                if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                {
                    amount = (int)Math.Ceiling(1.5f * amount);
                }
                */
            }
            //Puts("DEBUG: P: "+ playerId + " adding XP: " + amount);
            p?.AddExperience(amount);
        }
        private void AddLevel(ulong playerId, int amount) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return;
            int value = xpPerLevel[_pm[playerId].displayLevel];
            //Puts("DEBUG: P: " + playerId + " adding Levels: " + amount + " (XP: " + value+")");
            p?.AddExperience(value);
        }
        private bool CanAddLevel(ulong playerId, int amount) {
            ProfileManager p;
            if (!_pm.TryGetValue(playerId, out p)) return false;
            return (p.level + amount) <= Cfg.Settings.levelCap;
        }
        private void RegisterSkill(string id, string name, string groupId, int spCost, List<string> permissionEffect, string description, string prerequisiteSkillId, string followUpSkillId, bool isDefault, string prestigeUnlockId, string iconURL ) {
            if (storedData.Skills.ContainsKey(id)) {
                storedData.Skills[id] = new ZNSkill {
                    id = id, name = name, groupId = groupId, spCost = spCost, permissionEffect = permissionEffect, description = (description != "") ? description : null, prerequisiteSkillId = (prerequisiteSkillId != "") ? prerequisiteSkillId : null, followUpSkillId = (followUpSkillId != "") ? followUpSkillId : null, isDefault = isDefault, prestigeUnlockId = (prestigeUnlockId != "") ? prestigeUnlockId : null, iconURL = (iconURL != "") ? iconURL : null,
                }
                ;
            }
            else {
                ZNSkill s = new ZNSkill {
                    id = id, name = name, groupId = groupId, spCost = spCost, permissionEffect = permissionEffect, description = (description != "") ? description : null, prerequisiteSkillId = (prerequisiteSkillId != "") ? prerequisiteSkillId : null, followUpSkillId = (followUpSkillId != "") ? followUpSkillId : null, isDefault = isDefault, prestigeUnlockId = (prestigeUnlockId != "") ? prestigeUnlockId : null, iconURL = (iconURL != "") ? iconURL : null,
                }
                ;
                storedData.Skills.Add(s.id, s);
            }
            SaveData(storedData);
            //Puts("DEBUG: RegisterSkill (upsert) - " + id);
        }
        private void SaveSkillSetup() {
            initSkillGroups();
            SaveData(storedData);
            _tree = new ZNSkillTree();
        }
#endregion
#region helpers/formatters
        private int calculateXPForLevel(int prestige, int level) {
            int xp = -1;
            xp = (int) Math.Floor((Cfg.Settings.baseXPPerLevel + level*Cfg.Settings.xpGrowPerLevel) * (1 + prestige * Cfg.Settings.xpPerPrestigeMulti));
            return xp;
        }
        private void expPerLevelCache() {
            //string lvls = "";
            for(int p = 0; p < 50; p++) {
                for(int i = 1; i <= Cfg.Settings.levelCap; i++) {
                    xpPerLevel[(p*100+i)] = calculateXPForLevel(p, i);
                    if(i == 1) {
                        xpAtLevel[(p * 100 + i)] = xpPerLevel[(p * 100 + i)];
                    }
                    else {
                        xpAtLevel[(p * 100 + i)] = xpAtLevel[(p * 100 + (i-1))] + xpPerLevel[(p * 100 + i)];
                    }
                    //lvls += " --- Level: " + (p * 100 + i) + " xp: " + xpPerLevel[(p * 100 + i)];
                }
            }
            //Puts("DEBUG: " + lvls);
        }
        private string skillNameFromId(string skillID) {
            if (storedData.Skills.ContainsKey(skillID)) {
                return storedData.Skills[skillID].name;
            }
            return skillID;
        }
        private int getExpATLevel(int level) {
            int xp = 0;
            xpAtLevel.TryGetValue(level, out xp);
            return xp;
        }
        private int getExpForLevel(int level) {
            int xp = 0;
            xpPerLevel.TryGetValue(level, out xp);
            return xp;
        }
        private float getPercentToNextLevel(int displaylevel, int xp) {
            int reqXp = getExpForLevel(displaylevel+1);
            int baseXp = getExpATLevel(displaylevel);
            int levelXP = 1;
            xpPerLevel.TryGetValue(displaylevel+1, out levelXP);
            //Puts("base for current level " + baseXp + " next level base " + reqXp + " per level " + levelXP );
            return (float)(xp - baseXp ) / levelXP * 100f;
        }
        private string GetImage(string fileName, ulong skin = 0) {
            string imageId = (string)ImageLibrary.Call("GetImage", fileName, skin);
            if (!string.IsNullOrEmpty(imageId)) return imageId;
            return string.Empty;
        }
#endregion
#region Functions
        private void initSkills() {
            storedData.Skills["autoloot.lv0"] = new ZNSkill {
                id = "autoloot.lv0", name = "Autoloot Blood", groupId = "farming", spCost = 1, permissionEffect = new List<string> {
                    "znfarming.blood.pickup"
                }
                , description = "Passive skill that will automatically pick up Blood gained from farming etc.for you."
            }
            ;
            storedData.Skills["instanttp.lv0"] = new ZNSkill {
                id = "instanttp.lv0", name = "Instant Teleport", groupId = "abilities", spCost = 5, permissionEffect = new List<string> {
                    "warpsgui.none", "teleportgui.none", "homesgui.none"
                }
                , description = "Allows you to instant Teleport with /home /tp /warp.\nAlso removes TP cooldowns."
            }
            ;
            storedData.Skills["sil.lv0"] = new ZNSkill {
                id = "sil.lv0", name = "/sil(t) command", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "signartist.url", "signartist.text"
                }
                , description = "Allows you to put images and text on signs with /sil and /silt"
            }
            ;
            storedData.Skills["quarry.lv0"] = new ZNSkill {
                id = "quarry.lv0", name = "/mm command", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "virtualquarries.use"
                }
                , description = "Allows you to use virtual Quarries with /mm"
            }
            ;
            storedData.Skills["smelt.lv0"] = new ZNSkill {
                id = "smelt.lv0", name = "/smelt command", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "virtualsmelter.use"
                }
                , description = "Allows you to use our efficient super smelter with /smelt"
            }
            ;
            storedData.Skills["kits.lv0"] = new ZNSkill {
                id = "kits.lv0", name = "VIP Starter /kit", groupId = "abilities", spCost = 3, permissionEffect = new List<string> {
                    "kits.vipstarter"
                }
                , followUpSkillId = "kits.lv1", description = "Gives you a special once per wipe starter /kit"
            }
            ;
            storedData.Skills["kits.lv1"] = new ZNSkill {
                id = "kits.lv1", name = "Daily Horse /kit", groupId = "abilities", spCost = 3, permissionEffect = new List<string> {
                    "kits.dailyhorse"
                }
                , prerequisiteSkillId = "kits.lv0", followUpSkillId = "kits.lv2", description = "Gives you a daily Horse & Boat /kit"
            }
            ;
            storedData.Skills["kits.lv2"] = new ZNSkill {
                id = "kits.lv2", name = "Vet Starter /kit", groupId = "abilities", spCost = 5, permissionEffect = new List<string> {
                    "kits.vetstarter"
                }
                , prerequisiteSkillId = "kits.lv1", followUpSkillId = "kits.lv3", description = "Gives you another special once per wipe starter /kit"
            }
            ;
            storedData.Skills["kits.lv3"] = new ZNSkill {
                id = "kits.lv3", name = "Daily Heli /kit", groupId = "abilities", spCost = 5, permissionEffect = new List<string> {
                    "kits.vetcopter"
                }
                , prerequisiteSkillId = "kits.lv2", description = "Gives you a daily RHIB and Minicopter /kit"
            }
            ;
            storedData.Skills["buyday.lv0"] = new ZNSkill {
                id = "buyday.lv0", name = "/day command", groupId = "abilities", spCost = 3, permissionEffect = new List<string> {
                    "privatebuyday.use"
                }
                , followUpSkillId = "buyday.lv1", description = "Allows you to use /day and buy daylight whenever you want"
            }
            ;
            storedData.Skills["buyday.lv1"] = new ZNSkill {
                id = "buyday.lv1", name = "/day FREE", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "privatebuyday.free"
                }
                , prerequisiteSkillId = "buyday.lv0", description = "Allows you to use /day without RP cost at any time"
            }
            ;
            storedData.Skills["getmystuff.lvz"] = new ZNSkill {
                id = "getmystuff.lvz", name = "/getmystuff Base", groupId = "abilities", spCost = 0, permissionEffect = new List<string> {
                    "usrtools.getmystuff.base"
                }
                , isDefault = true, followUpSkillId = "getmystuff.lv0", description = "Allows you to use /getmystuff to help find your corpse or bag"
            }
            ;
            storedData.Skills["getmystuff.lv0"] = new ZNSkill {
                id = "getmystuff.lv0", name = "/getmystuff BUY", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "usrtools.getmystuff"
                }
                , followUpSkillId = "getmystuff.lv1", prerequisiteSkillId = "getmystuff.lvz", description = "Allows you to use /getmystuff buy and teleport loot from your corpse to you (for RP!).Only if your corpse hasn't despawned! Not a 100% guarantee!"
            }
            ;
            storedData.Skills["getmystuff.lv1"] = new ZNSkill {
                id = "getmystuff.lv1", name = "/getmystuff FREE", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "usrtools.getmystuff.free"
                }
                , prerequisiteSkillId = "getmystuff.lv0", followUpSkillId = "getmystuff.lv2", prestigeUnlockId = "pGetStuff", description = "Allows you to use /getmystuff buy for FREE.Not a 100% guarantee to not lose some stuff!"
            }
            ;
            storedData.Skills["getmystuff.lv2"] = new ZNSkill {
                id = "getmystuff.lv2", name = "/getmystuff AUTO", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "restoreupondeath.admin"
                }
                , prerequisiteSkillId = "getmystuff.lv1", prestigeUnlockId = "pGetStuff", description = "With this skill active you will automatically get your stuff back & equipped.!!! NOT IN RAIDS !!! Not a 100% guarantee to not lose some stuff!"
            }
            ;
            storedData.Skills["nodurability.lv0"] = new ZNSkill {
                id = "nodurability.lv0", name = "Items don't break", groupId = "abilities", spCost = 10, permissionEffect = new List<string> {
                    "nodurability.allowed"
                }
                , description = "Your Items will be repaired on use\nOnly if not fully broken and NOT within Raids!"
            }
            ;
            storedData.Skills["agrade.lv0"] = new ZNSkill {
                id = "agrade.lv0", name = "/agrade command", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "buildmanager.agrade.use"
                }
                , followUpSkillId = "agrade.lv1", description = "Allows you to use /agrade to upgrade the entire building at once (Costs RP and 1.5x Res)"
            }
            ;
            storedData.Skills["agrade.lv1"] = new ZNSkill {
                id = "agrade.lv1", name = "/agrade FREE", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "buildmanager.agrade.free"
                }
                , prerequisiteSkillId = "agrade.lv0", description = "Allows you to use /agrade without RP cost and with 1.1x res cost."
            }
            ;
            storedData.Skills["repairall.lv0"] = new ZNSkill {
                id = "repairall.lv0", name = "/repairall command", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "buildmanager.repairall.use"
                }
                , followUpSkillId = "repairall.lv1", description = "Allows you to use /repairall to repair the entire building at once (Costs RP and 1.5x Res)"
            }
            ;
            storedData.Skills["repairall.lv1"] = new ZNSkill {
                id = "repairall.lv1", name = "/repairall FREE", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "buildmanager.repairall.free"
                }
                , prerequisiteSkillId = "repairall.lv0", description = "Allows you to use /repairall without RP cost and with 1.1x res cost."
            }
            ;
            storedData.Skills["xpboost.lv0"] = new ZNSkill {
                id = "xpboost.lv0", name = "5% XP boost", groupId = "abilities", spCost = 7, permissionEffect = new List<string> {
                    "znexperience.xpboost_10"
                }
                , followUpSkillId = "xpboost.lv1", description = "All experience gained will be increased by 5% (Including Research Paper transfer)"
            }
            ;
            storedData.Skills["xpboost.lv1"] = new ZNSkill {
                id = "xpboost.lv1", name = "12% XP boost", groupId = "abilities", spCost = 10, permissionEffect = new List<string> {
                    "znexperience.xpboost_20"
                }
                , prerequisiteSkillId = "xpboost.lv0", followUpSkillId = "xpboost.lv2", description = "All experience gained will be increased by 12% (Including Research Paper transfer)"
            }
            ;
            storedData.Skills["xpboost.lv2"] = new ZNSkill {
                id = "xpboost.lv2", name = "20% XP boost", groupId = "abilities", spCost = 10, permissionEffect = new List<string> {
                    "znexperience.xpboost_30"
                }
                , prerequisiteSkillId = "xpboost.lv1", followUpSkillId = "xpboost.lv3", description = "All experience gained will be increased by 20% (Including Research Paper transfer)"
            }
            ;
            storedData.Skills["xpboost.lv3"] = new ZNSkill {
                id = "xpboost.lv3", name = "30% XP boost", groupId = "abilities", spCost = 10, permissionEffect = new List<string> {
                    "znexperience.xpboost_40"
                }
                , prerequisiteSkillId = "xpboost.lv2", followUpSkillId = "xpboost.lv4", prestigeUnlockId = "pXpboost", description = "All experience gained will be increased by 30% (Including Research Paper transfer)"
            }
            ;
            storedData.Skills["xpboost.lv4"] = new ZNSkill {
                id = "xpboost.lv4", name = "40% XP boost", groupId = "abilities", spCost = 10, permissionEffect = new List<string> {
                    "znexperience.xpboost_50"
                }
                , prerequisiteSkillId = "xpboost.lv3", prestigeUnlockId = "pXpboost", description = "All experience gained will be increased by 40% (Including Research Paper transfer)"
            }
            ;
            storedData.Skills["backpack.lv0"] = new ZNSkill {
                id = "backpack.lv0", name = "Backpack Base", groupId = "abilities", spCost = 0, permissionEffect = new List<string> {
                    "backpacks.use", "backpacks.size.12"
                }
                , followUpSkillId = "backpack.lv1", isDefault = true, description = "Gives you a Backpack with <color=green>2</color> rows"
            }
            ;
            storedData.Skills["backpack.lv1"] = new ZNSkill {
                id = "backpack.lv1", name = "Backpack Lv.1", groupId = "abilities", spCost = 1, permissionEffect = new List<string> {
                    "backpacks.size.18"
                }
                , prerequisiteSkillId = "backpack.lv0", followUpSkillId = "backpack.lv2", description = "Gives you a Backpack with <color=green>3</color> rows"
            }
            ;
            storedData.Skills["backpack.lv2"] = new ZNSkill {
                id = "backpack.lv2", name = "Backpack Lv.2", groupId = "abilities", spCost = 2, permissionEffect = new List<string> {
                    "backpacks.size.24"
                }
                , prerequisiteSkillId = "backpack.lv1", followUpSkillId = "backpack.lv3", description = "Gives you a Backpack with <color=green>4</color> rows"
            }
            ;
            storedData.Skills["backpack.lv3"] = new ZNSkill {
                id = "backpack.lv3", name = "Backpack Lv.3", groupId = "abilities", spCost = 3, permissionEffect = new List<string> {
                    "backpacks.size.30"
                }
                , prerequisiteSkillId = "backpack.lv2", followUpSkillId = "backpack.lv4", description = "Gives you a Backpack with <color=green>5</color> rows"
            }
            ;
            storedData.Skills["backpack.lv4"] = new ZNSkill {
                id = "backpack.lv4", name = "Backpack Lv.4", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "backpacks.size.36"
                }
                , prerequisiteSkillId = "backpack.lv3", followUpSkillId = "backpack.lv5", description = "Gives you a Backpack with <color=green>6</color> rows"
            }
            ;
            storedData.Skills["backpack.lv5"] = new ZNSkill {
                id = "backpack.lv5", name = "Backpack Lv.5", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "backpacks.size.42"
                }
                , prerequisiteSkillId = "backpack.lv4", followUpSkillId = "backpack.lv6", prestigeUnlockId = "pBackpack", description = "Gives you a Backpack with <color=green>7</color> rows"
            }
            ;
            storedData.Skills["backpack.lv6"] = new ZNSkill {
                id = "backpack.lv6", name = "Backpack Lv.6", groupId = "abilities", spCost = 4, permissionEffect = new List<string> {
                    "backpacks.size.48"
                }
                , prerequisiteSkillId = "backpack.lv5", followUpSkillId = "backpack.lv7", prestigeUnlockId = "pBackpack", description = "Gives you a Backpack with <color=green>8</color> rows"
            }
            ;
            storedData.Skills["backpack.lv7"] = new ZNSkill {
                id = "backpack.lv
// ... [Code preview truncated due to length. Full source in attached file] ...

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