public override void OnEnter()
        {
            go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                Finish();
                return;
            }

            var sendToFsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);

            if (sendToFsm == null)
            {
                if (requireReceiver)
                {
                    LogError("GameObject doesn't have FsmComponent: " + go.name + " " + fsmName.Value);
                }

                return;
            }

            if (delay.Value < 0.001)
            {
                sendToFsm.Fsm.Event(sendEvent.Value);
                Finish();
            }
            else
            {
                delayedEvent = sendToFsm.Fsm.DelayedEvent(FsmEvent.GetFsmEvent(sendEvent.Value), delay.Value);
            }
        }
Beispiel #2
0
 public static void BroadcastEvent(string fsmEventName)
 {
     if (!string.IsNullOrEmpty(fsmEventName))
     {
         BroadcastEvent(FsmEvent.GetFsmEvent(fsmEventName));
     }
 }
    public static bool CreateIfNeededGlobalEvent(string globalEventName)
    {
        FsmEvent _event = FsmEvent.GetFsmEvent(globalEventName);

        bool result = false;

        if (!FsmEvent.IsEventGlobal(globalEventName))
        {
            if (_event == null)
            {
                _event = new FsmEvent(globalEventName)
                {
                    IsGlobal = true
                };
                FsmEvent.AddFsmEvent(_event);
                if (!FsmEvent.globalEvents.Contains(globalEventName))
                {
                    FsmEvent.globalEvents.Add(globalEventName);
                }
            }

            result = true;
        }

        return(result);
    }
Beispiel #4
0
        public void SendEventag()
        {
            for (int i = 0; i < gos.Length; i++)
            {
                if (layerFilterOn.Value == true)
                {
                    if (gos[i].layer == layer)

                    {
                        if (sendEvent == null)
                        {
                            Fsm.SendEventToFsmOnGameObject(gos[i], fsmName, FsmEvent.GetFsmEvent(sendEventName.Value));
                        }


                        Fsm.SendEventToFsmOnGameObject(gos[i], fsmName, sendEvent);
                    }
                }

                if (layerFilterOn.Value == false)
                {
                    if (sendEvent == null)
                    {
                        Fsm.SendEventToFsmOnGameObject(gos[i], fsmName, FsmEvent.GetFsmEvent(sendEventName.Value));
                    }


                    Fsm.SendEventToFsmOnGameObject(gos[i], fsmName, sendEvent);
                }
            }
        }
Beispiel #5
0
        public override void OnEnter()
        {
            this.go = base.Fsm.GetOwnerDefaultTarget(this.gameObject);
            if (this.go == null)
            {
                base.Finish();
                return;
            }
            PlayMakerFSM gameObjectFsm = ActionHelpers.GetGameObjectFsm(this.go, this.fsmName.Value);

            if (gameObjectFsm == null)
            {
                if (this.requireReceiver)
                {
                    this.LogError("GameObject doesn't have FsmComponent: " + this.go.name + " " + this.fsmName.Value);
                }
                return;
            }
            if ((double)this.delay.Value < 0.001)
            {
                gameObjectFsm.Fsm.Event(this.sendEvent.Value);
                base.Finish();
            }
            else
            {
                this.delayedEvent = gameObjectFsm.Fsm.DelayedEvent(FsmEvent.GetFsmEvent(this.sendEvent.Value), this.delay.Value);
            }
        }
Beispiel #6
0
    public FsmEvent AddEvent(string eventName)
    {
        events.Add(eventName);
        FsmEvent fsmEvent = FsmEvent.FindEvent(eventName) ?? FsmEvent.GetFsmEvent(eventName);

        fsmEvent.IsGlobal = true;
        return(fsmEvent);
    }
