public virtual void OnAwake(TableApi table)
        {
            table.Plunger("Plunger").Init += (sender, args) => {
                KickNewBallToPlunger(table);
            };

            table.Kicker("Drain").Hit += (sender, args) => {
                ((KickerApi)sender).DestroyBall();
                KickNewBallToPlunger(table);
            };
        }
Exemple #2
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);
        }
Exemple #3
0
        public void OnInit(TableApi tableApi, BallManager ballManager)
        {
            _tableApi    = tableApi;
            _ballManager = ballManager;

            _switchStatus[SwLeftFlipper]     = false;
            _switchStatus[SwLeftFlipperEos]  = false;
            _switchStatus[SwRightFlipper]    = false;
            _switchStatus[SwRightFlipperEos] = false;
            _switchStatus[SwPlunger]         = false;
            _switchStatus[SwCreateBall]      = false;

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;
        }
Exemple #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);
        }
Exemple #5
0
        public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
        {
            _player      = player;
            _ballManager = ballManager;

            OnDisplaysRequested?.Invoke(this, new RequestedDisplays(new DisplayConfig(DisplayDmd, DmdWidth, DmdHeight)));

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;

            // eject ball onto playfield
            OnCoilChanged?.Invoke(this, new CoilEventArgs(CoilTroughEject, true));
            _player.ScheduleAction(100, () => OnCoilChanged?.Invoke(this, new CoilEventArgs(CoilTroughEject, false)));

            _playfieldComponent = GetComponentInChildren <PlayfieldComponent>();

            OnStarted?.Invoke(this, EventArgs.Empty);
        }
        public void OnInit(TableApi tableApi, BallManager ballManager)
        {
            _tableApi    = tableApi;
            _ballManager = ballManager;

            // flippers
            _leftFlipper = _tableApi.Flipper("LeftFlipper")
                           ?? _tableApi.Flipper("FlipperLeft")
                           ?? _tableApi.Flipper("FlipperL")
                           ?? _tableApi.Flipper("LFlipper");
            _rightFlipper = _tableApi.Flipper("RightFlipper")
                            ?? _tableApi.Flipper("FlipperRight")
                            ?? _tableApi.Flipper("FlipperR")
                            ?? _tableApi.Flipper("RFlipper");

            // debug print stuff
            OnCoilChanged += DebugPrintCoil;
        }
        public virtual void OnAwake(TableApi table, BallManager ballManager)
        {
            // table.Plunger("Plunger").Init += (sender, args) => {
            //  KickNewBallToPlunger(table);
            // };
            //
            // table.Kicker("Drain").Hit += (sender, args) => {
            //  ((KickerApi)sender).DestroyBall();
            //  KickNewBallToPlunger(table);
            // };

            table.Init += (sender, args) => {
                ballManager.CreateBall(new DebugBallCreator(200f, 620f));
                ballManager.CreateBall(new DebugBallCreator(330f, 360f));
                ballManager.CreateBall(new DebugBallCreator(400f, 700f));
                ballManager.CreateBall(new DebugBallCreator(620f, 820f));
                ballManager.CreateBall(new DebugBallCreator(720f, 400f));
                ballManager.CreateBall(new DebugBallCreator(830f, 870f));
                ballManager.CreateBall(new DebugBallCreator(470f, 230f));
                ballManager.CreateBall(new DebugBallCreator(620f, 1200f));
            };
        }
        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);
        }
 public void KickNewBallToPlunger(TableApi table)
 {
     table.Kicker("BallRelease").CreateBall();
     table.Kicker("BallRelease").Kick(90, 7);
 }
Exemple #10
0
 public virtual void OnAwake(TableApi table)
 {
 }