public static BoolToSignal ( bool signal ) : SignalType | ||
signal | bool | |
return | SignalType |
public static SignalType BoolToSignal(bool?signal) { if (signal == null) { return(SignalType.Swap); } return(AdvancedCircuits.BoolToSignal(signal.Value)); }
public bool HandleDoorUse( TSPlayer player, DPoint tileLocation, bool isOpening, NPC npc = null, Direction direction = Direction.Unknown ) { try { this.ProcessCircuit(player, tileLocation, AdvancedCircuits.BoolToSignal(isOpening), false); } catch (Exception ex) { this.PluginTrace.WriteLineError( "DoorUse for \"{0}\" at {1} failed. See inner exception for details.\n{2}", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)TerrariaUtils.Tiles[tileLocation].type), tileLocation, ex.ToString() ); } return(false); }
public void HandleGameUpdate() { this.frameCounter++; if (this.frameCounter % CircuitHandler.TimerUpdateFrameRate == 0) { List <DPoint> timersToDelete = null; List <KeyValuePair <DPoint, ActiveTimerMetadata> > timersToProcess = null; foreach (KeyValuePair <DPoint, ActiveTimerMetadata> activeTimer in this.WorldMetadata.ActiveTimers) { DPoint timerLocation = activeTimer.Key; ActiveTimerMetadata timerMetadata = activeTimer.Value; ITile timerTile = TerrariaUtils.Tiles[timerLocation]; if (timerMetadata == null || !timerTile.active() || timerTile.type != TileID.Timers) { if (timersToDelete == null) { timersToDelete = new List <DPoint>(); } timersToDelete.Add(timerLocation); continue; } if (timerMetadata.FramesLeft <= 0) { if (timersToProcess == null) { timersToProcess = new List <KeyValuePair <DPoint, ActiveTimerMetadata> >(); } timersToProcess.Add(activeTimer); timerMetadata.FramesLeft = AdvancedCircuits.MeasureTimerFrameTime(timerLocation); continue; } timerMetadata.FramesLeft -= CircuitHandler.TimerUpdateFrameRate; } if (timersToProcess != null) { DateTime now = DateTime.UtcNow; foreach (KeyValuePair <DPoint, ActiveTimerMetadata> activeTimer in timersToProcess) { SignalType signalType; // Is Advanced Circuit? if (!TerrariaUtils.Tiles[activeTimer.Key].HasWire()) { signalType = SignalType.On; } else { signalType = SignalType.Swap; } try { CircuitProcessingResult result = this.ProcessCircuit(null, activeTimer.Key, signalType, false); // If the circuit had errors or if it reached its max activity time, deactivate the timer. if ( result.CancellationReason != CircuitCancellationReason.None || ( this.Config.MaxTimerActivityTime != TimeSpan.Zero && (now - activeTimer.Value.TimeOfRegistration) >= this.Config.MaxTimerActivityTime ) ) { ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(activeTimer.Key); this.RegisterUnregisterTimer(result.TriggeringPlayer, measureData, false); TerrariaUtils.Tiles.SetObjectState(measureData, false); } } catch (Exception ex) { this.PluginTrace.WriteLineError("Circuit processing for a Timer at {0} failed. See inner exception for details.\n{1}", activeTimer.Key, ex.ToString()); } } } if (timersToDelete != null) { foreach (DPoint timerLocation in timersToDelete) { this.WorldMetadata.ActiveTimers.Remove(timerLocation); } } } if (this.frameCounter % CircuitHandler.ClockUpdateFrameRate == 0) { bool isDaylight = (Main.dayTime && Main.time >= 7200 && Main.time <= 46800); bool dayTimeChanged = (Main.dayTime != this.isDayTime); bool daylightChanged = (this.isDaylight != isDaylight); if (dayTimeChanged || daylightChanged) { List <DPoint> clocksToRemove = null; foreach (KeyValuePair <DPoint, GrandfatherClockMetadata> clock in this.WorldMetadata.Clocks) { DPoint clockLocation = clock.Key; ITile clockTile = TerrariaUtils.Tiles[clockLocation]; if (!clockTile.active() || clockTile.type != TileID.GrandfatherClocks) { if (clocksToRemove == null) { clocksToRemove = new List <DPoint>(); } clocksToRemove.Add(clock.Key); continue; } bool signal; switch ((PaintColor)TerrariaUtils.Tiles[clockLocation].color()) { case AdvancedCircuits.Paint_Clock_ByDaylight: if (!daylightChanged) { continue; } signal = !isDaylight; break; case AdvancedCircuits.Paint_Clock_ByNighttimeAndBloodmoon: if (!dayTimeChanged) { continue; } signal = !Main.dayTime && Main.bloodMoon; break; case AdvancedCircuits.Paint_Clock_ByNighttimeAndFullmoon: if (!dayTimeChanged) { continue; } signal = !Main.dayTime && Main.moonPhase == 0; break; default: if (!dayTimeChanged) { continue; } signal = !Main.dayTime; break; } try { TSPlayer triggeringPlayer = null; if (clock.Value.TriggeringPlayerName != null) { triggeringPlayer = TShockEx.GetPlayerByName(clock.Value.TriggeringPlayerName); } if (triggeringPlayer == null) { triggeringPlayer = TSPlayer.Server; } this.ProcessCircuit(triggeringPlayer, clockLocation, AdvancedCircuits.BoolToSignal(signal), false); } catch (Exception ex) { this.PluginTrace.WriteLineError( "Circuit processing for a Grandfather Clock at {0} failed. See inner exception for details.\n{1}", clockLocation, ex.ToString() ); } } if (clocksToRemove != null) { foreach (DPoint clockLocation in clocksToRemove) { this.WorldMetadata.Clocks.Remove(clockLocation); } } if (dayTimeChanged) { this.isDayTime = Main.dayTime; } if (daylightChanged) { this.isDaylight = isDaylight; } } if (this.frameCounter >= 100000) { this.frameCounter = 0; } } }