コード例 #1
0
ファイル: EventService.cs プロジェクト: C0D3Rs/GameProject
        public bool CheckCharacterMeetsEventRequiment(Event randomEvent, CharacterViewModel characterViewModel)
        {
            int points = characterViewModel.Strength > randomEvent.RequireStrength ? randomEvent.RequireStrength : characterViewModel.Strength;
            points += characterViewModel.Dexterity > randomEvent.RequireDexterity ? randomEvent.RequireDexterity : characterViewModel.Dexterity;
            points += characterViewModel.Intelligence > randomEvent.RequireInteligence ? randomEvent.RequireInteligence : characterViewModel.Intelligence;
            points += characterViewModel.Vitality > randomEvent.RequireVitality ? randomEvent.RequireVitality : characterViewModel.Vitality;

            int requiemtPoints = randomEvent.RequireStrength + randomEvent.RequireDexterity + randomEvent.RequireInteligence + randomEvent.RequireVitality;

            if(requiemtPoints == 0)
            {
                return true;
            }

            int range = (points * 100) / requiemtPoints;

            Random dice = new Random();

            int random = dice.Next(0, 100);

            if (random <= range)
            {
                return true;
            }

            return false;
        }
コード例 #2
0
        public CharacterViewModel GetCharacterViewModel(Character character, List<ItemViewModel> items)
        {
            CharacterViewModel characterViewModel = new CharacterViewModel();

            characterViewModel.Class = character.Class;
            characterViewModel.Name = character.Name;

            characterViewModel.Experience = character.Experience;
            characterViewModel.ExperienceToLevel = (characterViewModel.Level + 1) * 100;
            characterViewModel.Level = characterViewModel.Experience / 100 + 1;

            if (characterViewModel.Class == CharacterClass.Warrior)
            {
                characterViewModel.Strength += 3 * characterViewModel.Level;
                characterViewModel.Dexterity += 1 * characterViewModel.Level;
                characterViewModel.Intelligence += 1 * characterViewModel.Level;
            }
            else if (characterViewModel.Class == CharacterClass.Archer)
            {
                characterViewModel.Strength += 1 * characterViewModel.Level;
                characterViewModel.Dexterity += 3 * characterViewModel.Level;
                characterViewModel.Intelligence += 1 * characterViewModel.Level;
            }
            else if (characterViewModel.Class == CharacterClass.Mage)
            {
                characterViewModel.Strength += 1 * characterViewModel.Level;
                characterViewModel.Dexterity += 1 * characterViewModel.Level;
                characterViewModel.Intelligence += 3 * characterViewModel.Level;
            }

            characterViewModel.Vitality += 2 * characterViewModel.Level;

            ItemViewModel weapon = items.FirstOrDefault(i => i.Item.Type == ItemType.Weapon);
            List<ItemViewModel> armorsAndShields = items.FindAll(i => i.Item.Type == ItemType.Shield || i.Item.Type == ItemType.Armor);

            characterViewModel.Strength += items.Sum(gi => gi.GeneratedItem.Strength);
            characterViewModel.Dexterity += items.Sum(gi => gi.GeneratedItem.Dexterity);
            characterViewModel.Intelligence += items.Sum(gi => gi.GeneratedItem.Intelligence);
            characterViewModel.Vitality += items.Sum(gi => gi.GeneratedItem.Vitality);

            characterViewModel.MinDamage = (weapon != null ? weapon.GeneratedItem.PrimaryMinValue : 1);
            characterViewModel.MaxDamage = (weapon != null ? weapon.GeneratedItem.PrimaryMaxValue : 2);
            characterViewModel.Armor = armorsAndShields.Sum(aas => aas.GeneratedItem.PrimaryMinValue);

            characterViewModel.Life = characterViewModel.Vitality * 10 * characterViewModel.Level;
            characterViewModel.ChanceToHit = (weapon != null ? weapon.Item.ChanceToHit : 1) * characterViewModel.Dexterity / characterViewModel.Level;
            characterViewModel.AttackSpeed = characterViewModel.Dexterity / 100 + (weapon != null ? weapon.Item.AttackSpeed : 1);

            if (characterViewModel.ChanceToHit > 75)
            {
                characterViewModel.ChanceToHit = 75;
            }

            return characterViewModel;
        }
コード例 #3
0
ファイル: EventService.cs プロジェクト: C0D3Rs/GameProject
        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;
        }