예제 #1
0
        /// <summary>
        /// If there are any balls in the trough add one to play and
        /// trigger any switches which the remaining balls would activate
        /// </summary>
        internal void OnEjectCoil(bool closed)
        {
            if (closed && (_ballCount > 0))
            {
                Logger.Info("Spawning new ball.");

                _exitKicker.CreateBall();
                _exitKicker.Kick();

                for (int i = 0; i < _ballCount; i++)
                {
                    _ballSwitches[i].ScheduleSwitch(false, Data.SettleTime / 2);
                }

                _ballCount--;

                for (int i = 0; i < _ballCount; i++)
                {
                    _ballSwitches[i].ScheduleSwitch(true, Data.SettleTime);
                }
            }
        }
예제 #2
0
        /// <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);
        }