Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. using Storm;
  6. using Storm.StardewValley.Accessor;
  7. using Storm.StardewValley.Event;
  8. using Storm.StardewValley.Wrapper;
  9. using Storm.ExternalEvent;
  10. using xTile;
  11.  
  12. /* Advize's Farm Extension Mod (Storm API) source code*/
  13. namespace FarmExtension
  14. {
  15.     [Mod]
  16.     public class FarmExtension : DiskResource
  17.     {
  18.         /*[Subscribe]
  19.         public void Init(InitializeEvent e)
  20.         {
  21.             Logging.DebugLog.Invoke("FarmExtension has loaded successfully.");
  22.         }*/
  23.  
  24.         [Subscribe]
  25.         public void postGameLoaded(PostGameLoadedEvent e)
  26.         {
  27.             Logging.DebugLog.Invoke("There are currently " + e.Root.Locations.Count + " locations loaded"); //Remove later
  28.             Logging.DebugLog.Invoke("Attempting to add and load custom map...");
  29.  
  30.             for (int i = 0; i <= e.Root.Locations.Count - 1; i++)
  31.             {
  32.                 GameLocation currentLocation = e.Root.Locations[i];
  33.                 if (currentLocation.Name == "FarmExtension")
  34.                 {
  35.                     Logging.DebugLog.Invoke("Map name is in use. Map will not be added.");
  36.                     return;
  37.                 }
  38.             }
  39.  
  40.             if (e.Root.Locations.Count < 47)
  41.             {
  42.                 Logging.DebugLog.Invoke("Default game locations have not yet loaded for some reason. No new maps have been added.");
  43.                 return;
  44.             }
  45.  
  46.             Uri assetPath = new Uri(Path.Combine(PathOnDisk, "FarmExtension"), UriKind.Absolute);
  47.             Uri execPath = new Uri(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
  48.             string relativeAssetPath = "Mods/" + execPath.MakeRelativeUri(assetPath).ToString();
  49.  
  50.             Map map = e.Root.Content.Load<Map>(relativeAssetPath);
  51.             GameLocation workingMap;
  52.             workingMap = e.Root.Locations[e.Root.Locations.Count - 1];
  53.             workingMap.Name = "FarmExtension";
  54.             List<Warp> warps = new List<Warp>();
  55.             warps.Add(new Warp(40, -1, "Farm", 3, 21, false));
  56.             warps.Add(new Warp(41, -1, "Farm", 4, 21, false));
  57.  
  58.             workingMap.Cast<GameLocationAccessor>()._SetWarps(warps);
  59.             workingMap.Cast<GameLocationAccessor>()._SetIsOutdoors(true);
  60.             workingMap.Cast<GameLocationAccessor>()._SetIsFarm(true);
  61.             workingMap.Cast<GameLocationAccessor>()._SetMap(map);
  62.  
  63.             e.Root.Locations.Add(workingMap);
  64.             List<Warp> warps2 = new List<Warp>();
  65.             workingMap = e.Root.Locations[1];
  66.            
  67.  
  68.             //warps = (workingMap.Cast<GameLocationAccessor>()._GetWarps()).Cast<Warp>().ToList(); <--- Doesn't work, unfortunately
  69.            
  70.             warps2.Add(new Warp(3, 22, "FarmExtension", 40, 0, false));
  71.             warps2.Add(new Warp(4, 22, "FarmExtension", 41, 0, false));
  72.  
  73.             warps2.Add(new Warp(80, 15, "BusStop", 0, 23, false));
  74.             warps2.Add(new Warp(80, 18, "BusStop", 0, 24, false));
  75.             warps2.Add(new Warp(80, 16, "BusStop", 0, 23, false));
  76.             warps2.Add(new Warp(80, 17, "BusStop", 0, 23, false));
  77.             warps2.Add(new Warp(40, 65, "Forest", 68, 0, false));
  78.             warps2.Add(new Warp(41, 65, "Forest", 68, 0, false));
  79.             warps2.Add(new Warp(42, 65, "Forest", 68, 0, false));
  80.             warps2.Add(new Warp(40, -1, "Backwoods", 14, 39, false));
  81.             warps2.Add(new Warp(41, -1, "Backwoods", 14, 39, false));
  82.             warps2.Add(new Warp(34, 5, "FarmCave", 8, 11, false));
  83.  
  84.            
  85.             workingMap.Cast<GameLocationAccessor>()._SetWarps(warps2);
  86.  
  87.             Logging.DebugLog.Invoke("Custom map 'FarmExtension' loaded as the " + e.Root.Locations.Count + " game location index");
  88.         }
  89.  
  90.         public class Warp
  91.         {
  92.             private int x;
  93.             private int y;
  94.             private int targetX;
  95.             private int targetY;
  96.             public bool flipFarmer;
  97.             private string targetName;
  98.  
  99.             public Warp(int x, int y, string targetName, int targetX, int targetY, bool flipFarmer)
  100.             {
  101.                 this.x = x;
  102.                 this.y = y;
  103.                 this.targetX = targetX;
  104.                 this.targetY = targetY;
  105.                 this.targetName = targetName;
  106.                 this.flipFarmer = flipFarmer;
  107.             }
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement