コード例 #1
0
        public override void Start(ICoreAPI api)
        {
            base.Start(api);

            api.RegisterItemClass("ProgCard", typeof(ItemProgCard));
            api.RegisterItemClass("ItemDeployBot", typeof(ItemDeployBot));

            api.RegisterEntityBehaviorClass("program", typeof(EntityBehaviorProgram));

            api.RegisterEntity("EntityReprogLocust", typeof(EntityReprogLocust));

            AiTaskRegistry.Register <AiTaskHarvest>("harvest");
            AiTaskRegistry.Register <AiTaskSeekItem>("seekitem");
            AiTaskRegistry.Register <AiTaskToChest>("tochest");
            AiTaskRegistry.Register <AiTaskFromChest>("fromchest");
            AiTaskRegistry.Register <AiTaskPlant>("plant");
            AiTaskRegistry.Register <AiTaskSqueezeHoney>("squeezehoney");
            AiTaskRegistry.Register <AiTaskMilk>("milk");
            AiTaskRegistry.Register <AiTaskToBarrel>("tobarrel");
            AiTaskRegistry.Register <AiTaskGetSeed>("getseed");
            AiTaskRegistry.Register <AiTaskSeekItemAny>("seekanyitem");
            AiTaskRegistry.Register <AiTaskGetFuel>("getfuel");
            AiTaskRegistry.Register <AiTaskRefuel>("refuel");
            AiTaskRegistry.Register <AiTaskRepair>("repair");
            AiTaskRegistry.Register <AiTaskProgSeekEntity>("progseekentity");
            AiTaskRegistry.Register <AiTaskProgMeleeAttack>("progmeleeattack");
            AiTaskRegistry.Register <AiTaskQuarry>("quarry");
            AiTaskRegistry.Register <AiTaskStayCloseToOwner>("stayclosetoowner");
            AiTaskRegistry.Register <AiTaskPathBuilder>("pathbuilder");
            AiTaskRegistry.Register <AiTaskToAltChest>("toaltchest");
            AiTaskRegistry.Register <AiTaskProgRangedAttack>("prograngedattack");
            AiTaskRegistry.Register <AiTaskForm>("form");
            AiTaskRegistry.Register <AiTaskToPoint>("topoint");
            AiTaskRegistry.Register <AiTaskGetItem>("getitem");
            AiTaskRegistry.Register <AiTaskAnyFromChest>("anyfromchest");
            AiTaskRegistry.Register <AiTaskGetTool>("gettool");

            try
            {
                TemporalHackerConfig FromDisk;
                if ((FromDisk = api.LoadModConfig <TemporalHackerConfig>("TemporalHackerConfig.json")) == null)
                {
                    api.StoreModConfig <TemporalHackerConfig>(TemporalHackerConfig.Loaded, "TemporalHackerConfig.json");
                }
                else
                {
                    TemporalHackerConfig.Loaded = FromDisk;
                }
            }
            catch
            {
                api.StoreModConfig <TemporalHackerConfig>(TemporalHackerConfig.Loaded, "TemporalHackerConfig.json");
            }
        }
コード例 #2
0
ファイル: ApiExtensions.cs プロジェクト: p3t3rix/VsFoundation
        public static TModConfig LoadOrCreateConfig <TModConfig>(this ICoreAPI api, string filename, bool required) where TModConfig : ModConfigBase, new()
        {
            var modCode = filename.Split('.').First();

            try
            {
                var loadedConfig = api.LoadModConfig <TModConfig>(filename);
                if (loadedConfig != null)
                {
                    return(loadedConfig);
                }
            }
            catch (Exception e)
            {
                api.World.Logger.Error($"{modCode}: Failed loading modconfig file at 'ModConfig/{filename}', with an error of '{e}'! Stopping...");
                return(null);
            }

            var message = $"{modCode}: non-existant modconfig at 'ModConfig/{filename}', creating default" + (required ? " and disabling mod..." : "...");

            api.World.Logger.Notification(message);

            var newConfig = new TModConfig();

            api.StoreModConfig(newConfig, filename);

            return(required ? null : newConfig);
        }
