Пример #1
0
        public override void Entry(IModHelper helper)
        {
            // Load the monitor
            ModResources.LoadMonitor(this.Monitor);

            // Load assets
            ModResources.LoadAssets(helper, harvestStatuePath);

            // Load our Harmony patches
            try
            {
                harmonyPatch();
            }
            catch (Exception e)
            {
                Monitor.Log($"Issue with Harmony patch: {e}", LogLevel.Error);
                return;
            }

            // Load the config
            this.config = helper.ReadConfig <ModConfig>();

            // Hook into the game launch
            helper.Events.GameLoop.GameLaunched += this.OnGameLaunched;

            // Hook into Player.Warped event so we can spawn some Junimos if the area was recently harvested
            helper.Events.Player.Warped += this.OnWarped;

            // Hook into save related events
            helper.Events.GameLoop.DayStarted += this.OnDayStarted;
        }
    public ModResources()
    {
        modResources = this;
        get          = this;
#pragma warning disable CS4014
        LoadResources(Path.Combine(Application.dataPath, "Modding"), true, Path.Combine(Application.dataPath, "Modding\\Assemblies"), Path.Combine(Application.dataPath, "Modding\\Pictures"));
#pragma warning restore CS4014
    }
Пример #3
0
        public void HarvestCrops(GameLocation location, bool enableHarvestMessage = true, bool doJunimosEatExcessCrops = true, bool doJunimosHarvestFromPots = true, bool doJunimosHarvestFromFruitTrees = true, bool doJunimosHarvestFromFlowers = true, bool doJunimosSowSeedsAfterHarvest = false, int minimumFruitOnTreeBeforeHarvest = 3)
        {
            // Set configs
            this.enableHarvestMessage            = enableHarvestMessage;
            this.doJunimosEatExcessCrops         = doJunimosEatExcessCrops;
            this.doJunimosHarvestFromPots        = doJunimosHarvestFromPots;
            this.doJunimosHarvestFromFruitTrees  = doJunimosHarvestFromFruitTrees;
            this.doJunimosHarvestFromFlowers     = doJunimosHarvestFromFlowers;
            this.doJunimosSowSeedsAfterHarvest   = doJunimosSowSeedsAfterHarvest;
            this.minimumFruitOnTreeBeforeHarvest = minimumFruitOnTreeBeforeHarvest;

            string locationName = ModResources.SplitCamelCaseText(location.Name);

            // Check if we're at capacity and that Junimos aren't allowed to eat excess crops
            if (chest.items.Count >= chest.GetActualCapacity() && !doJunimosEatExcessCrops)
            {
                Game1.showRedMessage($"The Junimos at the {locationName} couldn't harvest due to lack of storage!");
                return;
            }

            // Look and harvest for crops & forage products on the ground
            monitor.Log("Searching for crops and forage products on ground...", LogLevel.Trace);
            SearchForGroundCrops(location);

            // Look and harvest for crops & forage products inside IndoorPots
            if (doJunimosHarvestFromPots)
            {
                monitor.Log("Searching for crops and forage products within Garden Pots...", LogLevel.Trace);
                SearchForIndoorPots(location);
            }

            if (doJunimosHarvestFromFruitTrees)
            {
                monitor.Log("Searching for fruits from Fruit Trees...", LogLevel.Trace);
                SearchForFruitTrees(location);
            }

            if (isFull)
            {
                Game1.showRedMessage($"The Junimos at the {locationName} couldn't harvest due to lack of storage!");
                return;
            }

            // Check if the Junimos ate the crops due to no inventory space
            if (bool.Parse(chest.modData[ModEntry.ateCropsFlag]))
            {
                Game1.showRedMessage($"The Junimos at the {locationName} ate harvested crops due to lack of storage!");
                return;
            }

            if (harvestedToday && enableHarvestMessage)
            {
                // Let the player know we harvested
                Game1.addHUDMessage(new HUDMessage($"The Junimos at the {locationName} have harvested crops.", 2));
                return;
            }
        }
Пример #4
0
        public static void RegisterFamiliars(this GameData data, ModResources resources)
        {
            var petExtensions = resources.LoadAllObjectsWithComponent <PetExt>();

            foreach (var extension in petExtensions)
            {
                data.Familiars.Add(extension);
            }
        }
Пример #5
0
        public static void RegisterStatusEffects(this GameData data, ModResources resources)
        {
            var statusEffects = resources.LoadAllObjectsWithComponent <StatusEffectExt>();

            foreach (var effect in statusEffects)
            {
                data.StatusEffects.Add(effect);
            }
        }
Пример #6
0
        public static void RegisterAll(this GameData data, ModResources resources)
        {
            data.RegisterItems(resources);
            data.RegisterStatusEffects(resources);
            data.RegisterFamiliars(resources);
            data.RegisterLootTables(resources);

            data.RegisterPopups(resources);
        }
