Esempio n. 1
0
 private static void AddLoot(Monster monster, int itemId, int chance)
 {
     if (GodOfRandom.NumberBetween(1, 100) <= chance)
     {
         monster.AddItemToInventory(LootFactory.CreateLoot(itemId));
     }
 }
Esempio n. 2
0
        public Monster GetMonster()
        {
            if (!Monsters.Any())
            {
                return(null);
            }

            int totalChance = Monsters.Sum(m => m.ChanceOfEncounter);

            int randomNumber = GodOfRandom.NumberBetween(1, totalChance);

            int runningTotal = 0;

            foreach (var monsterEncounter in Monsters)
            {
                runningTotal += monsterEncounter.ChanceOfEncounter;
                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterId));
                }
            }

            //fail check
            return(MonsterFactory.GetMonster(Monsters.Last().MonsterId));
        }
Esempio n. 3
0
        public void Execute(LivingBeing actor, LivingBeing target)
        {
            int damage = GodOfRandom.NumberBetween(_minDamage, _maxDamage);

            if (damage == 0)
            {
                ReportResult($"{actor.Name} missed");
            }
            else
            {
                ReportResult($"{actor.Name} hit {target.Name} for {damage}");
                target.TakeDamage(damage);
            }
        }