示例#1
0
        public void CheckIfResourceIsToTake(MoveInEvent moveInEvent)
        {
            Point middle = moveInEvent.Current;
            FindNearestResource findNearestResource = new FindNearestResource(middle, 0);

            _eventBus.Post(findNearestResource);
            if (findNearestResource.Nearest == null)
            {
                return;
            }
            if (moveInEvent.MoveToNextEvent.Owner.HasComponent <Army>())
            {
                Army army = moveInEvent.MoveToNextEvent.Owner.GetComponent <Army>();
                AddResourceToFraction(findNearestResource.Nearest, army);
            }
        }
        public void FindNearestResourceListener(FindNearestResource findNearestResource)
        {
            Point middle = findNearestResource.Location;

            foreach (var entity in _resources)
            {
                GeoEntity geoEntity = entity.GetComponent <GeoEntity>();
                float     distance  = Point.Distance(middle, geoEntity.Position);
                if (distance <= findNearestResource.MaxDistance)
                {
                    if (findNearestResource.Nearest == null || findNearestResource.Distance > distance)
                    {
                        findNearestResource.Nearest  = entity;
                        findNearestResource.Distance = distance;
                    }
                }
            }
        }