Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using Storm;
- using Storm.StardewValley.Accessor;
- using Storm.StardewValley.Event;
- using Storm.StardewValley.Wrapper;
- using Storm.ExternalEvent;
- using xTile;
- /* Advize's Farm Extension Mod (Storm API) source code*/
- namespace FarmExtension
- {
- [Mod]
- public class FarmExtension : DiskResource
- {
- /*[Subscribe]
- public void Init(InitializeEvent e)
- {
- Logging.DebugLog.Invoke("FarmExtension has loaded successfully.");
- }*/
- [Subscribe]
- public void postGameLoaded(PostGameLoadedEvent e)
- {
- Logging.DebugLog.Invoke("There are currently " + e.Root.Locations.Count + " locations loaded"); //Remove later
- Logging.DebugLog.Invoke("Attempting to add and load custom map...");
- for (int i = 0; i <= e.Root.Locations.Count - 1; i++)
- {
- GameLocation currentLocation = e.Root.Locations[i];
- if (currentLocation.Name == "FarmExtension")
- {
- Logging.DebugLog.Invoke("Map name is in use. Map will not be added.");
- return;
- }
- }
- if (e.Root.Locations.Count < 47)
- {
- Logging.DebugLog.Invoke("Default game locations have not yet loaded for some reason. No new maps have been added.");
- return;
- }
- Uri assetPath = new Uri(Path.Combine(PathOnDisk, "FarmExtension"), UriKind.Absolute);
- Uri execPath = new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
- string relativeAssetPath = "Mods/" + execPath.MakeRelativeUri(assetPath).ToString();
- Map map = e.Root.Content.Load<Map>(relativeAssetPath);
- GameLocation workingMap;
- workingMap = e.Root.Locations[e.Root.Locations.Count - 1];
- workingMap.Name = "FarmExtension";
- List<Warp> warps = new List<Warp>();
- warps.Add(new Warp(40, -1, "Farm", 3, 21, false));
- warps.Add(new Warp(41, -1, "Farm", 4, 21, false));
- workingMap.Cast<GameLocationAccessor>()._SetWarps(warps);
- workingMap.Cast<GameLocationAccessor>()._SetIsOutdoors(true);
- workingMap.Cast<GameLocationAccessor>()._SetIsFarm(true);
- workingMap.Cast<GameLocationAccessor>()._SetMap(map);
- e.Root.Locations.Add(workingMap);
- List<Warp> warps2 = new List<Warp>();
- workingMap = e.Root.Locations[1];
- //warps = (workingMap.Cast<GameLocationAccessor>()._GetWarps()).Cast<Warp>().ToList(); <--- Doesn't work, unfortunately
- warps2.Add(new Warp(3, 22, "FarmExtension", 40, 0, false));
- warps2.Add(new Warp(4, 22, "FarmExtension", 41, 0, false));
- warps2.Add(new Warp(80, 15, "BusStop", 0, 23, false));
- warps2.Add(new Warp(80, 18, "BusStop", 0, 24, false));
- warps2.Add(new Warp(80, 16, "BusStop", 0, 23, false));
- warps2.Add(new Warp(80, 17, "BusStop", 0, 23, false));
- warps2.Add(new Warp(40, 65, "Forest", 68, 0, false));
- warps2.Add(new Warp(41, 65, "Forest", 68, 0, false));
- warps2.Add(new Warp(42, 65, "Forest", 68, 0, false));
- warps2.Add(new Warp(40, -1, "Backwoods", 14, 39, false));
- warps2.Add(new Warp(41, -1, "Backwoods", 14, 39, false));
- warps2.Add(new Warp(34, 5, "FarmCave", 8, 11, false));
- workingMap.Cast<GameLocationAccessor>()._SetWarps(warps2);
- Logging.DebugLog.Invoke("Custom map 'FarmExtension' loaded as the " + e.Root.Locations.Count + " game location index");
- }
- public class Warp
- {
- private int x;
- private int y;
- private int targetX;
- private int targetY;
- public bool flipFarmer;
- private string targetName;
- public Warp(int x, int y, string targetName, int targetX, int targetY, bool flipFarmer)
- {
- this.x = x;
- this.y = y;
- this.targetX = targetX;
- this.targetY = targetY;
- this.targetName = targetName;
- this.flipFarmer = flipFarmer;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement