Exemple #1
0
        public static PlayerState GetStateWithItems(Randomiser world, List <Item> currentItems)
        {
            PlayerState state = new PlayerState(world);

            if (currentItems != null)
            {
                foreach (var item in currentItems)
                {
                    state.CollectItem(item);
                }
            }

            List <Location> requiredLocations = world.GetPlacedRequiredItemLocations();

            List <Location> reachableLocations;

            do
            {
                reachableLocations = state.GetReachableLocations(requiredLocations);
                foreach (var location in reachableLocations)
                {
                    state.CollectItem(location.item);
                    state.collectedLocations.Add(location.name, true);
                }

                state.ResetCheckedAreasAndEntrances();
            } while (reachableLocations.Count > 0);

            return(state);
        }
        public static void RandomiseRequiredItems(Randomiser world, List <Location> locations, List <Item> itemsToPlace)
        {
            PlayerState state;

            while (itemsToPlace.Count > 0)
            {
                Item item = itemsToPlace[itemsToPlace.Count - 1];
                itemsToPlace.Remove(item);
                locations = Shuffle.FisherYates(locations, world);

                state = PlayerState.GetStateWithItems(world, itemsToPlace);

                Location locationToPlaceAt = null;
                foreach (var location in locations)
                {
                    if (location.CanReach(state))
                    {
                        locationToPlaceAt = location;
                        break;
                    }
                }

                if (locationToPlaceAt != null)
                {
                    world.PlaceItem(locationToPlaceAt.name, item);
                    locations.Remove(locationToPlaceAt);
                    //Logger.GetLogger.Log("Placed Item {0} at location {1}", item[0], locationToPlaceAt.name);
                }
                else
                {
                    Logger.GetLogger.Log("Failed to place item {0}", item.name);
                }
            }
        }
Exemple #3
0
 public PlayerState(Randomiser world)
 {
     this.World         = world;
     areaChecks         = new Dictionary <string, bool>();
     entraceChecks      = new Dictionary <string, bool>();
     collectedLocations = new Dictionary <string, bool>();
     collectedItems     = new Dictionary <string, int>();
 }
        public static void RandomiseUnrequiredItems(Randomiser world, List <Location> locations, List <Item> itemsToPlace)
        {
            locations = Shuffle.FisherYates(locations, world);
            int index = (itemsToPlace.Count - 1);

            while (index >= 0)
            {
                Item item = itemsToPlace[index];
                itemsToPlace.Remove(item);

                Location location = locations[index];
                locations.Remove(location);

                world.PlaceItem(location.name, item);
                //Logger.GetLogger.Log("Placed Item {0} at location {1}", item[0], location.name);

                index--;
            }
        }
Exemple #5
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            bool       canBeatGame = false;
            Randomiser randomiser  = new Randomiser(settings, SeedInput.Text);

            OutputText.AppendText("Starting seed generation.");
            OutputText.AppendText(Environment.NewLine);

            if (!randomiser.SetupWorld())
            {
                OutputText.AppendText("Failed initial setup for generation.");
                OutputText.AppendText(Environment.NewLine);
                return;
            }

            do
            {
                randomiser.ClearItemsAndState();

                OutputText.AppendText("Placing non random items.");
                OutputText.AppendText(Environment.NewLine);

                if (!randomiser.PlaceNonRandomItems())
                {
                    OutputText.AppendText("Failed to read data for non random item placement.");
                    OutputText.AppendText(Environment.NewLine);
                    return;
                }

                OutputText.AppendText("Placing random items.");
                OutputText.AppendText(Environment.NewLine);
                if (!randomiser.PlaceRandomItems())
                {
                    OutputText.AppendText("Failed to read data for random item placement.");
                    OutputText.AppendText(Environment.NewLine);
                    return;
                }


                canBeatGame = randomiser.CanBeatGame();
                if (!canBeatGame)
                {
                    Logger.GetLogger.Log("Failed to generate beatable seed, generating new seed.");
                    OutputText.AppendText("Failed to generate seed, retrying.");
                    OutputText.AppendText(Environment.NewLine);
                }
            } while (!canBeatGame);

            if (!FileUtils.WriteSpoilers(randomiser))
            {
                OutputText.AppendText("Failed to write spoiler log.");
                OutputText.AppendText(Environment.NewLine);
            }

            if (!FileUtils.WriteSeedFile(randomiser))
            {
                OutputText.AppendText("Failed to write seed.");
                OutputText.AppendText(Environment.NewLine);
            }


            Logger.GetLogger.Log("Succesfully generated seed {0}", randomiser.Seed);
            OutputText.AppendText("Succesfully generated seed: " + randomiser.Seed);
            OutputText.AppendText(Environment.NewLine);
        }