コード例 #3
0
ファイル: ApiExtensions.cs プロジェクト: p3t3rix/VsFoundation
        public static void SaveConfig <TModConfig>(this ICoreAPI api, TModConfig config) where TModConfig : ModConfigBase
        {
            var filename = config.ModCode;

            if (string.IsNullOrEmpty(filename))
            {
                filename = ModConfigBase.GetModCode(config);
            }
            if (!filename.EndsWith(".json"))
            {
                filename += ".json";
            }

            api.World.Logger.Notification($"Saving modconfig at 'ModConfig/{filename}'...");

            api.StoreModConfig(config, filename);
        }
コード例 #4
0
        public void Save(ICoreAPI api, string filename = default)
        {
            if (string.IsNullOrEmpty(filename))
            {
                filename = this.ModCode;
            }
            if (string.IsNullOrEmpty(filename))
            {
                filename = ModConfigBase.GetModCode(this);
            }
            if (!filename.EndsWith(".json"))
            {
                filename += ".json";
            }

            api.World.Logger.Notification($"Saving modconfig at 'ModConfig/{filename}'...");

            api.StoreModConfig(this, filename);
        }
コード例 #5
0
        public static T LoadOrCreateConf <T>(this ICoreAPI serverApi, string filename) where T : new()
        {
            try
            {
                var loadedConf = serverApi.LoadModConfig <T>(filename);
                if (loadedConf != null)
                {
                    return(loadedConf);
                }
            }
            catch (Exception e)
            {
                serverApi.Logger.Error($"Failed to loading config {filename} with error {e}. Initialize new...");
            }
            var newConf = new T();

            serverApi.StoreModConfig(newConf, filename);
            serverApi.Logger.Warning($"Created new {filename} config.");
            return(newConf);
        }
コード例 #6
0
        public override void Start(ICoreAPI api)
        {
            base.Start(api);
            this.api = api;

            api.Logger.StoryEvent("[Tailor] Hello world!");

            // register network channel and message types
            api.Network.RegisterChannel("tailor")
            .RegisterMessageType(typeof(NetworkApiTailorRequest))
            .RegisterMessageType(typeof(NetworkApiTailorResponse))
            ;

            // load config file or write it with defaults
            config = api.LoadModConfig <ModConfig>("TailorConfig.json");
            if (config == null)
            {
                config = new ModConfig();
                api.StoreModConfig(config, "TailorConfig.json");
            }

            api.RegisterItemClass("boneneedle", typeof(BoneNeedleItem));
        }
コード例 #7
0
        public static TConfig LoadOrCreateConfig <TConfig>(this ICoreAPI api, string file, TConfig defaultConfig = null) where TConfig : class, new()
        {
            TConfig config = null;

            try
            {
                config = api.LoadModConfig <TConfig>(file);
            }
            catch (Exception e)
            {
                string format = "Failed loading config file ({0}), error {1}. Will initialize default config";
                Core.ModLogger.Error(string.Format(format), file, e);
            }

            if (config == null)
            {
                Core.ModLogger.Notification("Will initialize default config");
                config = defaultConfig ?? new TConfig();
            }

            api.StoreModConfig(config, file);
            return(config);
        }
コード例 #8
0
 public static void Save(ICoreAPI api, ModConfig config)
 {
     api.StoreModConfig(config, filename);
 }
コード例 #9
0
 public override void Dispose()
 {
     api.StoreModConfig <Config>(Config.Current, ConstantsCore.ModId + ".json");
 }
コード例 #10
0
 private void GenerateConfig(ICoreAPI api, MeteoricExpansionConfig previousConfig)
 {
     api.StoreModConfig <MeteoricExpansionConfig>(new MeteoricExpansionConfig(previousConfig), "MeteoricExpansionConfig.json");
 }
コード例 #11
0
 private void GenerateConfig(ICoreAPI api)
 {
     api.StoreModConfig <MeteoricExpansionConfig>(new MeteoricExpansionConfig(), "MeteoricExpansionConfig.json");
 }
コード例 #12
0
 private static void Save(ICoreAPI api, ModConfig config)
 {
     api.StoreModConfig(config, Filename);
 }