Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gameObject">The game object to pickup.</param>
        public GamePlayer(GameObject gameObject)
        {
            this.gameObject = gameObject;

            pickupFsm = Utils.GetPlaymakerScriptByName(gameObject, "PickUp");

            PlayMakerUtils.AddNewAction(pickupFsm.Fsm.GetState("Part picked"), new OnPickupAction(this));
            PlayMakerUtils.AddNewAction(pickupFsm.Fsm.GetState("Item picked"), new OnPickupAction(this));

            PlayMakerUtils.AddNewAction(pickupFsm.Fsm.GetState("Throw part"), new OnThrowAction(this));
            PlayMakerUtils.AddNewAction(pickupFsm.Fsm.GetState("Drop part"), new OnDropAction(this));
        }
Beispiel #2
0
        /// <summary>
        /// Setup player trigger related hooks.
        /// </summary>
        /// <param name="fsm">The fsm to hook.</param>
        private void SetupPlayerTriggerHooks(PlayMakerFSM fsm)
        {
            FsmState playerInCarState   = fsm.Fsm.GetState("Player in car");
            FsmState waitForPlayerState = fsm.Fsm.GetState("Wait for player");

            if (waitForPlayerState != null)
            {
                PlayMakerUtils.AddNewAction(waitForPlayerState, new OnLeaveAction(this));
            }

            if (playerInCarState != null)
            {
                PlayMakerUtils.AddNewAction(playerInCarState, new OnEnterAction(this));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gameObject">Game object of the light switch to represent by this wrapper.</param>
        public LightSwitch(GameObject gameObject)
        {
            go = gameObject;

            fsm = Utils.GetPlaymakerScriptByName(go, "Use");
            if (fsm.Fsm.HasEvent(EVENT_NAME))
            {
                //Already hooked
                Logger.Log($"Light switch {go.name} is already hooked!");
            }
            else
            {
                FsmEvent mpEventOn = fsm.Fsm.GetEvent(EVENT_NAME);
                PlayMakerUtils.AddNewGlobalTransition(fsm, mpEventOn, "Switch");
                PlayMakerUtils.AddNewAction(fsm.Fsm.GetState("Switch"), new OnLightSwitchUseAction(this));
            }
        }
Beispiel #4
0
 /// <summary>
 /// Adds a PlayMaker Event hook.
 /// </summary>
 /// <param name="fsm">The PlayMakerFSM that contains the event to hook.</param>
 /// <param name="eventName">The name of the event to hook.</param>
 /// <param name="action">The action to perform on event firing.</param>
 /// <param name="actionOnExit">Should action be put ran on exitting instead of entering event?</param>
 public static void Add(PlayMakerFSM fsm, string eventName, Func <bool> action, bool actionOnExit = false)
 {
     if (fsm == null)
     {
         Client.Assert(true, "EventHook Add: Failed to hook event. (FSM is null)");
     }
     else
     {
         FsmState state = fsm.Fsm.GetState(eventName);
         if (state != null)
         {
             PlayMakerUtils.AddNewAction(state, new CustomAction(action, eventName, actionOnExit));
             FsmEvent mpEvent = fsm.Fsm.GetEvent("MP_" + eventName);
             PlayMakerUtils.AddNewGlobalTransition(fsm, mpEvent, eventName);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Adds a PlayMaker Event hook and syncs event with remote clients.
        /// </summary>
        /// <param name="fsm">The PlayMakerFSM that contains the event to hook.</param>
        /// <param name="eventName">The name of the event to hook.</param>
        /// <param name="action">Optional action to run. (Action runs before duplicate
        /// check!)</param>
        public static void AddWithSync(
            PlayMakerFSM fsm, string eventName, Func <bool> action = null)
        {
            if (fsm == null)
            {
                Client.Assert(
                    true, "EventHook AddWithSync: Failed to hook event. (FSM is null)");
            }
            else
            {
                FsmState state = fsm.Fsm.GetState(eventName);
                if (state != null)
                {
                    bool duplicate = false;
                    int  fsmId     = Instance.fsmEvents.Count + 1;
                    if (Instance.fsms.ContainsValue(fsm))
                    {
                        duplicate = true;
                        foreach (KeyValuePair <int, PlayMakerFSM> entry in Instance.fsms)
                        {
                            if (entry.Value == fsm)
                            {
                                fsmId = entry.Key;
                                break;
                            }
                        }
                    }
                    int eventId = Instance.fsmEvents.Count + 1;
                    Instance.fsms.Add(Instance.fsms.Count + 1, fsm);
                    Instance.fsmEvents.Add(Instance.fsmEvents.Count + 1, eventName);

                    PlayMakerUtils.AddNewAction(state,
                                                new CustomActionSync(
                                                    Instance.fsms.Count, Instance.fsmEvents.Count, action));
                    FsmEvent mpEvent = fsm.Fsm.GetEvent("MP_" + eventName);
                    PlayMakerUtils.AddNewGlobalTransition(fsm, mpEvent, eventName);

                    // Sync with host
                    if (!Network.NetManager.Instance.IsHost &&
                        Network.NetManager.Instance.IsOnline && duplicate == false)
                    {
                        Network.NetLocalPlayer.Instance.RequestEventHookSync(fsmId);
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gameObject">Game object of the doors to represent by this wrapper.</param>
        public GameDoor(GameObject gameObject)
        {
            go  = gameObject;
            fsm = Utils.GetPlaymakerScriptByName(go, "Use");
            if (fsm.Fsm.HasEvent(MP_OPEN_EVENT_NAME))
            {
                Logger.Log("Failed to hook game door " + go.name + ". It is already hooked.");
                return;
            }

            FsmEvent mpOpenEvent  = fsm.Fsm.GetEvent(MP_OPEN_EVENT_NAME);
            FsmEvent mpCloseEvent = fsm.Fsm.GetEvent(MP_CLOSE_EVENT_NAME);

            PlayMakerUtils.AddNewGlobalTransition(fsm, mpOpenEvent, "Open door");
            PlayMakerUtils.AddNewGlobalTransition(fsm, mpCloseEvent, "Close door");

            PlayMakerUtils.AddNewAction(fsm.Fsm.GetState("Open door"), new OnOpenDoorsAction(this));
            PlayMakerUtils.AddNewAction(fsm.Fsm.GetState("Close door"), new OnCloseDoorsAction(this));
        }
Beispiel #7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gameObject">Game object of the beercases to represent by this wrapper.</param>
        public BeerCase(GameObject gameObject)
        {
            go = gameObject;

            fsm = Utils.GetPlaymakerScriptByName(go, "Use");
            if (fsm.Fsm.HasEvent(EVENT_NAME))
            {
                //Already hooked
                Logger.Debug($"Beercase {go.name} is already hooked!");
            }
            else
            {
                FsmEvent mpEvent = fsm.Fsm.GetEvent(EVENT_NAME);
                PlayMakerUtils.AddNewGlobalTransition(fsm, mpEvent, "Remove bottle");
                PlayMakerUtils.AddNewAction(fsm.Fsm.GetState("Remove bottle"), new OnConsumeBeerAction(this));
            }

            Logger.Debug($"Beercase found!");
        }
            /// <summary>
            /// Spawn new instance of the given pickupable at given world position.
            /// </summary>
            /// <param name="position">The position where to spawn pickupable at.</param>
            /// <param name="rotation">The rotation to apply on spawned pickupable.</param>
            /// <returns>Newly spawned pickupable game object.</returns>
            public GameObject Spawn(Vector3 position, Quaternion rotation)
            {
                // HACK: Jonnez is already spawned and there can be only one of it.
                // TODO: Get rid of it, it's ugly hack. Perhaps JONNEZ should behave like
                // pickupable.
                if (gameObject.name.StartsWith("JONNEZ ES"))
                {
                    return(GameObject.Find("JONNEZ ES(Clone)"));
                }

                GameObject pickupable =
                    (GameObject)Object.Instantiate(gameObject, position, rotation);

                pickupable.SetActive(true);
                pickupable.transform.SetParent(null);

                // Disable loading code on all spawned pickupables.

                PlayMakerFSM fsm = Utils.GetPlaymakerScriptByName(pickupable, "Use");

                if (fsm != null)
                {
                    FsmState loadState = fsm.Fsm.GetState("Load");
                    if (loadState != null)
                    {
                        var action = new SendEvent();
                        action.eventTarget             = new FsmEventTarget();
                        action.eventTarget.excludeSelf = false;
                        action.eventTarget.target      = FsmEventTarget.EventTarget.Self;
                        action.sendEvent = fsm.Fsm.GetEvent("FINISHED");
                        PlayMakerUtils.AddNewAction(loadState, action);

                        Logger.Log("Installed skip load hack for prefab " + pickupable.name);
                    }
                    else
                    {
                        Logger.Log("Failed to find state on " + pickupable.name);
                    }
                }

                return(pickupable);
            }
Beispiel #9
0
        public GameVehicle(GameObject go)
        {
            gameObject = go;

            dynamics = gameObject.GetComponent <CarDynamics>();

            /*PlayMakerFSM loadingFsm = Utils.GetPlaymakerScriptByName(gameObject, "LOD");
             * if (loadingFsm != null) {
             *      Component.Destroy(loadingFsm);
             * }*/


            PlayMakerFSM[] fsms = gameObject.GetComponentsInChildren <PlayMakerFSM>();

            Logger.Log("FSMS of " + gameObject.name);
            foreach (var fsm in fsms)
            {
                if (fsm.FsmName != "PlayerTrigger")
                {
                    continue;
                }

                FsmState playerInCarState   = fsm.Fsm.GetState("Player in car");
                FsmState waitForPlayerState = fsm.Fsm.GetState("Wait for player");

                if (waitForPlayerState != null)
                {
                    PlayMakerUtils.AddNewAction(waitForPlayerState, new OnLeaveAction(this));
                }

                if (playerInCarState != null)
                {
                    PlayMakerUtils.AddNewAction(playerInCarState, new OnEnterAction(this));
                }
            }
        }