public void setChangeEventsAfterLoad(DecoratableLocation dec, int whichRoom) { CustomWallsAndFloorsMod.skip = true; if (isFloor) { floorChange = (r, w) => Floor_OnChange(r, w, dec); dec.setFloor((int)((NetFieldBase <int, NetInt>) this.parentSheetIndex), whichRoom, true); dec.floor.OnChange += floorChange; } else { wallChange = (r, w) => WallPaper_OnChange(r, w, dec); dec.setWallpaper((int)((NetFieldBase <int, NetInt>) this.parentSheetIndex), whichRoom, true); dec.wallPaper.OnChange += wallChange; } PyTK.PyUtils.setDelayedAction(500, () => CustomWallsAndFloorsMod.skip = false); if (isFloor) { dec.setFloor((int)((NetFieldBase <int, NetInt>) this.parentSheetIndex), whichRoom, true); } else { dec.setWallpaper((int)((NetFieldBase <int, NetInt>) this.parentSheetIndex), whichRoom, true); } }
static void setMapTileIndexIfOnTileSheet(Map map, DecoratableLocation instance, int x, int y, int index, string layer, int tileSheet, int tileSheetToMatch) { if (map.GetLayer(layer).Tiles[x, y] != null && map.GetLayer(layer).Tiles[x, y].TileSheet.Equals((object)map.TileSheets[tileSheetToMatch])) { instance.setMapTileIndex(x, y, index, layer, tileSheet); } }
//private static void Floor_OnChange(int whichRoom, int which) //{ // GameLocation currentLoc = Game1.currentLocation; // if (currentLoc is DecoratableLocation) // return; // if (!decoratableHosts.ContainsKey(currentLoc.Name)) // { // Logger.Log("No host for " + currentLoc.Name + "!", StardewModdingAPI.LogLevel.Error); // return; // } // DecoratableLocation host = decoratableHosts[currentLoc.Name]; //} //private static void WallPaper_OnChange(int whichRoom, int which) //{ // throw new NotImplementedException(); //} public static GameLocation getClient(DecoratableLocation location) { if (!decoratableHosts.ContainsValue(location)) { return(null); } string nameOfClient = ""; foreach (string name in decoratableHosts.Keys) { if (decoratableHosts[name] == location) { nameOfClient = name; break; } } if (nameOfClient == "") { Logger.Log("Failed to find client of " + location.Name + "!", StardewModdingAPI.LogLevel.Error); return(null); } GameLocation client = Game1.getLocationFromName(nameOfClient); if (client == null) { Logger.Log("No location could be found by the name \"" + nameOfClient + "\"!", StardewModdingAPI.LogLevel.Error); return(null); } return(client); }
private static void removeQueuedFurniture(DecoratableLocation instance, Guid guid) { Farmer player = Game1.player; if (!instance.furniture.ContainsGuid(guid)) { return; } Furniture furniture = instance.furniture[guid]; if (!player.couldInventoryAcceptThisItem((Item)furniture)) { return; } furniture.performRemoveAction(furniture.TileLocation, instance); instance.furniture.Remove(guid); Item result = player.addItemToInventory(furniture); if (result != null) { // Something went very wrong - between the time we checked if the player could accept the item and when we did the placement, the inventory changed. // Drop the furniture on the ground so it isn't lost. Game1.createItemDebris(result, player.position, player.facingDirection); } else { player.CurrentToolIndex = player.getIndexOfInventoryItem(furniture); } instance.localSound("coin"); }
internal static void UpdateFurniture(DecoratableLocation l) { foreach (Furniture f in l.furniture) { f.minutesElapsed(0, l); } }
public static bool Prefix(DecoratableLocation __instance, ref bool __result, int x, int y, Farmer who) { if (Game1.activeClickableMenu != null) { __result = false; return(false); } for (int index1 = __instance.furniture.Count - 1; index1 >= 0; --index1) { Furniture current = __instance.furniture[index1]; if (current.boundingBox.Value.Contains(x, y) && current.clicked(who)) { if (current.flaggedForPickUp && who.couldInventoryAcceptThisItem(current)) { current.flaggedForPickUp.Value = false; current.performRemoveAction(new Vector2(x / Game1.tileSize, y / Game1.tileSize), __instance); Item item = who.addItemToInventory(current); __instance.furniture.RemoveAt(index1); Game1.playSound("coin"); } __result = true; return(false); } } return(true); }
public static bool CanReallyBePlacedHere( this Wallpaper wallpaper, DecoratableLocation location, Vector2 tileLocation) { int x = (int)tileLocation.X; int y = (int)tileLocation.Y; if (wallpaper.isFloor.Value) { List <Rectangle> floors = location.getFloors(); for (int i = 0; i < floors.Count; i++) { if (floors[i].Contains(x, y)) { return(true); } } } else { List <Rectangle> walls = location.getWalls(); for (int j = 0; j < walls.Count; j++) { if (walls[j].Contains(x, y)) { return(true); } } } return(false); }
public DecoratableState(DecoratableLocation location) { this.location = location; WallsData = null; FloorsData = null; wallDictionary = new Dictionary <Rectangle, string>(); floorDictionary = new Dictionary <Rectangle, string>(); }
public static bool IsFloorableOrWallpaperableTile_Prefix(DecoratableLocation __instance, ref bool __result, int x, int y, string layer_name) { if (!ModEntry.config.EnableMod || !ModEntry.floorsWallsDataDict.ContainsKey(__instance.Name)) { return(true); } __result = IsFloorableOrWallpaperableTile(x, y, layer_name, __instance); return(false); }
public static DecoratableState getState(DecoratableLocation location) { if (!states.ContainsKey(location)) { Logger.Log("No state found for " + location.name + "! (" + location.uniqueName + ")"); states[location] = new DecoratableState(location); } return(states[location]); }
internal static bool Prefix(DecoratableLocation __instance) { MapUtilities.FacadeHelper.setWallpaperDefaults(__instance); //if (__instance.Name.StartsWith("DECORHOST_")) //{ //} return(true); }
public static bool getWalls_Prefix(DecoratableLocation __instance, ref List<Rectangle> __result) { if (!__instance.Name.StartsWith("MultipleFloors")) return true; Floor floor = ModEntry.GetFloor(__instance.Name); __result = floor.walls; return false; }
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { if (who == null) { who = Game1.player; } if (who.currentLocation is DecoratableLocation) { Point value = new Point(x / Game1.tileSize, y / Game1.tileSize); DecoratableLocation decoratableLocation = who.currentLocation as DecoratableLocation; if (this.isFloor) { List <Rectangle> floors; if (decoratableLocation is FarmHouse) { floors = FarmHouse.getFloors((decoratableLocation as FarmHouse).upgradeLevel); } else { floors = DecoratableLocation.getFloors(); } for (int i = 0; i < floors.Count; i++) { if (floors[i].Contains(value)) { decoratableLocation.setFloor(this.parentSheetIndex, i, true); Game1.playSound("coin"); return(true); } } } else { List <Rectangle> walls; if (decoratableLocation is FarmHouse) { walls = FarmHouse.getWalls((decoratableLocation as FarmHouse).upgradeLevel); } else { walls = DecoratableLocation.getWalls(); } for (int j = 0; j < walls.Count; j++) { if (walls[j].Contains(value)) { decoratableLocation.setWallpaper(this.parentSheetIndex, j, true); Game1.playSound("coin"); return(true); } } } } return(false); }
internal static bool Prefix(GameLocation location, int x, int y, Farmer who, ref bool __result, Wallpaper __instance) { if (who == null) { who = Game1.player; } if (who.currentLocation is DecoratableLocation) { return(true); } DecoratableLocation host = OtherLocations.FakeDecor.FakeDecorHandler.getHost(who.currentLocation); if (host == null) { return(true); } //We have our host now, so we will instead be using it on that host. Point point = new Point(x / 64, y / 64); if ((bool)((NetFieldBase <bool, NetBool>)__instance.isFloor)) { List <Rectangle> floors = host.getFloors(); for (int whichRoom = 0; whichRoom < floors.Count; ++whichRoom) { if (floors[whichRoom].Contains(point)) { host.setFloor((int)((NetFieldBase <int, NetInt>)__instance.parentSheetIndex), whichRoom, true); host.setFloors(); location.playSound("coin", NetAudio.SoundContext.Default); __result = true; return(false); } } } else { List <Rectangle> walls = host.getWalls(); for (int whichRoom = 0; whichRoom < walls.Count; ++whichRoom) { if (walls[whichRoom].Contains(point)) { host.setWallpaper((int)((NetFieldBase <int, NetInt>)__instance.parentSheetIndex), whichRoom, true); host.setWallpapers(); location.playSound("coin", NetAudio.SoundContext.Default); __result = true; return(false); } } } return(true); }
public static void WallPaper_OnChange1(int whichRoom, int which, DecoratableLocation dec) { setWallsTilesheet(whichRoom, which, dec.map.TileSheets[2], dec); if (savFile.rooms.Find(sr => sr.Location == dec.Name && sr.Room == whichRoom) is SavedRoom sav) { sav.Walls = "na"; } dec.wallPaper.OnChange -= wallReset; }
public static void Floor_OnChange1(int whichRoom, int which, DecoratableLocation dec) { setFloorsTilesheet(whichRoom, which, dec.map.TileSheets[2], dec); if (savFile.rooms.Find(sr => sr.Location == dec.Name && sr.Room == whichRoom) is SavedRoom sav) { sav.Floors = "na"; } dec.floor.OnChange -= floorReset; }
internal static bool Prefix(int which, int whichRoom, bool persist, DecoratableLocation __instance) { //if (!(__instance is FarmHouse)) // return true; if (!persist) { return(true); } List <Rectangle> floors = __instance.getFloors(); if (__instance.floor.Count < floors.Count) { MapUtilities.FacadeHelper.setMissingFloorsToDefault(__instance); } //__instance.floor.SetCountAtLeast(floors.Count); if (whichRoom == -1) { for (int index = 0; index < __instance.floor.Count; ++index) { __instance.floor[index] = which; } } else { if (whichRoom > __instance.floor.Count - 1 || whichRoom >= floors.Count) { return(false); } //FarmHouseState state = FarmHouseStates.getState(__instance as FarmHouse); OtherLocations.DecoratableState state = OtherLocations.DecoratableStates.getState(__instance); if (state.floorDictionary.ContainsKey(floors[whichRoom])) { string roomLabel = state.floorDictionary[floors[whichRoom]]; Logger.Log("Finding all floors for room '" + roomLabel + "'..."); foreach (KeyValuePair <Rectangle, string> floorData in state.floorDictionary) { if (floors.Contains(floorData.Key) && floorData.Value == roomLabel) { Logger.Log(floors.IndexOf(floorData.Key) + " was a part of " + roomLabel); __instance.floor[floors.IndexOf(floorData.Key)] = which; } } } else { __instance.floor[whichRoom] = which; } } return(false); }
private void checkLocation(DecoratableLocation location) { location = (DecoratableLocation)Game1.currentLocation; for (int i = 0; i < location.furniture.Count; i++) { if (location.furniture[i] is TV tv) { location.furniture[i] = new TVIntercept(tv); } } }
private static void AssignDecoratableLocationModData(DecoratableLocation decoratableLocation, string modelName, AlternativeTextureModel textureModel, int variation, bool trackSeason = false) { decoratableLocation.modData["AlternativeTextureOwner"] = textureModel.Owner; decoratableLocation.modData["AlternativeTextureName"] = String.Concat(textureModel.Owner, ".", modelName); if (trackSeason && !String.IsNullOrEmpty(textureModel.Season)) { decoratableLocation.modData["AlternativeTextureSeason"] = Game1.currentSeason; } decoratableLocation.modData["AlternativeTextureVariation"] = variation.ToString(); }
internal static GameLocation GetNewLocation(LocationData data) { string type = data.Type.ToLower(); if (data.Save) { try { if (Helper.Data.ReadSaveData <LocationSaveData>($"{LocationSaveData}") is LocationSaveData saveDataStore && saveDataStore.Locations.ContainsKey(data.Name) && saveDataStore.Locations[data.Name] is string savedata && !string.IsNullOrEmpty(savedata)) { XmlSerializer serializer = null; if (Type.GetType(data.Type) is Type customType) { serializer = new XmlSerializer(customType, ExtraTypes); } else { serializer = new XmlSerializer(typeof(GameLocation), ExtraTypes); } using (StringReader dataReader = new StringReader(savedata)) using (var reader = XmlReader.Create(dataReader, SaveReaderSettings)) if (serializer.Deserialize(reader) is GameLocation savedLocation) { return(savedLocation); } } } catch { } } GameLocation result; switch (type) { case "buildable": result = new BuildableGameLocation(data.MapPath, data.Name); break; case "decoratable": result = new DecoratableLocation(data.MapPath, data.Name); break; case "default": result = new GameLocation(data.MapPath, data.Name); break; default: { if (Type.GetType(data.Type) is Type customType && Activator.CreateInstance(customType, data.MapPath, data.Name) is GameLocation customLocation) { result = customLocation; }
public static void DoSetVisibleWallpaper(int whichRoom, int which, DecoratableLocation location) { GameLocation client = OtherLocations.FakeDecor.FakeDecorHandler.getClient(location); if (client != null) { client.updateMap(); Logger.Log("Found client map to apply wallpaper to: " + client.Name); } else { Logger.Log("No client for " + location.Name); } location.updateMap(); //Gather a list of all the walls in this map List <Rectangle> walls = location.getWalls(); int index = which % 16 + which / 16 * 48; //Report the index of the wallpaper being pasted. Logger.Log("Chosen index " + index + "."); //Get the map for this DecoratableLocation Map map = location.map; Logger.Log("Applying wall rectangle..."); //It's possible that the number of saved wallpapers is greater than the number of walls, so we'll just skip any after we reach the end. if (walls.Count <= whichRoom) { Logger.Log("Wall rectangle exceeded walls count! You can ignore this if the farmhouse just upgraded, or you installed a new farmhouse mod.", StardewModdingAPI.LogLevel.Warn); return; } //Find the region to paste in Rectangle rectangle = walls[whichRoom]; for (int x = rectangle.X; x < rectangle.Right; x++) { for (int y = rectangle.Y; y < rectangle.Bottom; y++) { setWallMapTileIndexForAnyLayer(map, x, y, index); if (client != null) { setWallMapTileIndexForAnyLayer(client.map, x, y, index); } } } return; }
internal static bool Prefix(int which, int whichRoom, bool persist, DecoratableLocation __instance) { if (!(__instance is FarmHouse) || __instance is Cabin) { return(true); } List <Microsoft.Xna.Framework.Rectangle> floors = __instance.getFloors(); if (!persist) { return(true); } if (__instance.floor.Count < floors.Count) { FarmHouseStates.setMissingFloorsToDefault(__instance as FarmHouse); } //__instance.floor.SetCountAtLeast(floors.Count); if (whichRoom == -1) { for (int index = 0; index < __instance.floor.Count; ++index) { __instance.floor[index] = which; } } else { if (whichRoom > __instance.floor.Count - 1 || whichRoom >= floors.Count) { return(false); } if (FarmHouseStates.floorDictionary.ContainsKey(floors[whichRoom])) { string roomLabel = FarmHouseStates.floorDictionary[floors[whichRoom]]; Logger.Log("Finding all floors for room '" + roomLabel + "'..."); foreach (KeyValuePair <Rectangle, string> floorData in FarmHouseStates.floorDictionary) { if (floors.Contains(floorData.Key) && floorData.Value == roomLabel) { Logger.Log(floors.IndexOf(floorData.Key) + " was a part of " + roomLabel); __instance.floor[floors.IndexOf(floorData.Key)] = which; } } } else { __instance.floor[whichRoom] = which; } } return(false); }
public Shed(Map m, string name) : base(m, name) { List<Rectangle> list = DecoratableLocation.getWalls(); while (this.wallPaper.Count < list.Count) { this.wallPaper.Add(0); } list = DecoratableLocation.getFloors(); while (this.floor.Count < list.Count) { this.floor.Add(0); } }
private GameLocation addLocation(MapEdit edit) { GameLocation location; if (edit.type == "Deco") { location = new DecoratableLocation(Path.Combine("Maps", edit.name), edit.name); } else { location = new GameLocation(Path.Combine("Maps", edit.name), edit.name); } if (edit._map.Properties.ContainsKey("Outdoors") && edit._map.Properties["Outdoors"] == "F") { location.IsOutdoors = false; try { location.loadLights(); } catch { } location.IsOutdoors = false; } if (edit._map.Properties.ContainsKey("IsGreenHouse")) { location.IsGreenhouse = true; } if (edit._map.Properties.ContainsKey("IsStructure")) { location.isStructure.Value = true; } if (edit._map.Properties.ContainsKey("IsFarm")) { location.IsFarm = true; } if (!Game1.locations.Contains(location)) { Game1.locations.Add(location); } location.seasonUpdate(Game1.currentSeason); return(location); }
public static bool DecoratableLocation_IsFloorableOrWallpaperableTile_Prefix(DecoratableLocation __instance, int x, int y, ref bool __result) { if (!Config.EnableMod || !(__instance is FarmHouse)) { return(true); } foreach (var room in ModEntry.currentRoomData.Values) { Rectangle rect = new Rectangle(room.startPos.X + 1, room.startPos.Y + 1, (__instance as FarmHouse).GetSpouseRoomWidth(), (__instance as FarmHouse).GetSpouseRoomHeight()); if (rect.Contains(x, y)) { __result = true; return(false); } } return(true); }
static void setMapTileIndexForAnyLayer(Map map, DecoratableLocation instance, int x, int y, int index) { //Logger.Log("Working on tile (" + x + ", " + y + ") on the Back layer..."); if (isTileOnWallsSheet(map, "Back", x, y)) { instance.setMapTileIndex(x, y, getNewTileIndex(map, x, y, "Back", index), "Back", 0); } //Logger.Log("Working on tile (" + x + ", " + y + ") on the Buildings layer..."); if (isTileOnWallsSheet(map, "Buildings", x, y)) { instance.setMapTileIndex(x, y, getNewTileIndex(map, x, y, "Buildings", index), "Buildings", 0); } //Logger.Log("Working on tile (" + x + ", " + y + ") on the Front layer..."); if (isTileOnWallsSheet(map, "Front", x, y)) { instance.setMapTileIndex(x, y, getNewTileIndex(map, x, y, "Front", index), "Front", 0); } }
private void OnSaveLoaded(object sender, SaveLoadedEventArgs e) { if (!Game1.IsMasterGame) { return; } CustomWallpaper.savFile = helper.Data.ReadSaveData <SaveFile>("Platonymous.CustomWallsAndFloors.Data"); if (CustomWallpaper.savFile == null) { CustomWallpaper.savFile = new SaveFile(); } foreach (SavedRoom room in CustomWallpaper.savFile.rooms.Where(r => r.Id == Game1.player.UniqueMultiplayerID)) { try { DecoratableLocation dec = (DecoratableLocation)Game1.getLocationFromName(room.Location); if (room.Walls != "na") { CustomWallpaper walls = new CustomWallpaper(room.Walls, room.WallsNr, false); if (CustomWallpaper.Walls.ContainsKey(room.Walls)) { walls.Texture = CustomWallpaper.Floors[room.Walls]; walls.setChangeEventsAfterLoad(dec, room.Room); } } if (room.Floors != "na") { CustomWallpaper floors = new CustomWallpaper(room.Floors, room.FloorsNr, true); if (CustomWallpaper.Floors.ContainsKey(room.Floors)) { floors.Texture = CustomWallpaper.Floors[room.Floors]; floors.setChangeEventsAfterLoad(dec, room.Room); } } } catch { } } }
public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { if (who == null) { who = Game1.player; } if (who.currentLocation is DecoratableLocation) { Point tile = new Point(x / 64, y / 64); DecoratableLocation farmHouse = who.currentLocation as DecoratableLocation; if ((bool)isFloor) { List <Rectangle> floors = farmHouse.getFloors(); for (int j = 0; j < floors.Count; j++) { if (floors[j].Contains(tile)) { farmHouse.setFloor(parentSheetIndex, j, persist: true); location.playSound("coin"); return(true); } } } else { List <Rectangle> walls = farmHouse.getWalls(); for (int i = 0; i < walls.Count; i++) { Rectangle wall = walls[i]; if (wall.Height == 2) { wall.Height = 3; } if (wall.Contains(tile)) { farmHouse.setWallpaper(parentSheetIndex, i, persist: true); location.playSound("coin"); return(true); } } } } return(false); }
static void setMapTileIndexesInSquare(Map map, Rectangle floor, DecoratableLocation instance, int x, int y, int index) { if (floor.Contains(x, y)) { MapUtilities.MapMerger.setMapTileIndexIfOnTileSheet(map, x, y, index, "Back", MapUtilities.SheetHelper.getTileSheet(map, "walls_and_floors"), new Rectangle(0, 21, 16, 10)); } if (floor.Contains(x + 1, y)) { MapUtilities.MapMerger.setMapTileIndexIfOnTileSheet(map, x + 1, y, index + 1, "Back", MapUtilities.SheetHelper.getTileSheet(map, "walls_and_floors"), new Rectangle(0, 21, 16, 10)); } if (floor.Contains(x, y + 1)) { MapUtilities.MapMerger.setMapTileIndexIfOnTileSheet(map, x, y + 1, index + 16, "Back", MapUtilities.SheetHelper.getTileSheet(map, "walls_and_floors"), new Rectangle(0, 21, 16, 10)); } if (floor.Contains(x + 1, y + 1)) { MapUtilities.MapMerger.setMapTileIndexIfOnTileSheet(map, x + 1, y + 1, index + 17, "Back", MapUtilities.SheetHelper.getTileSheet(map, "walls_and_floors"), new Rectangle(0, 21, 16, 10)); } }
public static void Postfix(ref List <Rectangle> __result, DecoratableLocation __instance) { __result.Clear(); OtherLocations.DecoratableState state = OtherLocations.DecoratableStates.getState(__instance); __result = state.getFloors(); if (__result.Count > 0) { return; } else { __result = new List <Rectangle>() { new Rectangle(1, 3, 11, 11) }; } }