public void MoveToNextListener(MoveToNextEvent moveToNextEvent)
        {
            Point current = moveToNextEvent.CalculatedPath[moveToNextEvent.CurrentIndex];
            Point next    = moveToNextEvent.CalculatedPath[moveToNextEvent.CurrentIndex + 1];

            MoveOutEvent moveOutEvent = new MoveOutEvent(current, next, moveToNextEvent);

            JEventBus.GetDefault().Post(moveOutEvent);
        }
示例#2
0
        public void GoToListener(GoToEvent goToEvent)
        {
            Entity entity = goToEvent.Entity;

            if (!entity.HasComponent <GeoEntity>())
            {
                Error("GoTo ERROR: Missing GeoEntity");
                return;
            }

            GeoEntity geoEntity = entity.GetComponent <GeoEntity>();
            Army      army      = entity.GetComponent <Army>();

            FindPathEvent findPathEvent = new FindPathEvent(geoEntity.Position, goToEvent.Goal);

            JEventBus.GetDefault().Post(findPathEvent);
            if (findPathEvent.CalculatedPath == null || findPathEvent.CalculatedPath.Count == 0)
            {
                Warning("GoTo ERROR: Path not found");
                return;
            }

            //Go to the same place (SPACE)
            if (findPathEvent.CalculatedPath.Count == 1)
            {
                findPathEvent.CalculatedPath.Add(findPathEvent.CalculatedPath[0]);
            }

            int i = 0;

            while (army.MovementPoints > 0)
            {
                if (i >= findPathEvent.CalculatedPath.Count - 1)
                {
                    break;
                }
                MoveToNextEvent moveToNextEvent = new MoveToNextEvent(findPathEvent.CalculatedPath, entity, i);
                JEventBus.GetDefault().Post(moveToNextEvent);
                i++;
            }

            Debug("GoTo OK: " + geoEntity.Position);
            if (geoEntity.Position.Equals(goToEvent.Goal))
            {
                goToEvent.Complete = true;
            }
        }
示例#3
0
 public MoveInEvent(Point current, Point previous, MoveToNextEvent moveToNextEvent)
 {
     this.Current    = current;
     this.Previous   = previous;
     MoveToNextEvent = moveToNextEvent;
 }