void HandleUpdateElevatorPositionRequest(UpdateElevatorPositionRequest request) { uint nextFloor = elevatorData.curFloorLevel; if (elevatorData.status == ElevatorStatus.MovingDown) { nextFloor = elevatorData.curFloorLevel - 1; FloorController floorController = GetFloorController(nextFloor); if (floorController) { if (request.positionY <= floorController.GetFittedElevatorAnchoredPositionY()) { elevatorData.curFloorLevel = nextFloor; // Update elevator status SendElevatorStatusResponseToAllFloor(); } } } else if (elevatorData.status == ElevatorStatus.MovingUp) { nextFloor = elevatorData.curFloorLevel + 1; FloorController floorController = GetFloorController(nextFloor); if (floorController) { if (request.positionY >= floorController.GetFittedElevatorAnchoredPositionY()) { elevatorData.curFloorLevel = nextFloor; // Update elevator status SendElevatorStatusResponseToAllFloor(); } } } // Elevator arrived if (elevatorData.curFloorLevel == curDestFloor) { // Remove cur floor from list requesting listFloorsRequesting.Remove(curDestFloor); // Update floor status using elevator status if (elevatorData.status == ElevatorStatus.MovingDown || elevatorData.status == ElevatorStatus.MovingUp) { FloorData floorData = GetFloorData(elevatorData.curFloorLevel); floorData.OnElevatorArrived(curElevatorDirection); ElevatorArrivedResponse elevatorArrivedResponse = new ElevatorArrivedResponse(floorData); SendElevatorArrivedResponse(elevatorArrivedResponse); } elevatorData.status = ElevatorStatus.Arrived; UpdateElevatorResponse response = new UpdateElevatorResponse(elevatorData, 0); SendUpdateElevatorResponse(response); } else { UpdateElevatorPositionResponse response = new UpdateElevatorPositionResponse(ResultCode.Succeeded, elevatorData.curFloorLevel); SendUpdateElevatorPositionResponse(response); } }