public virtual void Init() { for (int index = 0; index < this.outputs.Length; ++index) { IOEntity.IOSlot output = this.outputs[index]; output.connectedTo.Init(); if (Object.op_Inequality((Object)output.connectedTo.Get(true), (Object)null)) { int connectedToSlot = output.connectedToSlot; if (connectedToSlot < 0 || connectedToSlot >= output.connectedTo.Get(true).inputs.Length) { Debug.LogError((object)("Slot IOR Error: " + ((Object)this).get_name() + " setting up inputs for " + ((Object)output.connectedTo.Get(true)).get_name() + " slot : " + (object)output.connectedToSlot)); } else { output.connectedTo.Get(true).inputs[output.connectedToSlot].connectedTo.Set(this); output.connectedTo.Get(true).inputs[output.connectedToSlot].connectedToSlot = index; output.connectedTo.Get(true).inputs[output.connectedToSlot].connectedTo.Init(); } } } if (!this.IsRootEntity()) { return; } this.Invoke(new Action(this.MarkDirtyForceUpdateOutputs), Random.Range(1f, 1f)); }
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}"); }
public void ServerUpdate() { if (base.isServer) { if (this.lastServerUpdateTime == 0f) { this.lastServerUpdateTime = Time.realtimeSinceStartup; } float single = Time.realtimeSinceStartup - this.lastServerUpdateTime; this.lastServerUpdateTime = Time.realtimeSinceStartup; if (Time.time > this.lastEnergyTime + 0.333f) { float single1 = this.energyForOpen * single / this.secondsToClose; float single2 = Mathf.Min(this.storedEnergy, single1); this.storedEnergy -= single2; this.storedEnergy = Mathf.Clamp(this.storedEnergy, 0f, this.energyForOpen); if (single2 > 0f) { IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { oSlot.connectedTo.Get(true).IOInput(this, this.ioType, -single2, oSlot.connectedToSlot); } } } } this.UpdateProgress(); } }
public bool IsConnectedTo(IOEntity entity, int depth, bool defaultReturn = false) { if (depth <= 0) { return(defaultReturn); } for (int i = 0; i < (int)this.inputs.Length; i++) { IOEntity.IOSlot oSlot = this.inputs[i]; if (oSlot.mainPowerSlot) { IOEntity oEntity = oSlot.connectedTo.Get(true); if (oEntity != null) { if (oEntity == entity) { return(true); } if (oEntity.IsConnectedTo(entity, depth - 1, defaultReturn)) { return(true); } } } } return(false); }
public virtual void UpdateOutputs() { if (UnityEngine.Time.realtimeSinceStartup - this.lastUpdateTime < IOEntity.responsetime) { IOEntity._processQueue.Enqueue(this); return; } this.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; this.SendIONetworkUpdate(); if (this.outputs.Length == 0) { this.ensureOutputsUpdated = false; return; } if (this.ensureOutputsUpdated) { int num = (this.cachedOutputsUsed == 0 ? 1 : this.cachedOutputsUsed); int num1 = Mathf.FloorToInt((float)this.GetPassthroughAmount(0) / (float)num); this.ensureOutputsUpdated = false; IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { oSlot.connectedTo.Get(true).UpdateFromInput(num1, oSlot.connectedToSlot); } } } }
public virtual void Init() { for (int i = 0; i < (int)this.outputs.Length; i++) { IOEntity.IOSlot oSlot = this.outputs[i]; oSlot.connectedTo.Init(); if (oSlot.connectedTo.Get(true) != null) { int num = oSlot.connectedToSlot; if (num < 0 || num >= (int)oSlot.connectedTo.Get(true).inputs.Length) { Debug.LogError(string.Concat(new object[] { "Slot IOR Error: ", base.name, " setting up inputs for ", oSlot.connectedTo.Get(true).name, " slot : ", oSlot.connectedToSlot })); } else { oSlot.connectedTo.Get(true).inputs[oSlot.connectedToSlot].connectedTo.Set(this); oSlot.connectedTo.Get(true).inputs[oSlot.connectedToSlot].connectedToSlot = i; oSlot.connectedTo.Get(true).inputs[oSlot.connectedToSlot].connectedTo.Init(); } } } if (this.IsRootEntity()) { base.Invoke(new Action(this.MarkDirtyForceUpdateOutputs), UnityEngine.Random.Range(1f, 1f)); } }
public void RequestClear(BaseEntity.RPCMessage msg) { IOEntity component; IOEntity.IOSlot oSlot; if (!WireTool.CanPlayerUseWires(msg.player)) { return; } uint num = msg.read.UInt32(); int num1 = msg.read.Int32(); bool flag = msg.read.Bit(); BaseNetworkable baseNetworkable = BaseNetworkable.serverEntities.Find(num); if (baseNetworkable == null) { component = null; } else { component = baseNetworkable.GetComponent <IOEntity>(); } IOEntity oEntity = component; if (oEntity == null) { return; } if (num1 >= (flag ? (int)oEntity.inputs.Length : (int)oEntity.outputs.Length)) { return; } IOEntity.IOSlot oSlot1 = (flag ? oEntity.inputs[num1] : oEntity.outputs[num1]); if (oSlot1.connectedTo.Get(true) == null) { return; } IOEntity oEntity1 = oSlot1.connectedTo.Get(true); oSlot = (flag ? oEntity1.outputs[oSlot1.connectedToSlot] : oEntity1.inputs[oSlot1.connectedToSlot]); if (flag) { oEntity.UpdateFromInput(0, num1); } else if (oEntity1) { oEntity1.UpdateFromInput(0, oSlot1.connectedToSlot); } oSlot1.Clear(); oSlot.Clear(); if (oEntity1) { oEntity1.MarkDirtyForceUpdateOutputs(); oEntity1.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } oEntity.MarkDirtyForceUpdateOutputs(); oEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
public virtual float IOInput(IOEntity from, IOEntity.IOType inputType, float inputAmount, int slot = 0) { IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { inputAmount = oSlot.connectedTo.Get(true).IOInput(this, oSlot.type, inputAmount, oSlot.connectedToSlot); } } return(inputAmount); }
public override void UpdateOutputs() { this.currentEnergy = this.GetCurrentEnergy(); IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { oSlot.connectedTo.Get(true).UpdateFromInput(this.currentEnergy, oSlot.connectedToSlot); } } }
public void CancelPlayerRotation() { base.CancelInvoke(new Action(this.RotateProgress)); base.SetFlag(this.BeingRotated, false, false, true); IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { oSlot.connectedTo.Get(true).IOInput(this, this.ioType, 0f, oSlot.connectedToSlot); } } this.rotatorPlayer = null; }
public void Powered() { float single = this.kineticEnergyPerSec * this.progressTickRate; IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { single = oSlot.connectedTo.Get(true).IOInput(this, this.ioType, single, oSlot.connectedToSlot); } } this.SetRotateProgress(this.rotateProgress + 0.1f); }
public bool IsConnectedTo(IOEntity entity, int slot, int depth, bool defaultReturn = false) { if (depth > 0 && slot < this.inputs.Length) { IOEntity.IOSlot input = this.inputs[slot]; if (input.mainPowerSlot) { IOEntity ioEntity = input.connectedTo.Get(true); if (Object.op_Inequality((Object)ioEntity, (Object)null) && (Object.op_Equality((Object)ioEntity, (Object)entity) || ioEntity.IsConnectedTo(entity, depth - 1, defaultReturn))) { return(true); } } } return(false); }
public override void Save(BaseNetworkable.SaveInfo info) { int i; base.Save(info); info.msg.ioEntity = Facepunch.Pool.Get <ProtoBuf.IOEntity>(); info.msg.ioEntity.inputs = Facepunch.Pool.GetList <ProtoBuf.IOEntity.IOConnection>(); info.msg.ioEntity.outputs = Facepunch.Pool.GetList <ProtoBuf.IOEntity.IOConnection>(); IOEntity.IOSlot[] oSlotArray = this.inputs; for (i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; ProtoBuf.IOEntity.IOConnection oConnection = Facepunch.Pool.Get <ProtoBuf.IOEntity.IOConnection>(); oConnection.connectedID = oSlot.connectedTo.entityRef.uid; oConnection.connectedToSlot = oSlot.connectedToSlot; oConnection.niceName = oSlot.niceName; oConnection.type = (int)oSlot.type; oConnection.inUse = oConnection.connectedID != 0; info.msg.ioEntity.inputs.Add(oConnection); } oSlotArray = this.outputs; for (i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot1 = oSlotArray[i]; ProtoBuf.IOEntity.IOConnection list = Facepunch.Pool.Get <ProtoBuf.IOEntity.IOConnection>(); list.connectedID = oSlot1.connectedTo.entityRef.uid; list.connectedToSlot = oSlot1.connectedToSlot; list.niceName = oSlot1.niceName; list.type = (int)oSlot1.type; list.inUse = list.connectedID != 0; if (oSlot1.linePoints != null) { list.linePointList = Facepunch.Pool.GetList <ProtoBuf.IOEntity.IOConnection.LineVec>(); list.linePointList.Clear(); Vector3[] vector3Array = oSlot1.linePoints; for (int j = 0; j < (int)vector3Array.Length; j++) { Vector3 vector3 = vector3Array[j]; ProtoBuf.IOEntity.IOConnection.LineVec lineVec = Facepunch.Pool.Get <ProtoBuf.IOEntity.IOConnection.LineVec>(); lineVec.vec = vector3; list.linePointList.Add(lineVec); } } info.msg.ioEntity.outputs.Add(list); } }
public static void ResetIOEntRecursive(IOEntity target, int resetIndex) { if (target.lastResetIndex == resetIndex) { return; } target.lastResetIndex = resetIndex; target.ResetIOState(); IOEntity.IOSlot[] oSlotArray = target.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null && oSlot.connectedTo.Get(true) != target) { PuzzleReset.ResetIOEntRecursive(oSlot.connectedTo.Get(true), resetIndex); } } }
public override void UpdateOutputs() { if (this.outputs.Length == 0) { this.ensureOutputsUpdated = false; return; } if (this.ensureOutputsUpdated) { for (int i = 0; i < 4; i++) { IOEntity.IOSlot oSlot = this.outputs[i]; if (oSlot.connectedTo.Get(true) != null) { oSlot.connectedTo.Get(true).UpdateFromInput(this.inputAmounts[i], oSlot.connectedToSlot); } } } }
public void RequestClear(BaseEntity.RPCMessage msg) { if (!WireTool.CanPlayerUseWires(msg.player)) { return; } uint uid = msg.read.UInt32(); int inputSlot = msg.read.Int32(); bool flag = msg.read.Bit(); BaseNetworkable baseNetworkable = BaseNetworkable.serverEntities.Find(uid); IOEntity ioEntity1 = Object.op_Equality((Object)baseNetworkable, (Object)null) ? (IOEntity)null : (IOEntity)((Component)baseNetworkable).GetComponent <IOEntity>(); if (Object.op_Equality((Object)ioEntity1, (Object)null) || inputSlot >= (flag ? ioEntity1.inputs.Length : ioEntity1.outputs.Length)) { return; } IOEntity.IOSlot ioSlot1 = flag ? ioEntity1.inputs[inputSlot] : ioEntity1.outputs[inputSlot]; if (Object.op_Equality((Object)ioSlot1.connectedTo.Get(true), (Object)null)) { return; } IOEntity ioEntity2 = ioSlot1.connectedTo.Get(true); IOEntity.IOSlot ioSlot2 = flag ? ioEntity2.outputs[ioSlot1.connectedToSlot] : ioEntity2.inputs[ioSlot1.connectedToSlot]; if (flag) { ioEntity1.UpdateFromInput(0, inputSlot); } else if (Object.op_Implicit((Object)ioEntity2)) { ioEntity2.UpdateFromInput(0, ioSlot1.connectedToSlot); } ioSlot1.Clear(); ioSlot2.Clear(); if (Object.op_Implicit((Object)ioEntity2)) { ioEntity2.MarkDirtyForceUpdateOutputs(); ioEntity2.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } ioEntity1.MarkDirtyForceUpdateOutputs(); ioEntity1.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
public override void UpdateOutputs() { if (this.outputs.Length == 0) { this.ensureOutputsUpdated = false; } else { if (!this.ensureOutputsUpdated) { return; } for (int index = 0; index < 4; ++index) { IOEntity.IOSlot output = this.outputs[index]; if (Object.op_Inequality((Object)output.connectedTo.Get(true), (Object)null)) { output.connectedTo.Get(true).UpdateFromInput(this.inputAmounts[index], output.connectedToSlot); } } } }
public void RotateProgress() { if (!this.rotatorPlayer || this.rotatorPlayer.IsDead() || this.rotatorPlayer.IsSleeping() || Vector3Ex.Distance2D(this.rotatorPlayer.transform.position, base.transform.position) > 2f) { this.CancelPlayerRotation(); return; } float single = this.kineticEnergyPerSec * this.progressTickRate; IOEntity.IOSlot[] oSlotArray = this.outputs; for (int i = 0; i < (int)oSlotArray.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray[i]; if (oSlot.connectedTo.Get(true) != null) { single = oSlot.connectedTo.Get(true).IOInput(this, this.ioType, single, oSlot.connectedToSlot); } } if (single == 0f) { this.SetRotateProgress(this.rotateProgress + 0.1f); } base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
public void ClearConnections() { int i; IOEntity.IOSlot[] oSlotArray; int j; List <IOEntity> oEntities = new List <IOEntity>(); IOEntity.IOSlot[] oSlotArray1 = this.inputs; for (i = 0; i < (int)oSlotArray1.Length; i++) { IOEntity.IOSlot oSlot = oSlotArray1[i]; IOEntity oEntity = null; if (oSlot.connectedTo.Get(true) != null) { oEntity = oSlot.connectedTo.Get(true); oSlotArray = oSlot.connectedTo.Get(true).outputs; for (j = 0; j < (int)oSlotArray.Length; j++) { IOEntity.IOSlot oSlot1 = oSlotArray[j]; if (oSlot1.connectedTo.Get(true) != null && oSlot1.connectedTo.Get(true).EqualNetID(this)) { oSlot1.Clear(); } } } oSlot.Clear(); if (oEntity) { oEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } oSlotArray1 = this.outputs; for (i = 0; i < (int)oSlotArray1.Length; i++) { IOEntity.IOSlot oSlot2 = oSlotArray1[i]; if (oSlot2.connectedTo.Get(true) != null) { oEntities.Add(oSlot2.connectedTo.Get(true)); oSlotArray = oSlot2.connectedTo.Get(true).inputs; for (j = 0; j < (int)oSlotArray.Length; j++) { IOEntity.IOSlot oSlot3 = oSlotArray[j]; if (oSlot3.connectedTo.Get(true) != null && oSlot3.connectedTo.Get(true).EqualNetID(this)) { oSlot3.Clear(); } } } if (oSlot2.connectedTo.Get(true)) { oSlot2.connectedTo.Get(true).UpdateFromInput(0, oSlot2.connectedToSlot); } oSlot2.Clear(); } base.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); foreach (IOEntity oEntity1 in oEntities) { if (oEntity1 == null) { continue; } oEntity1.MarkDirty(); oEntity1.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } for (int k = 0; k < (int)this.inputs.Length; k++) { this.UpdateFromInput(0, k); } }