public bool IsConnectedTo(IOEntity entity, int slot, int depth, bool defaultReturn = false) { if (depth > 0 && slot < inputs.Length) { IOSlot iOSlot = inputs[slot]; if (iOSlot.mainPowerSlot) { IOEntity iOEntity = iOSlot.connectedTo.Get(); if (iOEntity != null) { if (iOEntity == entity) { return(true); } if (ConsiderConnectedTo(entity)) { return(true); } if (iOEntity.IsConnectedTo(entity, depth - 1, defaultReturn)) { return(true); } } } } return(false); }
public bool IsConnectedTo(IOEntity entity, int depth, bool defaultReturn = false) { if (depth > 0) { for (int i = 0; i < inputs.Length; i++) { IOSlot iOSlot = inputs[i]; if (!iOSlot.mainPowerSlot) { continue; } IOEntity iOEntity = iOSlot.connectedTo.Get(); if (iOEntity != null) { if (iOEntity == entity) { return(true); } if (ConsiderConnectedTo(entity)) { return(true); } if (iOEntity.IsConnectedTo(entity, depth - 1, defaultReturn)) { return(true); } } } return(false); } return(defaultReturn); }
public IOEntity FindGravitySource(ref Vector3 worldHandlePosition, int depth, bool ignoreSelf) { if (depth <= 0) { return(null); } if (!ignoreSelf && IsGravitySource) { worldHandlePosition = base.transform.TransformPoint(outputs[0].handlePosition); return(this); } IOSlot[] array = inputs; for (int i = 0; i < array.Length; i++) { IOEntity iOEntity = array[i].connectedTo.Get(base.isServer); if (iOEntity != null) { if (iOEntity.IsGravitySource) { worldHandlePosition = iOEntity.transform.TransformPoint(iOEntity.outputs[0].handlePosition); return(iOEntity); } iOEntity = iOEntity.FindGravitySource(ref worldHandlePosition, depth - 1, false); if (iOEntity != null) { worldHandlePosition = iOEntity.transform.TransformPoint(iOEntity.outputs[0].handlePosition); return(iOEntity); } } } return(null); }
private void CheckPushLiquid(IOEntity connected, Item ourFuel, IOEntity fromSource, int depth) { if (depth <= 0 || ourFuel.amount <= 0) { return; } Vector3 worldHandlePosition = Vector3.zero; IOEntity iOEntity = connected.FindGravitySource(ref worldHandlePosition, IOEntity.backtracking, true); if ((iOEntity != null && !connected.AllowLiquidPassthrough(iOEntity, worldHandlePosition)) || connected == this || ConsiderConnectedTo(connected)) { return; } ContainerIOEntity containerIOEntity; if ((object)(containerIOEntity = connected as ContainerIOEntity) != null && !pushTargets.Contains(containerIOEntity) && containerIOEntity.inventory.CanAcceptItem(ourFuel, 0) == ItemContainer.CanAcceptResult.CanAccept) { pushTargets.Add(containerIOEntity); return; } IOSlot[] array = connected.outputs; foreach (IOSlot iOSlot in array) { IOEntity iOEntity2 = iOSlot.connectedTo.Get(); Vector3 sourceWorldPosition = connected.transform.TransformPoint(iOSlot.handlePosition); if (iOEntity2 != null && iOEntity2 != fromSource && iOEntity2.AllowLiquidPassthrough(connected, sourceWorldPosition)) { CheckPushLiquid(iOEntity2, ourFuel, fromSource, depth - 1); if (pushTargets.Count >= 3) { break; } } } }
public void InitClient() { if (this.entityRef.IsValid(false) && this.ioEnt == null) { this.ioEnt = this.entityRef.Get(false).GetComponent <IOEntity>(); } }
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 IEnumerator SetupIoEntities() { List <IOEntity> ioEntities = BaseNetworkable.serverEntities.OfType <IOEntity>().ToList(); for (int i = 0; i < ioEntities.Count; i++) { IOEntity entity = ioEntities[i]; if (entity.OwnerID == 0) { continue; } if (i % _pluginConfig.RepairsPerFrame == 0) { yield return(null); } BuildingPrivlidge priv = entity.GetBuildingPrivilege(); if (priv == null) { continue; } if (!_ioEntity.ContainsKey(priv.buildingID)) { _ioEntity[priv.buildingID] = new List <IOEntity> { entity }; } else { _ioEntity[priv.buildingID].Add(entity); } } }
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 void TryClear(BaseEntity.RPCMessage msg) { IOEntity component; if (!WireTool.CanPlayerUseWires(msg.player)) { return; } uint num = msg.read.UInt32(); BaseNetworkable baseNetworkable = BaseNetworkable.serverEntities.Find(num); if (baseNetworkable == null) { component = null; } else { component = baseNetworkable.GetComponent <IOEntity>(); } IOEntity oEntity = component; if (oEntity == null) { return; } oEntity.ClearConnections(); oEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
object CanMountEntity(BasePlayer player, BaseMountable entity) { if (!(entity is MiniCopter) && !(entity.GetParentEntity() is MiniCopter)) { return(null); } if (player.serverInput.IsDown(BUTTON.FIRE_PRIMARY) || player.serverInput.WasDown(BUTTON.FIRE_PRIMARY)) { GetTargetEntity(player); return(false); } if (!IsBatEnabled()) { return(null); } MiniCopter ent = entity.GetParentEntity() as MiniCopter; if (ent != null) { IOEntity ioe = GetBatteryConnected(ent); if (ioe != null) { SendReply(player, GetMsg("Err - Diconnect Battery"), ioe.GetDisplayName()); return(false); } } return(null); }
public void InitClient() { if (entityRef.IsValid(false) && ioEnt == null) { ioEnt = entityRef.Get(false).GetComponent <IOEntity>(); } }
private void CalculateDrain(IOEntity ent, Vector3 fromSlotWorld, int depth, ref int amount, IOEntity lastEntity, ItemDefinition waterType) { if (ent == this || depth <= 0 || ent == null || lastEntity == null || ent is LiquidContainer) { return; } if (!ent.BlockFluidDraining && ent.HasFlag(Flags.On)) { int num = ent.DesiredPower(); amount += num; ent.SetFuelType(waterType, this); connectedList.Add(ent); } if (!ent.AllowLiquidPassthrough(lastEntity, fromSlotWorld)) { return; } IOSlot[] array = ent.outputs; foreach (IOSlot iOSlot in array) { if (iOSlot.connectedTo.Get() != null && iOSlot.connectedTo.Get() != ent) { CalculateDrain(iOSlot.connectedTo.Get(), ent.transform.TransformPoint(iOSlot.handlePosition), depth - 1, ref amount, ent, waterType); } } }
public virtual void SendChangedToRootRecursive(bool forceUpdate, ref List <IOEntity> existing) { bool flag = IsRootEntity(); if (existing.Contains(this)) { return; } existing.Add(this); bool flag2 = false; for (int i = 0; i < inputs.Length; i++) { IOSlot iOSlot = inputs[i]; if (!iOSlot.mainPowerSlot) { continue; } IOEntity iOEntity = iOSlot.connectedTo.Get(); if (!(iOEntity == null) && !existing.Contains(iOEntity)) { flag2 = true; if (forceUpdate) { iOEntity.ensureOutputsUpdated = true; } iOEntity.SendChangedToRootRecursive(forceUpdate, ref existing); } } if (flag) { forceUpdate = forceUpdate && !flag2; OnCircuitChanged(forceUpdate); } }
public void MakeConnection(BaseEntity.RPCMessage msg) { if (!WireTool.CanPlayerUseWires(msg.player)) { return; } uint uid1 = msg.read.UInt32(); int index1 = msg.read.Int32(); uint uid2 = msg.read.UInt32(); int index2 = msg.read.Int32(); BaseNetworkable baseNetworkable1 = BaseNetworkable.serverEntities.Find(uid1); IOEntity newIOEnt1 = Object.op_Equality((Object)baseNetworkable1, (Object)null) ? (IOEntity)null : (IOEntity)((Component)baseNetworkable1).GetComponent <IOEntity>(); if (Object.op_Equality((Object)newIOEnt1, (Object)null)) { return; } BaseNetworkable baseNetworkable2 = BaseNetworkable.serverEntities.Find(uid2); IOEntity newIOEnt2 = Object.op_Equality((Object)baseNetworkable2, (Object)null) ? (IOEntity)null : (IOEntity)((Component)baseNetworkable2).GetComponent <IOEntity>(); if (Object.op_Equality((Object)newIOEnt2, (Object)null) || (double)Vector3.Distance(((Component)baseNetworkable2).get_transform().get_position(), ((Component)baseNetworkable1).get_transform().get_position()) > (double)WireTool.maxWireLength || (index1 >= newIOEnt1.inputs.Length || index2 >= newIOEnt2.outputs.Length) || (Object.op_Inequality((Object)newIOEnt1.inputs[index1].connectedTo.Get(true), (Object)null) || Object.op_Inequality((Object)newIOEnt2.outputs[index2].connectedTo.Get(true), (Object)null) || newIOEnt1.inputs[index1].rootConnectionsOnly && !newIOEnt2.IsRootEntity())) { return; } newIOEnt1.inputs[index1].connectedTo.Set(newIOEnt2); newIOEnt1.inputs[index1].connectedToSlot = index2; newIOEnt1.inputs[index1].connectedTo.Init(); newIOEnt2.outputs[index2].connectedTo.Set(newIOEnt1); newIOEnt2.outputs[index2].connectedToSlot = index1; newIOEnt2.outputs[index2].connectedTo.Init(); newIOEnt2.MarkDirtyForceUpdateOutputs(); newIOEnt2.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); newIOEnt1.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); }
private static void TryProvidePower(IOEntity ioEntity, int inputSlot, int powerAmount) { if (ioEntity.inputs.Length > inputSlot && !InputUpdateWasBlocked(ioEntity, inputSlot, powerAmount)) { ioEntity.UpdateFromInput(powerAmount, inputSlot); } }
public void AddConnectedRecursive(IOEntity root, ref HashSet <IOEntity> listToUse) { listToUse.Add(root); if (!root.WantsPassthroughPower()) { return; } for (int i = 0; i < root.outputs.Length; i++) { if (!root.AllowDrainFrom(i)) { continue; } IOEntity iOEntity = root.outputs[i].connectedTo.Get(); if (!(iOEntity != null)) { continue; } bool flag = iOEntity.WantsPower(); if (!listToUse.Contains(iOEntity)) { if (flag) { AddConnectedRecursive(iOEntity, ref listToUse); } else { listToUse.Add(iOEntity); } } } }
private IAudioConnectionSource GetConnectionSource(IOEntity entity, int depth) { if (depth <= 0) { return(null); } IOSlot[] array = entity.inputs; for (int i = 0; i < array.Length; i++) { IOEntity iOEntity = array[i].connectedTo.Get(base.isServer); if (iOEntity == this) { return(null); } IAudioConnectionSource result; if (iOEntity != null && (result = iOEntity as IAudioConnectionSource) != null) { return(result); } if (iOEntity != null) { IAudioConnectionSource connectionSource = GetConnectionSource(iOEntity, depth - 1); if (connectionSource != null) { return(connectionSource); } } } return(null); }
private void UpdatePushLiquidTargets() { pushTargets.Clear(); if (!HasLiquidItem() || IsConnectedTo(this, IOEntity.backtracking * 2)) { return; } Item liquidItem = GetLiquidItem(); using (TimeWarning.New("UpdatePushTargets")) { IOSlot[] array = outputs; foreach (IOSlot iOSlot in array) { if (iOSlot.type == IOType.Fluidic) { IOEntity iOEntity = iOSlot.connectedTo.Get(); if (iOEntity != null) { CheckPushLiquid(iOEntity, liquidItem, this, IOEntity.backtracking * 4); } } } } if (pushTargets.Count > 0) { InvokeRandomized(pushLiquidAction, 0f, autofillTickRate, autofillTickRate * 0.2f); } }
public virtual void UpdateOutputs() { if (Interface.CallHook("OnOutputUpdate", this) != null || !ShouldUpdateOutputs() || !ensureOutputsUpdated) { return; } ensureOutputsUpdated = false; using (TimeWarning.New("ProcessIOOutputs")) { for (int i = 0; i < outputs.Length; i++) { IOSlot iOSlot = outputs[i]; bool flag = true; IOEntity iOEntity = iOSlot.connectedTo.Get(); if (!(iOEntity != null)) { continue; } if (ioType == IOType.Fluidic && !DisregardGravityRestrictionsOnLiquid && !iOEntity.DisregardGravityRestrictionsOnLiquid) { using (TimeWarning.New("FluidOutputProcessing")) { if (!iOEntity.AllowLiquidPassthrough(this, base.transform.TransformPoint(iOSlot.handlePosition))) { flag = false; } } } int passthroughAmount = GetPassthroughAmount(i); iOEntity.UpdateFromInput(flag ? passthroughAmount : 0, iOSlot.connectedToSlot); } } }
public IOEntity Get(bool isServer = true) { if (Object.op_Equality((Object)this.ioEnt, (Object)null) && this.entityRef.IsValid(isServer)) { this.ioEnt = (IOEntity)((Component)this.entityRef.Get(isServer)).GetComponent <IOEntity>(); } return(this.ioEnt); }
public void Clear() { IOEntity obj = ioEnt; ioEnt = null; entityRef.Set(null); Interface.CallHook("OnIORefCleared", this, obj); }
public IOEntity Get(bool isServer = true) { if (ioEnt == null && entityRef.IsValid(isServer)) { ioEnt = entityRef.Get(isServer).GetComponent <IOEntity>(); } return(ioEnt); }
public void InitClient() { if (!this.entityRef.IsValid(false) || !Object.op_Equality((Object)this.ioEnt, (Object)null)) { return; } this.ioEnt = (IOEntity)((Component)this.entityRef.Get(false)).GetComponent <IOEntity>(); }
public override bool AllowLiquidPassthrough(IOEntity fromSource, Vector3 sourceWorldPosition, bool forPlacement = false) { if (!forPlacement && !IsOn()) { return(false); } return(base.AllowLiquidPassthrough(fromSource, sourceWorldPosition)); }
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 void ClearConnections() { List <IOEntity> ioEntityList = new List <IOEntity>(); foreach (IOEntity.IOSlot input in this.inputs) { IOEntity ioEntity = (IOEntity)null; if (Object.op_Inequality((Object)input.connectedTo.Get(true), (Object)null)) { ioEntity = input.connectedTo.Get(true); foreach (IOEntity.IOSlot output in input.connectedTo.Get(true).outputs) { if (Object.op_Inequality((Object)output.connectedTo.Get(true), (Object)null) && output.connectedTo.Get(true).EqualNetID((BaseNetworkable)this)) { output.Clear(); } } } input.Clear(); if (Object.op_Implicit((Object)ioEntity)) { ioEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } foreach (IOEntity.IOSlot output in this.outputs) { if (Object.op_Inequality((Object)output.connectedTo.Get(true), (Object)null)) { ioEntityList.Add(output.connectedTo.Get(true)); foreach (IOEntity.IOSlot input in output.connectedTo.Get(true).inputs) { if (Object.op_Inequality((Object)input.connectedTo.Get(true), (Object)null) && input.connectedTo.Get(true).EqualNetID((BaseNetworkable)this)) { input.Clear(); } } } if (Object.op_Implicit((Object)output.connectedTo.Get(true))) { output.connectedTo.Get(true).UpdateFromInput(0, output.connectedToSlot); } output.Clear(); } this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); foreach (IOEntity ioEntity in ioEntityList) { if (Object.op_Inequality((Object)ioEntity, (Object)null)) { ioEntity.MarkDirty(); ioEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } for (int inputSlot = 0; inputSlot < this.inputs.Length; ++inputSlot) { this.UpdateFromInput(0, inputSlot); } }
public void Init() { if (this.ioEnt != null && !this.entityRef.IsValid(true)) { this.entityRef.Set(this.ioEnt); } if (this.entityRef.IsValid(true)) { this.ioEnt = this.entityRef.Get(true).GetComponent <IOEntity>(); } }
public void Init() { if (ioEnt != null && !entityRef.IsValid(true)) { entityRef.Set(ioEnt); } if (entityRef.IsValid(true)) { ioEnt = entityRef.Get(true).GetComponent <IOEntity>(); } }
private static bool HasElectricalInput(IOEntity ioEntity) { foreach (var input in ioEntity.inputs) { if (input.type == IOEntity.IOType.Electric) { return(true); } } return(false); }
private bool BUTTONLOOKUP(BasePlayer player, out IOEntity button) { RaycastHit hit; button = null; if (Physics.Raycast(player.eyes.HeadRay(), out hit, 3)) { button = hit.GetEntity() as PressButton; } return(button != null); }
public IOCreatedEvent(IOEntity entity) : base(entity) { }
public static IObservable<IOEvent> Watch( this IIOSystem system,IOEntity entity) { return system.Watch(entity, IOWatchSettings.Default); }
public IOMovedEvent( IOEntity entity, IOEntity newEntity) : base(entity) { _newEntity = newEntity; }
public IOUpdatedEvent(IOEntity entity) : base(entity) { }
public IObservable<IOEvent> Watch( IOEntity entity, IOWatchSettings settings) { if (entity == null) throw new ArgumentNullException("entity"); return Observable .Create<IOEvent>( observer => { var fileSystemWatcher = new FileSystemWatcher(entity.Identifier) { EnableRaisingEvents = true, IncludeSubdirectories = settings.IncludeSubCategories }; GetFileSystemWatcherObservables(fileSystemWatcher) .Buffer(settings.Interval) .Subscribe(ae => { foreach (var es in ae.GroupBy(x => x.FullPath)) { var first = es.First(); var firstRenamed = es.First() as RenamedEventArgs; var last = es.Last(); if (last.ChangeType == WatcherChangeTypes.Deleted) { // if deleted, check if renamed // and raise the old file as deleted var path = firstRenamed == null ? last.FullPath : firstRenamed.OldFullPath; observer.OnNext( new IODeletedEvent( _fileSystemInfoProvider.GetEntity<IOEntity>(path))); } else { if (firstRenamed != null) { // raise the rename on the old file observer.OnNext( new IOMovedEvent( _fileSystemInfoProvider.GetEntity<IOEntity>(firstRenamed.OldFullPath), _fileSystemInfoProvider.GetEntity<IOEntity>(firstRenamed.FullPath))); } if (first.ChangeType == WatcherChangeTypes.Created) { observer.OnNext( new IOCreatedEvent( _fileSystemInfoProvider.GetEntity<IOEntity>(last.FullPath))); } else { observer.OnNext( new IOUpdatedEvent( _fileSystemInfoProvider.GetEntity<IOEntity>(first.FullPath)) ); } } } }, observer.OnError); return fileSystemWatcher.Dispose; }); }
protected IOEvent(IOEntity entity) { if (entity == null) throw new ArgumentNullException("entity"); _entity = entity; }
public IODeletedEvent(IOEntity entity) : base(entity) { }