Example #1
0
        public IActionResult InitializeZone()
        {
            Random rnd = new Random();

            for (int i = 0; i < _mapSize; i++)
            {
                for (int j = 0; j < _mapSize; j++)
                {
                    var zone = new gameModel.Zone
                    {
                        XPos = i,
                        YPos = j,
                        Type = rnd.Next(0, 3),
                    };
                    _context.Zones.Add(zone);
                }
            }
            _context.SaveChangesAsync();
            return(View("Done!"));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Email,Login,PasswordHash")] User user, string confirm_password)
        {
            if (ModelState.IsValid)
            {
                bool passwordsAreDifferent = (confirm_password != user.PasswordHash);
                int  id = _context.Users.Max(m => m.UserId) + 1;
                user.PasswordHash = getHashSha256(user.PasswordHash);
                user.UserId       = id;
                User matchByLogin = await _context.Users.FirstOrDefaultAsync(u => u.Login == user.Login);

                User matchByEmail = await _context.Users.FirstOrDefaultAsync(u => u.Email == user.Email);

                if ((matchByLogin != null) || (matchByEmail != null) || (passwordsAreDifferent))
                {
                    if (matchByLogin != null)
                    {
                        ModelState.AddModelError("Error", "This login already used. Please enter another");
                    }
                    if (matchByEmail != null)
                    {
                        ModelState.AddModelError("Error", "This email already used. Please enter another");
                    }
                    if (passwordsAreDifferent)
                    {
                        ModelState.AddModelError("Error", "Passwords are different. Please try again.");
                    }
                }
                else
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Login", true));
                }
            }
            return(View("Register"));
            //return RedirectToAction(nameof(Register));
        }
Example #3
0
        public bool InitCharacter(int? id)
        {
            var curent_character_info = _context.CharacterInfos.FirstOrDefault(i => i.CharacterId == id);
            var curent_character_state = _context.CharacterStates.FirstOrDefault(i => i.CharacterId == id);
            if (curent_character_info == null)
            {
                CharacterInfo newInfo = new CharacterInfo
                {
                    CharacterId = (int)id,
                    Cha = 1,
                    Con = 1,
                    Str = 1,
                    Dex = 1,
                    Int = 1,
                    Exp = 0,
                    Level = 1,
                    Gold = 0,
                    StatPoints = 0,
                    Race = "Human",
                    Sex = "male"
                };
                _context.CharacterInfos.AddAsync(newInfo);
                _context.SaveChangesAsync();
            }
            if (curent_character_state == null)
            {
                curent_character_info = _context.CharacterInfos.FirstOrDefault(i => i.CharacterId == id);
                CharacterState newState = new CharacterState
                {
                    CharacterId = (int)id,
                    MaxHp = curent_character_info.Con * 10,
                    MaxMp = curent_character_info.Int * 10,
                    MaxStamina = curent_character_info.Dex * 5 + curent_character_info.Str * 5 + curent_character_info.Con * 5,
                    XPos = 5,
                    YPos = 5
                };
                newState.Hp = newState.MaxHp;
                newState.Mp = newState.MaxMp;
                newState.Stamina = newState.MaxStamina;
                int existing_item_id;
                if (_context.ExistingItems.Count() != 0)
                    existing_item_id = _context.ExistingItems.Max(i => i.ExistingItemId) + 1;
                else
                    existing_item_id = 1;
                var baseWeapon = new ExistingItem
                {

                    ExistingItemId = existing_item_id,
                    CharacterId = id,
                    ItemId = 2,
                    ItemTypeId = 2
                };
                _context.ExistingItems.AddAsync(baseWeapon);
                _context.CharacterStates.AddAsync(newState);
                _context.SaveChangesAsync();
                return true;
            }
            return false;
        }