Пример #1
0
Файл: NPC.cs Проект: qmhoang/SKR
        private ActorAction CalculateNextMove()
        {
            var location = Holder.Entity.Get <GameObject>();

            if (_level != location.Level)
            {
                _level  = location.Level;
                _oldPos = location.Location;
                _pf     = new AStarPathFinder(_level, 1.41f);
            }


            _oldPos = location.Location;

            var player = _level.World.Player;

            var target = player.Get <GameObject>().Location;

            var sight = Holder.Entity.Get <SightComponent>();

            sight.CalculateSight();
            if (sight.IsVisible(target))
            {
                var distance = location.Location.DistanceTo(target);

                if (distance <= 1.5)
                {
                    return(new MeleeAttackAction(Holder.Entity, player, Holder.Entity, player.Get <BodyComponent>().GetRandomPart()));
                }
                else
                {
                    _pf.Compute(location.X, location.Y, target.X, target.Y);
                    int nx = location.X, ny = location.Y;

                    if (_pf.Walk(ref nx, ref ny, false))
                    {
                        var       newPosition = new Point(nx, ny);
                        Direction dir         = Direction.Towards(newPosition - location.Location);

                        return(new BumpAction(Holder.Entity, dir));
                    }
                }
            }
            return(new WaitAction(Holder.Entity));
        }