/// <summary> /// Initializes the lantern switch behaviour providing a mod handle and a scene light wrapper. /// </summary> /// <param name="_mod">A handle to the mod object initializing this switch.</param> /// <param name="_light">Contains references to the block and other components.</param> public void Load(CLanternShadows _mod, SSceneLight _light) { mi_mod = _mod; mi_sceneLight = _light; mi_nlCntrl = mi_sceneLight.LightComponent.GetComponent <NightLightController>(); mi_setLightIntensityInfo = typeof(NightLightController).GetMethod("SetLightIntensity", BindingFlags.NonPublic | BindingFlags.Instance); mi_network = ComponentManager <Semih_Network> .Value; //use our block objects index so we receive RPC calls //need to use an existing blockindex as clients/host need to be aware of it ObjectIndex = mi_sceneLight.BlockObject.ObjectIndex; NetworkIDManager.AddNetworkID(this); CheckLightState(true); mi_loaded = true; if (!Semih_Network.IsHost) //request lantern states from host after load { mi_network.SendP2P( mi_network.HostID, new Message_Battery_OnOff( //just use the battery message as it should never Messages.Battery_OnOff, mi_network.NetworkIDManager, mi_network.LocalSteamID, this.ObjectIndex, (int)ELanternRequestType.REQUEST_STATE, //we use the battery uses int to pass our custom command type IsOn), EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game); } else if (mi_mod.SavedLightData.ContainsKey(SaveAndLoad.CurrentGameFileName)) { var data = mi_mod.SavedLightData[SaveAndLoad.CurrentGameFileName].FirstOrDefault(_o => _o.ObjectID == ObjectIndex); if (data != null) { UserControlsState = true; SetLightOn(data.IsOn); } } }
public void OnBlockPlaced() { NetworkIDManager.AddNetworkID(this); }