Пример #1
0
        void IApi.OnInit(BallManager ballManager)
        {
            base.OnInit(ballManager);

            // reference playfield elements
            _drainSwitch = TableApi.Switch(MainComponent.PlayfieldEntrySwitch, MainComponent.PlayfieldEntrySwitchItem);
            _ejectCoil   = TableApi.Coil(MainComponent.PlayfieldExitKicker, MainComponent.PlayfieldExitKickerItem);
            _ejectKicker = TableApi.Kicker(MainComponent.PlayfieldExitKicker);

            // setup entry handler
            if (_drainSwitch != null)
            {
                _drainSwitch.Switch += OnEntry;
            }

            // setup switches
            if (MainComponent.Type != TroughType.ModernOpto && MainComponent.Type != TroughType.ModernMech)
            {
                EntrySwitch = CreateSwitch(TroughComponent.EntrySwitchId, false, SwitchDefault.NormallyOpen);
                _switchLookup[TroughComponent.EntrySwitchId] = EntrySwitch;
            }

            if (MainComponent.Type == TroughType.TwoCoilsOneSwitch)
            {
                _stackSwitches = new[] {
                    CreateSwitch(TroughComponent.TroughSwitchId, false, SwitchDefault.NormallyOpen)
                };
                _switchLookup[TroughComponent.TroughSwitchId] = StackSwitch();
            }
            else
            {
                _stackSwitches = new DeviceSwitch[MainComponent.SwitchCount];

                // ball_switch_# switches created in TroughComponent
                var ballSwitchRegex = new Regex(@"^ball_switch_(\d+)$");
                foreach (var @switch in MainComponent.AvailableSwitches)
                {
                    var match = ballSwitchRegex.Match(@switch.Id);
                    if (match.Success)
                    {
                        int.TryParse(match.Groups[1].Value, out int id);
                        if (id > 0)
                        {
                            _stackSwitches[id - 1]    = CreateSwitch(@switch.Id, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
                            _switchLookup[@switch.Id] = _stackSwitches[id - 1];
                        }
                    }
                }

                // pull next ball on modern
                if (MainComponent.Type == TroughType.ModernOpto || MainComponent.Type == TroughType.ModernMech)
                {
                    _stackSwitches[MainComponent.SwitchCount - 1].Switch += OnLastStackSwitch;
                }
            }

            if (MainComponent.JamSwitch)
            {
                JamSwitch = CreateSwitch(TroughComponent.JamSwitchId, false, MainComponent.Type == TroughType.ModernOpto ? SwitchDefault.NormallyClosed : SwitchDefault.NormallyOpen);
                _switchLookup[TroughComponent.JamSwitchId] = JamSwitch;
            }

            // setup coils
            EntryCoil = new DeviceCoil(Player, OnEntryCoilEnabled);
            ExitCoil  = new DeviceCoil(Player, () => EjectBall());

            // fill up the ball stack
            var ballCount = MainComponent.Type == TroughType.ClassicSingleBall ? 1 : MainComponent.BallCount;

            for (var i = 0; i < ballCount; i++)
            {
                AddBall();
            }

            // finally, emit the event for anyone else to chew on
            Init?.Invoke(this, EventArgs.Empty);
        }