public static void RandomizeStartingItems()
        {
            startItems = new List <string>();
            if (!RandomizerMod.Instance.Settings.RandomizeStartItems)
            {
                return;
            }

            List <string> pool1 = new List <string> {
                "Mantis_Claw", "Monarch_Wings"
            };
            List <string> pool2 = new List <string> {
                "Mantis_Claw", "Monarch_Wings", "Mothwing_Cloak", "Crystal_Heart"
            };
            List <string> pool3 = new List <string> {
                "Shade_Cloak", "Isma's_Tear", "Vengeful_Spirit", "Howling_Wraiths", "Desolate_Dive", "Cyclone_Slash", "Great_Slash", "Dash_Slash", "Dream_Nail"
            };
            List <string> pool4 = new List <string> {
                "City_Crest", "Lumafly_Lantern", "Tram_Pass", "Simple_Key-Sly", "Shopkeeper's_Key", "Elegant_Key", "Love_Key", "King's_Brand"
            };

            startItems.Add(pool1[rand.Next(pool1.Count)]);

            pool2.Remove(startItems[0]);
            startItems.Add(pool2[rand.Next(pool2.Count)]);


            for (int i = rand.Next(4); i > 0; i--)
            {
                startItems.Add(pool3[rand.Next(pool3.Count)]);
                pool3.Remove(startItems.Last());
            }

            for (int i = rand.Next(7 - startItems.Count); i > 0; i--) // no more than 4 tier3 or tier4 items
            {
                startItems.Add(pool4[rand.Next(pool4.Count)]);
                pool4.Remove(startItems.Last());
            }

            for (int i = rand.Next(2) + 1; i > 0; i--)
            {
                List <string> charms = LogicManager.ItemNames.Where(_item => LogicManager.GetItemDef(_item).action == GiveItemActions.GiveAction.Charm).Except(startItems).ToList();
                startItems.Add(charms[rand.Next(charms.Count)]);
            }

            if (startProgression == null)
            {
                startProgression = new List <string>();
            }

            foreach (string item in startItems)
            {
                if (LogicManager.GetItemDef(item).progression)
                {
                    startProgression.Add(item);
                }
            }
        }
        public static void RandomizeStartingLocation()
        {
            if (RandomizerMod.Instance.Settings.RandomizeStartLocation)
            {
                MiniPM pm = new MiniPM();
                pm.logicFlags["ITEMRANDO"] = !RandomizerMod.Instance.Settings.RandomizeTransitions;
                pm.logicFlags["AREARANDO"] = RandomizerMod.Instance.Settings.RandomizeAreas;
                pm.logicFlags["ROOMRANDO"] = RandomizerMod.Instance.Settings.RandomizeRooms;

                pm.logicFlags["MILDSKIPS"]     = RandomizerMod.Instance.Settings.MildSkips;
                pm.logicFlags["SHADESKIPS"]    = RandomizerMod.Instance.Settings.ShadeSkips;
                pm.logicFlags["ACIDSKIPS"]     = RandomizerMod.Instance.Settings.AcidSkips;
                pm.logicFlags["FIREBALLSKIPS"] = RandomizerMod.Instance.Settings.FireballSkips;
                pm.logicFlags["SPIKETUNNELS"]  = RandomizerMod.Instance.Settings.SpikeTunnels;
                pm.logicFlags["DARKROOMS"]     = RandomizerMod.Instance.Settings.DarkRooms;
                pm.logicFlags["SPICYSKIPS"]    = RandomizerMod.Instance.Settings.SpicySkips;

                pm.logicFlags["VERTICAL"]           = RandomizerMod.Instance.Settings.RandomizeStartItems;
                pm.logicFlags["SWIM"]               = !RandomizerMod.Instance.Settings.RandomizeSwim;
                pm.logicFlags["2MASKS"]             = !RandomizerMod.Instance.Settings.CursedMasks;
                pm.logicFlags["NONRANDOMELEVATORS"] = !RandomizerMod.Instance.Settings.ElevatorPass;

                List <string> startLocations = LogicManager.StartLocations
                                               .Where(start => pm.Evaluate(LogicManager.GetStartLocation(start).logic))
                                               .Except(new string[] { "King's Pass" })
                                               .ToList();
                StartName = startLocations[rand.Next(startLocations.Count)];
            }
            else if (!LogicManager.StartLocations.Contains(RandomizerMod.Instance.Settings.StartName))
            {
                StartName = "King's Pass";
            }
            else
            {
                StartName = RandomizerMod.Instance.Settings.StartName;
            }

            Log("Setting start location as " + StartName);

            StartDef def = LogicManager.GetStartLocation(StartName);

            if (startProgression == null)
            {
                startProgression = new List <string>();
            }
            if (!RandomizerMod.Instance.Settings.RandomizeRooms)
            {
                startProgression.Add(def.waypoint);
            }
            if (RandomizerMod.Instance.Settings.RandomizeAreas && !string.IsNullOrEmpty(def.areaTransition))
            {
                startProgression.Add(def.areaTransition);
            }
            if (RandomizerMod.Instance.Settings.RandomizeRooms)
            {
                startProgression.Add(def.roomTransition);
            }
        }
