示例#1
0
        private void Goto(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 warp to {farmerName}'s house");

            foreach (Farmer player in Game1.getAllFarmers())
            {
                if (player.Name.ToLower() == farmerName.ToLower())
                {
                    Console.WriteLine($"Found a match: {player.Name}, ID={player.UniqueMultiplayerID}");
                    Cabin cabin = CabinHelper.FindCabinInside(player);

                    Game1.warpFarmer(cabin.uniqueName.Value, cabin.warps[0].X, cabin.warps[0].Y - 1, 0);                    //Does this work when the cabin is upgraded?
                    return;
                }
            }
        }
示例#2
0
        private void RemoveEmptyElevatorCabins(string command, string[] args)
        {
            if (!Context.IsMainPlayer)
            {
                Monitor.Log("You must be the server to do that");
                return;
            }

            var toRemove = new List <Building>();

            foreach (Cabin cabin in CabinHelper.GetCabinsInsides())
            {
                if (cabin.getFarmhand().Value.Name.Length == 0)
                {
                    toRemove.Add(CabinHelper.FindCabinOutside(cabin.getFarmhand()));
                }
            }

            foreach (Building building in toRemove)
            {
                Game1.getFarm().buildings.Remove(building);
            }

            Monitor.Log($"Removed {toRemove.Count} unused cabins");
        }
示例#3
0
        public static bool Prefix(Vector2 tileLocation, Farmer who, NetPoint ___humanDoor, NetInt ___tileX, NetInt ___tileY, Building __instance)
        {
            int doorWidth = 2;
            int xDist     = (int)tileLocation.X - (___humanDoor.X + ___tileX.Value);

            if (who.IsLocalPlayer && CabinHelper.IsElevatorBuilding(__instance) &&
                xDist < doorWidth && xDist >= 0 && tileLocation.Y == ___humanDoor.Y + ___tileY.Value)
            {
                if (who.mount != null)
                {
                    Game1.showRedMessage(Game1.content.LoadString("Strings\\Buildings:DismountBeforeEntering"));
                    return(false);
                }
                if (who.team.buildLock.IsLocked())
                {
                    Game1.showRedMessage(Game1.content.LoadString("Strings\\Buildings:CantEnter"));
                    return(false);
                }

                //indoors.Value.isStructure.Value = true;

                who.currentLocation.playSoundAt("crystal", tileLocation);

                if (Game1.activeClickableMenu == null)
                {
                    Game1.activeClickableMenu = new ElevatorMenu();
                }

                return(false);
            }
            return(true);
        }
示例#4
0
 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;
     }
 }
示例#5
0
        private void BringBackCabin(string command, string[] args)
        {
            if (!Context.IsMainPlayer)
            {
                Monitor.Log("You must be the server to do that");
                return;
            }

            if (args.Length < 1)
            {
                Monitor.Log("Which player's house?");
                return;
            }

            if (Game1.getFarm() != Game1.player.currentLocation)
            {
                Monitor.Log("You need to be on the farm");
                return;
            }

            string farmerName = args[0];

            Monitor.Log($"Attempting to move {farmerName}'s house back");

            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(Game1.player.getTileX()));

                        targetBuilding.GetType()
                        .GetField("tileY", BindingFlags.Instance | BindingFlags.Public)                           //tileY is readonly
                        .SetValue(targetBuilding, new NetInt(Game1.player.getTileY() - 1));

                        foreach (var warp in cabin.warps)
                        {
                            warp.TargetX = targetBuilding.humanDoor.X + (int)targetBuilding.tileX.Value;
                            warp.TargetY = targetBuilding.humanDoor.Y + (int)targetBuilding.tileY.Value + 1;
                        }

                        Monitor.Log($"Moved it");
                    }
                    else
                    {
                        Monitor.Log("Could not find the cabin");
                    }
                }
            }
        }
示例#6
0
 public static bool Prefix(Building __instance)
 {
     if (CabinHelper.IsElevatorBuilding(__instance))
     {
         __instance.texture = new Lazy <Texture2D>(() => ModEntry.ElevatorBuildingTexture);
         return(false);
     }
     return(true);
 }
