public static GameObject MakeNewChest(AbstractPlacement location)
        {
            GameObject chest = ObjectCache.Chest;

            chest.name = GetChestName(location);
            return(chest);
        }
        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");
        }
        public static GameObject MakeNewMultiItemShiny(AbstractPlacement location)
        {
            GameObject shiny = ObjectCache.ShinyItem;

            shiny.name = GetShinyPrefix(location);
            return(shiny);
        }
        /// <summary>
        /// Makes a Shiny Item with a name tied to location and item index. Apply FSM edits in OnEnable instead.
        /// </summary>
        public static GameObject MakeNewShiny(AbstractPlacement location, AbstractItem item)
        {
            GameObject shiny = ObjectCache.ShinyItem;

            shiny.name = GetShinyName(location, item);
            return(shiny);
        }
        public static GameObject MakeNewGrubJar(AbstractPlacement location)
        {
            GameObject grubJar = ObjectCache.GrubJar;

            grubJar.name = GetGrubJarName(location);

            return(grubJar);
        }
        public static GameObject MakeNewGeoRock(AbstractPlacement location, IEnumerable <AbstractItem> items, out GeoRockSubtype type)
        {
            type = items.OfType <GeoRockItem>().FirstOrDefault()?.geoRockSubtype ?? GeoRockSubtype.Default;
            GameObject rock = ObjectCache.GeoRock(type);

            rock.AddComponent <GeoRockInfo>().type = type;
            rock.name = GetGeoRockName(location);
            return(rock);
        }
        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);
                }
            }
        }
        public static bool TryGetItemFromShinyName(string shinyObjectName, AbstractPlacement location, out AbstractItem item)
        {
            item = null;
            if (!shinyObjectName.StartsWith(GetShinyPrefix(location)) ||
                !int.TryParse(shinyObjectName.Split('-').Last(), out int index) ||
                index < 0 ||
                index >= location.items.Count)
            {
                return(false);
            }

            item = location.items[index];
            return(true);
        }
        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 GameObject MakeNewTablet(AbstractPlacement location)
        {
            GameObject tablet = ObjectCache.LoreTablet;

            GameObject lit_tablet = tablet.transform.Find("lit_tablet").gameObject; // doesn't appear after instantiation, for some reason
            GameObject lit        = new GameObject();

            lit.transform.SetParent(tablet.transform);
            lit.transform.localPosition = new Vector3(-0.1f, 0.1f, -1.8f);
            lit.transform.localScale    = Vector3.one;
            lit.AddComponent <SpriteRenderer>().sprite = lit_tablet.GetComponent <SpriteRenderer>().sprite;
            lit.GetComponent <SpriteRenderer>().color  = new Color(1, 1, 1, 0.8f);

            tablet.name = GetTabletName(location);

            return(tablet);
        }
        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 #12
0
        public static GameObject GetNewContainer(AbstractPlacement placement, IEnumerable <AbstractItem> items, Container type)
        {
            switch (type)
            {
            default:
            case Container.Shiny:
                return(ShinyUtility.MakeNewMultiItemShiny(placement));

            case Container.Chest:
                return(ChestUtility.MakeNewChest(placement));

            case Container.GeoRock:
                return(GeoRockUtility.MakeNewGeoRock(placement, items, out _));

            case Container.GrubJar:
                return(GrubJarUtility.MakeNewGrubJar(placement));
            }
        }
 public static string GetShinyPrefix(AbstractPlacement location)
 {
     return($"Shiny Item-{location.name}");
 }
 public static string GetShinyName(AbstractPlacement location, AbstractItem item)
 {
     return($"{GetShinyPrefix(location)}-{location.items.IndexOf(item)}");
 }
 public static string GetChestName(AbstractPlacement location)
 {
     return($"Chest-{location.name}");
 }
 public static string GetTabletName(AbstractPlacement location)
 {
     return($"Lore Tablet-{location.name}");
 }
 public static string GetGeoRockName(AbstractPlacement location)
 {
     return($"Geo Rock-{location.name}");
 }
 public static string GetGrubJarName(AbstractPlacement location)
 {
     return($"Grub Bottle-{location.name}");
 }