internal static CustomSkillDefinitionLoader Load(string filePath, bool createIfNeeded = true)
        {
            DefinitionFile <List <CustomSkillCategory> > fileDef = null;

            if (!File.Exists(filePath))
            {
                if (createIfNeeded)
                {
                    fileDef = CreateDefaultDataDefinition();

                    var json = JsonConvert.SerializeObject(fileDef, Formatting.Indented);
                    File.WriteAllText(filePath, json);
                }
            }
            else
            {
                var json = File.ReadAllText(filePath);
                fileDef = JsonConvert.DeserializeObject <DefinitionFile <List <CustomSkillCategory> > >(json);
            }

            //convert file def into a customskillmanager...
            var mgr = new CustomSkillDefinitionLoader(fileDef.Data);

            return(mgr);
        }
Exemplo n.º 2
0
        private void SkillListSubCommand(TSPlayer player, string categoryName = null)
        {
            CustomSkillCategory category = null;

            if (!string.IsNullOrWhiteSpace(categoryName))
            {
                category = CustomSkillDefinitionLoader.TryGetCategory(categoryName);

                if (category != null)
                {
                    //const int itemsPerPage = 4;

                    //var lines = category.Select(d => d.Value.Name).ToList();
                    //var pageCount = lines.PageCount(itemsPerPage);

                    //if (pageNumber < 1 || pageNumber > pageCount)
                    //	pageNumber = 1;

                    //var page = lines.GetPage(pageNumber - 1, itemsPerPage);//we display based off of 1

                    //player.SendInfoMessage($"Page #{pageNumber} of {pageCount}.");

                    //foreach (var l in page)
                    //{
                    //	player.SendInfoMessage(l);
                    //}

                    //player.SendMessage("Use /bank bal <page> or /bank bal <currency> to see more.", Color.Green);
                    //player.SendInfoMessage("Use /bank bal <page> or /bank bal <currency> to see more.");

                    foreach (var kvp in category)
                    {
                        player.SendInfoMessage(kvp.Value.Name);
                    }
                }
                else
                {
                    player.SendErrorMessage($"No such category as '{categoryName}'.");
                    return;
                }
            }
            else
            {
                category = CustomSkillDefinitionLoader.TryGetCategory(null);

                foreach (var def in category.Values)
                {
                    player.SendInfoMessage(def.Name);
                }
            }
        }
        private void OnLoad()
        {
            var cfg      = Config.Instance = JsonConfig.LoadOrCreate <Config>(this, ConfigPath);
            var dbConfig = cfg.DatabaseConfig;

            SessionRepository = SessionDatabaseFactory.LoadOrCreateDatabase(dbConfig.DatabaseType, dbConfig.ConnectionString);

            CustomSkillDefinitionLoader = CustomSkillDefinitionLoader.Load(Path.Combine(DataDirectory, cfg.DefinitionFilepath), cfg.AutoCreateDefinitionFile);
            CustomSkillRunner           = new CustomSkillRunner();

            //connected players need sessions regenerated, in case this was a reload
            foreach (var player in TShock.Players)
            {
                if (player?.Active == true)
                {
                    var session = Session.GetOrCreateSession(player);
                    //... may not need to actually do anything here
                }
            }
        }
Exemplo n.º 4
0
        private bool GetCategoryAndSkill(TSPlayer player, string skillName, string categoryName, out CustomSkillCategory category, out CustomSkillDefinition skillDef)
        {
            category = null;
            skillDef = null;

            if (string.IsNullOrWhiteSpace(skillName))
            {
                player.SendErrorMessage("Expected skill name.");
                player.SendSyntaxMessage(SyntaxSkillSub);
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(categoryName))
            {
                category = CustomSkillDefinitionLoader.TryGetCategory(categoryName);
            }
            else
            {
                category = CustomSkillDefinitionLoader.TryGetCategory();                //get default "uncategorized" category...
            }
            if (category == null)
            {
                player.SendErrorMessage($"No such category '{categoryName}'.");
                return(false);
            }

            category.TryGetValue(skillName, out skillDef);

            if (skillDef == null)
            {
                player.SendErrorMessage($"No such skill as '{skillName}'.");
                return(false);
            }

            return(true);
        }