private object CanLootEntity(BasePlayer player, StorageContainer container) { BaseEntity fridge = container.GetComponentInParent <BaseEntity>(); if (fridge.ShortPrefabName.Equals("fridge.deployed")) { ElectricalHeater electrified = container.GetComponentInChildren <ElectricalHeater>() ?? null; if (electrified == null) { return(null); } if (!electrified.IsPowered() && configData.Settings.blockLooting) { return(false); } string status = Lang("off"); if (electrified.IsPowered()) { status = Lang("on"); } PowerGUI(player, status); } return(null); }
private object CanPickupEntity(BasePlayer player, BaseCombatEntity fridge) { if (player == null || fridge == null) { return(null); } if (fridge.ShortPrefabName.Equals("fridge.deployed")) { ElectricalHeater electrified = fridge.GetComponentInChildren <ElectricalHeater>() ?? null; if (electrified == null) { return(null); } if (electrified.IsPowered()) { if (configData.Settings.blockPickup) { // Block pickup when powered, because danger or something. return(true); } if (fridges.Contains(fridge.net.ID)) { fridges.Remove(fridge.net.ID); SaveData(); } } } return(null); }
private void Connect(ElectricalHeater heater, ElectricalBranch branch) { const int inputSlot = 0; const int outputSlot = 1; branch.branchAmount = 5; IOEntity branchIO = branch as IOEntity; IOEntity heaterIO = heater as IOEntity; IOEntity.IOSlot branchOutput = branchIO.outputs[outputSlot]; IOEntity.IOSlot heaterInput = heaterIO.inputs[inputSlot]; heaterInput.connectedTo = new IOEntity.IORef(); heaterInput.connectedTo.Set(branch); heaterInput.connectedToSlot = outputSlot; heaterInput.connectedTo.Init(); heaterInput.connectedTo.ioEnt._limitedNetworking = true; //DoLog($"Heater input slot {inputSlot.ToString()}:{heaterInput.niceName} connected to {branchIO.ShortPrefabName}:{branchOutput.niceName}"); branchOutput.connectedTo = new IOEntity.IORef(); branchOutput.connectedTo.Set(heater); branchOutput.connectedToSlot = inputSlot; branchOutput.connectedTo.Init(); branchOutput.connectedTo.ioEnt._limitedNetworking = true; branch.MarkDirtyForceUpdateOutputs(); branch.SendNetworkUpdate(); //DoLog($"Branch output slot {outputSlot.ToString()}:{branchOutput.niceName} connected to {heaterIO.ShortPrefabName}:{heaterInput.niceName}"); }
private void OnEntitySpawned(BaseEntity fridge) { if (!startup) { return; } if (fridge == null) { return; } if (string.IsNullOrEmpty(fridge.ShortPrefabName)) { return; } if (fridge.ShortPrefabName.Equals("fridge.deployed")) { string ownerid = fridge.OwnerID.ToString(); if (configData.Settings.defaultEnabled && orDefault.Contains(ownerid)) { return; } else if (!configData.Settings.defaultEnabled && !orDefault.Contains(ownerid)) { return; } BaseEntity bent = fridge.gameObject.GetComponentInChildren <ElectricalBranch>() as BaseEntity ?? GameManager.server.CreateEntity("assets/prefabs/deployable/playerioents/gates/branch/electrical.branch.deployed.prefab", fridge.transform.position, fridge.transform.rotation, true); ElectricalBranch branch = bent as ElectricalBranch; if (bent != null) { bent.transform.localEulerAngles = new Vector3(0, 270, 180); bent.transform.localPosition = new Vector3(-0.49f, 0.65f, 0); bent.OwnerID = fridge.OwnerID; bent.SetParent(fridge); RemoveComps(bent); bent.Spawn(); } BaseEntity hent = fridge.gameObject.GetComponentInChildren <ElectricalHeater>() as BaseEntity ?? GameManager.server.CreateEntity("assets/prefabs/deployable/playerioents/electricheater/electrical.heater.prefab", fridge.transform.position, fridge.transform.rotation, true); ElectricalHeater heater = hent as ElectricalHeater; if (hent != null) { hent.transform.localEulerAngles = new Vector3(90, 90, 270); hent.transform.localPosition = new Vector3(0, 0.65f, 0); hent.OwnerID = fridge.OwnerID; hent.SetParent(fridge); RemoveComps(hent); hent.Spawn(); } DoLog("Adding FoodDecay object"); fridge.gameObject.AddComponent <FoodDecay>(); if (heater != null && branch != null) { Connect(heater, branch); } fridges.Add(fridge.net.ID); SaveData(); } }
public void Awake() { box = GetComponent <StorageContainer>() ?? null; Instance.DoLog("Found box"); heater = GetComponentInChildren <ElectricalHeater>() ?? null; if (heater != null && Instance.configData.Settings.decay) { Instance.DoLog("Found heater"); InvokeRepeating("ProcessContents", 0, Instance.configData.Settings.timespan); } }
private object CanPickupEntity(BasePlayer player, ElectricalHeater heater) { if (player == null || heater == null) { return(null); } BaseEntity f = heater.GetParentEntity(); if (f != null) { if (f.ShortPrefabName.Equals("fridge.deployed")) { return(false); } } return(null); }
private void OnEntityKill(ElectricalHeater heater) { BaseEntity f = heater.GetParentEntity(); if (f != null) { if (f.ShortPrefabName == "fridge.deployed") { if (fridges.Contains(f.net.ID)) { fridges.Remove(f.net.ID); SaveData(); } f.Kill(); } } }
private void OnServerInitialized() { LoadData(); List <uint> toremove = new List <uint>(); foreach (uint pid in fridges) { DoLog("Setting up old fridge"); BaseNetworkable fridge = BaseNetworkable.serverEntities.Find(pid); if (fridge == null) { toremove.Add(pid); continue; } ElectricalBranch br = fridge.gameObject.GetComponentInChildren <ElectricalBranch>(); if (br != null) { RemoveComps(br); } ElectricalHeater ht = fridge.gameObject.GetComponentInChildren <ElectricalHeater>(); if (ht != null) { RemoveComps(ht); } DoLog("Adding FoodDecay"); (fridge as BaseEntity)?.gameObject.AddComponent <FoodDecay>(); } foreach (uint tr in toremove) { fridges.Remove(tr); } SaveData(); startup = true; }