Esempio n. 1
0
        public ActionResult Create(Monster monster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Monsters.Add(monster);
                    db.SaveChanges();

                    FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Zapisanie nowych danych przebiegło pomyślnie.");
                    return RedirectToAction("Index");
                }
                FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zapisać nowych danych. Należy poprawić zaistniałe błędy.");
            }
            catch (Exception)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem nowych danych.");
            }

            return View(monster);
        }
Esempio n. 2
0
        public ActionResult Edit(Monster monster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(monster).State = EntityState.Modified;
                    db.SaveChanges();

                    FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie.");
                    return RedirectToAction("Index");
                }
                FlashMessageHelper.SetMessage(this, FlashMessageType.Info, "Nie można zaktualizować danych. Należy poprawić zaistniałe błędy.");
            }
            catch (DbUpdateConcurrencyException)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane został zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych.");
            }
            catch (Exception)
            {
                FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych.");
            }

            return View(monster);
        }
Esempio n. 3
0
        public string GetBattleReport(CharacterViewModel characterViewModel, Monster monster, ref bool characterWinner)
        {
            int round = 0;
            string raport = "";
            int finalDMG = 0;
            bool firstHitByMonster = false;
            int fullLifeOfCharacter = characterViewModel.Life;
            int fullLifeOfMonster = monster.Life;
            int characterChanceToHitMinInterval = 10;
            int characterChanceToHitMaxInterval = 90;
            int monster_chanceToHit = monster.ChanceToHit;
            int monster_life = monster.Life;
            decimal monster_AttackSpeed = monster.AttackSpeed;
            int character_chanceToHit = characterViewModel.ChanceToHit;
            int character_life = characterViewModel.Life;
            decimal character_AttackSpeed = characterViewModel.AttackSpeed;

            if (characterViewModel.Level < monster.Level)
            {
                character_chanceToHit = character_chanceToHit - 5;
            }

            // Przedział chance to hit 10 < chance to hit < 90
            if (characterChanceToHitMinInterval > character_chanceToHit)
            {
                character_chanceToHit = character_chanceToHit + 9;
            }

            if (character_chanceToHit > characterChanceToHitMaxInterval)
            {
                character_chanceToHit = character_chanceToHit - 9;
            }

            if (characterChanceToHitMinInterval > monster_chanceToHit)
            {
                monster_chanceToHit = 10;
            }

            if (monster_chanceToHit > characterChanceToHitMaxInterval)
            {
                monster_chanceToHit = 90;
            }

            if (monster_AttackSpeed > character_AttackSpeed)
            { // atak characteru
                firstHitByMonster = true;
            }

            Random dice = new Random();
            int intervalOfChanceToHit;

            do
            {
                round++;
                raport += String.Format("<roundvalue>{0}</roundvalue>", round);

                if (firstHitByMonster == true)
                {
                    goto monster;
                }
            character:
                for (int i = 0; i < GetNumberOfHits(round, character_AttackSpeed); i++)
                {
                    intervalOfChanceToHit = dice.Next(1, 101);
                    if (character_chanceToHit >= intervalOfChanceToHit)
                    {
                        finalDMG = HitBy(monster_life, monster.Defense, dice.Next(characterViewModel.MinDamage, characterViewModel.MaxDamage + 1));
                        monster_life = monster_life - finalDMG;

                        if (monster_life > 0)
                        {
                            raport += String.Format("<characternamewhenattack>{0}</characternamewhenattack><characterattackmonstername>{1}</characterattackmonstername><characterattackdmg>{2}</characterattackdmg>", characterViewModel.Name, monster.Name, finalDMG);
                        }
                        else
                        {
                            raport += String.Format("<characternamewhenfinalattack>{0}</characternamewhenfinalattack><characterattackfinaldmg>{1}</characterattackfinaldmg>", characterViewModel.Name, finalDMG);
                            goto CharacterWin;
                        }

                    }
                    else
                    {
                        if (monster_life <= 0 || character_life <= 0)
                            break;

                        raport += String.Format("<characternamewhenmonsterdododge>{0}</characternamewhenmonsterdododge><charactermonsternamewhenmonsterdododge>{1}</charactermonsternamewhenmonsterdododge>", characterViewModel.Name, monster.Name);
                    }
                }
                if (firstHitByMonster == true)
                {   // Podsumowanie
                    raport += String.Format("<summationcharactername>{0}</summationcharactername><summationcharacterlifefalldown>{1}</summationcharacterlifefalldown><summationcharacterlifeconstantly>{2}</summationcharacterlifeconstantly>", characterViewModel.Name, character_life, fullLifeOfCharacter);
                    raport += String.Format("<summationmonstername>{0}</summationmonstername><summationmonsterlifefalldown>{1}</summationmonsterlifefalldown><summationmonsterlifeconstantly>{2}</summationmonsterlifeconstantly>", monster.Name, monster_life, fullLifeOfMonster);

                    round++;
                    raport += String.Format("<roundvalue>{0}</roundvalue>", round);
                }

            monster:
                for (int i = 0; i < GetNumberOfHits(round, monster_AttackSpeed); i++)
                {
                    intervalOfChanceToHit = dice.Next(1, 101);
                    if (monster_chanceToHit >= intervalOfChanceToHit)
                    {
                        finalDMG = HitBy(character_life, characterViewModel.Armor, dice.Next(monster.MinDamage, monster.MaxDamage + 1));
                        character_life = character_life - finalDMG;

                        if (character_life > 0)
                        {
                            raport += String.Format("<monsterattackmonstername>{0}</monsterattackmonstername><monsterattackcharactername>{1}</monsterattackcharactername><monsterattackdmg>{2}</monsterattackdmg>", monster.Name, characterViewModel.Name, finalDMG);
                        }
                        else
                        {
                            raport += String.Format("<monsterfinalattackmonstername>{0}</monsterfinalattackmonstername><monsterfinalattackdmg>{1}</monsterfinalattackdmg>", monster.Name, finalDMG);
                            goto MonsterWin;
                        }
                    }
                    else
                    {
                        if (character_life <= 0 || monster_life <= 0)
                            break;

                        raport += String.Format("<monstermissattackmonstername>{0}</monstermissattackmonstername><monstermissattackcharactername>{1}</monstermissattackcharactername>", monster.Name, characterViewModel.Name);
                    }
                }
                if (firstHitByMonster == true)
                {
                    goto character;
                }
                else
                {   // Podsumowanie
                    raport += String.Format("<summationcharactername>{0}</summationcharactername><summationcharacterlifefalldown>{1}</summationcharacterlifefalldown><summationcharacterlifeconstantly>{2}</summationcharacterlifeconstantly>", characterViewModel.Name, character_life, fullLifeOfCharacter);
                    raport += String.Format("<summationmonstername>{0}</summationmonstername><summationmonsterlifefalldown>{1}</summationmonsterlifefalldown><summationmonsterlifeconstantly>{2}</summationmonsterlifeconstantly>", monster.Name, monster_life, fullLifeOfMonster);
                }
            }
            while (monster_life > 0 && character_life > 0);

            CharacterWin:
            if (monster_life == 0 || monster_life < 0)
            {
                monster_life = 0;
                raport += String.Format("<summationcharactername>{0}</summationcharactername><summationcharacterlifefalldown>{1}</summationcharacterlifefalldown><summationcharacterlifeconstantly>{2}</summationcharacterlifeconstantly>", characterViewModel.Name, character_life, fullLifeOfCharacter);
                raport += String.Format("<summationmonstername>{0}</summationmonstername><summationmonsterlifefalldown>{1}</summationmonsterlifefalldown><summationmonsterlifeconstantly>{2}</summationmonsterlifeconstantly>", monster.Name, monster_life, fullLifeOfMonster);
                characterWinner = true;
            }

            MonsterWin:
            if (character_life == 0 || character_life < 0)
            {
                character_life = 0;
                raport += String.Format("<summationcharactername>{0}</summationcharactername><summationcharacterlifefalldown>{1}</summationcharacterlifefalldown><summationcharacterlifeconstantly>{2}</summationcharacterlifeconstantly>", characterViewModel.Name, character_life, fullLifeOfCharacter);
                raport += String.Format("<summationmonstername>{0}</summationmonstername><summationmonsterlifefalldown>{1}</summationmonsterlifefalldown><summationmonsterlifeconstantly>{2}</summationmonsterlifeconstantly>", monster.Name, monster_life, fullLifeOfMonster);
                characterWinner = false;
            }

            return raport;
        }