Esempio n. 1
0
        public bool WorkerIsInBuilding(int WorkerID, int BuildingID)
        {
            Building building;
            Worker   worker;

            LogEnter();

            worker   = AssertExists(() => workerModule.GetWorker(WorkerID), $"WorkerID={WorkerID}");
            building = AssertExists(() => buildingModule.GetBuilding(BuildingID), $"BuildingID={BuildingID}");


            Log(LogLevels.Information, "Checking is worker is in building");
            if (worker.PlanetID != building.PlanetID)
            {
                Log(LogLevels.Information, "Worker and Building are not in same Planet");
                return(false);
            }
            if ((worker.X != building.X) || (worker.Y != building.Y))
            {
                Log(LogLevels.Information, "Worker is not in building");
                return(false);
            }

            Log(LogLevels.Information, "Worker is in building");
            return(true);
        }
Esempio n. 2
0
        protected Worker AssertWorkerIsIdle(int WorkerID, [CallerMemberName] string MethodName = null)
        {
            Worker worker;
            Task   task;

            Log(LogLevels.Information, $"Checking if worker exists and is idle (WorkerID={WorkerID})");
            worker = Try(() => workerModule.GetWorker(WorkerID)).OrThrow <PIOInternalErrorException>($"Failed to get worker");
            if (worker == null)
            {
                Throw <PIONotFoundException>(LogLevels.Warning, $"Worker doesn't exist (WorkerID={WorkerID})");
            }


            task = Try(() => taskModule.GetLastTask(WorkerID)).OrThrow <PIOInternalErrorException>("Failed to get last worker task");
            if (task != null)
            {
                Throw <PIOInvalidOperationException>(LogLevels.Warning, $"Worker is not free (WorkerID={WorkerID})");
            }

            return(worker);
        }
Esempio n. 3
0
 public Worker GetWorker(int WorkerID)
 {
     LogEnter();
     return(Try(() => workerModule.GetWorker(WorkerID)).OrThrow(GenerateFaultException));
 }