internal override Option <ICommand> ResolveInput(Item item) { if (!(item is IUsable usableItem)) { Game.MessageHandler.AddMessage($"Cannot apply {item}."); return(Option.None <ICommand>()); } IAction action = usableItem.ApplySkill; TargettingState state = new TargettingState(Game.Player, action.Area, returnTarget => { Item split = Game.Player.Inventory.Split(item, 1); Game.StateHandler.PopState(); // exit targetting state return(new ApplyCommand(Game.Player, split as IUsable, returnTarget)); }); Game.StateHandler.PushState(state); return(Option.None <ICommand>()); }
public override Option <ICommand> HandleKeyInput(int key) { switch (key) { case Terminal.TK_A: if (!_usable) { Game.MessageHandler.AddMessage($"Cannot apply {_item}."); return(Option.None <ICommand>()); } IAction action = ((IUsable)_item).ApplySkill; TargettingState state = new TargettingState(Game.Player, action.Area, returnTarget => { Item usable = Game.Player.Inventory.Split(_item, 1); Game.StateHandler.PopState(); return(new ApplyCommand(Game.Player, usable as IUsable, returnTarget)); }); Game.StateHandler.PushState(state); return(Option.None <ICommand>()); case Terminal.TK_C: case Terminal.TK_T: return(Option.None <ICommand>()); case Terminal.TK_W: if (!_equippable) { Game.MessageHandler.AddMessage($"Cannot equip {_item}."); return(Option.None <ICommand>()); } Item split = Game.Player.Inventory.Split(_item, 1); IEquippable equipable = split as IEquippable; return(Option.Some <ICommand>(new EquipCommand(Game.Player, equipable))); default: return(Option.None <ICommand>()); } }