package gameServerMgr

import (
	. "Framework/managecenterModel"
)

var (
	mAreaList = make([]*Area, 0)
)

// 解析大区信息
func ParseAreaInfo(areaList []*Area) {
	mAreaList = areaList
}

// 根据服务器组id获取大区Id
func GetAreaIdByGroupId(groupId int32) (areaId int32) {
	areaId = 0

	//如果没有大区数据，返回0
	if mAreaList == nil || len(mAreaList) < 1 {
		return
	}

	for _, area := range mAreaList {
		if area.CheckServerIdIsInRange(groupId) {
			areaId = area.AreaId

			break
		}
	}

	return
}

// 根据服务器组id获取大区对象数据
func GetAreaDBByGroupId(groupId int32) (areaDB *Area, exist bool) {
	//如果没有大区数据，返回空
	exist = false
	if mAreaList == nil || len(mAreaList) < 1 {
		return
	}

	for _, area := range mAreaList {
		if area.CheckServerIdIsInRange(groupId) {
			areaDB = area
			exist = true
			break
		}
	}
	return
}

// 根据大区ID获取大区信息
func GetAreaDBbyAreaID(areaId int32) (areaDB *Area, exist bool) {
	//如果没有大区数据，返回空
	exist = false
	if mAreaList == nil || len(mAreaList) < 1 {
		return
	}

	for _, area := range mAreaList {
		if area.AreaId == areaId {
			areaDB = area
			exist = true
			break
		}
	}
	return
}

// 获取所有大区信息
func GetAllAreaDB() []*Area {
	tempList := mAreaList
	return tempList
}