示例#7
0
        public override void OnClicked()
        {
            Console.WriteLine($"Warping to {player.Name}'s cabin");

            Cabin cabin = CabinHelper.FindCabinInside(player);

            Game1.warpFarmer(cabin.uniqueName.Value, cabin.warps[0].X, cabin.warps[0].Y - 1, 0);

            Game1.activeClickableMenu.exitThisMenu(false);
        }
示例#8
0
        private void AddNewCabin(string command, string[] args)
        {
            if (!Context.IsMainPlayer)
            {
                Monitor.Log("You must be the server to do that");
                return;
            }

            CabinHelper.AddNewCabin();
            Monitor.Log("Added a new cabin");
        }
示例#9
0
 private void ReloadTextures()
 {
     foreach (Building building in Game1.getFarm().buildings)
     {
         if (CabinHelper.IsElevatorBuilding(building))
         {
             Monitor.Log("(Re)loading an elevator building texture");
             building.resetTexture();                    //Otherwise the clients will just see a shed
         }
     }
 }
示例#10
0
        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));
                }
            };
        }
示例#11
0
        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");
                    }
                }
            }
        }
示例#12
0
        public ElevatorMenu() : base(1, 1, Game1.viewport.Width - 200, Game1.viewport.Height - 140, true)
        {
            numberOfPlayersPerColumn = Game1.viewport.Height / 100;
            numberOfColumns          = Game1.viewport.Width / 230;

            UpdatePosition();

            //If you want the elevator menu to show all cabins (not just the ones off the map), use this instead: players.AddRange(Game1.getAllFarmhands().Where(x => x.Name.Length > 0));
            players.AddRange(Game1.getAllFarmhands().Where(x => x.Name.Length > 0 && CabinHelper.FindCabinOutside(x)?.tileX.Value <= -10000));

            players = players.OrderBy(x => x != Game1.player).ThenBy(x => x.Name).ToList();            //Sort alphabetically, and put the local player first

            UpdateButtonList();

            forwardButton  = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen + base.width + 64 - 48, base.yPositionOnScreen + base.height - 48, 48, 44), Game1.mouseCursors, new Rectangle(365, 495, 12, 11), 4f, false);
            backwardButton = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen - 64, base.yPositionOnScreen + base.height - 48, 48, 44), Game1.mouseCursors, new Rectangle(352, 495, 12, 11), 4f, false);
        }
示例#13
0
        public static bool Postfix(bool b, int xTile, int yTile, Farmer who, Building __instance, NetPoint ___humanDoor, bool __result, NetInt ___tileX, NetInt ___tileY)
        {
            if (!CabinHelper.IsElevatorBuilding(__instance))
            {
                return(__result);
            }


            int doorWidth = 2;
            int dist      = xTile - (___tileX.Value + ___humanDoor.X);

            if (___humanDoor.X >= 0 && yTile == ___tileY.Value + ___humanDoor.Y &&
                dist < doorWidth && dist >= 0)
            {
                return(true);
            }

            return(false);
        }
        public static bool Prefix(NetFarmerRoot f)
        {
            if (f.Value.Name.Length == 0)
            {
                //Don't create a cabin unless there is an elevator building
                bool elevatorBuildingExists = false;
                foreach (Building building in Game1.getFarm().buildings)
                {
                    if (CabinHelper.IsElevatorBuilding(building))
                    {
                        elevatorBuildingExists = true;
                        break;
                    }
                }
                if (!elevatorBuildingExists)
                {
                    return(true);
                }

                //A new player has joined. If there is less then 10 spots availible, mark up until 10
                int emptyPlaces = 0;
                foreach (Farmer player in Game1.getAllFarmhands())
                {
                    if (player.Name.Length == 0)
                    {
                        emptyPlaces++;
                    }
                }

                Console.WriteLine($"Generating {10 - emptyPlaces} new cabins");

                if (emptyPlaces < 10)
                {
                    for (int i = 0; i <= 10 - emptyPlaces; i++)                    //Make up to 10
                    {
                        CabinHelper.AddNewCabin(Game1.random.Next(1, 4));
                    }
                }
            }

            return(true);
        }