示例#1
0
 public override void UnloadAmmo()
 {
     _nextAmmoHandlerState = new AmmoUnloadState(Module);
 }
示例#2
0
            public override void Update(TimeSpan time)
            {
                if (_timer.Elapsed == TimeSpan.Zero)
                {
                    if (!CheckAmmo())
                    {
                        var loadState = AmmoLoadState.CreateFromCurrentAmmo(Module);
                        if (loadState == null)
                        {
                            Module.OnError(ErrorCodes.AmmoNotFound);
                            SwitchTo(ModuleStateType.Idle);
                            return;
                        }

                        Module._states.Push(loadState);
                        return;
                    }

                    if (!CheckCore())
                    {
                        Module.OnError(ErrorCodes.OutOfCore);
                        SwitchTo(ModuleStateType.Idle);
                        return;
                    }

                    try
                    {
                        Module.OnAction();
                        DecreaseCore();
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                        SwitchTo(ModuleStateType.Idle);
                        return;
                    }
                }

                _timer.Update(time);

                if (!_timer.Passed)
                {
                    return;
                }

                ResetTimer();

                var ammoLoadState = _nextAmmoHandlerState;

                if (ammoLoadState != null)
                {
                    _nextAmmoHandlerState = null;

                    if (Type == ModuleStateType.Oneshot)
                    {
                        Module._states.DirectClear();
                        Module._states.Push(new IdleState(Module));
                    }

                    Module._states.Push(ammoLoadState);
                    return;
                }

                if (Type == ModuleStateType.Oneshot)
                {
                    SwitchTo(ModuleStateType.Idle);
                }
            }
示例#3
0
 public override void LoadAmmo(int ammoDefinition)
 {
     _nextAmmoHandlerState = new AmmoLoadState(Module, ammoDefinition);
 }