package srvdata

import "mongo.games.com/game/protocol/server"

var PlayerTypeMgrSington = &PlayerTypeMgr{
	types: make(map[int32][]*server.DB_PlayerType),
}

type PlayerTypeMgr struct {
	types map[int32][]*server.DB_PlayerType
}

func (this *PlayerTypeMgr) Load(fileFullPath string) error {
	this.updateData()
	return nil
}

func (this *PlayerTypeMgr) Reload(fileFullPath string) error {
	return this.Load(fileFullPath)
}

func (this *PlayerTypeMgr) updateData() {
	types := make(map[int32][]*server.DB_PlayerType)
	for _, data := range PBDB_PlayerTypeMgr.Datas.Arr {
		types[data.GetGameFreeId()] = append(types[data.GetGameFreeId()], data)
	}
	this.types = types
}

func (this *PlayerTypeMgr) GetPlayerType(id int32) []*server.DB_PlayerType {
	if data, exist := this.types[id]; exist {
		return data
	}
	return nil
}

func init() {
	DataMgrAfter.RegisterLoader("DB_PlayerType.dat", PlayerTypeMgrSington)
}
