Ejemplo n.º 1
0
 private static void HandleDirection(Direction direction, Map map, GameWindow window, IGameEngine engine)
 {
     if (!map.InTargettingMode)
     {
         if (Keyboard.Modifiers != ModifierKeys.Shift)
         {
             engine.Actions.Move(direction);
             window.UpdateWorld();
         }
         else
         {
             RunningKeyboardHandler runner = new RunningKeyboardHandler(window, engine);
             runner.StartRunning(direction);
         }
     }
     else
     {
         throw new InvalidOperationException("DefaultKeyboardHandler and Map disagree on current state");
     }
 }
Ejemplo n.º 2
0
        public void OnKeyboardDown(MagecrawlKey key, Map map, GameWindow window, IGameEngine engine)
        {
            // TODO - This switch is unfortunate and too large...
            switch (key)
            {
                case MagecrawlKey.LessThan:
                {
                    HandleStairs(m_engine.Actions.MoveUpStairs);
                    break;
                }
                case MagecrawlKey.GreaterThan:
                {
                    HandleStairs(m_engine.Actions.MoveDownStairs);
                    break;
                }
                case MagecrawlKey.Q:
                {
                    string text = "Quitting the game will delete your current character. To stop playing now and continue your adventure later, use save instead.";
                    TwoButtonDialog d = new TwoButtonDialog(window, text);
                    d.Closed += (o, e) =>
                    {
                        if (((TwoButtonDialog)o).DialogResult == true)
                        {
                            // Do quit here? How do you quit SL? go back to main menu?
                        }
                    };

                    d.Show();
                    break;
                }
                case MagecrawlKey.S:
                {
                    string text = "Saving the game will end your current session and allow you to pickup playing later.";
                    TwoButtonDialog d = new TwoButtonDialog(window, text);
                    d.Closed += (o, e) =>
                    {
                        if (((TwoButtonDialog)o).DialogResult == true)
                        {
                            m_engine.Save();
                            // Do quit here? How do you quit SL? go back to main menu?
                        }
                    };

                    d.Show();
                    break;
                }
                case MagecrawlKey.a:
                {
                    if (m_engine.Player.CurrentWeapon.IsRanged && !m_engine.Player.CurrentWeapon.IsLoaded)
                    {
                        m_engine.Actions.ReloadWeapon();
                        window.MessageBox.AddMessage(string.Format("{0} reloads the {1}.", m_engine.Player.Name, m_engine.Player.CurrentWeapon.DisplayName));
                    }
                    else
                    {
                        List<EffectivePoint> targetPoints = m_engine.GameState.CalculateTargetablePointsForEquippedWeapon();
                        OnTargetSelect selectionDelegate = (w, e, p) => 
                        {
                            if (p != m_engine.Player.Position)
                                m_engine.Actions.Attack(p);
                        };
                        TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.Monster, engine, m_map, selectionDelegate, targetPoints);
                        window.SetKeyboardHandler(handler.OnKeyboardDown);
                    }
                    break;
                }
                case MagecrawlKey.o:
                {
                    List<EffectivePoint> operatePoints = CalculateOperatePoints();
                    TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.Operatable, engine, m_map, (w,e,p) => m_engine.Actions.Operate(p), operatePoints);
                    window.SetKeyboardHandler(handler.OnKeyboardDown);
                    break;
                }
                case MagecrawlKey.v:
                {
                    TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.None, engine, m_map, null);
                    m_map.UseViewCursor = true;                    
                    window.SetKeyboardHandler(handler.OnKeyboardDown);
                    break;
                }
                case MagecrawlKey.A:
                {
                    TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.None, engine, m_map, OnRunTargetSelected, null);
                    window.SetKeyboardHandler(handler.OnKeyboardDown);
                    break;
                }
                case MagecrawlKey.i:
                {
                    ListSelection listSelection = new ListSelection(window, engine.Player.Items.OfType<INamedItem>(), "Inventory");
                    listSelection.SelectionDelegate = i =>
                    {
                        ItemSelection.OnSelection onItemSelection = (item, option) =>
                        {
                            TargetingInfo targetInfo = m_engine.Targetting.GetTargettingTypeForInventoryItem(item, option);
                            HandleInvoke(targetInfo, p => m_engine.Actions.SelectedItemOption(item, option, p), item);
                        };

                        ItemSelection selection = new ItemSelection(engine, (IItem)i, onItemSelection);
                        selection.ParentWindow = listSelection;
                        selection.Show();
                    };
                    listSelection.DismissOnSelection = false;
                    listSelection.Show();
                    break;
                }
                case MagecrawlKey.z:
                {
                    ListSelection listSelection = new ListSelection(window, engine.Player.Spells.OfType<INamedItem>(), "Spellbook");
                    listSelection.SelectionDelegate = s =>
                    {
                        TargetingInfo targetInfo = ((ISpell)s).Targeting;
                        HandleInvoke(targetInfo, p => m_engine.Actions.CastSpell((ISpell)s, p), s);
                    };

                    listSelection.Show();
                    break;
                }
                case MagecrawlKey.E:
                {
                    ListSelection listSelection = new ListSelection(window, engine.Player.StatusEffects.OfType<INamedItem>(), "Dismiss Effect");
                    listSelection.SelectionDelegate = i => engine.Actions.DismissEffect(i.DisplayName);
                    listSelection.Show();
                    break;
                }
                case MagecrawlKey.Comma:
                {
                    List<INamedItem> itemsAtLocation = engine.Map.Items.Where(i => i.Second == engine.Player.Position).Select(i => i.First).OfType<INamedItem>().ToList();
                    if (itemsAtLocation.Count > 1)
                    {
                        ListSelection listSelection = new ListSelection(window, itemsAtLocation, "Pickup Item");
                        listSelection.SelectionDelegate = i => engine.Actions.GetItem((IItem)i);
                        listSelection.Show();
                    }
                    else
                    {
                        engine.Actions.GetItem();
                        window.UpdateWorld();
                    }
                    break;
                }
                case MagecrawlKey.Backquote:
                {
                    engine.Actions.SwapPrimarySecondaryWeapons();
                    window.UpdateWorld();
                    break;
                }
                case MagecrawlKey.Period:
                {
                    engine.Actions.Wait();
                    window.UpdateWorld();
                    break;
                }
                case MagecrawlKey.PageUp:
                {
                    window.MessageBox.PageUp();
                    break;
                }
                case MagecrawlKey.PageDown:
                {
                    window.MessageBox.PageDown();
                    break;
                }
                case MagecrawlKey.Backspace:
                {
                    window.MessageBox.Clear();
                    break;
                }
                case MagecrawlKey.Left:
                    HandleDirection(Direction.West, m_map, window, engine);
                    break;
                case MagecrawlKey.Right:
                    HandleDirection(Direction.East, m_map, window, engine);
                    break;
                case MagecrawlKey.Down:
                    HandleDirection(Direction.South, m_map, window, engine);
                    break;
                case MagecrawlKey.Up:
                    HandleDirection(Direction.North, m_map, window, engine);
                    break;
                case MagecrawlKey.Insert:
                    HandleDirection(Direction.Northwest, m_map, window, engine);
                    break;
                case MagecrawlKey.Delete:
                    HandleDirection(Direction.Southwest, m_map, window, engine);
                    break;
                case MagecrawlKey.Home:
                    HandleDirection(Direction.Northeast, m_map, window, engine);
                    break;
                case MagecrawlKey.End:
                    HandleDirection(Direction.Southeast, m_map, window, engine);
                    break;
            }
        }