Beispiel #1
0
        public void AfterItemTypesDefined()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Roaming Job Objective Loaded----------------------");
            var i = 0;

            foreach (var s in LoadedAssembalies)
            {
                if (Activator.CreateInstance(s) is IRoamingJobObjective roamingJobObjective &&
                    !string.IsNullOrEmpty(roamingJobObjective.ItemIndex))
                {
                    sb.Append($"{roamingJobObjective.ItemIndex}, ");
                    RoamingJobManager.RegisterObjectiveType(roamingJobObjective);
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #2
0
        public void AfterItemTypesDefined()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Tutorials Loaded----------------------");
            var i = 0;

            foreach (var s in LoadedAssembalies)
            {
                if (Activator.CreateInstance(s) is ITutorial tutorial &&
                    !string.IsNullOrEmpty(tutorial.Name))
                {
                    sb.Append($"{tutorial.Name}, ");
                    TutorialFactory.Tutorials[tutorial.Name] = tutorial;
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #3
0
        public void OnAddResearchables()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Panda Quests Loaded----------------------");
            var i = 0;

            foreach (var quest in LoadedAssembalies)
            {
                if (Activator.CreateInstance(quest) is IPandaQuest pandaQuest &&
                    !(pandaQuest is IPandaQuest) &&
                    !string.IsNullOrEmpty(pandaQuest.QuestKey))
                {
                    sb.Append($"{pandaQuest.QuestKey}, ");
                    Questing.QuestingSystem.QuestPool[pandaQuest.QuestKey] = pandaQuest;
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("------------------------------------------------------");
        }
        public void AfterModsLoaded(List <ModLoader.ModDescription> list)
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Connected Block CalculationType Loaded----------------------");
            var i = 0;

            foreach (var s in LoadedAssembalies)
            {
                if (Activator.CreateInstance(s) is IConnectedBlockCalculationType connectedBlockCalcType &&
                    !string.IsNullOrEmpty(connectedBlockCalcType.name))
                {
                    sb.Append($"{connectedBlockCalcType.name}, ");
                    ConnectedBlockCalculator.CalculationTypes[connectedBlockCalcType.name] = connectedBlockCalcType;
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #5
0
        public void AfterWorldLoad()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Bosses Loaded----------------------");
            var i = 0;

            foreach (var monster in LoadedAssembalies)
            {
                if (Activator.CreateInstance(monster) is IPandaBoss pandaBoss &&
                    !string.IsNullOrEmpty(pandaBoss.name))
                {
                    sb.Append($"{pandaBoss.name}, ");
                    MonsterManager.AddBoss(pandaBoss);
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("------------------------------------------------------");
        }
        public void OnRegisterUpgrades(UpgradesManager upgrades)
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Colony Upgrades Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is IPandaUpgrade upgrade)
                {
                    upgrades.RegisterUpgrade(upgrade);

                    sb.Append($"{upgrade.UniqueKey}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #7
0
        public void AfterWorldLoad()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Panda Zombies Loaded----------------------");
            var i = 0;

            foreach (var monster in LoadedAssembalies)
            {
                if (Activator.CreateInstance(monster) is IPandaZombie pandaZombie &&
                    !(pandaZombie is IPandaBoss) &&
                    !string.IsNullOrEmpty(pandaZombie.name))
                {
                    sb.Append($"{pandaZombie.name}, ");
                    PandaMonsterSpawner.PandaZombies.Add(pandaZombie);
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("------------------------------------------------------");
        }
Beispiel #8
0
        public void AfterSelectedWorld()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Texture Mapping Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ICSTextureMapping texture &&
                    !string.IsNullOrEmpty(texture.name))
                {
                    ItemTypesServer.SetTextureMapping(texture.name, new ItemTypesServer.TextureMapping(texture.JsonSerialize()));
                    sb.Append($"{texture.name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
        public void ColonyCreated(Colony c)
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Happiness Effects Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is IHappinessEffect effect)
                {
                    c.HappinessData.HappinessEffects.Add(effect);
                    sb.Append($"{effect.GetType().Name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
        public void AfterItemTypesDefined()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Recipes Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ICSRecipe recipe &&
                    !string.IsNullOrEmpty(recipe.name))
                {
                    var requirements = new List <InventoryItem>();
                    var results      = new List <RecipeResult>();
                    recipe.JsonSerialize();

                    foreach (var ri in recipe.requires)
                    {
                        if (ItemTypes.IndexLookup.TryGetIndex(ri.type, out var itemIndex))
                        {
                            requirements.Add(new InventoryItem(itemIndex, ri.amount));
                        }
                    }

                    foreach (var ri in recipe.results)
                    {
                        results.Add(ri);
                    }

                    var newRecipe = new Recipe(recipe.name, requirements, results, recipe.defaultLimit, 0, (int)recipe.defaultPriority);

                    ServerManager.RecipeStorage.AddLimitTypeRecipe(recipe.Job, newRecipe);

                    if (recipe.JobBlock != null && recipe.JobBlock.Count != 0)
                    {
                        foreach (var block in recipe.JobBlock)
                        {
                            if (!ServerManager.RecipeStorage.BlockNameToLimitTypeMapping.ContainsKey(block))
                            {
                                ServerManager.RecipeStorage.AddBlockToRecipeMapping(block, recipe.Job);
                            }
                        }
                    }

                    sb.Append($"{recipe.name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #11
0
        public void OnAddResearchables()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Research Loaded----------------------");
            var i = 0;

            foreach (var s in LoadedAssembalies)
            {
                if (Activator.CreateInstance(s) is IPandaResearch pandaResearch &&
                    !string.IsNullOrEmpty(pandaResearch.name))
                {
                    sb.Append(pandaResearch.name + ", ");
                    pandaResearch.BeforeRegister();

                    for (var l = 1; l <= pandaResearch.NumberOfLevels; l++)
                    {
                        var research = new PandaResearchable(pandaResearch, l);
                        research.ResearchComplete += pandaResearch.ResearchComplete;

                        foreach (var item in research.Recipes)
                        {
                            if (item.UnlockType == Science.ERecipeUnlockType.Recipe)
                            {
                                if (ServerManager.RecipeStorage.TryGetRecipe(new Recipes.RecipeKey(item.Identifier), out var recipe))
                                {
                                    ServerManager.RecipeStorage.AddScienceRequirement(recipe);
                                }
                            }
                            else
                            {
                                if (ServerManager.RecipeStorage.TryGetRecipes(item.Identifier, out var recipe))
                                {
                                    for (int r = 0; r < recipe.Count; r++)
                                    {
                                        ServerManager.RecipeStorage.AddScienceRequirement(recipe[r]);
                                    }
                                }
                            }
                        }

                        research.Register();
                    }

                    pandaResearch.OnRegister();
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
        public PandaResearchable(IPandaResearch pandaResearch, int currentLevel)
        {
            Conditions    = new List <IResearchableCondition>();
            RecipeUnlocks = new List <RecipeUnlock>();
            Dependencies  = new List <string>();

            try
            {
                List <IResearchableCondition> researchableConditions;

                if (pandaResearch.Conditions != null && (pandaResearch.Conditions.TryGetValue(currentLevel, out researchableConditions) || pandaResearch.Conditions.TryGetValue(0, out researchableConditions)))
                {
                    Conditions.AddRange(researchableConditions);
                }

                List <string> dependancies = null;

                if (pandaResearch.Dependancies != null && !pandaResearch.Dependancies.TryGetValue(currentLevel, out dependancies))
                {
                    pandaResearch.Dependancies.TryGetValue(0, out dependancies);
                }

                Initialize(currentLevel, pandaResearch.name, pandaResearch.BaseValue, pandaResearch.IconDirectory, dependancies, pandaResearch.BaseIterationCount, pandaResearch.AddLevelToName);

                List <InventoryItem> inventoryItems;

                if (pandaResearch.RequiredItems != null && (pandaResearch.RequiredItems.TryGetValue(currentLevel, out inventoryItems) || pandaResearch.RequiredItems.TryGetValue(0, out inventoryItems)))
                {
                    AddCraftingCondition(inventoryItems, currentLevel);
                }

                List <RecipeUnlock> listUnlocks;
                if (pandaResearch.Unlocks != null && (pandaResearch.Unlocks.TryGetValue(currentLevel, out listUnlocks) || pandaResearch.Unlocks.TryGetValue(0, out listUnlocks)))
                {
                    RecipeUnlocks.AddRange(listUnlocks);
                }

                Register(currentLevel, pandaResearch.name);
            }
            catch (NullReferenceException nullRef)
            {
                APILogger.LogToFile(nullRef.StackTrace);
                APILogger.LogToFile(nullRef.Message);
                APILogger.LogError(nullRef);
            }
            catch (Exception ex)
            {
                APILogger.LogError(ex);
            }
        }
        public void AfterItemTypesDefined()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Player Recipes Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ICSPlayerRecipe recipe &&
                    !string.IsNullOrEmpty(recipe.name))
                {
                    var requirements = new List <InventoryItem>();
                    var results      = new List <RecipeResult>();
                    recipe.JsonSerialize();

                    foreach (var ri in recipe.requires)
                    {
                        if (ItemTypes.IndexLookup.TryGetIndex(ri.type, out var itemIndex))
                        {
                            requirements.Add(new InventoryItem(itemIndex, ri.amount));
                        }
                    }

                    foreach (var ri in recipe.results)
                    {
                        results.Add(ri);
                    }

                    var newRecipe = new Recipe(recipe.name, requirements, results);

                    ServerManager.RecipeStorage.AddPlayerRecipe(newRecipe);

                    sb.Append($"{recipe.name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #14
0
        public static void AfterItemTypesDefined()
        {
            APILogger.Log("{0} objective types loaded", ObjectiveCallbacks.Count);

            foreach (var cKvp in _loadedColonies)
            {
                var c = cKvp.Key;
                var n = cKvp.Value;

                if (n.TryGetChild(GameInitializer.NAMESPACE + ".Objectives", out var objectivesNode))
                {
                    lock (Objectives)
                    {
                        int countLoaded = 0;
                        foreach (var node in objectivesNode.LoopArray())
                        {
                            try
                            {
                                RegisterRoamingJobState(c, new RoamingJobState(node, c));
                                countLoaded++;
                            }
                            catch (Exception ex)
                            {
                                APILogger.LogError(ex, node.ToString());
                            }
                        }

                        if (Objectives.ContainsKey(c))
                        {
                            APILogger.LogToFile($"{countLoaded} of {Objectives[c].Count} objectives loaded from save for {c.ColonyID}!");
                        }
                        else
                        {
                            APILogger.LogToFile($"No objectives found in save for {c.ColonyID}.");
                        }
                    }
                }
                else
                {
                    APILogger.LogToFile($"No objectives found in save for {c.ColonyID}.");
                }
            }
        }
Beispiel #15
0
        public void OnAddResearchables()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Research Loaded----------------------");
            var i = 0;

            foreach (var s in LoadedAssembalies)
            {
                if (Activator.CreateInstance(s) is IPandaResearch pandaResearch &&
                    !string.IsNullOrEmpty(pandaResearch.name))
                {
                    var research = new PandaResearchable(pandaResearch, 1);
                    research.ResearchComplete += pandaResearch.ResearchComplete;

                    if (pandaResearch.NumberOfLevels > 1)
                    {
                        for (var l = 2; l <= pandaResearch.NumberOfLevels; l++)
                        {
                            research = new PandaResearchable(pandaResearch, l);
                            research.ResearchComplete += pandaResearch.ResearchComplete;
                        }
                    }

                    sb.Append(pandaResearch.name + ", ");
                    pandaResearch.OnRegister();
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
        public void AfterSelectedWorld()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Generate Type Loaded----------------------");
            var i = 0;
            List <ICSGenerateType> json = new List <ICSGenerateType>();

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ICSGenerateType generateType &&
                    !string.IsNullOrEmpty(generateType.typeName))
                {
                    json.Add(generateType);

                    sb.Append($"{generateType.typeName}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            if (json.Count != 0)
            {
                var strValue = JsonConvert.SerializeObject(json, Formatting.None, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                APILogger.LogToFile(strValue);
                ItemTypesServer.BlockRotator.Patches.AddPatch(new ItemTypesServer.BlockRotator.BlockGeneratePatch(GameInitializer.MOD_FOLDER, -99999, JSON.DeserializeString(strValue)));
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
        public void AfterModsLoaded(List <ModLoader.ModDescription> list)
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Guard Settings Loaded----------------------");
            var i = 0;
            List <ICSGuardJobSettings> json = new List <ICSGuardJobSettings>();

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ICSGuardJobSettings generateType &&
                    !string.IsNullOrEmpty(generateType.jobType))
                {
                    json.Add(generateType);

                    sb.Append($"{generateType.jobType}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            if (json.Count != 0)
            {
                var strValue = JsonConvert.SerializeObject(json, Formatting.None, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                APILogger.LogToFile(strValue);
                BlockJobLoader.BlockJobPatches.AddPatch(new BlockJobLoader.BlockJobPatch(-99999, JSON.DeserializeString(strValue)));
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
Beispiel #18
0
        public void AfterWorldLoad()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Loot Tables Loaded----------------------");
            var i = 0;

            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is ILootTable lootTable)
                {
                    foreach (var table in lootTable.MonsterTypes)
                    {
                        if (LootTables.Lookup.TryGetValue(table, out var existingTable))
                        {
                            existingTable.LootPoolList.AddRange(existingTable.LootPoolList);
                        }
                        else
                        {
                            LootTables.Lookup[table] = lootTable;
                        }
                    }

                    sb.Append($"{lootTable.name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }
 private void Register(int currentLevel, string name)
 {
     ServerManager.ScienceManager.RegisterResearchable(this);
     APILogger.LogToFile($"PandaResearch Added: {name} Level {currentLevel}");
 }
Beispiel #20
0
        public PandaResearchable(IPandaResearch pandaResearch, int currentLevel)
        {
            Conditions              = new List <IResearchableCondition>();
            RecipeUnlocks           = new List <RecipeUnlock>();
            Dependencies            = new List <string>();
            AdditionalClientUnlocks = new List <RecipeUnlockClient>();

            try
            {
                List <IResearchableCondition> researchableConditions;

                if (pandaResearch.Conditions != null && (pandaResearch.Conditions.TryGetValue(currentLevel, out researchableConditions) || pandaResearch.Conditions.TryGetValue(0, out researchableConditions)))
                {
                    foreach (var condition in researchableConditions)
                    {
                        if (condition is HappinessCondition happinessCondition)
                        {
                            if (ServerManager.WorldSettingsReadOnly.EnableHappiness)
                            {
                                Conditions.Add(condition);
                            }
                        }
                        else
                        {
                            Conditions.Add(condition);
                        }
                    }
                }

                List <string> dependancies = null;

                if (pandaResearch.Dependancies != null && !pandaResearch.Dependancies.TryGetValue(currentLevel, out dependancies))
                {
                    pandaResearch.Dependancies.TryGetValue(0, out dependancies);
                }

                Initialize(currentLevel, pandaResearch.name, pandaResearch.BaseValue, pandaResearch.IconDirectory, dependancies, pandaResearch.BaseIterationCount, pandaResearch.AddLevelToName);

                List <InventoryItem> inventoryItems;

                if (pandaResearch.RequiredItems != null && (pandaResearch.RequiredItems.TryGetValue(currentLevel, out inventoryItems) || pandaResearch.RequiredItems.TryGetValue(0, out inventoryItems)))
                {
                    AddCraftingCondition(inventoryItems, currentLevel);
                }

                List <RecipeUnlock> listUnlocks;
                if (pandaResearch.Unlocks != null && (pandaResearch.Unlocks.TryGetValue(currentLevel, out listUnlocks) || pandaResearch.Unlocks.TryGetValue(0, out listUnlocks)))
                {
                    RecipeUnlocks.AddRange(listUnlocks);
                }

                List <(string, RecipeUnlockClient.EType)> additionalUnlocks;
                if (pandaResearch.AdditionalUnlocks != null && (pandaResearch.AdditionalUnlocks.TryGetValue(currentLevel, out additionalUnlocks) || pandaResearch.AdditionalUnlocks.TryGetValue(0, out additionalUnlocks)))
                {
                    AdditionalClientUnlocks.AddRange(additionalUnlocks.Select(tuple =>
                    {
                        if (tuple.Item2 == RecipeUnlockClient.EType.Recipe)
                        {
                            return(new RecipeUnlockClient
                            {
                                Payload = new Recipes.RecipeKey(tuple.Item1).Index,
                                UnlockType = tuple.Item2
                            });
                        }
                        else if (tuple.Item2 == RecipeUnlockClient.EType.NPCType)
                        {
                            return(new RecipeUnlockClient
                            {
                                Payload = NPC.NPCType.GetByKeyNameOrDefault(tuple.Item1).Type,
                                UnlockType = tuple.Item2
                            });
                        }
                        else
                        {
                            throw new ArgumentOutOfRangeException("type", tuple.Item2, "unexpected recipe unlock type");
                        }
                    }));
                }

                APILogger.LogToFile($"PandaResearch Added: {pandaResearch.name} Level {currentLevel}");
            }
            catch (NullReferenceException nullRef)
            {
                APILogger.LogToFile(nullRef.StackTrace);
                APILogger.LogToFile(nullRef.Message);
                APILogger.LogError(nullRef);
            }
            catch (Exception ex)
            {
                APILogger.LogError(ex);
            }
        }
        private static void LoadImplementation(List <ModLoader.ModDescription> list)
        {
            foreach (var mod in list.Where(m => m.HasAssembly && !string.IsNullOrEmpty(m.assemblyPath) && !m.assemblyPath.Contains("Pipliz\\modInfo.json")))
            {
                try
                {
                    // Get all Types available in the assembly in an array
                    var typeArray = mod.LoadedAssembly.GetTypes();

                    // Walk through each Type and list their Information
                    foreach (var type in typeArray)
                    {
                        var ifaces = type.GetInterfaces();

                        foreach (var iface in ifaces)
                        {
                            foreach (var vals in _settlersExtensions.Values)
                            {
                                foreach (var e in vals)
                                {
                                    if (!string.IsNullOrEmpty(e.InterfaceName) && e.InterfaceName == iface.Name && !type.IsInterface)
                                    {
                                        var constructor = type.GetConstructor(Type.EmptyTypes);

                                        if (constructor != null)
                                        {
                                            e.LoadedAssembalies.Add(type);
                                        }
                                        else
                                        {
                                            APILogger.LogToFile("Warning: No empty constructor for " + type.Name);
                                        }
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(iface.Name) && nameof(IOnTimedUpdate) == iface.Name && !type.IsInterface)
                            {
                                var constructor = type.GetConstructor(Type.EmptyTypes);

                                if (constructor != null && Activator.CreateInstance(type) is IOnTimedUpdate onUpdateCallback)
                                {
                                    APILogger.LogToFile("OnTimedUpdateLoaded: {0}", onUpdateCallback.GetType().Name);
                                    _timedUpdate.Add(onUpdateCallback);
                                }
                            }
                        }

                        foreach (var vals in _settlersExtensions.Values)
                        {
                            foreach (var e in vals)
                            {
                                if (e.ClassType != null && type.Equals(e.ClassType))
                                {
                                    e.LoadedAssembalies.Add(type);
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // Do not log it is not the correct type.
                }
            }
        }
Beispiel #22
0
        public void AfterWorldLoad()
        {
            StringBuilder sb = new StringBuilder();

            APILogger.LogToFile("-------------------Armor Loaded----------------------");
            var           i      = 0;
            List <IArmor> armors = new List <IArmor>();


            foreach (var item in LoadedAssembalies)
            {
                if (Activator.CreateInstance(item) is IArmor armor &&
                    !string.IsNullOrEmpty(armor.name))
                {
                    armors.Add(armor);
                }
            }

            var settings = GameInitializer.GetJSONSettingPaths(GameInitializer.NAMESPACE + ".CSItems");

            foreach (var modInfo in settings)
            {
                foreach (var path in modInfo.Value)
                {
                    try
                    {
                        var jsonFile = JSON.Deserialize(modInfo.Key + "/" + path);

                        if (jsonFile.NodeType == NodeType.Array && jsonFile.ChildCount > 0)
                        {
                            foreach (var item in jsonFile.LoopArray())
                            {
                                if (item.TryGetAs("Durability", out int durability))
                                {
                                    armors.Add(item.JsonDeerialize <MagicArmor>());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        APILogger.LogError(ex);
                    }
                }
            }

            foreach (var armor in armors)
            {
                if (ItemTypes.IndexLookup.TryGetIndex(armor.name, out var index))
                {
                    ArmorFactory.ArmorLookup[index] = armor;
                    sb.Append($"{armor.name}, ");
                    i++;

                    if (i > 5)
                    {
                        i = 0;
                        sb.AppendLine();
                    }
                }
            }

            APILogger.LogToFile(sb.ToString());
            APILogger.LogToFile("---------------------------------------------------------");
        }