Beispiel #7
0
        public static void AddToShiny(PlayMakerFSM fsm, string text, Func <bool> canBuy)
        {
            FsmState noState = new FsmState(fsm.GetState("Idle"))
            {
                Name = "YN No"
            };

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

            noState.AddTransition("FINISHED", "Give Control");

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

            noState.AddAction(new ExecuteLambda(CloseYNDialogue));
            noState.AddAction(heroUp);

            FsmState giveControl = new FsmState(fsm.GetState("Idle"))
            {
                Name = "Give Control"
            };

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

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

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

            fsm.AddState(noState);
            fsm.AddState(giveControl);

            FsmState charm    = fsm.GetState("Charm?");
            string   yesState = charm.Transitions[0].ToState;

            charm.ClearTransitions();

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

            fsm.GetState(yesState).AddAction(new ExecuteLambda(CloseYNDialogue));

            charm.AddFirstAction(new ExecuteLambda(() => OpenYNDialogue(fsm.gameObject, text, canBuy)));
        }
        /// <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)));
        }
Beispiel #9
0
 public override void OnEnter()
 {
     if (delay.Value < 0.001f)
     {
         Fsm.Event(eventTarget, sendEvent.Value);
         Finish();
     }
     else
     {
         delayedEvent = Fsm.DelayedEvent(eventTarget, FsmEvent.GetFsmEvent(sendEvent.Value), delay.Value);
     }
 }
Beispiel #10
0
 public override void OnEnter()
 {
     if (this.delay.Value < 0.001f)
     {
         base.Fsm.Event(this.eventTarget, this.sendEvent.Value);
         base.Finish();
     }
     else
     {
         this.delayedEvent = base.Fsm.DelayedEvent(this.eventTarget, FsmEvent.GetFsmEvent(this.sendEvent.Value), this.delay.Value);
     }
 }
Beispiel #11
0
 public override void OnEnter()
 {
     if (delay.Value < 0.001f)
     {
         base.Fsm.Event(eventTarget, sendEvent.Value);
         if (!everyFrame)
         {
             Finish();
         }
     }
     else
     {
         delayedEvent = base.Fsm.DelayedEvent(eventTarget, FsmEvent.GetFsmEvent(sendEvent.Value), delay.Value);
     }
 }
Beispiel #12
0
        public static FsmEvent AddFsmTransition(this FsmState state, string eventName, string toState)
        {
            var ret = FsmEvent.GetFsmEvent(eventName);

            FsmTransition[] origTransitions = state.Transitions;
            FsmTransition[] transitions     = new FsmTransition[origTransitions.Length + 1];
            origTransitions.CopyTo(transitions, 0);
            transitions[origTransitions.Length] = new FsmTransition
            {
                ToState    = toState,
                ToFsmState = state.Fsm.GetState(toState),
                FsmEvent   = ret
            };
            state.Transitions = transitions;
            return(ret);
        }
Beispiel #13
0
        public static void AddTransition(this FsmState self, string eventName, string toState)
        {
            FsmTransition[] transitions = new FsmTransition[self.Transitions.Length + 1];
            Array.Copy(self.Transitions, transitions, self.Transitions.Length);
            self.Transitions = transitions;

            FsmTransition trans = new FsmTransition
            {
                ToState  = toState,
                FsmEvent = FsmEvent.EventListContains(eventName)
                    ? FsmEvent.GetFsmEvent(eventName)
                    : new FsmEvent(eventName)
            };


            self.Transitions[self.Transitions.Length - 1] = trans;
        }
        public static void addTransition(this FsmState self, string eventName, string toState)
        {
            List <FsmTransition> transitions = self.Transitions.ToList();

            FsmTransition trans = new FsmTransition
            {
                ToState  = toState,
                FsmEvent = FsmEvent.EventListContains(eventName)
                    ? FsmEvent.GetFsmEvent(eventName)
                    : new FsmEvent(eventName)
            };


            transitions.Add(trans);

            self.Transitions = transitions.ToArray();
        }
        public static void AddTransition(this FsmState self, string eventName, string toState)
        {
            List <FsmTransition> transitions = self.Transitions.ToList();

            FsmTransition trans = new FsmTransition();

            trans.ToState = toState;

            if (FsmEvent.EventListContains(eventName))
            {
                trans.FsmEvent = FsmEvent.GetFsmEvent(eventName);
            }
            else
            {
                trans.FsmEvent = new FsmEvent(eventName);
            }

            transitions.Add(trans);

            self.Transitions = transitions.ToArray();
        }
