Пример #1
0
        private void RandomiseWithChecks(List <Location> locations, List <Item> itemsToPlace, List <Item> currentItems)
        {
            PlayerState state;

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

                state = PlayerState.GetStateWithItems(this, currentItems);

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

                if (locationToPlaceAt != null)
                {
                    locationToPlaceAt.PlaceItem(item);
                    locations.Remove(locationToPlaceAt);
                }
                else
                {
                    Logger.Log($"Failed to place item {item.name}");
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
 private void RandomiseCurses()
 {
     CursedLocations = new List <Location>();
     if (Settings.RandomCurses)
     {
         var chestLocations = Shuffle.FisherYates(GetUnplacedLocationsOfType(LocationType.Chest), random);
         for (int i = 0; i < 4; i++)
         {
             Location location = chestLocations[i];
             location.AppendRuleString("and Has(Mulana Talisman)");
             location.BuildLogicTree();
             CursedLocations.Add(location);
         }
     }
     else
     {
         var defaultLocations = new List <string> {
             "Flame Torc Chest", "Giants Flutes Chest", "Destiny Tablet Chest", "Power Band Chest"
         };
         foreach (string locationName in defaultLocations)
         {
             Location location = GetLocation(locationName);
             location.AppendRuleString("and Has(Mulana Talisman)");
             location.BuildLogicTree();
             CursedLocations.Add(location);
         }
     }
 }
Пример #4
0
        private void RandomiseWithoutChecks(List <Location> locations, List <Item> itemsToPlace)
        {
            locations = Shuffle.FisherYates(locations, random);
            int index = (itemsToPlace.Count - 1);

            while (index >= 0)
            {
                Item     item     = itemsToPlace[index];
                Location location = locations[index];

                itemsToPlace.Remove(item);
                locations.Remove(location);
                location.PlaceItem(item);
                index--;
            }
        }
Пример #5
0
        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--;
            }
        }
Пример #6
0
 public static void Sort <T>(T[] a) where T : IComparable <T>
 {
     Shuffle.FisherYates(a);
     Sort(a, 0, a.Length - 1);
 }
Пример #7
0
        public bool PlaceRandomItems()
        {
            string currentDir = Directory.GetCurrentDirectory();

            //Note: Changed this to to create the items from the data here rather than later

            //get shop only items
            if (!FileUtils.GetItemsFromJson("Data\\shopitems.json", out List <Item> shopItems))
            {
                return(false);
            }

            //get required items
            if (!FileUtils.GetItemsFromJson("Data\\reqitems.json", out List <Item> requiredItems))
            {
                return(false);
            }

            //get skulls
            if (!FileUtils.GetItemsFromJson("Data\\skulls.json", out List <Item> skulls))
            {
                return(false);
            }

            //get unrequired items
            if (!FileUtils.GetItemsFromJson("Data\\unreqitems.json", out List <Item> unrequiredItems))
            {
                return(false);
            }

            //NOTE: when more options get add move these to a seperate method or something
            if (!settings.randomiseGrail)
            {
                PlaceItem("Holy Grail Chest", ItemPool.GetAndRemove(ItemID.HolyGrail, requiredItems));
            }

            if (!settings.randomiseScanner)
            {
                PlaceItem("Sidro Shop 1", ItemPool.GetAndRemove(ItemID.HandScanner, requiredItems));
            }

            //Shuffle all the item pools once
            shopItems       = Shuffle.FisherYates(shopItems, this);
            requiredItems   = Shuffle.FisherYates(requiredItems, this);
            unrequiredItems = Shuffle.FisherYates(unrequiredItems, this);

            //Places weights at a starting shop since they are needed for alot of early items
            //this means that player will not have to rely on drops or weights from pots
            PlaceItem("Nebur Shop 1", ItemPool.GetAndRemove(ItemID.Weights, shopItems));

            //ammo can't be placed here since there is an second item that takes this slot after
            //the first is purchased
            GetLocation("Hiner Shop 3").isLocked = true;

            //get list of shop locations as weights and ammo items can only be placed here
            List <Location> shopLocations = GetUnplacedShopLocations();

            //place shop only items
            ItemRandomisation.RandomiseSpecificItems(this, shopLocations, shopItems, requiredItems);

            //items can be placed here now
            GetLocation("Hiner Shop 3").isLocked = false;

            //lock locations that currently can't be randomised
            GetLocation("Funeral Item").isLocked     = true;
            GetLocation("Mulbruk Item").isLocked     = true;
            GetLocation("Fobos Skull Item").isLocked = true;

            //Get all unplaced locations as required items can go anywhere aslong as it can be reached
            List <Location> unplacedLocations = GetUnplacedLocations();

            //place required items
            ItemRandomisation.RandomiseRequiredItems(this, unplacedLocations, requiredItems);

            //unlock the locked locations now since any item that is not required can go there
            GetLocation("Funeral Item").isLocked = false;
            GetLocation("Mulbruk Item").isLocked = false;

            //randomise all skulls bar one seperately since its seem better for generation, needs testing
            unplacedLocations = GetUnplacedLocations();
            ItemRandomisation.RandomiseSpecificItems(this, unplacedLocations, skulls, null);

            //anything left can go here
            GetLocation("Fobos Skull Item").isLocked = false;

            //Get unplaced locations after the required items have been placed
            unplacedLocations = GetUnplacedLocations();
            //places no requires items
            ItemRandomisation.RandomiseUnrequiredItems(this, unplacedLocations, unrequiredItems);

            return(true);
        }