예제 #3
0
        private HashSet <string> FakeUpdateReachableTransitions(string newThing = null, ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }
            if (newThing == null)
            {
                newThing = Randomizer.startTransition;
            }

            Queue <string>   updates   = new Queue <string>();
            HashSet <string> reachable = new HashSet <string>(reachableTransitions);

            reachable.Add(newThing);
            pm.AddTemp(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                foreach (string transition in LogicManager.GetTransitionsByProgression(recentProgression))
                {
                    if (!reachable.Contains(transition) && pm.CanGet(transition))
                    {
                        reachable.Add(transition);
                        pm.AddTemp(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachable.Add(transition2);
                            pm.AddTemp(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }
                if (!updates.Any()) // check vanilla items last, because these almost never change
                {
                    foreach (string loc in LogicManager.GetLocationsByProgression(recentProgression))
                    {
                        if (!vanillaProgression.Contains(loc) && !checkProgression.Contains(loc))
                        {
                            continue;
                        }
                        if (!pm.Has(loc) && pm.CanGet(loc))
                        {
                            pm.AddTemp(loc);
                            updates.Enqueue(loc);
                        }
                    }
                }
            }
            reachable.ExceptWith(reachableTransitions);
            pm.RemoveTempItems();
            return(reachable);
        }
        public void UpdateReachableLocations(string newThing = null)
        {
            if (newThing != null)
            {
                pm.Add(newThing);
                updateQueue.Enqueue(newThing);
            }

            HashSet <string> potentialLocations;
            HashSet <string> potentialTransitions = new HashSet <string>();

            while (updateQueue.Any())
            {
                potentialLocations = LogicManager.GetLocationsByProgression(recentProgression);
                if (RandomizerMod.Instance.Settings.RandomizeTransitions)
                {
                    potentialTransitions = LogicManager.GetTransitionsByProgression(recentProgression);
                }
                recentProgression = new HashSet <string>();

                string item = updateQueue.Dequeue();
                foreach (string location in potentialLocations)
                {
                    if (pm.CanGet(location))
                    {
                        reachableLocations.Add(location);
                        if (vm.progressionLocations.Contains(location))
                        {
                            vm.UpdateVanillaLocations(location);
                        }
                    }
                }

                if (RandomizerMod.Instance.Settings.RandomizeTransitions)
                {
                    if (TransitionManager.transitionPlacements.TryGetValue(item, out string transition1) && !pm.Has(transition1))
                    {
                        pm.Add(transition1);
                        updateQueue.Enqueue(transition1);
                    }
                    foreach (string transition in potentialTransitions)
                    {
                        if (!pm.Has(transition) && pm.CanGet(transition))
                        {
                            pm.Add(transition);
                            updateQueue.Enqueue(transition);
                            if (TransitionManager.transitionPlacements.TryGetValue(transition, out string transition2) && !pm.Has(transition2))
                            {
                                pm.Add(transition2);
                                updateQueue.Enqueue(transition2);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        public void Add(string item)
        {
            item = LogicManager.RemoveDuplicateSuffix(item);
            if (!LogicManager.progressionBitMask.TryGetValue(item, out (int, int)a))
            {
                // RandomizerMod.Instance.LogWarn("Could not find progression value corresponding to: " + item);
                return;
            }
            obtained[a.Item2] |= a.Item1;
            if (temp)
            {
                tempItems.Add(item);
            }
            if (share)
            {
                Share(item);
            }

            // Take into account root essence found; this should only ever happen during helper log generation
            if (RandomizerMod.Instance.Settings.RandomizeWhisperingRoots && concealRandom)
            {
                if (LogicManager.TryGetItemDef(item, out ReqDef itemDef))
                {
                    if (itemDef.pool == "Root")
                    {
                        randomEssence += itemDef.geo;
                    }
                }
            }
            if (RandomizerMod.Instance.Settings.RandomizeBossEssence && concealRandom)
            {
                if (LogicManager.TryGetItemDef(item, out ReqDef itemDef))
                {
                    if (itemDef.pool == "Essence_Boss")
                    {
                        randomEssence += itemDef.geo;
                    }
                }
            }
            if (RandomizerMod.Instance.Settings.RandomizeGrimmkinFlames && concealRandom)
            {
                if (LogicManager.TryGetItemDef(item, out ReqDef itemDef))
                {
                    if (itemDef.pool == "Flame")
                    {
                        randomFlames += 1;
                    }
                }
            }

            RecalculateGrubs();
            RecalculateEssence();
            RecalculateFlames();
            RecalculateEggs();
            UpdateWaypoints();
        }
예제 #6
0
 public bool Has(string item)
 {
     item = LogicManager.RemoveDuplicateSuffix(item);
     if (!LogicManager.progressionBitMask.TryGetValue(item, out (int, int)a))
     {
         RandomizerMod.Instance.LogWarn("Could not find progression value corresponding to: " + item);
         return(false);
     }
     return((obtained[a.Item2] & a.Item1) == a.Item1);
 }
        public static void BuildRoomSpanningTree()
        {
            List <string> rooms = new List <string>();
            Dictionary <string, List <string> > roomTransitions = new Dictionary <string, List <string> >();

            foreach (string transition in LogicManager.TransitionNames())
            {
                if (transition == startTransition)
                {
                    continue;
                }
                TransitionDef def      = LogicManager.GetTransitionDef(transition);
                string        roomName = def.sceneName;
                if (new List <string> {
                    "Crossroads_46", "Crossroads_46b"
                }.Contains(roomName))
                {
                    roomName = "Crossroads_46";
                }
                if (new List <string> {
                    "Abyss_03", "Abyss_03_b", "Abyss_03_c"
                }.Contains(roomName))
                {
                    roomName = "Abyss_03";
                }
                if (new List <string> {
                    "Ruins2_10", "Ruins2_10b"
                }.Contains(roomName))
                {
                    roomName = "Ruins2_10";
                }

                if (!rooms.Contains(roomName) && !def.deadEnd && !def.isolated)
                {
                    rooms.Add(roomName);
                    roomTransitions.Add(roomName, new List <string>());
                }
            }

            foreach (string transition in LogicManager.TransitionNames())
            {
                if (transition == startTransition)
                {
                    continue;
                }
                TransitionDef def      = LogicManager.GetTransitionDef(transition);
                string        roomName = def.sceneName;
                if (def.oneWay == 0 && rooms.Contains(roomName))
                {
                    roomTransitions[roomName].Add(transition);
                }
            }

            BuildSpanningTree(roomTransitions);
        }
 private void FetchGrubLocations(RandomizerState state)
 {
     if (RandomizerMod.Instance.Settings.RandomizeGrubs)
     {
         grubLocations = FetchLocationsByPool(state, "Grub");
     }
     else
     {
         grubLocations = LogicManager.GetItemsByPool("Grub").ToDictionary(grub => grub, grub => 1);
     }
 }
예제 #9
0
        private HashSet <string> GetRandomizedLocations()
        {
            HashSet <string> locations = new HashSet <string>();

            if (RandomizerMod.Instance.Settings.RandomizeDreamers)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Dreamer"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeSkills)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Skill"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeCharms)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Charm"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeKeys)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Key"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeMaskShards)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Mask"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeVesselFragments)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Vessel"));
            }
            if (RandomizerMod.Instance.Settings.RandomizePaleOre)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Ore"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeCharmNotches)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Notch"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeGeoChests)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Geo"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeRancidEggs)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Egg"));
            }
            if (RandomizerMod.Instance.Settings.RandomizeRelics)
            {
                locations.UnionWith(LogicManager.GetItemsByPool("Relic"));
            }

            locations = new HashSet <string>(locations.Where(item => LogicManager.GetItemDef(item).type != ItemType.Shop));
            locations.UnionWith(LogicManager.ShopNames);
            return(locations);
        }
