public static void ModifyShiny(PlayMakerFSM shinyFsm, FlingType flingType, AbstractPlacement location, AbstractItem item)
        {
            FsmState pdBool     = shinyFsm.GetState("PD Bool?");
            FsmState charm      = shinyFsm.GetState("Charm?");
            FsmState trinkFlash = shinyFsm.GetState("Trink Flash");

            FsmStateAction checkAction = new RandomizerExecuteLambda(() => shinyFsm.SendEvent(item.IsObtained() ? "COLLECTED" : null));
            FsmStateAction giveAction  = new RandomizerExecuteLambda(() => item.Give(location, Container.Shiny, flingType, shinyFsm.gameObject.transform, message: MessageType.Any, callback: (_) => shinyFsm.SendEvent("GAVE ITEM")));

            // Remove actions that stop shiny from spawning
            pdBool.RemoveActionsOfType <StringCompare>();

            // Change pd bool test to our new bool
            pdBool.RemoveActionsOfType <PlayerDataBoolTest>();
            pdBool.AddAction(checkAction);

            // Charm must be preserved as the entry point for AddYNDialogueToShiny
            charm.ClearTransitions();
            charm.AddTransition("FINISHED", "Trink Flash");

            trinkFlash.ClearTransitions();
            trinkFlash.Actions = new FsmStateAction[]
            {
                trinkFlash.Actions[0], // Audio
                trinkFlash.Actions[1], // Audio
                trinkFlash.Actions[2], // visual effect
                trinkFlash.Actions[3], // hide shiny
                trinkFlash.Actions[4], // pickup animation
                // [5] -- spawn message
                // [6] -- store message text
                // [7] -- store message icon
                giveAction, // give item and await callback
            };
            trinkFlash.AddTransition("GAVE ITEM", "Hero Up");
        }
        /// <summary>
        /// Call after ModifyShiny to add cost.
        /// </summary>
        public static void AddYNDialogueToShiny(PlayMakerFSM shinyFsm, Cost cost, IEnumerable <AbstractItem> items)
        {
            FsmState charm    = shinyFsm.GetState("Charm?");
            FsmState yesState = shinyFsm.GetState(charm.Transitions[0].ToState);
            FsmState noState  = new FsmState(shinyFsm.GetState("Idle"))
            {
                Name = "YN No"
            };
            FsmState giveControl = new FsmState(shinyFsm.GetState("Idle"))
            {
                Name = "Give Control"
            };

            FsmStateAction closeYNDialogue = new RandomizerExecuteLambda(() => CloseYNDialogue());

            noState.ClearTransitions();
            noState.RemoveActionsOfType <FsmStateAction>();
            noState.AddTransition("FINISHED", "Give Control");

            Tk2dPlayAnimationWithEvents heroUp = new Tk2dPlayAnimationWithEvents
            {
                gameObject = new FsmOwnerDefault
                {
                    OwnerOption = OwnerDefaultOption.SpecifyGameObject,
                    GameObject  = SereCore.Ref.Hero.gameObject
                },
                clipName = "Collect Normal 3",
                animationTriggerEvent  = null,
                animationCompleteEvent = FsmEvent.GetFsmEvent("FINISHED")
            };

            noState.AddAction(closeYNDialogue);
            noState.AddAction(heroUp);

            giveControl.ClearTransitions();
            giveControl.RemoveActionsOfType <FsmStateAction>();

            giveControl.AddTransition("FINISHED", "Idle");

            giveControl.AddAction(new RandomizerExecuteLambda(() => PlayMakerFSM.BroadcastEvent("END INSPECT")));

            shinyFsm.AddState(noState);
            shinyFsm.AddState(giveControl);

            charm.ClearTransitions();

            charm.AddTransition("HERO DAMAGED", noState.Name);
            charm.AddTransition("NO", noState.Name);
            charm.AddTransition("YES", yesState.Name);

            yesState.AddFirstAction(new RandomizerExecuteLambda(() => cost.Pay()));
            yesState.AddFirstAction(closeYNDialogue);

            charm.AddFirstAction(new RandomizerExecuteLambda(() => OpenYNDialogue(shinyFsm.gameObject, items, cost)));
        }
        public static void ModifyGeoRock(PlayMakerFSM rockFsm, FlingType flingType, AbstractPlacement location, IEnumerable <AbstractItem> items)
        {
            GameObject rock = rockFsm.gameObject;

            FsmState init   = rockFsm.GetState("Initiate");
            FsmState hit    = rockFsm.GetState("Hit");
            FsmState payout = rockFsm.GetState("Destroy");
            FsmState broken = rockFsm.GetState("Broken");

            FsmStateAction checkAction = new RandomizerExecuteLambda(() => rockFsm.SendEvent(location.HasVisited() ? "BROKEN" : null));

            init.RemoveActionsOfType <IntCompare>();
            init.AddAction(checkAction);

            hit.ClearTransitions();
            hit.AddTransition("HIT", "Pause Frame");
            hit.AddTransition("FINISHED", "Pause Frame");
            hit.RemoveActionsOfType <FlingObjectsFromGlobalPool>();

            var payoutAction = payout.GetActionOfType <FlingObjectsFromGlobalPool>();

            payoutAction.spawnMin.Value = 0;
            payoutAction.spawnMax.Value = 0;

            GameObject itemParent = new GameObject("item");

            itemParent.transform.SetParent(rock.transform);
            itemParent.transform.position      = rock.transform.position;
            itemParent.transform.localPosition = Vector3.zero;
            itemParent.SetActive(true);

            FsmStateAction spawnShinies = new ActivateAllChildren {
                gameObject = new FsmGameObject {
                    Value = itemParent,
                }, activate = true
            };

            payout.AddAction(spawnShinies);
            broken.AddAction(spawnShinies);

            foreach (AbstractItem item in items)
            {
                if (item.GiveEarly(Container.GeoRock))
                {
                    FsmStateAction giveAction = new RandomizerExecuteLambda(() => item.Give(location, Container.GeoRock, flingType, rockFsm.gameObject.transform, message: MessageType.None));
                    payout.AddAction(giveAction);
                }
                else
                {
                    GameObject shiny = ShinyUtility.MakeNewShiny(location, item);
                    ShinyUtility.PutShinyInContainer(itemParent, shiny);
                }
            }
        }