Beispiel #16
0
        public RandomizerBoolTest(string boolName, string failEventName, string successEventName,
                                  bool playerdata = false)
        {
            _boolName   = boolName;
            _playerdata = playerdata;

            if (failEventName != null)
            {
                _failEvent = FsmEvent.EventListContains(failEventName)
                    ? FsmEvent.GetFsmEvent(failEventName)
                    : new FsmEvent(failEventName);
            }

            if (successEventName == null)
            {
                return;
            }

            _successEvent = FsmEvent.EventListContains(successEventName)
                ? FsmEvent.GetFsmEvent(successEventName)
                : new FsmEvent(successEventName);
        }
Beispiel #17
0
    /// <summary>
    /// Creates the global event if needed.
    /// </summary>
    /// <returns><c>true</c>, if global event was created <c>false</c> if event existed already.</returns>
    /// <param name="EventName">Event name.</param>
    public FsmEvent CreateGlobalEvent(string EventName, out bool ExistsAlready)
    {
        FsmEvent _event = FsmEvent.GetFsmEvent(EventName);

        ExistsAlready = FsmEvent.EventListContains(EventName);

        if (ExistsAlready)
        {
            if (_event != null && _event.IsGlobal)
            {
                _event.IsGlobal = true;
            }

            return(_event);
        }

        _event          = new FsmEvent(EventName);
        _event.IsGlobal = true;
        FsmEvent.AddFsmEvent(_event);

        return(_event);
    }
        private IEnumerator ToggleShadeSpawnCoroutine()
        {
            yield return(null);

            yield return(new WaitWhile(() => HeroController.instance == null || HeroController.instance.heroDeathPrefab == null));

            try
            {
                PlayMakerFSM fsm     = HeroController.instance.heroDeathPrefab.LocateMyFSM("Hero Death Anim");
                FsmState     mapZone = fsm.GetState("Map Zone");
                FsmState     wpCheck = fsm.GetState("WP Check");
                FsmString    zone    = fsm.FsmVariables.FindFsmString("Map Zone");

                if (Settings.NoShadeOnDeath)
                {
                    FsmState animStart = fsm.GetState("Anim Start");
                    mapZone.Transitions.First(t => t.EventName == "FINISHED").SetToState(animStart);

                    wpCheck.Actions = new FsmStateAction[]
                    {
                        new StringCompare
                        {
                            stringVariable = zone,
                            compareTo      = "DREAM_WORLD",
                            equalEvent     = FsmEvent.Finished,
                            notEqualEvent  = null,
                            everyFrame     = false,
                            storeResult    = false,
                        },
                        new StringCompare
                        {
                            stringVariable = zone,
                            compareTo      = "GODS_GLORY",
                            equalEvent     = FsmEvent.Finished,
                            notEqualEvent  = FsmEvent.GetFsmEvent("WHITE PALACE"),
                            everyFrame     = false,
                            storeResult    = false,
                        },
                    };
                }
                else
                {
                    FsmState breakGlassHP = fsm.GetState("Break Glass HP");
                    mapZone.Transitions.First(t => t.EventName == "FINISHED").SetToState(breakGlassHP);

                    wpCheck.Actions = new FsmStateAction[]
                    {
                        new StringCompare
                        {
                            stringVariable = zone,
                            compareTo      = "WHITE_PALACE",
                            equalEvent     = FsmEvent.GetFsmEvent("WHITE PALACE"),
                            notEqualEvent  = null,
                            everyFrame     = false,
                            storeResult    = false,
                        },
                    };
                }
            }
            catch (Exception e)
            {
                LogError(e);
            }
        }