예제 #10
0
        private List <string> GetReachableTransitions(ProgressionManager _pm = null) // essentially the same as the method in transitionManager, using that class's static placement dictionary
        {
            if (_pm != null)
            {
                pm = _pm;
            }
            bool          done    = false;
            bool          updated = false;
            List <string> reachableTransitions   = new List <string>();
            List <string> unreachableTransitions = LogicManager.TransitionNames().ToList();

            while (!done)
            {
                foreach (string transition in unreachableTransitions)
                {
                    if (pm.Has(transition))
                    {
                        reachableTransitions.Add(transition);
                    }
                    else if (LogicManager.GetTransitionDef(transition).oneWay == 2)
                    {
                        string entrance = TransitionManager.transitionPlacements.FirstOrDefault(exit => exit.Value == transition).Key;

                        if (entrance != null && pm.CanGet(entrance))
                        {
                            reachableTransitions.Add(transition);
                            updated = true;
                        }
                    }
                    else if (!LogicManager.GetTransitionDef(transition).isolated&& pm.CanGet(transition))
                    {
                        reachableTransitions.Add(transition);
                        updated = true;
                    }

                    else if (TransitionManager.transitionPlacements.TryGetValue(transition, out string altTransition) && LogicManager.GetTransitionDef(altTransition).oneWay != 2 &&
                             !LogicManager.GetTransitionDef(altTransition).isolated&& pm.CanGet(altTransition))
                    {
                        reachableTransitions.Add(transition);
                        updated = true;
                    }
                }
                foreach (string transition in reachableTransitions)
                {
                    unreachableTransitions.Remove(transition);
                    pm.Add(transition);
                }
                done    = !updated;
                updated = false;
            }
            return(reachableTransitions);
        }
        public void UpdateReachableTransitions(string newThing = null, bool item = false, ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }
            if (newThing == null)
            {
                newThing = Randomizer.startTransition;
            }

            Queue <string> updates = new Queue <string>();

            if (!item)
            {
                reachableTransitions.Add(newThing);
            }
            pm.Add(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                if (transitionPlacements.TryGetValue(next, out string next2) && !reachableTransitions.Contains(next2))
                {
                    reachableTransitions.Add(next2);
                    pm.Add(next2);
                    updates.Enqueue(next2);
                }

                HashSet <string> potentialTransitions = LogicManager.GetTransitionsByProgression(recentProgression);
                recentProgression = new HashSet <string>();

                foreach (string transition in potentialTransitions)
                {
                    if (!reachableTransitions.Contains(transition) && pm.CanGet(transition))
                    {
                        reachableTransitions.Add(transition);
                        pm.Add(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachableTransitions.Add(transition2);
                            pm.Add(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }
            }
        }
        public static void BuildAreaSpanningTree()
        {
            List <string> areas = new List <string>();
            Dictionary <string, List <string> > areaTransitions = new Dictionary <string, List <string> >();

            foreach (string transition in LogicManager.TransitionNames())
            {
                if (transition == startTransition)
                {
                    continue;
                }
                TransitionDef def      = LogicManager.GetTransitionDef(transition);
                string        areaName = def.areaName;
                if (new List <string> {
                    "City_of_Tears", "Forgotten_Crossroads", "Resting_Grounds"
                }.Contains(areaName))
                {
                    areaName = "Kings_Station";
                }
                if (new List <string> {
                    "Ancient_Basin", "Kingdoms_Edge"
                }.Contains(areaName))
                {
                    areaName = "Deepnest";
                }

                if (!areas.Contains(areaName) && !def.deadEnd && !def.isolated)
                {
                    areas.Add(areaName);
                    areaTransitions.Add(areaName, new List <string>());
                }
            }

            foreach (string transition in LogicManager.TransitionNames())
            {
                if (transition == startTransition)
                {
                    continue;
                }
                TransitionDef def      = LogicManager.GetTransitionDef(transition);
                string        areaName = def.areaName;
                if (def.oneWay == 0 && areas.Contains(areaName))
                {
                    areaTransitions[areaName].Add(transition);
                }
            }

            BuildSpanningTree(areaTransitions);
        }
 public void Remove(string item)
 {
     item = LogicManager.RemoveDuplicateSuffix(item);
     if (!LogicManager.progressionBitMask.TryGetValue(item, out (int, int)a))
     {
         RandomizerMod.Instance.LogWarn("Could not find progression value corresponding to: " + item);
         return;
     }
     obtained[a.Item2] &= ~a.Item1;
     if (LogicManager.grubProgression.Contains(item))
     {
         RecalculateGrubs();
     }
     if (LogicManager.essenceProgression.Contains(item))
     {
         RecalculateEssence();
     }
 }
예제 #14
0
        private void FetchEggLocations(RandomizerState state)
        {
            if (!RandomizerMod.Instance.Settings.EggShop)
            {
                return;
            }

            if (RandomizerMod.Instance.Settings.RandomizeRancidEggs)
            {
                eggLocations = FetchLocationsByPool(state, "EggShopItem");
            }
            else
            {
                // Easiest to simply ignore the egg at sly
                eggLocations = LogicManager.GetItemsByPool("Egg").Where(egg => LogicManager.GetItemDef(egg).type != ItemType.Shop)
                               .ToDictionary(egg => egg, egg => 1);
            }
        }
        public static void RandomizeNonShopCosts()
        {
            foreach (string item in LogicManager.ItemNames)
            {
                ReqDef def = LogicManager.GetItemDef(item);
                if (!RandomizerMod.Instance.Settings.GetRandomizeByPool(def.pool))
                {
                    RandomizerMod.Instance.Settings.AddNewCost(item, def.cost);
                    continue; //Skip cost rando if this item's pool is vanilla
                }

                if (def.costType == AddYNDialogueToShiny.CostType.Essence) //essence cost
                {
                    int cost = 1 + rand.Next(MAX_ESSENCE_COST);

                    def.cost = cost;
                    LogicManager.EditItemDef(item, def); // really shouldn't be editing this, bad idea
                    RandomizerMod.Instance.Settings.AddNewCost(item, cost);
                    continue;
                }

                if (def.costType == AddYNDialogueToShiny.CostType.Grub) //grub cost
                {
                    int cost = 1 + rand.Next(MAX_GRUB_COST);

                    def.cost = cost;
                    LogicManager.EditItemDef(item, def); // yeah, I'm probably not fixing it though
                    RandomizerMod.Instance.Settings.AddNewCost(item, cost);
                    continue;
                }

                if (def.costType == AddYNDialogueToShiny.CostType.RancidEggs) //eggu cost
                {
                    int cost = MIN_EGG_COST + rand.Next(MAX_EGG_COST - MIN_EGG_COST + 1);

                    def.cost = cost;
                    LogicManager.EditItemDef(item, def); // blah blah blah would be nicer to have a random number of items in the eggu shop
                    RandomizerMod.Instance.Settings.AddNewCost(item, cost);
                    continue;
                }
            }
        }
        public void UpdateReachableTransitions(string newThing = "Tutorial_01[right1]", bool item = false, ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }

            Queue <string> updates = new Queue <string>();

            if (!item)
            {
                reachableTransitions.Add(newThing);
            }
            pm.Add(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                if (transitionPlacements.TryGetValue(next, out string next2) && !reachableTransitions.Contains(next2))
                {
                    reachableTransitions.Add(next2);
                    pm.Add(next2);
                    updates.Enqueue(next2);
                }
                foreach (string transition in LogicManager.GetTransitionsByProgression(next))
                {
                    if (!reachableTransitions.Contains(transition) && pm.CanGet(transition))
                    {
                        reachableTransitions.Add(transition);
                        pm.Add(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachableTransitions.Add(transition2);
                            pm.Add(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }
            }
        }
예제 #17
0
        // useful for debugging
        public string ListObtainedProgression()
        {
            string progression = string.Empty;

            foreach (string item in LogicManager.ItemNames)
            {
                if (LogicManager.GetItemDef(item).progression&& Has(item))
                {
                    progression += item + ", ";
                }
            }
            foreach (string transition in LogicManager.TransitionNames())
            {
                if (Has(transition))
                {
                    progression += transition + ", ";
                }
            }
            return(progression);
        }
        private static bool TestStartLocation(string start)
        {
            // could potentially add logic checks here in the future
            StartDef startDef = LogicManager.GetStartLocation(start);

            if (RandomizerMod.Instance.Settings.RandomizeStartItems)
            {
                return(true);
            }
            if (RandomizerMod.Instance.Settings.RandomizeRooms)
            {
                if (startDef.roomSafe)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (RandomizerMod.Instance.Settings.RandomizeAreas)
            {
                if (startDef.areaSafe)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (startDef.sceneName == "Mines_35" && !RandomizerMod.Instance.Settings.EarlyGeo)
            {
                return(false);
            }
            if (startDef.itemSafe)
            {
                return(true);
            }
            return(false);
        }
        private HashSet <string> FakeUpdateReachableTransitions(string newThing = null, ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }
            if (newThing == null)
            {
                newThing = Randomizer.startTransition;
            }

            Queue <string>   updates   = new Queue <string>();
            HashSet <string> reachable = new HashSet <string>(reachableTransitions);

            reachable.Add(newThing);
            pm.AddTemp(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                foreach (string transition in LogicManager.GetTransitionsByProgression(recentProgression))
                {
                    if (!reachable.Contains(transition) && pm.CanGet(transition))
                    {
                        reachable.Add(transition);
                        pm.AddTemp(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachable.Add(transition2);
                            pm.AddTemp(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }
            }
            reachable.ExceptWith(reachableTransitions);
            pm.RemoveTempItems();
            return(reachable);
        }
        public bool Test(string transitionTarget)
        {
            if (SinglyCompatible())
            {
                return(true);
            }
            string doorName = LogicManager.GetTransitionDef(transitionTarget).doorName;

            switch (doorName.Substring(0, 3))
            {
            case "doo":
            case "rig":
                if (left)
                {
                    return(true);
                }
                break;

            case "lef":
                if (right)
                {
                    return(true);
                }
                break;

            case "top":
                if (bot)
                {
                    return(true);
                }
                break;

            case "bot":
                if (top)
                {
                    return(true);
                }
                break;
            }
            return(false);
        }
 public void Add(string item)
 {
     item = LogicManager.RemoveDuplicateSuffix(item);
     if (!LogicManager.progressionBitMask.TryGetValue(item, out (int, int)a))
     {
         RandomizerMod.Instance.LogWarn("Could not find progression value corresponding to: " + item);
         return;
     }
     obtained[a.Item2] |= a.Item1;
     if (temp)
     {
         tempItems.Add(item);
     }
     if (share)
     {
         Share(item);
     }
     RecalculateGrubs();
     RecalculateEssence();
     UpdateWaypoints();
 }
        private HashSet <string> FakeUpdateReachableTransitions(string newThing = "Tutorial_01[right1]", ProgressionManager _pm = null)
        {
            if (_pm != null)
            {
                pm = _pm;
            }

            Queue <string>   updates   = new Queue <string>();
            HashSet <string> reachable = new HashSet <string>(reachableTransitions);

            reachable.Add(newThing);
            pm.Add(newThing);
            updates.Enqueue(newThing);

            while (updates.Any())
            {
                string next = updates.Dequeue();
                foreach (string transition in LogicManager.GetTransitionsByProgression(next))
                {
                    if (!reachable.Contains(transition) && pm.CanGet(transition))
                    {
                        reachable.Add(transition);
                        pm.Add(transition);
                        updates.Enqueue(transition);
                        if (transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            reachable.Add(transition2);
                            pm.Add(transition2);
                            updates.Enqueue(transition2);
                        }
                    }
                }
            }
            reachable.ExceptWith(reachableTransitions);
            foreach (string transition in reachable)
            {
                pm.Remove(transition);
            }
            return(reachable);
        }
예제 #23
0
        public void RecalculateGrubs()
        {
            int grubs = 0;

            if (grubItems == null)
            {
                grubItems = LogicManager.ItemNames.Where(item => LogicManager.GetItemDef(item).pool == "Grub").ToList();
            }

            foreach (string item in grubItems)
            {
                if (CanGet(item))
                {
                    grubs++;
                }
                if (grubs >= 24)
                {
                    break;
                }
            }
            obtained[LogicManager.grubIndex] = grubs;
        }
예제 #24
0
        public void RecalculateEssence()
        {
            int essence = 0;

            if (essenceItems == null)
            {
                essenceItems = LogicManager.ItemNames.Where(item => LogicManager.GetItemDef(item).pool.StartsWith("Essence")).ToList();
            }

            foreach (string item in essenceItems)
            {
                if (CanGet(item))
                {
                    essence += LogicManager.GetItemDef(item).geo;
                }
                if (essence >= 930)
                {
                    break;
                }
            }
            obtained[LogicManager.essenceIndex] = essence;
        }
예제 #25
0
        public void PlaceItem(string item, string location)
        {
            if (shopItems.ContainsKey(location))
            {
                shopItems[location].Add(item);
            }
            else
            {
                nonShopItems.Add(location, item);
            }

            unplacedLocations.Remove(location);
            if (LogicManager.GetItemDef(item).progression)
            {
                unplacedProgression.Remove(item);
                UpdateReachableLocations(item);
            }
            else
            {
                unplacedItems.Remove(item);
            }
        }
예제 #26
0
        private Dictionary <string, int> FetchLocationsByPool(RandomizerState state, string pool)
        {
            Dictionary <string, int> locations;

            switch (state)
            {
            case RandomizerState.InProgress:
                return(new Dictionary <string, int>());

            case RandomizerState.Validating:
                locations = ItemManager.nonShopItems.Where(kvp => LogicManager.GetItemDef(kvp.Value).pool == pool).ToDictionary(kvp => kvp.Key, kvp => 1);
                foreach (var kvp in ItemManager.shopItems)
                {
                    if (kvp.Value.Any(item => LogicManager.GetItemDef(item).pool == pool))
                    {
                        locations.Add(kvp.Key, kvp.Value.Count(item => LogicManager.GetItemDef(item).pool == pool));
                    }
                }
                return(locations);

            case RandomizerState.Completed:
            case RandomizerState.HelperLog:
                locations = RandomizerMod.Instance.Settings.ItemPlacements
                            .Where(pair => LogicManager.GetItemDef(pair.Item1).pool == pool && !LogicManager.ShopNames.Contains(pair.Item2))
                            .ToDictionary(pair => pair.Item2, kvp => 1);
                foreach (string shop in LogicManager.ShopNames)
                {
                    if (RandomizerMod.Instance.Settings.ItemPlacements.Any(pair => pair.Item2 == shop && LogicManager.GetItemDef(pair.Item1).pool == pool))
                    {
                        locations.Add(shop, RandomizerMod.Instance.Settings.ItemPlacements.Count(pair => pair.Item2 == shop && LogicManager.GetItemDef(pair.Item1).pool == pool));
                    }
                }
                return(locations);

            default:
                Log("FetchLocationsByPool: unexpected RandomizerState");
                return(new Dictionary <string, int>());
            }
        }
        public string GetNextTransition(string input)
        {
            string doorName = LogicManager.GetTransitionDef(input).doorName;
            string output   = null;

            switch (doorName.Substring(0, 3))
            {
            case "doo":
            case "rig":
                if (leftTransitions.Any())
                {
                    output = leftTransitions[rand.Next(leftTransitions.Count)];
                }
                break;

            case "lef":
                if (rightTransitions.Any())
                {
                    output = rightTransitions[rand.Next(rightTransitions.Count)];
                }
                break;

            case "top":
                if (botTransitions.Any())
                {
                    output = botTransitions[rand.Next(botTransitions.Count)];
                }
                break;

            case "bot":
                if (topTransitions.Any())
                {
                    output = topTransitions[rand.Next(topTransitions.Count)];
                }
                break;
            }
            return(output);
        }
        public TransitionManager(Random rnd)
        {
            rand = rnd;
            dt   = new DirectedTransitions(rnd);
            pm   = new ProgressionManager();

            transitionPlacements = new Dictionary <string, string>();

            List <string> iterate = LogicManager.TransitionNames().ToList();

            unplacedTransitions = new List <string>();
            while (iterate.Any())
            {
                string t = iterate[rand.Next(iterate.Count)];
                unplacedTransitions.Add(t);
                iterate.Remove(t);
            }

            standbyTransitions   = new Dictionary <string, string>();
            reachableTransitions = new HashSet <string>();

            dt.Add(unplacedTransitions);
        }
        public static void RandomizeCosts()
        {
            foreach (string item in LogicManager.ItemNames)
            {
                if (LogicManager.GetItemDef(item).costType == 1) //essence cost
                {
                    ReqDef def  = LogicManager.GetItemDef(item);
                    int    cost = 1 + rand.Next(900);
                    def.cost = cost;
                    LogicManager.EditItemDef(item, def);
                    RandomizerMod.Instance.Settings.AddNewCost(item, cost);
                }

                if (LogicManager.GetItemDef(item).costType == 3) //grub cost
                {
                    ReqDef def  = LogicManager.GetItemDef(item);
                    int    cost = 1 + rand.Next(23);
                    def.cost = cost;
                    LogicManager.EditItemDef(item, def);
                    RandomizerMod.Instance.Settings.AddNewCost(item, cost);
                }
            }
        }
        public static void RandomizeStartingLocation()
        {
            if (RandomizerMod.Instance.Settings.RandomizeStartLocation)
            {
                List <string> startLocations = LogicManager.StartLocations.Where(start => TestStartLocation(start)).Except(new string[] { "King's Pass" }).ToList();
                StartName = startLocations[rand.Next(startLocations.Count)];
            }
            else if (!LogicManager.StartLocations.Contains(RandomizerMod.Instance.Settings.StartName))
            {
                StartName = "King's Pass";
            }
            else
            {
                StartName = RandomizerMod.Instance.Settings.StartName;
            }

            Log("Setting start location as " + StartName);

            StartDef def = LogicManager.GetStartLocation(StartName);

            if (startProgression == null)
            {
                startProgression = new List <string>();
            }
            if (!RandomizerMod.Instance.Settings.RandomizeRooms)
            {
                startProgression.Add(def.waypoint);
            }
            if (RandomizerMod.Instance.Settings.RandomizeAreas && !string.IsNullOrEmpty(def.areaTransition))
            {
                startProgression.Add(def.areaTransition);
            }
            if (RandomizerMod.Instance.Settings.RandomizeRooms)
            {
                startProgression.Add(def.roomTransition);
            }
        }