예제 #1
0
        private void HandleInvoke(TargetingInfo targetInfo, OnTargettingPointSelected onInvoke, object invokingObject)
        {
            if (targetInfo == null)
            {
                onInvoke(m_engine.Player.Position);
                m_window.UpdateWorld();
            }
            else
            {
                switch (targetInfo.Type)
                {
                    case TargetingInfo.TargettingType.Stream:
                    {
                        List<EffectivePoint> targetablePoints = PointListUtils.EffectivePointListOneStepAllDirections(m_engine.Player.Position);
                        HandleRangedSinglePointInvoke(onInvoke, targetablePoints);
                        break;
                    }
                    case TargetingInfo.TargettingType.RangedSingle:
                    case TargetingInfo.TargettingType.RangedBlast:
                    case TargetingInfo.TargettingType.RangedExplodingPoint:
                    {
                        List<EffectivePoint> targetablePoints = PointListUtils.EffectivePointListFromBurstPosition(m_engine.Player.Position, targetInfo.Range);
                        HandleRangedSinglePointInvoke(onInvoke, targetablePoints);
                        break;
                    }
                    case TargetingInfo.TargettingType.Cone:
                    {
                        MageCrawlPoint playerPosition = m_engine.Player.Position;
                        List<EffectivePoint> targetablePoints = GetConeTargetablePoints(playerPosition);
                        OnTargetSelect selectionDelegate = (w, e, p) =>
                        {
                            if (p != m_engine.Player.Position)
                                onInvoke(p);
                        };

                        TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.Monster, m_engine, m_map, selectionDelegate, targetablePoints);
                        m_window.SetKeyboardHandler(handler.OnKeyboardDown);
                        break;
                    }
                    case TargetingInfo.TargettingType.Self:
                    {
                        onInvoke(m_engine.Player.Position);
                        m_window.UpdateWorld();
                        break;
                    }
                    default:
                        throw new System.InvalidOperationException("InvokingKeystrokeHandler - HandleInvoke, don't know how to handle: " + targetInfo.Type.ToString());
                }
            }
        }
예제 #2
0
        private void HandleRangedSinglePointInvoke(OnTargettingPointSelected selectionDelegate, List<EffectivePoint> targetablePoints)
        {
            m_engine.Targetting.FilterNotTargetableToPlayerPointsFromList(targetablePoints, true);
            m_engine.Targetting.FilterNotVisibleToPlayerBothWaysFromList(targetablePoints, true);

            OnTargetSelect onSelection = (window, engine, point) => 
                {
                    if (point != m_engine.Player.Position)
                        selectionDelegate(point);
                };

            TargettingModeKeyboardHandler handler = new TargettingModeKeyboardHandler(TargettingModeKeyboardHandler.TargettingType.Monster, m_engine, m_map, onSelection, targetablePoints);

            m_window.SetKeyboardHandler(handler.OnKeyboardDown);
        }
예제 #3
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;
            }
        }