Beispiel #19
0
        private void SetupOrb()
        {
            var orb = orbPre;

            orb.layer = 17;   //PhysLayers.HERO_ATTACK
            AddDamageEnemy(orb);

            var orbcontrol = orb.LocateMyFSM("Orb Control");

            FsmState chaseEnemy = new FsmState(orbcontrol.Fsm)
            {
                Name = "Chase Enemy"
            };

            #region Event&Transition
            FsmEvent hitevent     = new FsmEvent("ORBHIT");
            FsmEvent dispateevent = FsmEvent.GetFsmEvent("DISSIPATE");
            orbcontrol.ChangeTransition("Init", "FIRE", "Chase Enemy");
            orbcontrol.ChangeTransition("Init", "FINISHED", "Chase Enemy");
            chaseEnemy.Transitions = new FsmTransition[]
            {
                new FsmTransition
                {
                    FsmEvent = hitevent,
                    ToState  = "Impact pause"
                },
                new FsmTransition
                {
                    FsmEvent = dispateevent,
                    ToState  = "Dissipate"
                },
            };
            #endregion

            var _list = orbcontrol.FsmStates.ToList();
            _list.Add(chaseEnemy);
            var _toremove = new List <FsmState>();
            foreach (var s in _list)
            {
                if (s.Name == "Orbiting" || s.Name.Contains("Chase Hero"))
                {
                    _toremove.Add(s);
                }
            }
            foreach (var s in _toremove)
            {
                _list.Remove(s);
            }

            orbcontrol.Fsm.States = _list.ToArray();

            chaseEnemy.Actions = new FsmStateAction[]
            {
                new Trigger2dEventLayer {
                    trigger       = PlayMakerUnity2d.Trigger2DType.OnTriggerEnter2D,
                    collideLayer  = 11,
                    sendEvent     = hitevent,
                    collideTag    = "",
                    storeCollider = new FsmGameObject()
                },
                new Trigger2dEventLayer {
                    trigger       = PlayMakerUnity2d.Trigger2DType.OnTriggerStay2D,
                    collideLayer  = 11,
                    sendEvent     = hitevent,
                    collideTag    = "",
                    storeCollider = new FsmGameObject()
                },
                new Wait
                {
                    time        = 3.5f,
                    finishEvent = dispateevent
                },
            };
            //orbcontrol.SetState("Chase Enemy");

            orbcontrol.GetAction <Wait>("Impact", 7).time = 0.1f;
            //orb.AddComponent<MyChaseObject>();
            orbcontrol.Fsm.SaveActions();

            setupDone++;
        }
        public void CR_Change_Room_temple(Scene scene)
        {
            if (scene.name != "Room_temple")
            {
                return;
            }

            Log("CR_Change_Room_temple()");
            //yield return null;

            #region Hornet NPC FSM

            GameObject   hornetNpcGo     = scene.FindRoot("Hornet Black Egg NPC");
            PlayMakerFSM hornetNpcFsm    = hornetNpcGo.LocateMyFSM("Conversation Control");
            FsmVariables hornetNpcFsmVar = hornetNpcFsm.FsmVariables;

            hornetNpcFsm.CopyState("Greet", "Give Item");
            hornetNpcFsm.RemoveAction("Give Item", 0);

            hornetNpcFsm.GetAction <CallMethodProper>("Give Item", 0).parameters = new FsmVar[]
            {
                new FsmVar(typeof(string))
                {
                    stringValue = "CUSTOM_HORNET_PRE_FINAL_BATTLE"
                },
                new FsmVar(typeof(string))
                {
                    stringValue = "Hornet"
                }
            };

            var pdbtAction = new PlayerDataBoolTest();
            pdbtAction.gameObject = hornetNpcFsm.GetAction <PlayerDataBoolTest>("Choice", 1).gameObject;
            pdbtAction.boolName   = "SFGrenadeTestOfTeamworkHornetCompanion";
            pdbtAction.isFalse    = FsmEvent.GetFsmEvent("ABSENT");

            hornetNpcFsm.InsertAction("Choice", pdbtAction, 1);

            hornetNpcFsm.AddTransition("Choice", "ABSENT", "Give Item");

            #endregion

            #region Shiny FSM

            GameObject shinyParent = GameObject.Instantiate(PrefabHolder.shinyPrefab);
            shinyParent.name = "Necklace";
            shinyParent.SetActive(false);
            shinyParent.transform.GetChild(0).gameObject.SetActive(true);
            shinyParent.transform.position = new Vector3(29.0f, 4.3f, 0.0f);

            hornetNpcFsm.CopyState("Box Up", "Give Item Spawn");

            hornetNpcFsm.ChangeTransition("Give Item Spawn", FsmEvent.Finished.Name, "Talk Finish");
            hornetNpcFsm.GetState("Give Item").Transitions.First(x => x.ToState == "Talk Finish").ToState = "Give Item Spawn";

            hornetNpcFsm.RemoveAction("Give Item Spawn", 5);
            hornetNpcFsm.RemoveAction("Give Item Spawn", 4);
            hornetNpcFsm.RemoveAction("Give Item Spawn", 3);
            hornetNpcFsm.RemoveAction("Give Item Spawn", 2);
            hornetNpcFsm.RemoveAction("Give Item Spawn", 1);
            hornetNpcFsm.RemoveAction("Give Item Spawn", 0);

            var agoAction = new ActivateGameObject();
            agoAction.gameObject             = new FsmOwnerDefault();
            agoAction.gameObject.OwnerOption = OwnerDefaultOption.SpecifyGameObject;
            agoAction.gameObject.GameObject  = shinyParent;
            agoAction.activate    = true;
            agoAction.recursive   = false;
            agoAction.resetOnExit = false;
            agoAction.everyFrame  = false;
            hornetNpcFsm.AddAction("Give Item Spawn", agoAction);
            hornetNpcFsm.AddAction("Give Item Spawn", new NextFrameEvent()
            {
                sendEvent = FsmEvent.Finished
            });

            PlayMakerFSM shinyFsm     = shinyParent.transform.GetChild(0).gameObject.LocateMyFSM("Shiny Control");
            FsmVariables shinyFsmVars = shinyFsm.FsmVariables;
            shinyFsmVars.FindFsmInt("Charm ID").Value         = 0;
            shinyFsmVars.FindFsmInt("Type").Value             = 0;
            shinyFsmVars.FindFsmBool("Activated").Value       = false;
            shinyFsmVars.FindFsmBool("Charm").Value           = false;
            shinyFsmVars.FindFsmBool("Dash Cloak").Value      = false;
            shinyFsmVars.FindFsmBool("Exit Dream").Value      = false;
            shinyFsmVars.FindFsmBool("Fling L").Value         = false;
            shinyFsmVars.FindFsmBool("Fling On Start").Value  = true;
            shinyFsmVars.FindFsmBool("Journal").Value         = false;
            shinyFsmVars.FindFsmBool("King's Brand").Value    = false;
            shinyFsmVars.FindFsmBool("Mantis Claw").Value     = false;
            shinyFsmVars.FindFsmBool("Pure Seed").Value       = false;
            shinyFsmVars.FindFsmBool("Quake").Value           = false;
            shinyFsmVars.FindFsmBool("Show Charm Tute").Value = false;
            shinyFsmVars.FindFsmBool("Slug Fling").Value      = false;
            shinyFsmVars.FindFsmBool("Super Dash").Value      = false;
            shinyFsmVars.FindFsmString("Item Name").Value     = Consts.LanguageStrings.HornetInvNameKey;
            shinyFsmVars.FindFsmString("PD Bool Name").Value  = "SFGrenadeTestOfTeamworkHornetCompanion";

            IntSwitch isAction     = shinyFsm.GetAction <IntSwitch>("Trinket Type", 0);
            var       tmpCompareTo = new List <FsmInt>(isAction.compareTo);
            tmpCompareTo.Add(tmpCompareTo.Count + 1);
            isAction.compareTo = tmpCompareTo.ToArray();
            shinyFsmVars.FindFsmInt("Trinket Num").Value = tmpCompareTo.Count;
            var tmpSendEvent = new List <FsmEvent>(isAction.sendEvent);
            tmpSendEvent.Add(FsmEvent.FindEvent("PURE SEED"));
            isAction.sendEvent = tmpSendEvent.ToArray();

            shinyFsm.CopyState("Love Key", "Necklace");

            shinyFsm.GetAction <SetPlayerDataBool>("Necklace", 0).boolName     = "SFGrenadeTestOfTeamworkHornetCompanion";
            shinyFsm.GetAction <SetSpriteRendererSprite>("Necklace", 1).sprite = TestOfTeamwork.Instance.SpriteDict.Get(TextureStrings.InvHornetKey);
            shinyFsm.GetAction <GetLanguageString>("Necklace", 2).convName     = Consts.LanguageStrings.HornetInvNameKey;

            shinyFsm.AddTransition("Trinket Type", "PURE SEED", "Necklace");

            #endregion

            Log("~CR_Change_Room_temple()");
        }
