Пример #1
0
        public void LotsOfPotionsTest()
        {
            var des = EquipmentKind.Weapon.ToDescription();
            var env = CreateTestEnv();

            //GenerationInfo.DebugInfo.EachEnemyGivesPotion = true;
            try
            {
                var         lootInfo = new LootInfo(game, null);
                ILootSource lootSrc  = ActivePlainEnemies.First();//env.Game.Hero
                for (int i = 0; i < 10; i++)
                {
                    var pot   = env.LootGenerator.GetRandomLoot(LootKind.Potion, 1);
                    var added = game.GameManager.AddLootReward(pot, lootSrc, false);
                    Assert.True(added);
                    var dist = pot.DistanceFrom(lootSrc.GetPoint());
                    Assert.Less(dist, 5);
                    Assert.True(dist < 4 || i > 5);
                }
                var newLootItems = lootInfo.GetDiff();
                Assert.AreEqual(newLootItems.Count, 10);
            }
            catch (System.Exception)
            {
                //GenerationInfo.DebugInfo.EachEnemyGivesPotion = false;
            }
        }
Пример #2
0
        public void TestLastingEffectDescription()
        {
            var game = CreateGame();

            var en = ActivePlainEnemies.First();
            var le = game.Hero.LastingEffectsSet.EnsureEffect(EffectType.Bleeding, 10, en);

            Assert.NotNull(le);

            var expectedDesc = le.Type.ToDescription() + ", -10.00 Health (per turn)";///game.Hero.Stats.Defense
            var desc         = le.Description;

            Assert.AreEqual(desc, expectedDesc);

            CheckDesc(EffectType.IronSkin, EntityStatKind.Defense, '+');
            //CheckDesc(EffectType.Rage, EntityStatKind.Attack, '+');
            CheckDesc(EffectType.Inaccuracy, EntityStatKind.ChanceToMeleeHit, '-');
            CheckDesc(EffectType.Weaken, EntityStatKind.Defense, '-');
            CheckDesc(EffectType.ResistAll, EntityStatKind.Unset, '+');

            //le = game.Hero.LastingEffectsSet.AddLastingEffectFromSpell(EffectType.ResistAll, 3, EntityStatKind.Unset, 10);
            //Assert.NotNull(le);
            //expectedDesc = le.Type.ToDescription() + " +" + le.EffectiveFactor.EffectiveFactor;
            //Assert.AreEqual(le.Description, expectedDesc);

            //var calculated = new LastingEffectCalcInfo(EffectType.Bleeding, 3, new LastingEffectFactor(10));
            //le = game.Hero.AddLastingEffect(calculated);
            //Assert.NotNull(le);
            //expectedDesc = le.Type.ToDescription() + " -" + le.EffectAbsoluteValue.Factor;
            //Assert.AreEqual(le.GetDescription(game.Hero), expectedDesc);
        }
Пример #3
0
        public void StunnedEffectFromWeapon()
        {
            var game = CreateGame();
            var hero = game.Hero;

            hero.Stats.SetNominal(Roguelike.Attributes.EntityStatKind.ChanceToMeleeHit, 100);
            var wpn = GenerateEquipment <Weapon>("hammer");

            wpn.MakeMagic(EntityStatKind.ChanceToCauseStunning, 100);
            wpn.Identify();
            SetHeroEquipment(wpn);
            var ccs = hero.GetCurrentValue(EntityStatKind.ChanceToCauseStunning);

            Assert.AreEqual(ccs, 100);

            var enemy = ActivePlainEnemies.First();

            enemy.OnMeleeHitBy(hero);
            Assert.True(enemy.LastingEffects.Any());
            Assert.AreEqual(enemy.LastingEffects[0].Type, EffectType.Stunned);
            Assert.AreEqual(enemy.LastingEffects[0].Description, "Stunned");
            GotoNextHeroTurn();
            Assert.AreEqual(enemy.LastingEffects[0].Type, EffectType.Stunned);
            GotoNextHeroTurn();
            Assert.AreEqual(enemy.LastingEffects[0].Type, EffectType.Stunned);
            GotoNextHeroTurn();
            Assert.False(enemy.LastingEffects.Any());
        }
