Пример #1
0
        public override Action Behaviour()
        {
            if (Energy < WalkAction.StaticEnergyCost && Energy < EatFlowerAction.StaticEnergyCost)
            {
                return(new PassAction(this));
            }

            if (TileOfActor.BlockOfTile != null && TileOfActor.BlockOfTile.Name == "Flower")
            {
                FlowerPath = null;
                return(new EatFlowerAction(TileOfActor.BlockOfTile));
            }

            if (FlowerPath == null)
            {
                Tile FlowerTile = FindClosestFlower();
                if (FlowerTile == null)
                {
                    RandomTile = FindRandomTile();
                    if (RandomTile == null)
                    {
                        return(new PassAction(this));
                    }
                    else
                    {
                        return(new WalkAction(RandomTile));
                    }
                }
                else
                {
                    FlowerPath = BM.GetPathToTile(TileOfActor, FlowerTile, this);

                    if (FlowerPath == null)
                    {
                        RandomTile = FindRandomTile();
                        if (RandomTile == null)
                        {
                            return(new PassAction(this));
                        }
                        else
                        {
                            return(new WalkAction(RandomTile));
                        }
                    }
                    return(Behaviour());
                }
            }
            else
            {
                if (FlowerPath.Count != 0 && FlowerPath.Last().BlockOfTile != null && FlowerPath.Last().BlockOfTile.Name == "Flower")
                {
                    if (Methods.CanMoveActor(this, FlowerPath[0]))
                    {
                        return(new WalkAction(FlowerPath[0]));
                    }
                    else
                    {
                        FlowerPath = BM.GetPathToTile(TileOfActor, FlowerPath.Last(), this);
                        return(Behaviour());
                    }
                }
                else
                {
                    FlowerPath = null;
                    return(this.Behaviour());
                }
            }
        }