Beispiel #4
0
        public override void Process(string scene, Object changeObj)
        {
            if (scene != _sceneName || !(changeObj is PlayMakerFSM fsm) || fsm.FsmName != _fsmName ||
                fsm.gameObject.name != _objectName)
            {
                return;
            }

            // Open the chest if the item has already been collected
            FsmState init = fsm.GetState("Init");
            RandomizerExecuteLambda disableChest = new RandomizerExecuteLambda(() => fsm.SendEvent(
                                                                                   RandomizerMod.Instance.Settings.CheckLocationFound(_location) ? "ACTIVATE" : null
                                                                                   ));

            init.Actions = new FsmStateAction[]
            {
                init.Actions[0],
                init.Actions[1],
                init.Actions[2],
                init.Actions[3],
                init.Actions[4],
                disableChest,
                init.Actions[5],
                init.Actions[6],
            };

            // Remove actions that activate shiny item
            FsmState spawnItems = fsm.GetState("Spawn Items");

            spawnItems.RemoveActionsOfType <ActivateAllChildren>();
            fsm.GetState("Activated").RemoveActionsOfType <ActivateAllChildren>();

            // Add geo to chest
            // Chest geo pool cannot be trusted, often spawns less than it should
            spawnItems.AddAction(new RandomizerAddGeo(fsm.gameObject, _geoAmount));
            spawnItems.AddAction(new RandomizerExecuteLambda(() => GiveItemActions.GiveItem(GiveItemActions.GiveAction.None, _item, _location)));

            // Remove pre-existing geo from chest
            foreach (FlingObjectsFromGlobalPool fling in spawnItems.GetActionsOfType <FlingObjectsFromGlobalPool>())
            {
                fling.spawnMin = 0;
                fling.spawnMax = 0;
            }

            // Need to check SpawnFromPool action too because of Mantis Lords chest
            foreach (SpawnFromPool spawn in spawnItems.GetActionsOfType <SpawnFromPool>())
            {
                spawn.spawnMin = 0;
                spawn.spawnMax = 0;
            }
        }
        public static void ModifyBottleFsm(GameObject jar, FlingType flingType, AbstractPlacement location, IEnumerable <AbstractItem> items)
        {
            PlayMakerFSM fsm      = jar.LocateFSM("Bottle Control");
            FsmState     init     = fsm.GetState("Init");
            FsmState     shatter  = fsm.GetState("Shatter");
            FsmState     activate = fsm.GetState("Activate");

            init.RemoveActionsOfType <BoolTest>();
            shatter.RemoveActionsOfType <IncrementPlayerDataInt>();
            shatter.RemoveActionsOfType <SendMessage>();

            FsmStateAction checkAction = new RandomizerExecuteLambda(() => fsm.SendEvent(location.HasVisited() ? "ACTIVATE" : null));

            init.AddFirstAction(checkAction);

            GameObject itemParent = new GameObject("item");

            itemParent.transform.SetParent(jar.transform);
            itemParent.transform.position      = jar.transform.position;
            itemParent.transform.localPosition = Vector3.zero;
            itemParent.SetActive(true);

            FsmStateAction spawnShinies = new ActivateAllChildren {
                gameObject = new FsmGameObject {
                    Value = itemParent,
                }, activate = true
            };
            FsmStateAction removeParent = new RandomizerExecuteLambda(() => itemParent.transform.parent = null);

            shatter.AddAction(spawnShinies);
            activate.AddFirstAction(removeParent); // activate has a destroy all children action
            activate.AddFirstAction(spawnShinies);

            foreach (AbstractItem item in items)
            {
                if (item.GiveEarly(Container.GrubJar))
                {
                    FsmStateAction giveAction = new RandomizerExecuteLambda(() => item.Give(location, Container.GrubJar, flingType, jar.transform, MessageType.Corner));
                    shatter.AddAction(giveAction);
                }
                else
                {
                    GameObject shiny = ShinyUtility.MakeNewShiny(location, item);
                    ShinyUtility.PutShinyInContainer(itemParent, shiny);
                }
            }
        }
        public static void ModifyChest(PlayMakerFSM chestFsm, FlingType flingType, AbstractPlacement location, IEnumerable <AbstractItem> items)
        {
            FsmState init       = chestFsm.GetState("Init");
            FsmState spawnItems = chestFsm.GetState("Spawn Items");

            FsmStateAction checkAction = new RandomizerExecuteLambda(() => chestFsm.SendEvent(location.HasVisited() ? "ACTIVATE" : null));

            init.RemoveActionsOfType <BoolTest>();
            init.AddAction(checkAction);

            // Destroy any existing shinies in the chest
            GameObject itemParent = chestFsm.gameObject.transform.Find("Item").gameObject;

            foreach (Transform t in itemParent.transform)
            {
                UnityEngine.Object.Destroy(t.gameObject);
            }

            // Remove pre-existing geo from chest
            foreach (FlingObjectsFromGlobalPool fling in spawnItems.GetActionsOfType <FlingObjectsFromGlobalPool>())
            {
                fling.spawnMin = 0;
                fling.spawnMax = 0;
            }

            // Need to check SpawnFromPool action too because of Mantis Lords chest
            foreach (SpawnFromPool spawn in spawnItems.GetActionsOfType <SpawnFromPool>())
            {
                spawn.spawnMin = 0;
                spawn.spawnMax = 0;
            }

            foreach (AbstractItem item in items)
            {
                if (item.GiveEarly(Container.Chest))
                {
                    spawnItems.AddAction(new RandomizerExecuteLambda(() => item.Give(location, Container.Chest, flingType, chestFsm.gameObject.transform, MessageType.Corner)));
                }
                else
                {
                    GameObject shiny = ShinyUtility.MakeNewShiny(location, item);
                    ShinyUtility.PutShinyInContainer(itemParent, shiny);
                }
            }
        }
