コード例 #1
0
        public void RegisterKicker(Kicker kicker, Entity entity, GameObject go)
        {
            var kickerApi = new KickerApi(kicker, entity, this);

            _tableApi.Kickers[kicker.Name] = kickerApi;
            _initializables.Add(kickerApi);
            _hittables[entity] = kickerApi;
        }
コード例 #2
0
        void IApi.OnInit(BallManager ballManager)
        {
            _teleporterCoil = new DeviceCoil(_player, OnTeleport);
            _fromKicker     = _player.TableApi.Kicker(_component.FromKicker);
            _toKicker       = _player.TableApi.Kicker(_component.ToKicker);

            Init?.Invoke(this, EventArgs.Empty);
        }
コード例 #3
0
        void IApiInitializable.OnInit(BallManager ballManager)
        {
            // playfield elements
            _entryKicker = TableApi.Kicker(Data.EntryKicker);
            _exitKicker  = TableApi.Kicker(Data.ExitKicker);
            _jamTrigger  = TableApi.Trigger(Data.JamSwitch);

            // setup entry kicker handler
            if (_entryKicker != null)
            {
                _entryKicker.Hit += OnEntryKickerHit;
            }

            // in case we need also need to handle jam events here, uncomment
            // if (_jamTrigger != null) {
            //  _jamTrigger.Hit += OnJamTriggerHit;
            //  _jamTrigger.UnHit += OnJamTriggerUnHit;
            // }

            // create switches to hook up
            _ballSwitches = new DeviceSwitch[Data.SwitchCount];
            foreach (var sw in Item.AvailableSwitches)
            {
                if (int.TryParse(sw.Id, out var id))
                {
                    _ballSwitches[id - 1] = CreateSwitch(false);
                    _switchLookup[sw.Id]  = _ballSwitches[id - 1];
                }
                else if (sw.Id == Trough.JamSwitchId)
                {
                    // we short-wire the jam trigger to the switch, so we don't care about it here,
                    // all the jam trigger does push its switch events to the gamelogic engine. in
                    // case we need to hook into the jam trigger logic here, uncomment those two
                    // lines and and relay the events manually to the engine.
                    //_jamSwitch = CreateSwitch(false);
                    //_switchLookup[sw.Id] = _jamSwitch;
                }
                else
                {
                    Logger.Warn($"Unknown switch ID {sw.Id}");
                }
            }

            // setup eject coil
            _ejectCoil = new TroughEjectCoil(this);

            // finally, emit the event for anyone else to chew on
            Init?.Invoke(this, EventArgs.Empty);
        }
コード例 #4
0
        void IApiInitializable.OnInit(BallManager ballManager)
        {
            _entryKicker = TableApi.Kicker(Data.EntryKicker);
            _exitKicker  = TableApi.Kicker(Data.ExitKicker);

            if (_entryKicker != null)
            {
                _entryKicker.Hit += OnEntryKickerHit;
            }

            if (_exitKicker != null)
            {
                _exitKicker.Hit += OnExitKickerFire;
            }

            Init?.Invoke(this, EventArgs.Empty);
        }
コード例 #5
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);
        }