Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Detail(Guid?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            var model = await CharacterFacade.GetAsync(id.GetValueOrDefault());

            if (model == null)
            {
                return(RedirectToAction("Index"));
            }
            var u = await UserFacade.GetUserAccordingToUsernameAsync(User.Identity.Name);

            ViewBag.isMine = u.Character.Equals(model);
            return(View(model));
        }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 4
0
        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"));
        }