Exemplo n.º 1
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);
        }
        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 string ForceItem()
        {
            Queue <string> progressionQueue = new Queue <string>();
            List <string>  tempProgression  = new List <string>();

            void UpdateTransitions()
            {
                foreach (string transition in LogicManager.GetTransitionsByProgression(pm.tempItems))
                {
                    if (!pm.Has(transition) && pm.CanGet(transition))
                    {
                        tempProgression.Add(transition);
                        progressionQueue.Enqueue(transition);
                        pm.Add(transition);
                        if (TransitionManager.transitionPlacements.TryGetValue(transition, out string transition2))
                        {
                            tempProgression.Add(transition2);
                            progressionQueue.Enqueue(transition2);
                            pm.Add(transition2);
                        }
                    }
                }
            }

            bool CheckForNewLocations()
            {
                foreach (string location in LogicManager.GetLocationsByProgression(pm.tempItems))
                {
                    if (randomizedLocations.Contains(location) && !reachableLocations.Contains(location) && pm.CanGet(location))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            for (int i = 0; i < unplacedProgression.Count; i++)
            {
                bool   found = false;
                string item  = unplacedProgression[i];
                pm.AddTemp(item);
                if (CheckForNewLocations())
                {
                    found = true;
                }
                else if (RandomizerMod.Instance.Settings.RandomizeTransitions)
                {
                    UpdateTransitions();
                    while (progressionQueue.Any())
                    {
                        progressionQueue.Dequeue();
                        UpdateTransitions();
                        found = found || CheckForNewLocations();
                    }
                }
                pm.RemoveTempItems();
                if (found)
                {
                    return(item);
                }
            }
            return(null);
        }