Exemple #1
0
        private Point GetRandomSq()
        {
            MovementSystem ms = (MovementSystem)this.ecs.GetSystem(nameof(MovementSystem));
            Point          p  = ms.GetRandomAccessibleSquare();

            return(p);
        }
        public override void ProcessEntity(AbstractEntity entity)
        {
            JonesTheCatComponent cat = (JonesTheCatComponent)entity.GetComponent(nameof(JonesTheCatComponent));

            if (cat == null)   // Are we a cat?
            {
                return;
            }
            CarryableComponent cc = (CarryableComponent)entity.GetComponent(nameof(CarryableComponent));

            if (cc.carrier != null)   // Don't move if we're bring carried
            {
                return;
            }
            MobDataComponent us = (MobDataComponent)entity.GetComponent(nameof(MobDataComponent));

            if (us.actionPoints <= 0)   // Only do stuff if we've got any APs
            {
                return;
            }

            MovementDataComponent mdc = (MovementDataComponent)entity.GetComponent(nameof(MovementDataComponent));

            if (mdc.route == null || mdc.route.Count == 0)
            {
                MovementSystem    ms  = (MovementSystem)this.ecs.GetSystem(nameof(MovementSystem));
                PositionComponent pos = (PositionComponent)entity.GetComponent(nameof(PositionComponent));
                Point             p   = ms.GetRandomAccessibleSquare();
                mdc.route = ms.GetAStarRoute(pos.x, pos.y, p.X, p.Y);
            }
        }
        public override void ProcessEntity(AbstractEntity entity)
        {
            AlienComponent alienData = (AlienComponent)entity.GetComponent(nameof(AlienComponent));

            if (alienData == null)   // Are we an alien?
            {
                return;
            }
            MobDataComponent us = (MobDataComponent)entity.GetComponent(nameof(MobDataComponent));

            if (us.actionPoints <= 0)   // Only do stuff if we've got any APs
            {
                return;
            }

            PositionComponent     pos    = (PositionComponent)entity.GetComponent(nameof(PositionComponent));
            AbstractEntity        target = this.GetTarget(pos.x, pos.y, us.side);
            MovementDataComponent mdc    = (MovementDataComponent)entity.GetComponent(nameof(MovementDataComponent));

            if (target != null)
            {
                Console.WriteLine($"Alien can see {target.name}");
                alienData.moveWhenNoEnemy = true;
                PositionComponent targetPos = (PositionComponent)target.GetComponent(nameof(PositionComponent));
                if (this.CheckForImpregnation(alienData, pos, target, targetPos))
                {
                    us.actionPoints -= 50;
                }
                else
                {
                    mdc.route = Misc.GetLine(pos.x, pos.y, targetPos.x, targetPos.y, true);
                }
            }
            else
            {
                if (alienData.moveWhenNoEnemy)
                {
                    alienData.moveWhenNoEnemy = false;

                    alienData.impregnateNextEnemy = Misc.random.Next(1, 2) == 1;

                    // Move to a random point on the map
                    MovementSystem ms = (MovementSystem)this.ecs.GetSystem(nameof(MovementSystem));
                    Point          p  = ms.GetRandomAccessibleSquare();
                    mdc.route = ms.GetAStarRoute(pos.x, pos.y, p.X, p.Y);
                }
                if (mdc.route == null || mdc.route.Count == 0)
                {
                    us.actionPoints -= 100; // Waiting....
                }
            }
        }