Пример #1
0
        public override bool Tick()
        {
            switch (_state)
            {
            case TaskState.Init:
                _targetEntity.SetPathfindingTarget(_targetPosition, _targetGraph);
                _state = TaskState.MoveToDestination;
                break;

            case TaskState.MoveToDestination:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }

                _state           = TaskState.Finished;
                this._isFinished = true;
                break;

            case TaskState.Finished:
                break;
            }
            return(base.Tick());
        }
        public override bool Tick()
        {
            switch (State)
            {
            case RobotLoadTruckTask.TaskState.Init:
                _targetEntity.SetPathfindingTarget(_item.Position, _targetEntity.GetPathfindingGraph());
                _state = TaskState.MoveToItem;
                break;

            case RobotLoadTruckTask.TaskState.MoveToItem:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }
                _state = TaskState.PickupCargo;
                break;

            case RobotLoadTruckTask.TaskState.PickupCargo:
                if (!_targetEntity.TryAddCargo(_item))
                {
                    break;
                }
                _state = TaskState.MoveToQueue;
                _targetEntity.SetPathfindingTarget(Constants.RobotEnterTruck, _targetEntity.GetPathfindingGraph());
                break;

            case RobotLoadTruckTask.TaskState.MoveToQueue:
                if (_targetEntity.IsAtDestination())
                {
                    _state = TaskState.AwaitTruckAvailable;
                }
                break;

            case RobotLoadTruckTask.TaskState.AwaitTruckAvailable:
                if (_truck.IsOccupied)
                {
                    break;
                }
                _lock = _truck.Occupy(_targetEntity);
                _targetEntity.SetTarget(_destination.PositionAbsolute);
                _state = TaskState.DropOffDestination;
                break;

            case RobotLoadTruckTask.TaskState.DropOffDestination:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }
                _destination.SetCargo(_targetEntity.CargoSlots[0].ReleaseCargo());
                _targetEntity.SetTarget(Constants.RobotExitTruck);
                _state = TaskState.LeaveTruck;
                break;

            case RobotLoadTruckTask.TaskState.LeaveTruck:
                if (!_targetEntity.IsAtDestination())
                {
                    break;
                }

                _targetEntity.SetPathfindingTarget(_targetEntity.IdlePos, _targetEntity.GetPathfindingGraph());
                _lock.Release();
                _state           = TaskState.Finished;
                this._isFinished = true;
                break;

            case RobotLoadTruckTask.TaskState.Finished:
                break;
            }
            return(base.Tick());
        }
Пример #3
0
        public override bool Tick()
        {
            switch (_state)
            {
            case TaskState.Init:
                _truck = _targetEntity.CreateTruck(Constants.TruckSpawn.X, Constants.TruckSpawn.Y, Constants.TruckSpawn.Z, 0f, 0f, 0f, 0);
                _truck.SetTarget(Constants.TruckStop);

                this._state = TaskState.WaitTruckArrival;
                break;

            case TaskState.WaitTruckArrival:
                if (!_truck.IsAtTarget)
                {
                    break;
                }
                var occupied = _targetEntity.ObjectsOfType <StoragePlot>().SelectMany(plot => plot.OccupiedCargoSlots).ToList();
                _slotsToUnload = new Queue <CargoSlot>(occupied.Take(Math.Min(Math.Min(occupied.Count(), _truck.FreeCargoSlots.Count), amount)));
                _robotTasks    = new List <RobotLoadTruckTask>();
                this._state    = TaskState.WaitTruckLoaded;
                break;

            case TaskState.WaitTruckLoaded:
                _truck.setDoorOpen(true);
                List <Robot>     idleRobots            = _targetEntity.ObjectsOfType <Robot>().Where((r) => r.IsStandBy).ToList();
                List <CargoSlot> availableStorageSlots = _truck.FreeCargoSlots;
                availableStorageSlots.Reverse();
                if (idleRobots.Count == 0 || availableStorageSlots.Count == 0)
                {
                    break;
                }

                if (_slotsToUnload.Count != 0)
                {
                    RobotLoadTruckTask rt = new RobotLoadTruckTask(idleRobots[0], _truck, _slotsToUnload.Dequeue().ReleaseCargo(), availableStorageSlots[0]);
                    idleRobots[0].AssignTask(rt);
                    _robotTasks.Add(rt);
                }

                if (_slotsToUnload.Count == 0)
                {
                    _state = TaskState.WaitCargoTasksFinished;
                }
                break;

            case TaskState.WaitCargoTasksFinished:
                if (!_robotTasks.All((task) => task.IsFinished))
                {
                    break;
                }
                _truck.SetTarget(Constants.TruckDespawn);
                _state = TaskState.WaitTruckExit;
                _truck.setDoorOpen(false);
                break;

            case TaskState.WaitTruckExit:
                if (!_truck.IsAtTarget)
                {
                    break;
                }
                _truck.Destroy();
                _state = TaskState.Finished;
                break;

            case TaskState.Finished:
                this._isFinished = true;
                break;
            }
            return(base.Tick());
        }