// Code generated by xlsx2proto.
// DO NOT EDIT!

package srvdata

import (
	"mongo.games.com/game/proto"
	"mongo.games.com/game/protocol/server"
)

var PBDB_SystemChanceMgr = &DB_SystemChanceMgr{pool: make(map[int32]*server.DB_SystemChance), Datas: &server.DB_SystemChanceArray{}}

type DB_SystemChanceMgr struct {
	Datas *server.DB_SystemChanceArray
	pool  map[int32]*server.DB_SystemChance
}

func (this *DB_SystemChanceMgr) unmarshal(data []byte) error {
	err := proto.Unmarshal(data, this.Datas)
	if err == nil {
		this.arrangeData()
	}
	return err
}

func (this *DB_SystemChanceMgr) reunmarshal(data []byte) error {
	newDatas := &server.DB_SystemChanceArray{}
	err := proto.Unmarshal(data, newDatas)
	if err == nil {
		for _, item := range newDatas.Arr {
			existItem := this.GetData(item.GetId())
			if existItem == nil {
				this.pool[item.GetId()] = item
				this.Datas.Arr = append(this.Datas.Arr, item)
			} else {
				*existItem = *item
			}
		}
	}
	return err
}

func (this *DB_SystemChanceMgr) arrangeData() {
	if this.Datas == nil {
		return
	}

	dataArr := this.Datas.GetArr()
	if dataArr == nil {
		return
	}

	for _, data := range dataArr {
		this.pool[data.GetId()] = data
	}
}

func (this *DB_SystemChanceMgr) GetData(id int32) *server.DB_SystemChance {
	if data, ok := this.pool[id]; ok {
		return data
	}
	return nil
}

func init() {
	DataMgr.RegisteLoader("DB_SystemChance.dat", &ProtobufDataLoader{dh: PBDB_SystemChanceMgr})
}
