Пример #1
0
 public ActionResult Edit([Bind(Include = "ID,CharacterName,CharacterClass,Level,StatPointsAvailable,CurrentExperience,MaxExperienceForLevel,Health,Strength,Dexterity,Vitality,Luck,PlayerID,DuelsAvailable,DuelWins,DuelLosses,Damage,CritChance,Dodge,CharacterInfo")] CharacterInfoViewModel characterInfoReturn)
 {
     if (ModelState.IsValid)
     {
         CharacterInfo characterInfoSet = characterInfoReturn.CharacterInfo;
         characterInfoSet.Health          = characterInfoSet.CalculateHealth(characterInfoSet);
         characterInfoSet.Damage          = characterInfoSet.CalculateDamage(characterInfoSet);
         characterInfoSet.CritChance      = characterInfoSet.CalculateCritChance(characterInfoSet);
         characterInfoSet.DodgeChance     = characterInfoSet.CalculateDodgeChance(characterInfoSet);
         db.Entry(characterInfoSet).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     TempData["message"] = "Messed Up.";
     return(View(characterInfoReturn));
 }
Пример #2
0
        public ActionResult Create([Bind(Include = "ID,CharacterName,CharacterClass,Level,StatPointsAvailable,CurrentExperience,MaxExperienceForLevel,Health,Strength,Dexterity,Vitality,Luck,PlayerID")] CharacterInfo characterInfo)
        {
            if (ModelState.IsValid)
            {
                //Check if the name is taken, if it is ask them to retry, reloading page with their stats distributed already.
                var characterNameCheck = db.CharacterInfo.FirstOrDefault(x => x.CharacterName == characterInfo.CharacterName);
                //If characterNameCheck is null then there was no match for an existing name, so we continue to check if everything else is correct for creation
                if (characterNameCheck == null)
                {
                    //Every character upon creation must spend their 30 stat points, giving them a total of 34. If their total stats
                    //is greater than 34, we know they tampered with something and redirect them to create.
                    if ((characterInfo.Strength + characterInfo.Dexterity + characterInfo.Vitality + characterInfo.Luck) == 34)
                    {
                        characterInfo.Health      = characterInfo.CalculateHealth(characterInfo);
                        characterInfo.Damage      = characterInfo.CalculateDamage(characterInfo);
                        characterInfo.CritChance  = characterInfo.CalculateCritChance(characterInfo);
                        characterInfo.DodgeChance = characterInfo.CalculateDodgeChance(characterInfo);
                        db.CharacterInfo.Add(characterInfo);
                        db.SaveChanges();
                        return(RedirectToAction("Index", "CharacterInfo"));
                    }
                    else
                    {
                        TempData["message"] = "Invalid stat points.";
                        return(RedirectToAction("Create"));
                    }
                    //Might be redundant, but another check to see if the names are the same and send back an error
                }
                else if (characterNameCheck.CharacterName == characterInfo.CharacterName)
                {
                    TempData["message"] = "Character name already taken.";
                    return(View(characterInfo));
                }
            }

            return(View(characterInfo));
        }