예제 #1
0
 public static void RemoveDreamOrbEssence(Location location)
 {
     foreach (PlayMakerFSM dreamOrb in USceneManager.GetSceneByName(location.Scene)
              .GetRootGameObjects()
              .SelectMany(obj => obj.GetComponentsInChildren <PlayMakerFSM>())
              .Where(fsm => fsm.FsmName == "Control" && fsm.gameObject.name.StartsWith("Dream Plant Orb")))
     {
         dreamOrb.GetState("Collect").RemoveActionsOfType <IncrementPlayerDataInt>();
     }
 }
예제 #2
0
        private static void EditRandomizedItems(string scene)
        {
            Dictionary <GameObject, List <string> > shopItems = new Dictionary <GameObject, List <string> >();

            foreach (KeyValuePair <string, string> pair in RandomizerMod.Instance.ItemPlacements)
            {
                string itemId = pair.Key.Substring(0, pair.Key.IndexOf('.'));
                string locId  = pair.Value;

                Item     item = RandoResources.Items.FirstOrDefault(i => i.Id == itemId);
                Location loc  = RandoResources.Locations.FirstOrDefault(l => l.Id == locId)
                                ?? RandoResources.Shops.FirstOrDefault(s => s.Id == locId);

                if (item == null)
                {
                    RandomizerMod.Instance.Log("Failed to find item " + itemId + " in resources, skipping");
                    continue;
                }

                if (loc == null)
                {
                    RandomizerMod.Instance.Log("Failed to find location " + locId + " in resources, skipping");
                    continue;
                }

                if (loc.Scene != scene)
                {
                    continue;
                }

                loc.SceneLoaded();

                PlayMakerFSM fsm;
                if (loc is ObjectLocation objLoc)
                {
                    GameObject obj = USceneManager.GetSceneByName(scene).FindGameObject(objLoc.MainObject);
                    if (obj.name == "Shop Menu")
                    {
                        if (!shopItems.TryGetValue(obj, out List <string> objShopItems))
                        {
                            objShopItems   = new List <string>();
                            shopItems[obj] = objShopItems;
                        }

                        objShopItems.Add(pair.Key);
                        continue;
                    }

                    fsm = ShinyUtil.GetShiny(obj);
                }
                else if (loc is NewLocation newLoc)
                {
                    fsm = ShinyUtil.CreateNewShiny(newLoc.X, newLoc.Y);
                }
                else
                {
                    continue;
                }

                // Begin patching shiny item fsm from vanilla -> rando
                ShinyUtil.CancelFling(fsm);
                ShinyUtil.SetLocationId(fsm, locId);
                fsm.ForceTransitions("Charm?", "Trink Flash", "Store Key");

                // Replace giving the store key with giving our new item
                FsmState giveTrinket = fsm.GetState("Store Key");
                giveTrinket.RemoveActionsOfType <SetPlayerDataBool>();
                giveTrinket.AddFirstAction(new CollectItem(loc, item));

                // Set the sprite/text on the popup to make it obvious if the above fails
                giveTrinket.GetActionOfType <GetLanguageString>().convName     = "IT BROKE";
                giveTrinket.GetActionOfType <SetSpriteRendererSprite>().sprite = Sprites.Get("NullTex");

                // Add dialogue box if necessary
                YNDialogue.AddToShiny(fsm, loc, item);
            }

            // Shop items
            foreach (KeyValuePair <GameObject, List <string> > pair in shopItems)
            {
                ShopModifier.SetShopItems(pair.Key, pair.Value.ToArray());
            }
        }
예제 #3
0
        public SceneManager()
        {
            var        subscriber       = new Subscriber();
            var        currentSceneName = "";
            GameObject loading          = null;

            // Scene Loaded
            subscriber.Subscribe(EventTopics.SceneAwake, () => currentSceneName = SceneManagement.GetActiveScene().name);

            // Scene Change
            subscriber.Subscribe <string>(EventTopics.SceneChange, (triggerName) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, currentSceneName, StringComparison.InvariantCultureIgnoreCase));
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneNext next = scene.LinkTo.FirstOrDefault(x => String.Equals(x.TriggerName, triggerName, StringComparison.InvariantCultureIgnoreCase));
                if (next == null)
                {
                    throw new Exception($"{this} no configuration for this trigger scene: {currentSceneName}, trigger: {triggerName}");
                }

                SceneConfig nextConfig = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, next.SceneName.Name, StringComparison.InvariantCultureIgnoreCase));
                if (nextConfig == null)
                {
                    throw new Exception($"{this} no configuration for this scene: {next.SceneName.Name}");
                }

                if (nextConfig.Async)
                {
                    SceneManagement.LoadSceneAsync(next.SceneName.Name, UnityEngine.SceneManagement.LoadSceneMode.Single);
                }
                else
                {
                    SceneManagement.LoadScene(next.SceneName.Name);
                }
            });

            // Scene Loading
            subscriber.Subscribe(EventTopics.SceneLoading, () =>
            {
                loading = Object.Instantiate(config.LoadingPrefab);
                loading.GetComponent <CanvasGroup>().alpha = 1;
            });

            subscriber.Subscribe(EventTopics.SceneLoaded, () =>
            {
                loading.GetComponent <CanvasGroup>().alpha = 0;
                Object.Destroy(loading);
                loading = null;
            });

            // Additive Scene
            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditive, (name) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                currentScene.StartCoroutine(LoadAdditiveScene(additive.Name));
            });

            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditiveAwake, (name) =>
            {
                // if the additive scene is opened directly
                if (currentScene == null)
                {
                    return;
                }

                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                if (additive.ActiveOnLoad)
                {
                    SceneManagement.SetActiveScene(SceneManagement.GetSceneByName(additive.Name));
                }
            });
        }