public async Task <ActionResult> EatItem(Guid?itemId, Guid charId) { var model = await CharacterFacade.GetAsync(charId); if (model.CurrentHp == model.CalculateAttributes().Hp * 10) { return(RedirectToAction("Detail")); } var toHeal = model.CalculateAttributes().Hp * 10 - model.CurrentHp; DateTime?sickness = DateTime.Now.AddHours(1); if (itemId != null) { sickness = model.Sickness; var item = await EquipmentFacade.GetItemAsync(itemId.GetValueOrDefault()); toHeal = (item.Attributes.Hp * 10) >= toHeal ? toHeal : (item.Attributes.Hp * 10); await EquipmentFacade.DeleteFromInventoryAsync(model.Inventory, item); } var charUpdate = new CharacterUpdateDto() { Id = model.Id, Name = model.Name, Experience = model.Experience, Gold = model.Gold, CurrentHp = model.CurrentHp + toHeal, Sickness = sickness, SkillPoints = model.SkillPoints }; await CharacterFacade.EditAsync(charUpdate); return(RedirectToAction("Detail")); }
public async Task <ActionResult> FightForCredits() { var user = await UserFacade.GetUserAccordingToUsernameAsync(User.Identity.Name); if (user.Credits < 10) { return(Json(new { CanFight = false }, JsonRequestBehavior.AllowGet)); } var charUpdate = new CharacterUpdateDto() { Id = user.Character.Id, Name = user.Character.Name, Experience = user.Character.Experience, Gold = user.Character.Gold, CurrentHp = user.Character.CurrentHp, SkillPoints = user.Character.SkillPoints, Sickness = null }; await CharacterFacade.EditAsync(charUpdate); var userUpdate = new UserEditDto() { Credits = user.Credits - 10, CharacterId = user.CharacterId, Id = user.Id, Score = user.Score }; await UserFacade.EditAsync(userUpdate); return(Json(new { CanFight = true }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> SellItem(Guid itemId, Guid charId) { var item = await EquipmentFacade.GetItemAsync(itemId); var model = await CharacterFacade.GetAsync(charId); var charUpdate = new CharacterUpdateDto() { Id = model.Id, Name = model.Name, Experience = model.Experience, Gold = model.Gold + item.Price, CurrentHp = model.CurrentHp, Sickness = model.Sickness, SkillPoints = model.SkillPoints }; await EquipmentFacade.DeleteFromInventoryAsync(model.Inventory, item); await CharacterFacade.EditAsync(charUpdate); return(RedirectToAction("Detail")); }
public async Task <ActionResult> EquipItem(Guid itemId, Guid charId) { var item = await EquipmentFacade.GetItemAsync(itemId); var model = await CharacterFacade.GetAsync(charId); var charUpdate = new CharacterUpdateDto() { Id = model.Id, Name = model.Name, Experience = model.Experience, Gold = model.Gold, CurrentHp = model.CurrentHp + (item.Attributes.Hp * 10), Sickness = model.Sickness, SkillPoints = model.SkillPoints }; ItemDto equipped = null; foreach (var itemDto in model.Equipment.ListItems()) { if (itemDto != null && itemDto.ArmorClass == item.ArmorClass) { equipped = itemDto; } } await EquipmentFacade.DeleteFromInventoryAsync(model.Inventory, item); if (equipped != null) { charUpdate.CurrentHp -= equipped.Attributes.Hp * 10; await EquipmentFacade.AddToInventoryAsync(model.Inventory, equipped); } await EquipmentFacade.EquipItemAsync(model.Equipment, item); await CharacterFacade.EditAsync(charUpdate); return(RedirectToAction("Detail")); }