Fix the calculation of max room count
Fix possible empty foreach with array cast