private IIndividual _CheckHit(IEnumerable <IIndividual> controllers, Vector2 center, Guid self, Vector2 ray)
        {
            foreach (var individual in controllers)
            {
                if (individual.Id == _Player.Id)
                {
                    continue;
                }
                if (individual.Id == self)
                {
                    continue;
                }

                float   distance;
                Vector2 hitPoint;
                Vector2 normal;
                if (StandardBehavior.RayPolygonIntersect(
                        center,
                        ray,
                        individual.Mesh.Points,
                        out distance,
                        out hitPoint,
                        out normal))
                {
                    return(individual);
                }
            }
            return(null);
        }
Beispiel #2
0
        private Hit _Detect(float scan_angle, float max_distance)
        {
            scan_angle += 360f;
            scan_angle %= 360f;
            var pos  = _Entiry.GetPosition();
            var view = Vector2.AngleToVector(scan_angle);

            //Unity Debug Code
#if UNITY_EDITOR
            UnityEngine.Debug.DrawRay(new UnityEngine.Vector3(pos.X, 0, pos.Y), new UnityEngine.Vector3(view.X, 0, view.Y), UnityEngine.Color.blue, 0.5f);
#endif

            var hit = new Hit();
            hit.HitPoint = pos + view * max_distance;
            hit.Distance = max_distance;
            foreach (var visible in _FieldOfVision)
            {
                var     mesh = StandardBehavior._BuildMesh(visible);
                float   dis;
                Vector2 normal;
                Vector2 point;
                if (RayPolygonIntersect(pos, view, mesh.Points, out dis, out point, out normal))
                {
                    if (dis < hit.Distance)
                    {
                        hit.Visible  = visible;
                        hit.HitPoint = point;
                        hit.Distance = dis;
                    }
                }
            }


            return(hit);
        }
        private Aboriginal _Create(Map map, ENTITY type, ItemProvider item_provider)
        {
            var entiry = EntityProvider.Create(type);
            var items  = item_provider.FromStolen();

            foreach (var item in items)
            {
                entiry.Bag.Add(item);
            }
            var wisdom     = new StandardBehavior(entiry);
            var aboriginal = new Aboriginal(map, this, entiry, wisdom);

            return(aboriginal);
        }
Beispiel #4
0
        public TraceStrategy(StandardBehavior behavior)
        {
            _Behavior = behavior;

            _BuildNode();
        }
Beispiel #5
0
        public TICKRESULT Detect(float delta, float decision_time, Entity entiry, StandardBehavior standard_behavior, float view_distance, int scan_angle)
        {
            var decisionTime = decision_time;
            var _Entiry      = entiry;

            if (_Entiry == null)
            {
                throw new ArgumentNullException("_Entiry");
            }
            var goblinWisdom = standard_behavior;
            var distance     = view_distance;
            var scanAngle    = scan_angle;

            var pos = _Entiry.GetPosition();

            _TimeCounter += delta;
            if (_TimeCounter < decisionTime)
            {
                var view = (float)distance;
                var x    = Math.PI * _TimeCounter / decisionTime;
                var y    = (float)Math.Sin(x);
                var a    = scanAngle * y - (scanAngle / 2);


                var target = goblinWisdom.Detect(a + _Entiry.Direction, view);

                if (target.Visible == null || (target.Visible != null && goblinWisdom.IsWall(target.Visible.EntityType)))
                {
                    var hitDistnace = target.HitPoint.DistanceTo(pos);
                    hitDistnace = (float)Math.Floor(hitDistnace);
                    var vector   = target.HitPoint - pos;
                    var hitAngle = Vector2.VectorToAngle(vector.GetNormalized());
                    hitAngle += 360;
                    hitAngle %= 360;
                    //Unity Debug Code
#if UNITY_EDITOR
                    _UnityDrawLine(hitAngle, pos, UnityEngine.Color.red, view_distance, decisionTime);
#endif

                    _Nears.Add(new Exit()
                    {
                        Distance = hitDistnace, Direction = hitAngle
                    });
                }


                return(TICKRESULT.RUNNING);
            }


            var sortedDirections = from e in _Nears
                                   let diff = Math.Abs(e.Direction - _Entiry.Direction)
                                              where diff > 0.0f
                                              orderby diff
                                              select e;
            var soteds = from e in sortedDirections orderby e.Distance descending select e;
            var first  = soteds.FirstOrDefault();

            OutputEvent(first.Direction - _Entiry.Direction);
            _Nears.Clear();
            _TimeCounter = 0.0f;

#if UNITY_EDITOR
            var trunForce = Vector2.AngleToVector(first.Direction);
            var forcePos  = pos + trunForce * (distance);
            UnityEngine.Debug.DrawLine(new UnityEngine.Vector3(pos.X, 0, pos.Y), new UnityEngine.Vector3(forcePos.X, 0, forcePos.Y), UnityEngine.Color.yellow, decisionTime);
            //UnityEngine.Debug.Log("TurnDirection = " + _StandardBehavior.TurnDirection);
#endif
            return(TICKRESULT.SUCCESS);
        }
 public TurnHandler(StandardBehavior standard_behavior)
 {
     _StandardBehavior = standard_behavior;
 }