Ejemplo n.º 1
0
        private bool SetEnemyPosition(Entity ent, EnemyGroup eg)
        {
            int x     = -1;
            int y     = -1;
            int count = 0;

            while (!engine.Collision.IsValidTile(x, y, ent.MovementType, false) && count < 10)
            {
                if (count == 0)
                {
                    x = eg.PosX + Utils.RandBetween(0, eg.Width);
                    y = eg.PosY + Utils.RandBetween(0, eg.Height);
                }
                else
                {
                    x = eg.PosX + Utils.RandBetween(-1, eg.Width + 1);
                    y = eg.PosY + Utils.RandBetween(-1, eg.Height + 1);
                }
                count++;
            }
            if (engine.Collision.IsValidTile(x, y, ent.MovementType, false))
            {
                ent.MapPosX = x + 0.5f;
                ent.MapPosY = y + 0.5f;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 private void SpwanEnemies(EnemyGroup eg)
 {
     if (Utils.PercentChance(eg.Chance))
     {
         int    num   = Utils.RandBetween(eg.MinNumber, eg.MaxNumber);
         string eName = eg.Name + ".txt";
         for (int i = 0; i < num; i++)
         {
             Entity e = FindEnemyTemplate(eg);
             if (e != null)
             {
                 e = new Entity(e);
             }
             else
             {
                 e = engine.LoadEnemy(eName);
             }
             if (e != null)
             {
                 //e.Summoner = eg.Summoner;
                 if (SetEnemyPosition(e, eg))
                 {
                     e.WayPoints = eg.WayPoints;
                     if (eg.WanderRadius > 0)
                     {
                         e.Wander = true;
                         e.SetWanderArea(eg.WanderRadius);
                     }
                     engine.EntityManager.AddEntity(e);
                     int dir = eg.Direction;
                     if (dir < 0)
                     {
                         dir = Utils.Rand() % 7;
                     }
                     if (e.InitAnimation(EntityStance.Spawning, dir))
                     {
                         Logger.Info("Enemy", $"{e.Name} (Level {e.Level}) spawned at {new FPoint(e.MapPosX, e.MapPosY)}");
                     }
                     else
                     {
                         Logger.Warn("Enemy", $"Could not load enemy animations {e.Name}");
                     }
                 }
                 else
                 {
                     Logger.Warn("Enemy", $"Cold not place enemy {e.Name} at {new Rect(eg.PosX, eg.PosY, eg.Width, eg.Height)}");
                 }
             }
             else
             {
                 Logger.Warn("Enemy", $"Could not load enemy {eg.Name}");
             }
         }
     }
     else
     {
         Logger.Info("Enemy", $"{eg.Category} not spawnd (chance was {eg.Chance}%)");
     }
 }
Ejemplo n.º 3
0
        public void SpawnMapSpawn(MapSpawn spawn)
        {
            EnemyGroup eg = new EnemyGroup(spawn.Type);

            eg.MapSpawn  = true;
            eg.Chance    = 100;
            eg.Category  = spawn.Type;
            eg.PosX      = spawn.MapX;
            eg.PosY      = spawn.MapY;
            eg.Width     = 1;
            eg.Height    = 1;
            eg.MinNumber = 1;
            eg.MaxNumber = 1;
            eg.MinLevel  = 0;
            eg.MaxLevel  = 0;
            eg.Direction = spawn.Direction;
            eg.Summoner  = spawn.Summoner;
            SpwanEnemies(eg);
        }
Ejemplo n.º 4
0
        private Entity FindEnemyTemplate(EnemyGroup eg)
        {
            List <Entity> enemyCandidates = new List <Entity>();
            var           catMatch        = enemyTemplates.Where(e => e.Categories.Contains(eg.Category));

            foreach (var e in catMatch)
            {
                if ((e.Level >= eg.MinLevel && e.Level <= eg.MaxLevel) || (eg.MinLevel == 0 && eg.MaxLevel == 0))
                {
                    int addTimes = 0;
                    switch (e.Rarity)
                    {
                    case "common":
                        addTimes = 6;
                        break;

                    case "uncommon":
                        addTimes = 3;
                        break;

                    case "rare":
                        addTimes = 1;
                        break;
                    }
                    for (int j = 0; j < addTimes; j++)
                    {
                        enemyCandidates.Add(e);
                    }
                }
            }
            if (enemyCandidates.Count > 0)
            {
                return(enemyCandidates[Utils.Rand() % enemyCandidates.Count]);
            }
            return(null);
        }
Ejemplo n.º 5
0
 public void AddEnemyGroup(EnemyGroup enemyGroup)
 {
     enemyGroups.Add(enemyGroup);
 }