Пример #7
0
        public override void Initialize(ModInitializer initializer)
        {
            var modId = initializer.Registry.Mods.Register(ModPath);
//            var modRegistry = modId.Value;
            var surrogate = ModResources.Load <ModSurrogate>(ModPath, "").Values;

            //For now we use a proxy to register
            //Should actually consider following Unity Patterns instead of this.
//            initializer.Registry.Mods.RegistrySurrogates(surrogate);

            initializer.Registry.Raw[modId].RegistrySurrogates(surrogate);

            var matReg    = initializer.Registry.ArrayMaterials;
            var subMatReg = initializer.Registry.SubArrayMaterials;
            var blockReg  = initializer.Registry.Blocks;

            //YEah, this is a cluster, need to think of a better way to orgnaize data
            if (!matReg.TryGetIdentity(GrassDirtMaterialKey, out var grassDirtMaterialId))
            {
                throw new AssetNotFoundException(nameof(GrassDirtMaterialKey), GrassDirtMaterialKey.ToString());
            }

            if (!subMatReg.TryGetValue(GrassSubMaterialKey, out var grassSubMatIndex))
            {
                throw new AssetNotFoundException(nameof(GrassSubMaterialKey), grassSubMatIndex.ToString());
            }
            if (!subMatReg.TryGetValue(GrassSideSubMaterialKey, out var sideSubMatIndex))
            {
                throw new AssetNotFoundException(nameof(GrassSideSubMaterialKey), sideSubMatIndex.ToString());
            }
            if (!subMatReg.TryGetValue(DirtSubMaterialKey, out var dirtSubMatIndex))
            {
                throw new AssetNotFoundException(nameof(DirtSubMaterialKey), dirtSubMatIndex.ToString());
            }

            if (!matReg.TryGetIdentity(StoneMaterialKey, out var stoneMaterialId))
            {
                throw new AssetNotFoundException(nameof(StoneMaterialKey), stoneMaterialId.ToString());
            }
            if (!matReg.TryGetIdentity(SandMaterialKey, out var sandMaterialId))
            {
                throw new AssetNotFoundException(nameof(SandMaterialKey), sandMaterialId.ToString());
            }
            ;
            blockReg.Register(GrassBlock,
                              new TopSideBlockRef(grassDirtMaterialId, grassSubMatIndex, sideSubMatIndex, dirtSubMatIndex));
            blockReg.Register(DirtBlock, new RegularBlockRef(grassDirtMaterialId, dirtSubMatIndex));
            blockReg.Register(StoneBlock, new RegularBlockRef(stoneMaterialId));
            blockReg.Register(SandBlock, new RegularBlockRef(sandMaterialId));
        }
Пример #8
0
        public void Load(string path)
        {
            var directories = Directory.EnumerateDirectories(path).ToList();

            _logger.LogInfo($"Searching {directories.Count} directories at {Path.GetFullPath(path)}.");

            foreach (var directory in directories)
            {
                var mod = LoadMod(directory);
                if (mod != null)
                {
                    _mods.Add(mod.Info.Id, mod);
                }
            }
            Resources = new ModResources(Mods.SelectMany(x => x.Resources.Bundles));

            _logger.LogInfo($"Found {_mods.Count} valid mods.");
        }
Пример #9
0
        public static void RegisterLootTables(this GameData data, ModResources resources)
        {
            var lootTables = resources.LoadAllAssets <LootTable>();

            foreach (var table in lootTables)
            {
                var orig = data.LootTables.FirstOrDefault(x => x.guid == table.guid);
                if (orig == null)
                {
                    data.LootTables.Add(table);
                }
                else
                {
                    if (table.Replace)
                    {
                        orig.Loot.Clear();
                    }
                    orig.Loot.AddRange(table.Loot);
                }
            }
        }
Пример #10
0
 public ExampleMod(ModResources resources) : base(resources)
 {
     Instance = this;
     GameEvents.Register <SetupEvent.Post>(OnSetup);
 }
Пример #11
0
 public Mod(ModResources resources) : this()
 {
     Resources = resources;
 }
Пример #12
0
        public static void RegisterItems(this GameData data, ModResources resources)
        {
            var items             = resources.LoadAllAssets <ItemData>();
            var defaultUnlocked   = data.GetField <List <string> >("mDefaultUnlocked");
            var defaultDiscovered = data.GetField <List <string> >("mDefaultDiscovered");

            foreach (var item in items)
            {
                data.Items.Add(item);

                if ((item.Hint & ItemData.ItemHint.Relic) != 0)
                {
                    data.RelicCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Curse) != 0)
                {
                    data.CurseCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Blessing) != 0)
                {
                    data.BlessingCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Familiar) != 0)
                {
                    data.FamiliarCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Misc) != 0)
                {
                    data.MiscCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Potion) != 0)
                {
                    data.PotionCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Health) != 0)
                {
                    data.HexCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Resource) != 0)
                {
                    data.ResourceItemCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Artifact) != 0)
                {
                    data.ArtifactCollection.Add(item);
                }
                if ((item.Hint & ItemData.ItemHint.Skin) != 0)
                {
                    data.SkinCollection.Add(item);
                }

                if (item.IsDefault)
                {
                    defaultUnlocked.Add(item.guid);
                }
                if (item.IsDefaultDiscovered)
                {
                    defaultDiscovered.Add(item.guid);
                }
            }
        }
Пример #13
0
        public static void RegisterPopups(this GameData data, ModResources resources)
        {
            var popups = resources.LoadAllAssets <Popup>();

            data.Popups.AddRange(popups);
        }