private void UpdateCabinWarps() { foreach (Warp warp in CabinHelper.GetCabinsOutsides().Where(x => x.tileX.Value <= -10000).SelectMany(x => x.indoors.Value.warps)) { var d = CabinHelper.GetDoorPositionOfFirstElevatorBuilding(); warp.TargetX = d.X; warp.TargetY = d.Y; } }
public override void Entry(IModHelper helper) { ElevatorBuildingTexture = helper.Content.Load <Texture2D>("Hotel.png"); //Must be before PatchAll //Harmony patch everything Patch.PatchAll("me.ilyaki.elevator"); //Commands helper.ConsoleCommands.Add("elevator_goto", "Warp to cabin. first arg is name of player", this.Goto); helper.ConsoleCommands.Add("elevator_relocateCabin", "Move cabin off the map and mark it for use by the elevator/hotel. first arg is name of player", this.MoveCabinFarAway); helper.ConsoleCommands.Add("elevator_addCabin", "Builds a cabin outside the map for elevator/hotel", this.AddNewCabin); helper.ConsoleCommands.Add("elevator_bringBackCabin", "Moves a cabin to your location, so it will not be used by the elevator. First arg is name of player", this.BringBackCabin); helper.ConsoleCommands.Add("elevator_makeBuildingHere", "Spawn an elevator building on top of you", (o, e) => { if (Context.IsMainPlayer) { CabinHelper.SpawnElevatorBuilding(); } }); helper.ConsoleCommands.Add("elevator_removeUnusedElevatorCabins", "Remove any empty cabins inside the elevator system.", this.RemoveEmptyElevatorCabins); //Events Helper.Events.GameLoop.DayStarted += (o, e) => UpdateWarpsAndReloadTextures(); Helper.Events.Input.ButtonPressed += (o, e) => { if (e.Button.TryGetKeyboard(out Keys key) && key == Keys.F7) { if (Game1.IsServer) { UpdateWarpsAndReloadTextures(); } else { ReloadTextures(); } } }; Helper.Events.Player.Warped += (o, e) => { if (Game1.player.getTileX() <= -9000) //The door position is a bit to the right of -10000 { //Something broke: this seems to happen when a cabin has been upgraded var d = CabinHelper.GetDoorPositionOfFirstElevatorBuilding(); Game1.player.setTileLocation(new Microsoft.Xna.Framework.Vector2(d.X, d.Y)); } }; }
private void MoveCabinFarAway(string command, string[] args) { if (!Context.IsMainPlayer) { Monitor.Log("You must be the server to do that"); return; } if (args.Length < 1) { return; } string farmerName = args[0]; Monitor.Log($"Attempting to move {farmerName}'s house (very) far away"); foreach (Farmer player in Game1.getAllFarmers()) { if (player.Name.ToLower() == farmerName.ToLower()) { Monitor.Log($"Found a match: {player.Name}, ID={player.UniqueMultiplayerID}"); Building targetBuilding = CabinHelper.FindCabinOutside(player); Cabin cabin = CabinHelper.FindCabinInside(player); if (cabin != null && targetBuilding != null) { targetBuilding.GetType() .GetField("tileX", BindingFlags.Instance | BindingFlags.Public) //tileX is readonly .SetValue(targetBuilding, new NetInt(-10000)); foreach (var warp in cabin.warps) { var d = CabinHelper.GetDoorPositionOfFirstElevatorBuilding(); warp.TargetX = d.X; warp.TargetY = d.Y; } Monitor.Log($"Deleted the house (technically moved it out of bounds)"); return; } else { Monitor.Log("Could not find the cabin"); } } } }