/// <summary> /// Kicks the ball from the drain into the ball stack. /// </summary> /// /// <remarks> /// If there are any uncounted drain balls, the next ball is drained afterwards. /// </remarks> private void OnEntryCoilEnabled() { switch (MainComponent.Type) { case TroughType.ModernOpto: case TroughType.ModernMech: // modern troughs don't have an entry coil break; case TroughType.TwoCoilsNSwitches: case TroughType.TwoCoilsOneSwitch: // push the ball from the drain to the trough if (EntrySwitch.IsSwitchEnabled) { EntrySwitch.SetSwitch(false); RollOverEntryBall(0); DrainNextUncountedBall(); } break; case TroughType.ClassicSingleBall: throw new InvalidOperationException("Single ball trough does not have an entry coil."); break; default: throw new ArgumentOutOfRangeException(); } #if UNITY_EDITOR RefreshUI(); #endif }
/// <summary> /// Create a ball in the ball stack without triggering extra events. /// </summary> private void AddBall() { switch (MainComponent.Type) { case TroughType.ModernOpto: case TroughType.ModernMech: case TroughType.TwoCoilsNSwitches: if (_countedStackBalls < MainComponent.BallCount) { _stackSwitches[_countedStackBalls].SetSwitch(true); _countedStackBalls++; } else { UncountedStackBalls++; } break; case TroughType.TwoCoilsOneSwitch: if (_countedStackBalls < MainComponent.SwitchCount - 1) { _countedStackBalls++; } else if (_countedStackBalls == MainComponent.SwitchCount - 1) { _countedStackBalls++; StackSwitch().SetSwitch(true); } else { UncountedStackBalls++; } break; case TroughType.ClassicSingleBall: if (!EntrySwitch.IsSwitchEnabled) { _countedStackBalls++; // entry and stack is the same here EntrySwitch.SetSwitch(true); } else { UncountedStackBalls++; } break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// If there are any balls in the ball stack, eject one to the playfield. /// </summary> /// /// <remarks> /// This triggers any switches which the remaining balls would activate by rolling to the next position. /// </remarks> /// /// <returns>True if a ball was ejected, false if there were no balls in the stack to eject.</returns> public bool EjectBall() { if (_countedStackBalls > 0) { // open the switch of the ejected ball immediately switch (MainComponent.Type) { case TroughType.ModernOpto: case TroughType.ModernMech: case TroughType.TwoCoilsNSwitches: if (!_stackSwitches[0].IsSwitchEnabled) { Logger.Warn("Ball not in eject position yet, ignoring."); return(false); } break; case TroughType.TwoCoilsOneSwitch: // no switches at position 0 here. break; case TroughType.ClassicSingleBall: if (!EntrySwitch.IsSwitchEnabled) { Logger.Warn("No ball, ignoring."); return(false); } break; default: throw new ArgumentOutOfRangeException(); } Logger.Info("Trough: Spawning new ball."); _ejectKicker.CreateBall(); _ejectCoil.OnCoil(true); // open the switch of the ejected ball immediately switch (MainComponent.Type) { case TroughType.ModernOpto: case TroughType.ModernMech: case TroughType.TwoCoilsNSwitches: _stackSwitches[0].SetSwitch(false); break; case TroughType.ClassicSingleBall: EntrySwitch.SetSwitch(false); break; // no switches at position 0 for other types. } TriggerJamSwitch(); RollOverStackBalls(); RollOverNextUncountedStackBall(); #if UNITY_EDITOR RefreshUI(); #endif return(true); } return(false); }