Beispiel #21
0
 public static void AddTransition(this FsmState state, string eventName, string toState)
 {
     state.AddTransition(FsmEvent.GetFsmEvent(eventName) ?? new FsmEvent(eventName), toState);
 }
        public override void Process(string scene, Object changeObj)
        {
            if (scene != _sceneName || !(changeObj is PlayMakerFSM fsm) || fsm.FsmName != _fsmName ||
                fsm.gameObject.name != _objectName)
            {
                return;
            }

            FsmState noState = new FsmState(fsm.GetState("Idle"))
            {
                Name = "YN No"
            };

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

            noState.AddTransition("FINISHED", "Give Control");

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

            noState.AddAction(new RandomizerCallStaticMethod(GetType(), nameof(CloseYNDialogue)));
            noState.AddAction(heroUp);

            FsmState giveControl = new FsmState(fsm.GetState("Idle"))
            {
                Name = "Give Control"
            };

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

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

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

            fsm.AddState(noState);
            fsm.AddState(giveControl);

            FsmState charm    = fsm.GetState("Charm?");
            string   yesState = charm.Transitions[0].ToState;

            charm.ClearTransitions();

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

            fsm.GetState(yesState).AddAction(new RandomizerCallStaticMethod(GetType(), nameof(CloseYNDialogue)));

            charm.AddFirstAction(new RandomizerCallStaticMethod(GetType(), nameof(OpenYNDialogue), fsm.gameObject,
                                                                _itemName, _cost, _type));
        }
 public static FsmTransition AddTransition(this FsmState state, string eventName, string toState)
 {
     return(state.AddTransition(FsmEvent.GetFsmEvent(eventName), state.Fsm.GetState(toState)));
 }
