public override ViewModel Index() { var menu = new Menu(); var id = 1; if (_currentSpell == null) { var spellBook = _gameWorld.Player.SpellBook.ToList(); foreach (var x in spellBook .Skip(_pageIndex * PageSize) .Take(PageSize) .Select((spell, index) => new { Spell = spell, Index = (_pageIndex * PageSize) + index })) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = x.Spell.GetLeveledName(), ActionResult = Actions.Reload, OnInputAccepted = () => { _currentSpell = x.Spell; _currentSpellIndex = x.Index; _title = x.Spell.GetLeveledName(); _information = x.Spell.GetDescription(); } }; menu.AddMenuItem(menuItem); id++; } if (_pageIndex > 0) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = "Previous", ActionResult = Actions.Reload, OnInputAccepted = () => _pageIndex-- }; menu.AddMenuItem(menuItem); id++; } if (spellBook.Count > ((_pageIndex * PageSize) + PageSize)) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = "Next", ActionResult = Actions.Reload, OnInputAccepted = () => _pageIndex++ }; menu.AddMenuItem(menuItem); id++; } menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Back", ActionResult = Actions.GoBack }); } else { if (_currentSpell is INonCombatSpell && _currentSpell.CanCast(_gameWorld.Player, new NonCombatContext())) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = "Cast", ActionResult = Actions.Reload, OnInputAccepted = () => { var logEntry = ((INonCombatSpell)_currentSpell).Cast(_dice, _gameWorld.Player); _title = string.Format("Cast {0}", _currentSpell.GetLeveledName()); _information = logEntry != null ? logEntry.Text : null; _currentSpell = null; _currentSpellIndex = -1; if ((_pageIndex * PageSize) > _gameWorld.Player.SpellBook.Count()) { _pageIndex--; } } }; menu.AddMenuItem(menuItem); id++; }; menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Move to top", ActionResult = Actions.Reload, OnInputAccepted = () => { _gameWorld.Player.MoveSpellToTopOfSpellBook(_currentSpell, _currentSpellIndex); _currentSpell = null; _currentSpellIndex = -1; } }); id++; menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Back", ActionResult = Actions.Reload, OnInputAccepted = () => { _title = DefaultTitle; _information = DefaultInformation; _currentSpell = null; _currentSpellIndex = -1; } }); } var viewModel = ViewModel.CreateWithMenu<SpellBookViewModel>(menu); viewModel.Stats = StatsViewModel.FromPlayer(_gameWorld.Player); viewModel.Title = _title; viewModel.Information = _information; viewModel.AsciiArt = _asciiArtRepository.GetSpellBookArt(); return viewModel; }
public override ViewModel Index() { var menu = new Menu(); var id = 1; if (_currentItem == null) { var inventory = _gameWorld.Player.Inventory.Where(item => item.Quantity > 0).ToList(); foreach (var x in inventory .Skip(_pageIndex * PageSize) .Take(PageSize) .Select((item, index) => new { Item = item, Index = (_pageIndex * PageSize) + index })) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = x.Item.GetLeveledName() + (x.Item.Quantity > 1 ? string.Format(" ({0})", x.Item.Quantity) : ""), ActionResult = Actions.Reload, OnInputAccepted = () => { _currentItem = x.Item; _currentItemIndex = x.Index; _title = x.Item.GetLeveledName(); _information = x.Item.GetDescription(); } }; menu.AddMenuItem(menuItem); id++; } if (_pageIndex > 0) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = "Previous", ActionResult = Actions.Reload, OnInputAccepted = () => _pageIndex-- }; menu.AddMenuItem(menuItem); id++; } if (inventory.Count > ((_pageIndex * PageSize) + PageSize)) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = "Next", ActionResult = Actions.Reload, OnInputAccepted = () => _pageIndex++ }; menu.AddMenuItem(menuItem); id++; } menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Back", ActionResult = Actions.GoBack }); } else { if (_currentItem is INonCombatItem && _currentItem.CanUse(_gameWorld.Player, new NonCombatContext())) { var menuItem = new MenuItem { Id = id.ToString()[0], Text = _currentItem is Weapon ? "Equip" : "Use", ActionResult = Actions.Reload, OnInputAccepted = () => { var logEntry = ((INonCombatItem)_currentItem).Use(_dice, _gameWorld.Player); _title = (_currentItem is Weapon ? "Equipped " : "Used 1 ") + _currentItem.GetLeveledName(); _information = logEntry != null ? logEntry.Text : null; _currentItem = null; _currentItemIndex = -1; if ((_pageIndex * PageSize) > _gameWorld.Player.Inventory.Count(item => item.Quantity > 0)) { _pageIndex--; } } }; menu.AddMenuItem(menuItem); id++; }; if (!(_currentItem is Weapon) || !_currentItem.Equals(Weapon.BareHands)) { menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Discard", ActionResult = Actions.Reload, OnInputAccepted = () => { _title = DefaultTitle; _information = "Discarded 1 " + _currentItem.Name; _gameWorld.Player.RemoveItemFromInventory(_currentItem); _currentItem = null; _currentItemIndex = -1; if ((_pageIndex * PageSize) > _gameWorld.Player.Inventory.Count(item => item.Quantity > 0)) { _pageIndex--; } } }); id++; } menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Move to top", ActionResult = Actions.Reload, OnInputAccepted = () => { _gameWorld.Player.MoveItemToTopOfInventory(_currentItem, _currentItemIndex); _currentItem = null; _currentItemIndex = -1; } }); id++; menu.AddMenuItem( new MenuItem { Id = id.ToString()[0], Text = "Back", ActionResult = Actions.Reload, OnInputAccepted = () => { _title = DefaultTitle; _information = DefaultInformation; _currentItem = null; _currentItemIndex = -1; } }); } var viewModel = ViewModel.CreateWithMenu<InventoryViewModel>(menu); viewModel.Stats = StatsViewModel.FromPlayer(_gameWorld.Player); viewModel.Title = _title; viewModel.Information = _information; viewModel.AsciiArt = _asciiArtRepository.GetInventoryArt(); return viewModel; }