Example #1
0
        //
        public ActionResult Index()
        {
            DAL.ProjectStrawberryEntities ctx         = new DAL.ProjectStrawberryEntities();
            List <WeaponType>             weaponTypes = ctx.WeaponTypes.ToList();

            return(PartialView("Market", weaponTypes));
        }
Example #2
0
        public ActionResult GetWeapons(int weaponTypeId)
        {
            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();

            List <Weapon> weapons = ctx.Weapons.Where(w => w.WeaponTypeId == weaponTypeId).OrderBy(w => w.Price).ToList();

            return(PartialView("_Weapons", weapons));
        }
Example #3
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();

            Regex regex        = new Regex(@"^[a-zA-Z0-9]*$");
            bool  errorDisplay = regex.IsMatch(model.DisplayName);

            if (!errorDisplay)
            {
                ModelState.AddModelError("DisplayName", "Your displayname can only contain letters and numbers.");
                return(View(model));
            }

            bool displayNameExist = ctx.AspNetUsers.Any(a => a.DisplayName == model.DisplayName);

            if (ModelState.IsValid && !displayNameExist)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, DisplayName = model.DisplayName
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }
            else
            {
                ModelState.AddModelError("DisplayName", "Displayname is already taken.");
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Example #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();

            Regex regex        = new Regex(@"^[a-zA-Z0-9]*$");
            bool  errorDisplay = regex.IsMatch(model.DisplayName);

            if (!errorDisplay)
            {
                ModelState.AddModelError("DisplayName", "Your displayname can only contain letters and numbers.");
                return(View(model));
            }

            bool displayNameExist = ctx.AspNetUsers.Any(a => a.DisplayName == model.DisplayName);

            if (displayNameExist)
            {
                ModelState.AddModelError("DisplayName", "Displayname is already taken.");
                return(View(model));
            }

            if (ModelState.IsValid && !displayNameExist)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, DisplayName = model.DisplayName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #5
0
        public ActionResult Game()
        {
            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();
            string currentUserId = User.Identity.GetUserId();

            #region FighterModel
            CharacterModel character = ctx.Characters.Select(f => new CharacterModel
            {
                AccountId = f.AccountId,
                Avatar    = f.Avatar + ".jpg",
                Axe       = f.Axe,
                Block     = f.Block,
                Class     = ctx.Classes.Select(c => new ClassModel {
                    Id = c.Id, Name = c.ClassName
                }).FirstOrDefault(c => c.Id == f.ClassId),
                Dagger     = f.Dagger,
                Evasion    = f.Evasion,
                Experience = f.Experience,
                Gender     = ctx.Genders.Select(g => new GenderModel {
                    Id = g.Id, Name = g.Name
                }).FirstOrDefault(g => g.Id == f.GenderId),
                Gold      = f.Gold,
                Health    = f.Health,
                Level     = f.Level,
                Mace      = f.Mace,
                Name      = f.Name,
                Parry     = f.Parry,
                Polearm   = f.Polearm,
                Quickness = f.Quickness,
                Stamina   = f.Stamina,
                Strength  = f.Strength,
                Sword     = f.Sword,
                Vitality  = f.Vitality,
                Alive     = f.Alive,
            }).FirstOrDefault(f => f.AccountId == currentUserId && f.Alive);
            #endregion

            return(View(character));
        }
Example #6
0
        public ActionResult Index()
        {
            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();
            string currentUserId       = currentUserId = User.Identity.GetUserId();
            bool   doUserHaveCharacter = ctx.Characters.Any(c => c.AccountId == currentUserId && c.Alive);

            if (!doUserHaveCharacter)
            {
                List <SelectListItem> GenderOptions     = new List <SelectListItem>();
                List <SelectListItem> ClassOptions      = new List <SelectListItem>();
                List <SelectListItem> ProfessionOptions = new List <SelectListItem>();
                List <SelectListItem> AvatarOptions     = new List <SelectListItem>();

                foreach (var item in ctx.Classes)
                {
                    ClassOptions.Add(new SelectListItem {
                        Text = item.ClassName, Value = item.Id.ToString()
                    });
                }

                foreach (var item in ctx.Genders)
                {
                    GenderOptions.Add(new SelectListItem {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                }

                ViewBag.GenderId      = GenderOptions;
                ViewBag.ClassId       = ClassOptions;
                ViewBag.ProfessionId  = ProfessionOptions;
                ViewBag.AvatarFemales = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/AvatarFemales/")).Select(a => Path.GetFileNameWithoutExtension(a));
                ViewBag.AvatarMales   = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/AvatarMales/")).Select(a => Path.GetFileNameWithoutExtension(a));

                return(View());
            }

            return(RedirectToAction("Game"));
        }
Example #7
0
        public ActionResult Index(CharacterModel model)
        {
            DAL.ProjectStrawberryEntities ctx = new DAL.ProjectStrawberryEntities();
            string currentUserId = User.Identity.GetUserId();

            if (ctx.Characters.Any(c => c.AccountId == currentUserId && c.Alive))
            {
                return(RedirectToAction("Game"));
            }

            Match checkNameAndEdit = Regex.Match(model.Name, @"(?i)^[a-z]+");

            model.Name = checkNameAndEdit.ToString();

            bool attributeIs60 = model.Axe + model.Dagger + model.Evasion + model.Mace + model.Parry + model.Polearm + model.Quickness + model.Spear + model.Stamina + model.Strength + model.Sword + model.Vitality == 60;
            bool doesNameExist = ctx.Characters.Any(c => c.Name == model.Name && c.Alive);

            if (ModelState.IsValid && attributeIs60 && !doesNameExist)
            {
                var character = new Character
                {
                    AccountId  = currentUserId,
                    Avatar     = model.Avatar,
                    Axe        = model.Axe,
                    Block      = model.Block,
                    Class      = ctx.Classes.FirstOrDefault(c => c.Id == model.ClassId),
                    Dagger     = model.Dagger,
                    Evasion    = model.Evasion,
                    Experience = 0,
                    Gender     = ctx.Genders.FirstOrDefault(g => g.Id == model.GenderId),
                    Gold       = 5000,
                    Level      = 1,
                    Mace       = model.Mace,
                    Name       = model.Name,
                    Parry      = model.Parry,
                    Polearm    = model.Polearm,
                    Quickness  = model.Quickness,
                    Spear      = model.Spear,
                    Stamina    = model.Stamina,
                    Strength   = model.Strength,
                    Sword      = model.Sword,
                    Vitality   = model.Vitality,
                    Alive      = true,
                };

                if (character.Class.ClassName == "Assassin")
                {
                    character.Quickness += 2;
                    character.Strength  += 1;
                }
                else if (character.Class.ClassName == "Bounty Hunter")
                {
                    character.Strength  += 2;
                    character.Quickness += 1;
                }
                else if (character.Class.ClassName == "Crusader")
                {
                    character.Vitality += 2;
                    character.Stamina  += 1;
                }
                else if (character.Class.ClassName == "Duelist")
                {
                    character.Evasion   += 1;
                    character.Strength  += 1;
                    character.Quickness += 1;
                }
                else if (character.Class.ClassName == "Fighter")
                {
                    character.Strength += 2;
                    character.Vitality += 1;
                }
                else if (character.Class.ClassName == "Guard")
                {
                    character.Vitality += 2;
                    character.Parry    += 1;
                }
                else if (character.Class.ClassName == "Thief")
                {
                    character.Quickness += 2;
                    character.Evasion   += 1;
                }

                character.Health = character.Vitality;

                ctx.Characters.Add(character);
                ctx.SaveChanges();

                return(RedirectToAction("Game"));
            }

            return(View(model));
        }