Пример #4
0
        public void DamageFromEnemiesVaries(AttackKind attackKind)
        {
            var game = CreateGame();
            var hero = game.Hero;

            Assert.Greater(ActivePlainEnemies.Count, 0);
            var enemy = ActivePlainEnemies.First();
            var emp   = game.Level.GetEmptyTiles().Where(i => i.DistanceFrom(hero) < 6 && i.DistanceFrom(hero) > 1).First();

            game.Level.SetTile(enemy, emp.point);
            //PlaceCloseToHero(enemy);
            if (attackKind == AttackKind.Unset)
            {
                DoDamage(enemy, game.Hero, (LivingEntity attacker, LivingEntity victim) => { victim.OnMeleeHitBy(attacker); });
            }

            else if (attackKind == AttackKind.PhysicalProjectile)
            {
                var en = enemy as Enemy;
                var fi = en.AddFightItem(FightItemKind.ThrowingKnife);
                fi.Count           = 10;
                en.ActiveFightItem = fi as ProjectileFightItem;
                DoDamage(enemy, game.Hero, (LivingEntity attacker, LivingEntity victim) => CallDoDamagePhysicalProjectile(attacker, victim));
            }
            //else if (attackKind == AttackKind.WeaponElementalProjectile)
            //{
            //  healthChanges = DoDamage(game.Hero, enemy, (LivingEntity attacker, LivingEntity en) => CallDoDamageWeaponElementalProjectile(attacker, en));
            //}
            else if (attackKind == AttackKind.SpellElementalProjectile)
            {
                enemy.ActiveManaPoweredSpellSource = new Scroll(SpellKind.FireBall);
                enemy.Stats.SetNominal(EntityStatKind.Mana, 1000);
                DoDamage(enemy, game.Hero, (LivingEntity attacker, LivingEntity victim) => CallDoDamageSpellElementalProjectile(attacker, victim));
            }
        }
Пример #5
0
        public void TestBleedingProlong()
        {
            var game          = CreateGame();
            int actionCounter = 0;

            game.GameManager.EventsManager.ActionAppended += (object sender, Roguelike.Events.GameEvent e) =>
            {
                if (e is LivingEntityAction)
                {
                    var lea = e as LivingEntityAction;
                    if (lea.Kind == LivingEntityActionKind.ExperiencedEffect)
                    {
                        if (lea.Info.Contains(EffectType.Bleeding.ToDescription()))
                        {
                            actionCounter++;
                        }
                    }
                }
            };

            var enemy      = ActivePlainEnemies.First();
            var healthStat = enemy.Stats.GetStat(EntityStatKind.Health);

            healthStat.Value.Nominal = 150;
            enemy.SetIsWounded(true);//make sure will bleed
            var wpn = game.GameManager.LootGenerator.GetLootByTileName <Weapon>("rusty_sword");

            SetHeroEquipment(wpn);

            enemy.OnMeleeHitBy(game.Hero);
            var le1 = enemy.LastingEffects.Where(i => i.Type == EffectType.Bleeding).SingleOrDefault();

            Assert.NotNull(le1);

            LastingEffect castedAgain = null;

            var value       = game.Hero.Stats.GetStat(EntityStatKind.Defense).Value;
            var turns       = le1.PendingTurns;
            var enemyHealth = enemy.Stats.Health;

            for (int i = 0; i < turns * 2; i++)//there will be prolong
            {
                castedAgain = enemy.LastingEffects.Where(le => le.Type == EffectType.Bleeding).SingleOrDefault();
                Assert.AreEqual(castedAgain, le1);

                game.GameManager.SkipHeroTurn();
                GotoNextHeroTurn();
                if (i == 0)
                {
                    enemy.OnMeleeHitBy(game.Hero);
                }
            }
            Assert.Greater(enemyHealth, enemy.Stats.Health);
            Assert.AreEqual(actionCounter, 5);
        }
Пример #6
0
        private Enemy PrepareEnemy(bool addImmunities = true)
        {
            var hero  = game.Hero;
            var enemy = ActivePlainEnemies.First();

            enemy.Stats.Stats[EntityStatKind.Health].Value.Nominal = 300;
            PlaceCloseToHero(enemy);
            if (addImmunities)
            {
                enemy.AddImmunity(Roguelike.Effects.EffectType.Bleeding);
            }

            if (!enemy.Name.Any())
            {
                enemy.Name = "enemy";
            }
            return(enemy);
        }
Пример #7
0
        public void GemsLevel()
        {
            var env = CreateTestEnv();

            try
            {
                var         lootInfo = new LootInfo(game, null);
                ILootSource lootSrc  = ActivePlainEnemies.First();
                for (int i = 0; i < 10; i++)
                {
                    var loot = env.LootGenerator.GetRandomLoot(LootKind.Gem, 1) as Gem;
                    Assert.AreEqual(loot.EnchanterSize, EnchanterSize.Small);
                }
            }
            catch (System.Exception)
            {
                //GenerationInfo.DebugInfo.EachEnemyGivesPotion = false;
            }
        }
Пример #8
0
        public void WeaponImpactTest()
        {
            var game = CreateGame();
            var hero = game.Hero;

            Assert.Greater(ActivePlainEnemies.Count, 0);
            var enemy       = ActivePlainEnemies.First();
            var enemyHealth = enemy.Stats.Health;

            enemy.OnMeleeHitBy(hero);
            Assert.Greater(enemyHealth, enemy.Stats.Health);
            enemyHealth = enemy.Stats.Health;

            var wpn = GenerateRandomEqOnLevelAndCollectIt <Weapon>();

            enemy.OnMeleeHitBy(hero);

            Assert.Greater(enemyHealth, enemy.Stats.Health);
        }
