public void CheckIfResourceIsToTake(MoveInEvent moveInEvent)
        {
            Point middle = moveInEvent.Current;
            FindNearestStructure findNearestStructure = new FindNearestStructure(middle, 0);

            _eventBus.Post(findNearestStructure);
            if (findNearestStructure.Nearest == null)
            {
                return;
            }
            if (moveInEvent.MoveToNextEvent.Owner.HasComponent <Army>())
            {
                Army army = moveInEvent.MoveToNextEvent.Owner.GetComponent <Army>();
                MinesApi.AddMineToFraction(findNearestStructure.Nearest, army.Fraction);
            }
        }
示例#2
0
        public static void AddMineToFraction(Point tilePosition, Fraction fraction, JEventBus eventBus = null)
        {
            if (eventBus == null)
            {
                eventBus = JEventBus.GetDefault();
            }

            FindNearestStructure findNearestStructure = new FindNearestStructure(tilePosition, 0);

            eventBus.Post(findNearestStructure);
            var entity = findNearestStructure.Nearest;

            if (entity == null)
            {
                return;
            }
            AddMineToFraction(entity, fraction, eventBus);
        }
        public void FindNearestStructureListener(FindNearestStructure findNearestStructure)
        {
            Point middle = findNearestStructure.Location;

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