示例#1
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");
        }
        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);
        }