// ReSharper disable once CyclomaticComplexity public Option <ICommand> HandleKeyInput(int key) { Player player = Game.Player; switch (InputMapping.GetNormalInput(key)) { case NormalInput.None: return(Option.None <ICommand>()); #region Movement Keys case NormalInput.MoveW: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.W))); case NormalInput.MoveS: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.S))); case NormalInput.MoveN: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.N))); case NormalInput.MoveE: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.E))); case NormalInput.MoveNW: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.NW))); case NormalInput.MoveNE: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.NE))); case NormalInput.MoveSW: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.SW))); case NormalInput.MoveSE: return(Option.Some <ICommand>(new MoveCommand(player, player.Pos + Direction.SE))); case NormalInput.Wait: return(Option.Some <ICommand>(new WaitCommand(player))); #endregion case NormalInput.Cast: int spellnum = key - BearLib.Terminal.TK_1; if (spellnum >= player.SpellList.Count) { return(Option.None <ICommand>()); } Spell.ISpell spell = player.SpellList[spellnum]; return(CastSpell(player, spellnum, spell)); case NormalInput.Get: return(Game.MapHandler.GetItem(player.Pos) .FlatMap(item => Option.Some <ICommand>(new PickupCommand(player, item)))); case NormalInput.OpenMenu: Game.Exit(); return(Option.None <ICommand>()); } return(Option.None <ICommand>()); }
// ReSharper disable once CyclomaticComplexity public Option <ICommand> HandleKeyInput(int key) { Mech player = (Mech)BaseGame.Player; (int px, int py) = player.Pos; switch (InputMapping.GetNormalInput(key)) { case NormalInput.None: return(Option.None <ICommand>()); #region Movement Keys case NormalInput.MoveLeft: return(Option.Some <ICommand>(new MoveCommand(player, new Loc(px - 1, py)))); case NormalInput.MoveDown: return(Option.Some <ICommand>(new MoveCommand(player, new Loc(px, py + 1)))); case NormalInput.MoveUp: return(Option.Some <ICommand>(new MoveCommand(player, new Loc(px, py - 1)))); case NormalInput.MoveRight: return(Option.Some <ICommand>(new MoveCommand(player, new Loc(px + 1, py)))); case NormalInput.TurnLeft: return(Option.Some <ICommand>(new TurnCommand(player, Math.PI / 2))); case NormalInput.TurnRight: return(Option.Some <ICommand>(new TurnCommand(player, -Math.PI / 2))); case NormalInput.Wait: return(Option.Some <ICommand>(new WaitCommand(player))); #endregion #region Weapon Group Firing; case NormalInput.WeaponGroup1: return(player.PartHandler.WeaponGroup.FireGroup(player, 0)); case NormalInput.WeaponGroup2: return(player.PartHandler.WeaponGroup.FireGroup(player, 1)); case NormalInput.WeaponGroup3: return(player.PartHandler.WeaponGroup.FireGroup(player, 2)); case NormalInput.WeaponGroup4: return(player.PartHandler.WeaponGroup.FireGroup(player, 3)); case NormalInput.WeaponGroup5: return(player.PartHandler.WeaponGroup.FireGroup(player, 4)); case NormalInput.WeaponGroup6: return(player.PartHandler.WeaponGroup.FireGroup(player, 5)); #endregion case NormalInput.UseCoolant: player.UseCoolant(); return(Option.Some <ICommand>(new WaitCommand(EngineConsts.COOL_USE_TICKS))); } return(Option.None <ICommand>()); }
// ReSharper disable once CyclomaticComplexity public Option <ICommand> HandleKeyInput(int key) { Player player = Game.Player; Weapon weapon = player.Equipment.PrimaryWeapon; switch (InputMapping.GetNormalInput(key)) { //case NormalInput.None: // return null; #region Movement Keys case NormalInput.MoveW: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.W))); case NormalInput.MoveS: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.S))); case NormalInput.MoveN: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.N))); case NormalInput.MoveE: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.E))); case NormalInput.MoveNW: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.NW))); case NormalInput.MoveNE: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.NE))); case NormalInput.MoveSW: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.SW))); case NormalInput.MoveSE: return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.SE))); case NormalInput.Wait: return(Option.Some <ICommand>(new WaitCommand(player))); #endregion case NormalInput.Get: return(Option.Some <ICommand>(new PickupCommand(player, Game.Map.GetStack(player.Loc)))); case NormalInput.Throw: // TODO: Add ability to throw without wielding if (weapon == null) { Game.MessageHandler.AddMessage("Nothing to throw."); return(Option.None <ICommand>()); } IAction thrown = weapon.Throw(); Game.StateHandler.PushState(new TargettingState( player, thrown.Area, returnTarget => { Game.MessageHandler.AddMessage($"You throw a {weapon}."); // Switch to offhand weapon if possible. player.Equipment.PrimaryWeapon = player.Equipment.OffhandWeapon; // Drop the item on the map. // TODO: Add possibility of weapon stuck / breaking // TODO: Handle case of multiple thrown at once? Loc[] enumerable = returnTarget as Loc[] ?? returnTarget.ToArray(); Loc point = enumerable[0]; weapon.Loc = point; Game.Map.AddItem(weapon); return(new DelayActionCommand(player, thrown, enumerable)); })); return(Option.None <ICommand>()); case NormalInput.ChangeLevel: return(Option.Some <ICommand>(new ChangeLevelCommand(Game.Map.TryChangeLocation(player)))); case NormalInput.OpenApply: Game.StateHandler.PushState(ApplyState.Instance); return(Option.None <ICommand>()); case NormalInput.OpenDrop: Game.StateHandler.PushState(DropState.Instance); return(Option.None <ICommand>()); case NormalInput.OpenEquip: Game.StateHandler.PushState(EquipState.Instance); return(Option.None <ICommand>()); case NormalInput.OpenInventory: Game.StateHandler.PushState(InventoryState.Instance); return(Option.None <ICommand>()); case NormalInput.OpenUnequip: Game.StateHandler.PushState(UnequipState.Instance); return(Option.None <ICommand>()); case NormalInput.AutoExplore: Game.StateHandler.PushState(AutoexploreState.Instance); return(Option.None <ICommand>()); case NormalInput.OpenMenu: Game.Exit(); return(Option.None <ICommand>()); } // HACK: debugging commands if (key == Terminal.TK_Q) { // NOTE: Movement occurs after the hook is used. This means that using the hook // to pull enemies will often give the Player a first hit on enemies, but using // the hook to escape will give enemies an "attack of opportunity". IAction hookAction = new HookAction(10); Game.StateHandler.PushState(new TargettingState( player, hookAction.Area, returnTarget => new DelayActionCommand(player, hookAction, returnTarget))); return(Option.None <ICommand>()); } // TODO: Create a debug menu for test commands if (key == Terminal.TK_GRAVE) { Game.EventScheduler.Clear(); Game.NewGame(); return(Option.Some <ICommand>(new WaitCommand(player))); } // TODO: Use weapon's attack sequence if equipped??? IAction action = player.GetBasicAttack(); if (key == Terminal.TK_Z) { action = weapon?.AttackLeft() ?? player.GetBasicAttack(); } else if (key == Terminal.TK_X) { action = weapon?.AttackRight() ?? player.GetBasicAttack(); } else if (Terminal.Check(Terminal.TK_SHIFT)) { // TODO: Change to an arbitrary facing // TODO: Should attacks update facing? player.Facing = player.Facing.Right(); Game.Map.Refresh(); return(Option.None <ICommand>()); } if (Terminal.Check(Terminal.TK_SHIFT)) { Game.StateHandler.PushState(new TargettingState( player, action.Area, target => new DelayActionCommand(player, action, target))); return(Option.None <ICommand>()); } else { (int dx, int dy) = player.Facing; IEnumerable <Loc> target = action.Area.GetTilesInRange( player, player.Loc + player.Facing); return(Option.Some <ICommand>(new DelayActionCommand(player, action, target))); } }