Beispiel #7
0
        public override void OnEnableFsm(PlayMakerFSM fsm)
        {
            RepairCosts();

            if (fsm.FsmName == "Inspection" && fsm.gameObject.name == TabletUtility.GetTabletName(this))
            {
                fsm.FsmVariables.FindFsmString("Convo Name").Value = fsm.gameObject.name;
                fsm.FsmVariables.FindFsmString("Sheet Name").Value = "ItemChanger.Locations";
            }

            if (fsm.FsmName == "Shiny Control" && ShinyUtility.TryGetItemFromShinyName(fsm.gameObject.name, this, out var shinyItem))
            {
                ShinyUtility.ModifyShiny(fsm, chestLocation.flingType, this, shinyItem);
                if (chestLocation.flingType == FlingType.Everywhere)
                {
                    ShinyUtility.FlingShinyRandomly(fsm);
                }
                else
                {
                    ShinyUtility.FlingShinyDown(fsm);
                }
            }

            if (fsm.FsmName == "Chest Control" && fsm.gameObject.name == ChestUtility.GetChestName(this))
            {
                FsmState init       = fsm.GetState("Init");
                FsmState spawnItems = fsm.GetState("Spawn Items");

                FsmStateAction checkAction = new RandomizerExecuteLambda(() => fsm.SendEvent(items.All(i => i.IsObtained()) ? "ACTIVATE" : null));

                init.RemoveActionsOfType <BoolTest>();
                init.AddAction(checkAction);

                // Destroy any existing shinies in the chest
                GameObject itemParent = fsm.gameObject.transform.Find("Item").gameObject;
                foreach (Transform t in itemParent.transform)
                {
                    GameObject.Destroy(t.gameObject);
                }

                // Remove pre-existing geo from chest
                foreach (FlingObjectsFromGlobalPool fling in spawnItems.GetActionsOfType <FlingObjectsFromGlobalPool>())
                {
                    fling.spawnMin = 0;
                    fling.spawnMax = 0;
                }

                // Need to check SpawnFromPool action too because of Mantis Lords chest
                foreach (SpawnFromPool spawn in spawnItems.GetActionsOfType <SpawnFromPool>())
                {
                    spawn.spawnMin = 0;
                    spawn.spawnMax = 0;
                }

                FsmStateAction generateItems = new RandomizerExecuteLambda(() =>
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        var item = items[i];
                        var cost = costs[i];

                        if (!item.IsObtained())
                        {
                            if (cost != null && !cost.Paid() && !cost.CanPay())
                            {
                                continue;
                            }
                            if (cost != null && !cost.Paid())
                            {
                                cost.Pay();
                            }
                            if (item.GiveEarly(Container.Chest))
                            {
                                item.Give(this, Container.Chest, chestLocation.flingType, fsm.gameObject.transform, MessageType.Corner);
                            }
                            else
                            {
                                GameObject shiny = ShinyUtility.MakeNewShiny(this, item);
                                ShinyUtility.PutShinyInContainer(itemParent, shiny);
                            }
                        }
                    }
                });

                fsm.GetState("Open").AddAction(generateItems);
            }
        }