/// <summary> /// Collect given objects. /// </summary> /// <param name="gameObject">The game object to collect.</param> public void CollectGameObject(GameObject gameObject) { if (gameObject.name == "SUN" && worldTimeFsm == null) { // Yep it's called "Color" :> worldTimeFsm = Utils.GetPlaymakerScriptByName(gameObject, "Color"); if (worldTimeFsm == null) { return; } // Register refresh world time event. if (!worldTimeFsm.Fsm.HasEvent(REFRESH_WORLD_TIME_EVENT)) { FsmEvent mpRefreshWorldTimeEvent = worldTimeFsm.Fsm.GetEvent(REFRESH_WORLD_TIME_EVENT); PlayMakerUtils.AddNewGlobalTransition(worldTimeFsm, mpRefreshWorldTimeEvent, "State 1"); } // Make sure world time is up-to-date with cache. WorldTime = worldTimeCached; } else if (Utils.IsGameObjectHierarchyMatching(gameObject, "mailbox_bottom_player/Name")) { SetupMailbox(gameObject); } else if (IsVehicleGameObject(gameObject)) { vehicles.Add(new GameVehicle(gameObject)); } }
/// <summary> /// Callback called when world is loaded. /// </summary> public void OnLoad() { // Cache world time management fsm. GameObject sunGameObject = GameObject.Find("SUN"); Client.Assert(sunGameObject != null, "SUN game object is missing!"); // Yep it's called "Color" :> worldTimeFsm = Utils.GetPlaymakerScriptByName(sunGameObject, "Color"); Client.Assert(worldTimeFsm != null, "Now world time FSM found :("); // Register refresh world time event. if (!worldTimeFsm.Fsm.HasEvent(REFRESH_WORLD_TIME_EVENT)) { FsmEvent mpRefreshWorldTimeEvent = worldTimeFsm.Fsm.GetEvent(REFRESH_WORLD_TIME_EVENT); PlayMakerUtils.AddNewGlobalTransition(worldTimeFsm, mpRefreshWorldTimeEvent, "State 1"); } // Make sure world time is up-to-date with cache. WorldTime = worldTimeCached; gameAnimDatabase.Rebuild(); gamePickupableDatabase.Rebuild(); doorsManager.OnWorldLoad(); beerCaseManager.OnWorldLoad(); lightSwitchManager.OnWorldLoad(); LoadMailbox(); LoadVehicles(); if (GameCallbacks.onWorldLoad != null) { GameCallbacks.onWorldLoad(); } }
/// <summary> /// Finds Cloud System and adds custom Multiplayer weather events. /// </summary> public void OnWorldLoad() { GameObject cloudSystem = GameObject.Find("Clouds"); Client.Assert(cloudSystem != null, "cloudSystem couldn't be found!"); weatherSystemFSM = Utils.GetPlaymakerScriptByName(cloudSystem, "Weather"); FsmEvent rainEvent = weatherSystemFSM.Fsm.GetEvent(RAIN_ENAME); FsmEvent thunderEvent = weatherSystemFSM.Fsm.GetEvent(THUNDER_ENAME); FsmEvent noweatherEvent = weatherSystemFSM.Fsm.GetEvent(SUNNY_ENAME); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, rainEvent, "Rain"); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, thunderEvent, "Thunder"); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, noweatherEvent, "No weather"); }
/// <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)); } }
/// <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); } } }
/// <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); } } } }
/// <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)); }
/// <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> /// Finds Cloud System and adds custom Multiplayer weather events. /// </summary> public void CollectGameObject(GameObject gameObject) { if (gameObject.name != "Clouds") { return; } GameObject cloudSystem = gameObject; Client.Assert(cloudSystem != null, "cloudSystem couldn't be found!"); weatherSystemFSM = Utils.GetPlaymakerScriptByName(cloudSystem, "Weather"); FsmEvent rainEvent = weatherSystemFSM.Fsm.GetEvent(RAIN_ENAME); FsmEvent thunderEvent = weatherSystemFSM.Fsm.GetEvent(THUNDER_ENAME); FsmEvent noweatherEvent = weatherSystemFSM.Fsm.GetEvent(SUNNY_ENAME); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, rainEvent, "Rain"); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, thunderEvent, "Thunder"); PlayMakerUtils.AddNewGlobalTransition(weatherSystemFSM, noweatherEvent, "No weather"); }
/// <summary> /// Collect given objects. /// </summary> /// <param name="gameObject">The game object to collect.</param> public void CollectGameObject(GameObject gameObject) { if (gameObject.name == "SUN" && worldTimeFsm == null) { // Yep it's called "Color" :> worldTimeFsm = Utils.GetPlaymakerScriptByName(gameObject, "Color"); if (worldTimeFsm == null) { return; } // Register refresh world time event. if (!worldTimeFsm.Fsm.HasEvent(REFRESH_WORLD_TIME_EVENT)) { FsmEvent mpRefreshWorldTimeEvent = worldTimeFsm.Fsm.GetEvent(REFRESH_WORLD_TIME_EVENT); PlayMakerUtils.AddNewGlobalTransition(worldTimeFsm, mpRefreshWorldTimeEvent, "State 1"); } // Make sure world time is up-to-date with cache. WorldTime = worldTimeCached; } else if (Utils.IsGameObjectHierarchyMatching(gameObject, "mailbox_bottom_player/Name")) { SetupMailbox(gameObject); } else if (gameObject.name == "TRAFFIC") { new TrafficManager(gameObject); } else if (gameObject.name == "STORE") { new Shop(gameObject); } else if (gameObject.name == "BOAT") { ObjectSyncComponent osc = gameObject.transform.FindChild("GFX").FindChild("Colliders").FindChild("Collider").gameObject.AddComponent<ObjectSyncComponent>(); osc.Setup(ObjectSyncManager.ObjectTypes.Boat, ObjectSyncManager.AUTOMATIC_ID); } else if (gameObject.name == "GarageDoors") { ObjectSyncComponent oscLeft = gameObject.transform.FindChild("DoorLeft").FindChild("Coll").gameObject.AddComponent<ObjectSyncComponent>(); oscLeft.Setup(ObjectSyncManager.ObjectTypes.GarageDoor, ObjectSyncManager.AUTOMATIC_ID); ObjectSyncComponent oscRight = gameObject.transform.FindChild("DoorRight").FindChild("Coll").gameObject.AddComponent<ObjectSyncComponent>(); oscRight.Setup(ObjectSyncManager.ObjectTypes.GarageDoor, ObjectSyncManager.AUTOMATIC_ID); } }
/// <summary> /// Collect given objects. /// </summary> /// <param name="gameObject">The game object to collect.</param> public void CollectGameObject(GameObject gameObject) { if (gameObject.name == "SUN" && worldTimeFsm == null) { // Yep it's called "Color" :> worldTimeFsm = Utils.GetPlaymakerScriptByName(gameObject, "Color"); if (worldTimeFsm == null) { return; } // Register refresh world time event. if (!worldTimeFsm.Fsm.HasEvent(REFRESH_WORLD_TIME_EVENT)) { FsmEvent mpRefreshWorldTimeEvent = worldTimeFsm.Fsm.GetEvent(REFRESH_WORLD_TIME_EVENT); PlayMakerUtils.AddNewGlobalTransition(worldTimeFsm, mpRefreshWorldTimeEvent, "State 1"); } // Make sure world time is up-to-date with cache. WorldTime = worldTimeCached; } else if (Utils.IsGameObjectHierarchyMatching(gameObject, "mailbox_bottom_player/Name")) { SetupMailbox(gameObject); } else if (gameObject.name == "TRAFFIC") { trafficManager.Setup(gameObject); } else if (gameObject.name == "STORE") { shopManager.Setup(gameObject); } else if (gameObject.name == "BOAT") { ObjectSyncComponent osc = gameObject.transform.FindChild("GFX/Colliders/Collider").gameObject.AddComponent <ObjectSyncComponent>(); osc.Setup(ObjectSyncManager.ObjectTypes.Boat, ObjectSyncManager.AUTOMATIC_ID); } // Garage doors. else if (gameObject.name == "GarageDoors") { ObjectSyncComponent oscLeft = gameObject.transform.FindChild("DoorLeft/Coll").gameObject.AddComponent <ObjectSyncComponent>(); oscLeft.Setup(ObjectSyncManager.ObjectTypes.GarageDoor, ObjectSyncManager.AUTOMATIC_ID); ObjectSyncComponent oscRight = gameObject.transform.FindChild("DoorRight/Coll").gameObject.AddComponent <ObjectSyncComponent>(); oscRight.Setup(ObjectSyncManager.ObjectTypes.GarageDoor, ObjectSyncManager.AUTOMATIC_ID); } // Old car shed doors. else if (gameObject.name == "Doors" && gameObject.transform.parent.name == "Shed") { PlayMakerFSM doorLeft = gameObject.transform.FindChild("DoorLeft/Mesh").gameObject.GetComponent <PlayMakerFSM>(); EventHook.AddWithSync(doorLeft, "Open door"); EventHook.AddWithSync(doorLeft, "Close door"); PlayMakerFSM doorRight = gameObject.transform.FindChild("DoorRight/Mesh").gameObject.GetComponent <PlayMakerFSM>(); EventHook.AddWithSync(doorRight, "Open door"); EventHook.AddWithSync(doorRight, "Close door"); } // Weather system. else if (gameObject.name == "Clouds" && gameObject.transform.parent.name == "CloudSystem") { ObjectSyncComponent osc = gameObject.AddComponent <ObjectSyncComponent>(); osc.Setup(ObjectSyncManager.ObjectTypes.Weather, ObjectSyncManager.AUTOMATIC_ID); } // Sewage well jobs. else if (gameObject.name.StartsWith("HouseShit")) { ObjectSyncComponent osc = gameObject.AddComponent <ObjectSyncComponent>(); osc.Setup(ObjectSyncManager.ObjectTypes.SewageWell, ObjectSyncManager.AUTOMATIC_ID); } // Phone. else if (gameObject.name == "Ring") { phoneManager.Setup(gameObject); } // Map. else if (gameObject.name == "MAP" && gameObject.transform.FindChild("Darts")) { mapManager.Setup(gameObject); } }