Beispiel #24
0
        public override void Process(string scene, Object changeObj)
        {
            if (scene != _sceneName || !(changeObj is PlayMakerFSM fsm) || fsm.FsmName != _fsmName ||
                fsm.gameObject.name != _objectName)
            {
                return;
            }

            FsmState noState = new FsmState(fsm.GetState("Idle"))
            {
                Name = "YN No"
            };

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

            noState.AddTransition("FINISHED", "Give Control");

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

            noState.AddAction(new RandomizerCallStaticMethod(GetType(), nameof(CloseYNDialogue)));
            noState.AddAction(heroUp);

            // For some reason playing the animation doesn't work if we come here from being damaged, locking us in the
            // YN No state. I think just having a separate state to come from if we were damaged is the simplest fix.
            FsmState damageState = new FsmState(fsm.GetState("Idle"))
            {
                Name = "YN Damaged"
            };

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

            damageState.AddTransition("FINISHED", "Give Control");

            damageState.AddAction(new RandomizerCallStaticMethod(GetType(), nameof(CloseYNDialogue)));


            FsmState giveControl = new FsmState(fsm.GetState("Idle"))
            {
                Name = "Give Control"
            };

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

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

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

            fsm.AddState(noState);
            fsm.AddState(damageState);
            fsm.AddState(giveControl);

            FsmState charm    = fsm.GetState("Charm?");
            string   yesState = charm.Transitions[0].ToState;

            charm.ClearTransitions();

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

            // Here is a good place to remove the spent simple key
            if (_type == CostType.Simple)
            {
                fsm.GetState(yesState).AddFirstAction(new RandomizerExecuteLambda(() => PlayerData.instance.DecrementInt("simpleKeys")));
            }

            fsm.GetState(yesState).AddAction(new RandomizerCallStaticMethod(GetType(), nameof(CloseYNDialogue)));

            charm.AddFirstAction(new RandomizerCallStaticMethod(GetType(), nameof(OpenYNDialogue), fsm.gameObject,
                                                                _itemName, _cost, _type));
        }
        public void Start()
        {
            if (type == Type.FLOOR)
            {
                GameObject actualBlocker = GameObject.Instantiate(PrefabHolder.popQuakeFloorPrefab, transform.parent, true);
                actualBlocker.SetActive(false);
                actualBlocker.transform.position    = transform.position;
                actualBlocker.transform.localScale  = transform.lossyScale;
                actualBlocker.transform.eulerAngles = transform.eulerAngles;

                var t  = actualBlocker.Find("Active").transform;
                var t2 = gameObject.Find("Active").transform;
                for (int c = t2.childCount - 1; c >= 0; c--)
                {
                    t2.GetChild(c).SetParent(t, true);
                }
                t  = actualBlocker.Find("Inactive").transform;
                t2 = gameObject.Find("Inactive").transform;
                for (int c = t2.childCount - 1; c >= 0; c--)
                {
                    t2.GetChild(c).SetParent(t, true);
                }
                actualBlocker.Find("Inactive").SetActive(false);

                var blockerFsm = actualBlocker.LocateMyFSM("quake_floor");
                if (blockerFsm.GetState("Init").Fsm == null)
                {
                    blockerFsm.Preprocess();
                }
                blockerFsm.SetAttr("fsmTemplate", (FsmTemplate)null);
                var blockerFsmVars = blockerFsm.FsmVariables;
                blockerFsmVars.GetFsmBool("Glass").Value             = false;
                blockerFsmVars.GetFsmString("Playerdata Bool").Value = pdBool;

                DestroyObject doAction = new DestroyObject
                {
                    gameObject     = blockerFsmVars.GetFsmGameObject("Inactive"),
                    delay          = 0.0f,
                    detachChildren = true
                };
                var agoAction = new ActivateGameObject
                {
                    gameObject = new FsmOwnerDefault
                    {
                        OwnerOption = OwnerDefaultOption.SpecifyGameObject,
                        GameObject  = blockerFsmVars.GetFsmGameObject("Inactive")
                    },
                    activate    = false,
                    recursive   = false,
                    resetOnExit = false,
                    everyFrame  = false
                };
                blockerFsm.AddAction("Destroy", agoAction);
                blockerFsm.AddAction("Destroy", doAction);

                blockerFsm.RemoveAction("Activate", 0);
                blockerFsm.AddAction("Activate", new SetBoolValue()
                {
                    boolVariable = blockerFsmVars.GetFsmBool("Activated"),
                    boolValue    = true,
                    everyFrame   = false
                });
                blockerFsm.AddAction("Activate", new ActivateGameObject()
                {
                    gameObject = new FsmOwnerDefault()
                    {
                        OwnerOption = OwnerDefaultOption.SpecifyGameObject,
                        GameObject  = blockerFsmVars.GetFsmGameObject("Active")
                    },
                    activate    = false,
                    recursive   = false,
                    resetOnExit = false,
                    everyFrame  = false
                });
                blockerFsm.AddAction("Activate", new ActivateGameObject()
                {
                    gameObject = new FsmOwnerDefault()
                    {
                        OwnerOption = OwnerDefaultOption.SpecifyGameObject,
                        GameObject  = blockerFsmVars.GetFsmGameObject("Inactive")
                    },
                    activate    = true,
                    recursive   = false,
                    resetOnExit = false,
                    everyFrame  = false
                });
                blockerFsm.AddAction("Activate", new SetCollider()
                {
                    gameObject = new FsmOwnerDefault()
                    {
                        OwnerOption = OwnerDefaultOption.UseOwner
                    },
                    active = false
                });
                blockerFsm.AddAction("Init", new PlayerDataBoolTest()
                {
                    gameObject = new FsmOwnerDefault()
                    {
                        OwnerOption = OwnerDefaultOption.SpecifyGameObject,
                        GameObject  = GameManager.instance.gameObject
                    },
                    boolName = blockerFsmVars.GetFsmString("Playerdata Bool"),
                    isTrue   = FsmEvent.GetFsmEvent("ACTIVATE"),
                    isFalse  = FsmEvent.Finished
                });
                blockerFsm.RemoveAction("Init", 0);
                blockerFsm.RemoveAction("PD Bool?", 0);

                blockerFsm.SetState("Pause");

                blockerFsm.MakeLog(true);

                actualBlocker.SetActive(true);
                Object.Destroy(gameObject);
            }
            else if (type == Type.WALL)
            {
            }
        }