Exemplo n.º 1
0
        public void InitializeAI(Agent.Creature creature, OperacjeMapy.Pole[,] mapa)
        {
            if (creature.attributes.AIType == AILoop.AIType.BasicAi)
            {
                Console.WriteLine("My AI is BasicAi: {0}", creature.name);
                var stateMachine = new StateMachineBasic();
                var ai           = new BasicAIDij();

                if (creature.attributes.HP < creature.attributes.morale)
                {
                    stateMachine.ProcessEvent(StateMachineBasic.Events.HPLow);
                }
                var enemies = new EnemiesInSight(mapa, creature);
                if (enemies.enemiesInSight.Count != 0)
                {
                    stateMachine.ProcessEvent(StateMachineBasic.Events.EnemyInSight);
                    Console.WriteLine("Theres {1} enemy in sight. My current state is {2}: {0}", creature.name, enemies.enemiesInSight.Count, stateMachine.State);
                    ai.Attack(creature, mapa, enemies.enemiesInSight[0]);
                }
                else
                {
                    stateMachine.ProcessEvent(StateMachineBasic.Events.NoEnemyInSight);
                }
                Needs.CheckNeeds.CheckCreaturesNeeds(creature);


                if (stateMachine.State == StateMachineBasic.States.Roaming)
                {
                    ai.Roam(creature, mapa);
                }
                //Console.WriteLine(" My current state is {1}: {0}", creature.name, stateMachine.State);
            }
        }
Exemplo n.º 2
0
        public void CallAIs()
        {
            AllCreatures.Sort((x, y) => y.attributes.initiative.CompareTo(x.attributes.initiative));

            foreach (Agent.Creature creature in AllCreatures)
            {
                var ai = new BasicAIDij();
                ai.InitializeAI(creature, mapa);
                //Console.WriteLine("My AI was initialized: {0}", creature.name);
            }
        }
Exemplo n.º 3
0
        public void Run(Agent.Creature creature, Point chaserPos, OperacjeMapy.Pole[,] mapa)
        {
            var ai     = new BasicAIDij();
            var random = new Random();

            var r             = creature.currentpossition;
            var c             = chaserPos;
            var vectorX       = r.X - c.X;
            var vectorY       = r.Y - c.Y;
            var adjPassPoints = GetAdjecentPassablePoints(mapa, r);
            var escapeTo      = new Point(r.X + vectorX, r.Y + vectorY);

            if (adjPassPoints.Contains(escapeTo))
            {
                ai.GoTo(r, escapeTo, mapa, creature);
            }
            else
            {
                var rand = random.Next(0, adjPassPoints.Count);
                ai.GoTo(r, adjPassPoints[rand], mapa, creature);
            }
        }
Exemplo n.º 4
0
        public void Roam(Agent.Creature creature, OperacjeMapy.Pole[,] mapa)
        {
            Random r = new Random(Guid.NewGuid().GetHashCode());

            BasicAIDij ai = new BasicAIDij();
            //Point whereTo = new Point();
            //whereTo = creature.currentpossition;
            var adjecent = new List <Point>();

            adjecent = GetAdjecentPassablePoints(mapa, creature.currentpossition);
            int randDir = r.Next(0, adjecent.Count);

            ai.GoTo(creature.currentpossition, adjecent[randDir], mapa, creature);

            /*switch (randDir){
             *      case 1:
             *              {
             *                      whereTo.X--;
             *                      whereTo.Y++;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 2:
             *              {
             *                      whereTo.Y++;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 3:
             *              {
             *                      whereTo.X++;
             *                      whereTo.Y++;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 4:
             *              {
             *                      whereTo.X--;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 5:
             *              {
             *
             *                      break;
             *              }
             *      case 6:
             *              {
             *                      whereTo.X++;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 7:
             *              {
             *                      whereTo.X--;
             *                      whereTo.Y--;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 8:
             *              {
             *
             *                      whereTo.Y--;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             *      case 9:
             *              {
             *                      whereTo.X++;
             *                      whereTo.Y--;
             *                      ai.GoTo(creature.currentpossition, whereTo, mapa, creature);
             *                      break;
             *              }
             * }
             */
        }
Exemplo n.º 5
0
        public void AttackMapEntity(Agent.Creature attacker, OperacjeMapy.Pole[,] mapa, Point defender)
        {
            BasicAIDij ai         = new BasicAIDij();
            Random     r          = new Random();
            int        damageDone = r.Next(1, 10);

            var  kill = new KillAgent(defender, mapa, CreaturesToDo.FindEntity.KindOfEntity.mapEntity);
            bool defenderIsAdjacent;


            int aPX = attacker.currentpossition.X;
            int aPY = attacker.currentpossition.Y;
            int dPX = defender.X;
            int dPY = defender.Y;

            if (aPX - 1 == dPX && aPY == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX - 1 == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX - 1 == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else
            {
                defenderIsAdjacent = false;
            }

            if (defenderIsAdjacent)
            {
                Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent);
                Console.WriteLine("Hadzia!");
                var dmg = Convert.ToByte(r.Next(attacker.weaponsWielded[0].minDamage, attacker.weaponsWielded[0].maxDamage));
                mapa[dPX, dPY].mapEntities.HP -= dmg;
                if (mapa[dPX, dPY].mapEntities.HP <= 0)
                {
                    kill.Kill();
                }
            }
            else
            {
                Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent);
                ai.GoTo(attacker.currentpossition, defender, mapa, attacker);
            }
            //return mapa;
        }
Exemplo n.º 6
0
        public void Attack(Agent.Creature attacker, OperacjeMapy.Pole[,] mapa, Agent.Creature defender)
        {
            BasicAIDij ai         = new BasicAIDij();
            Random     r          = new Random();
            int        damageDone = r.Next(1, 10);


            bool defenderIsAdjacent;


            int aPX = attacker.currentpossition.X;
            int aPY = attacker.currentpossition.Y;
            int dPX = defender.currentpossition.X;
            int dPY = defender.currentpossition.Y;

            if (aPX - 1 == dPX && aPY == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX - 1 == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX - 1 == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY - 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else if (aPX + 1 == dPX && aPY + 1 == dPY)
            {
                defenderIsAdjacent = true;
            }
            else
            {
                defenderIsAdjacent = false;
            }

            if (defenderIsAdjacent)
            {
                Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent);
                Console.WriteLine("Hadzia!");
            }
            else
            {
                Console.WriteLine("DefenderIsAdjacent: {0}", defenderIsAdjacent);
                ai.GoTo(attacker.currentpossition, defender.currentpossition, mapa, attacker);
            }
            //return mapa;
        }