Пример #8
0
        public void PlaceItems()
        {
            FileUtils.GetItemsFromJson("Data//Items.json", out List <Item> items);
            FileUtils.GetItemsFromJson("Data//Mantras.json", out List <Item> mantras);
            FileUtils.GetItemsFromJson("Data//ShopOnlyItems.json", out List <Item> shopOnlyItems);

            StartingWeapon = ItemPool.GetAndRemove(ItemID.Whip, items);

            //Places weights at a starting shop since they are needed for alot of early items
            //this means that player will not have to rely on drops or weights from pots
            GetLocation("Nebur Shop 1").PlaceItem(ItemPool.GetAndRemove(ItemID.Weights, shopOnlyItems));

            if (Settings.ShopPlacement != ShopPlacement.Original)
            {
                //these locations cant be included properly atm since the reason the shop switches is unknown
                GetLocation("Hiner Shop 3").PlaceItem(ItemPool.GetAndRemove(ItemID.Map1, items));
                GetLocation("Hiner Shop 4").PlaceItem(ItemPool.GetAndRemove(ItemID.Map2, items));
            }

            shopOnlyItems = Shuffle.FisherYates(shopOnlyItems, random);
            //place the weights and ammo in shops first since they can only be in shops
            PlaceShopItems(shopOnlyItems, items);

            //create a list of the items we want to place that are accessible from the start
            List <Item> earlyItems = new List <Item>();

            if (!Settings.RandomGrail)
            {
                earlyItems.Add(ItemPool.GetAndRemove(ItemID.HolyGrail, items));
            }
            if (!Settings.RandomScanner && Settings.ShopPlacement != ShopPlacement.Original)
            {
                earlyItems.Add(ItemPool.GetAndRemove(ItemID.HandScanner, items));
            }
            if (!Settings.RandomCodices && Settings.ShopPlacement != ShopPlacement.Original)
            {
                earlyItems.Add(ItemPool.GetAndRemove(ItemID.Codices, items));
            }
            if (!Settings.RandomFDC && Settings.ShopPlacement != ShopPlacement.Original)
            {
                earlyItems.Add(ItemPool.GetAndRemove(ItemID.FutureDevelopmentCompany, items));
            }

            earlyItems = Shuffle.FisherYates(earlyItems, random);
            RandomiseWithChecks(GetUnplacedLocations(), earlyItems, new List <Item>());

            //split the remaining item it required/non required
            List <Item> requiredItems    = ItemPool.GetRequiredItems(items);
            List <Item> nonRequiredItems = ItemPool.GetNonRequiredItems(items);

            requiredItems    = Shuffle.FisherYates(requiredItems, random);
            nonRequiredItems = Shuffle.FisherYates(nonRequiredItems, random);

            mantras = Shuffle.FisherYates(mantras, random);
            //place mantras if they are not fully randomised
            PlaceMantras(mantras, requiredItems);

            //place required items
            RandomiseAssumedFill(GetUnplacedLocations(), requiredItems);

            //place non requires items
            RandomiseWithoutChecks(GetUnplacedLocations(), nonRequiredItems);
        }