94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package srvdata
|
|
|
|
import (
|
|
"mongo.games.com/game/model"
|
|
"mongo.games.com/game/protocol/server"
|
|
)
|
|
|
|
func init() {
|
|
DataMgr.RegisterLoader("DB_Game_Role.dat", RolePetMgrSington)
|
|
DataMgr.RegisterLoader("DB_Game_Pet.dat", RolePetMgrSington)
|
|
DataMgr.RegisterLoader("DB_SkinLevel.dat", RolePetMgrSington)
|
|
}
|
|
|
|
var RolePetMgrSington = &RolePetMgr{
|
|
Roles: make(map[int32][]*server.DB_Game_Role),
|
|
Pets: make(map[int32][]*server.DB_Game_Pet),
|
|
Skins: make(map[int32][]*server.DB_SkinLevel),
|
|
}
|
|
|
|
type RolePetMgr struct {
|
|
Roles map[int32][]*server.DB_Game_Role
|
|
Pets map[int32][]*server.DB_Game_Pet
|
|
Skins map[int32][]*server.DB_SkinLevel
|
|
}
|
|
|
|
func (this *RolePetMgr) Load(fileFullPath string) error {
|
|
this.Init()
|
|
return nil
|
|
}
|
|
|
|
func (this *RolePetMgr) Reload(fileFullPath string) error {
|
|
this.Init()
|
|
return nil
|
|
}
|
|
|
|
func (this *RolePetMgr) Init() {
|
|
this.Roles = make(map[int32][]*server.DB_Game_Role)
|
|
this.Pets = make(map[int32][]*server.DB_Game_Pet)
|
|
this.Skins = make(map[int32][]*server.DB_SkinLevel)
|
|
for _, v := range PBDB_Game_RoleMgr.Datas.GetArr() {
|
|
this.Roles[v.GetRoleId()] = append(this.Roles[v.GetRoleId()], v)
|
|
}
|
|
for _, v := range PBDB_Game_PetMgr.Datas.GetArr() {
|
|
this.Pets[v.GetPetId()] = append(this.Pets[v.GetPetId()], v)
|
|
}
|
|
for _, v := range PBDB_SkinLevelMgr.Datas.GetArr() {
|
|
this.Skins[v.GetSkinId()] = append(this.Skins[v.GetSkinId()], v)
|
|
}
|
|
}
|
|
func (this *RolePetMgr) GetRoleByRoleIdAndLevel(roleId, level int32) *server.DB_Game_Role {
|
|
if roleInfo, ok := this.Roles[roleId]; ok {
|
|
if len(roleInfo) > int(level) {
|
|
return roleInfo[level]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
func (this *RolePetMgr) GetPetByPetIdAndLevel(petId, level int32) *server.DB_Game_Pet {
|
|
if petInfo, ok := this.Pets[petId]; ok {
|
|
if len(petInfo) > int(level) {
|
|
return petInfo[level]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
func (this *RolePetMgr) GetSkinBySkinIdAndLevel(id, level int32) *server.DB_SkinLevel {
|
|
if v, ok := this.Skins[id]; ok {
|
|
if len(v) > int(level) {
|
|
return v[level]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
func (this *RolePetMgr) GetSkinMaxLevel(id int32) int32 {
|
|
return this.Skins[id][len(this.Skins[id])-1].GetLevel()
|
|
}
|
|
|
|
// GetRoleAdd 获取角色加成
|
|
// roleId 角色id
|
|
// tp 加成类型
|
|
// 返回 角色id, 加成值
|
|
// 获得角色,就有加成,不用使用
|
|
func (this *RolePetMgr) GetRoleAdd(p *model.PlayerData, tp int32) (int32, int32) {
|
|
if p.Roles != nil && p.Roles.ModUnlock != nil {
|
|
for k, v := range p.Roles.ModUnlock {
|
|
info := this.GetRoleByRoleIdAndLevel(k, v)
|
|
if info.AwardType == tp {
|
|
return k, info.Award
|
|
}
|
|
}
|
|
}
|
|
return 0, 0
|
|
}
|