61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package srvdata
|
|
|
|
import (
|
|
"mongo.games.com/game/model"
|
|
"mongo.games.com/game/protocol/server"
|
|
)
|
|
|
|
var RolePetMgrSington = &RolePetMgr{
|
|
Roles: make(map[int32][]*server.DB_Game_Role),
|
|
Pets: make(map[int32][]*server.DB_Game_Pet),
|
|
}
|
|
|
|
type RolePetMgr struct {
|
|
Roles map[int32][]*server.DB_Game_Role
|
|
Pets map[int32][]*server.DB_Game_Pet
|
|
}
|
|
|
|
func (this *RolePetMgr) Init() {
|
|
this.Roles = make(map[int32][]*server.DB_Game_Role)
|
|
this.Pets = make(map[int32][]*server.DB_Game_Pet)
|
|
for _, v := range PBDB_Game_RoleMgr.Datas.GetArr() {
|
|
this.Roles[v.RoleId] = append(this.Roles[v.RoleId], v)
|
|
}
|
|
for _, v := range PBDB_Game_PetMgr.Datas.GetArr() {
|
|
this.Pets[v.PetId] = append(this.Pets[v.PetId], 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
|
|
}
|
|
|
|
// 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
|
|
}
|