Пример #1
0
        private void Update()
        {
            // flippers will be handled via script later, but until scripting works, do it here.
            if (Input.GetKeyDown("left shift"))
            {
                _tableApi.Flipper("LeftFlipper")?.RotateToEnd();
            }
            if (Input.GetKeyUp("left shift"))
            {
                _tableApi.Flipper("LeftFlipper")?.RotateToStart();
            }
            if (Input.GetKeyDown("right shift"))
            {
                _tableApi.Flipper("RightFlipper")?.RotateToEnd();
            }
            if (Input.GetKeyUp("right shift"))
            {
                _tableApi.Flipper("RightFlipper")?.RotateToStart();
            }

            if (Input.GetKeyUp("b"))
            {
                _ballManager.CreateBall(new DebugBallCreator());
            }

            if (Input.GetKeyUp("n"))
            {
                //_ballManager.CreateBall(new DebugBallCreator(Table.Width / 2f, Table.Height / 2f - 300f, 0, -5));
                _tableApi.Kicker("Kicker1").CreateBall();
                _tableApi.Kicker("Kicker1").Kick(0, -1);

                //_tableApi.Flippers["LeftFlipper"].RotateToEnd();
            }

            if (Input.GetKeyDown(KeyCode.Return))
            {
                _tableApi.Plunger("Plunger")?.PullBack();
            }
            if (Input.GetKeyUp(KeyCode.Return))
            {
                _tableApi.Plunger("Plunger")?.Fire();
            }
        }
        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);
            };
        }
Пример #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);
        }
 public void KickNewBallToPlunger(TableApi table)
 {
     table.Kicker("BallRelease").CreateBall();
     table.Kicker("BallRelease").Kick(90, 7);
 }