Пример #9
0
        public void SimpleSpellSourceTest(bool scroll)
        {
            var game = CreateGame();
            var hero = game.Hero;
            //SpellSource spellSource = scroll ? new Scroll ?

            var enemy       = ActivePlainEnemies.First();
            var enemyHealth = enemy.Stats.Health;
            var mana        = hero.Stats.Mana;

            Assert.True(game.GameManager.HeroTurn);

            UseFireBallSpellSource(hero, enemy, scroll);

            Assert.Greater(enemyHealth, enemy.Stats.Health);
            Assert.Greater(mana, hero.Stats.Mana);
            Assert.False(game.GameManager.HeroTurn);

            var diff = enemyHealth - enemy.Stats.Health;
        }
Пример #10
0
        public void ArrowFightItemTest()
        {
            var game = CreateGame();
            var hero = game.Hero;

            hero.UseAttackVariation = false;//other tests do it

            var fi = ActivateFightItem(FightItemKind.PlainArrow, hero);

            var enemy       = ActivePlainEnemies.First();
            var enemyHealth = enemy.Stats.Health;

            enemy.Stats.SetNominal(Roguelike.Attributes.EntityStatKind.Defense, 10);
            var mana = hero.Stats.Mana;

            Assert.True(game.GameManager.HeroTurn);
            var bow = GenerateEquipment <Weapon>("Bow");

            Assert.True(SetHeroEquipment(bow));

            var tile = game.GameManager.CurrentNode.GetClosestEmpty(hero);

            game.GameManager.CurrentNode.SetTile(enemy, tile.point);

            Assert.True(UseFightItem(hero, enemy, fi));

            Assert.Greater(enemyHealth, enemy.Stats.Health);
            Assert.AreEqual(mana, hero.Stats.Mana);
            Assert.False(game.GameManager.HeroTurn);
            var diffBow = enemyHealth - enemy.Stats.Health;

            enemyHealth = enemy.Stats.Health;

            GotoNextHeroTurn();
            fi = ActivateFightItem(FightItemKind.ThrowingKnife, hero);
            Assert.True(UseFightItem(hero, enemy, fi));
            Assert.Greater(enemyHealth, enemy.Stats.Health);
            var diffKnife = enemyHealth - enemy.Stats.Health;

            Assert.Greater(diffBow, diffKnife);
        }
Пример #11
0
        public void TestLastingEffectAction()
        {
            var game = CreateGame();

            game.Hero.Name = "Edd";
            var en = ActivePlainEnemies.First();
            var le = game.Hero.LastingEffectsSet.EnsureEffect(EffectType.Bleeding, 10, en);

            Assert.NotNull(le);

            var expectedDesc = le.Type.ToDescription() + ", -10.00 Health (per turn)";
            var desc         = le.Description;

            Assert.AreEqual(desc, expectedDesc);

            CheckActionDesc(EffectType.IronSkin, EntityStatKind.Defense, '+', game.Hero);
            //CheckActionDesc(EffectType.Rage, EntityStatKind.Attack, '+', game.Hero);
            CheckActionDesc(EffectType.Inaccuracy, EntityStatKind.ChanceToMeleeHit, '-', game.Hero);
            CheckActionDesc(EffectType.Weaken, EntityStatKind.Defense, '-', game.Hero);
            CheckActionDesc(EffectType.ResistAll, EntityStatKind.Unset, '+', game.Hero);
        }
Пример #12
0
        public void KillEnemy()
        {
            var game = CreateGame();
            //var hero = game.Hero;

            var enemies        = game.GameManager.EnemiesManager.AllEntities;
            var initEnemyCount = enemies.Count;

            Assert.Greater(initEnemyCount, 0);
            Assert.AreEqual(initEnemyCount, CurrentNode.GetTiles <Enemy>().Count);

            var enemy = ActivePlainEnemies.First();

            while (enemy.Alive)
            {
                InteractHeroWith(enemy as Enemy);
            }
            var finalEnemyCount = enemies.Count;

            Assert.AreEqual(finalEnemyCount, initEnemyCount - 1);
            Assert.AreEqual(finalEnemyCount, CurrentNode.GetTiles <Enemy>().Count);
        }
Пример #13
0
        public void TestHealthPotionConsume()
        {
            var game = CreateGame();
            var hero = game.Hero;

            Assert.Greater(ActivePlainEnemies.Count, 0);
            var heroHealth = hero.Stats.Health;
            var halfHealth = heroHealth / 2;

            while (hero.Stats.Health > halfHealth)
            {
                hero.OnMeleeHitBy(ActivePlainEnemies.First());
            }
            Assert.Greater(heroHealth, hero.Stats.Health);
            heroHealth = hero.Stats.Health;

            var hp = Helper.AddTile <Potion>();

            hp.SetKind(PotionKind.Health);
            AddItemToInv(hp);

            hero.Consume(hp);
            Assert.Greater(hero.Stats.Health, heroHealth);
        }