480 lines
14 KiB
Go
480 lines
14 KiB
Go
|
|
package hero
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
const moduleName = "hero"
|
|
const (
|
|
equip_suit = "game_equipsuit.json" //装备套装表
|
|
new_hero = "game_hero.json" //英雄
|
|
hero_stargrow = "game_herostargrow.json" //英雄品质系数
|
|
hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数
|
|
hero_starup = "game_herostarup.json" // 升星
|
|
hero_levelup = "game_herolevelup.json" //英雄等级基础属性
|
|
hero_exp = "game_heroexp.json" // 升级
|
|
hero_skillup = "game_heroskilllevel.json" // 英雄技能升级
|
|
game_skillatk = "game_skillatk.json" // 英雄技能
|
|
hero_awaken = "game_heroawaken.json" // 英雄觉醒
|
|
//hero_drawcard = "game_drawcard.json" // 抽卡
|
|
hero_drawupdraw = "game_drawupdraw.json" // 抽卡概率调整
|
|
hero_drawcost = "game_drawcost.json" // 抽卡消耗
|
|
hero_fusion = "game_herofusion.json" // 卡牌融合
|
|
hero_talent = "game_herotalent.json" // 天赋详细数据
|
|
hero_talentbox = "game_talentbox.json" // 天赋详细数据
|
|
game_shopitem = "game_shopitem.json"
|
|
hero_skill = "game_heroskill.json"
|
|
|
|
hero_draw = "game_drawpool.json" // 新版抽卡
|
|
hero_cardweight = "game_drawweight.json" // 新版抽卡权重
|
|
hero_cardpool = "game_cardpool.json" // 新版卡池
|
|
)
|
|
|
|
// /配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
hlock sync.RWMutex
|
|
//drawCardCfg map[string]map[int32][]*cfg.GameDrawCardData // 第一个key 卡池id 第二个key 星级
|
|
awakenMap map[int64]*cfg.GameHeroAwakenData
|
|
starMap map[int64]*cfg.GameHeroStarupData
|
|
module *Hero
|
|
starW map[int64]int32
|
|
cardPool map[string][]*cfg.GameCardPoolData
|
|
}
|
|
|
|
// 组件初始化接口
|
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
|
|
err = this.MCompConfigure.Init(service, module, comp, options)
|
|
this.module = module.(*Hero)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
equip_suit: cfg.NewGameEquipSuit,
|
|
new_hero: cfg.NewGameHero,
|
|
hero_stargrow: cfg.NewGameHeroStargrow,
|
|
hero_levelgrow: cfg.NewGameHeroLevelgrow,
|
|
hero_levelup: cfg.NewGameHeroLevelup,
|
|
hero_exp: cfg.NewGameHeroExp,
|
|
hero_skillup: cfg.NewGameHeroSkillLevel,
|
|
game_skillatk: cfg.NewGameSkillAtk,
|
|
//hero_drawcard: cfg.NewGameDrawCard,
|
|
hero_talent: cfg.NewGameHeroTalent,
|
|
hero_talentbox: cfg.NewGameTalentBox,
|
|
game_shopitem: cfg.NewGameShopitem,
|
|
hero_skill: cfg.NewGameHeroSkill,
|
|
hero_draw: cfg.NewGameDrawPool,
|
|
//hero_cardweight: cfg.NewGameDrawWeight,
|
|
})
|
|
//this.drawCardCfg = make(map[string]map[int32][]*cfg.GameDrawCardData, 0)
|
|
//configure.RegisterConfigure(hero_drawcard, cfg.NewGameDrawCard, this.SetHeroDrawConfig)
|
|
this.awakenMap = make(map[int64]*cfg.GameHeroAwakenData, 0)
|
|
configure.RegisterConfigure(hero_awaken, cfg.NewGameHeroAwaken, func() {
|
|
if v, err := this.GetConfigure(hero_awaken); err == nil {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
if _configure, ok := v.(*cfg.GameHeroAwaken); ok {
|
|
for _, v := range _configure.GetDataList() {
|
|
this.awakenMap[utils.ToInt64(v.Hid)+int64(v.Phase)<<31] = v
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.GameHeroAwaken", v)
|
|
}
|
|
})
|
|
|
|
// 升星
|
|
this.starMap = make(map[int64]*cfg.GameHeroStarupData, 0)
|
|
configure.RegisterConfigure(hero_starup, cfg.NewGameHeroStarup, func() {
|
|
if v, err := this.GetConfigure(hero_starup); err == nil {
|
|
if _configure, ok := v.(*cfg.GameHeroStarup); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, v := range _configure.GetDataList() {
|
|
key := utils.ToInt64(v.Id)
|
|
key += int64(v.Star) << 31
|
|
this.starMap[key] = v
|
|
}
|
|
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
|
|
}
|
|
})
|
|
configure.RegisterConfigure(hero_cardweight, cfg.NewGameDrawWeight, func() {
|
|
if v, err := this.GetConfigure(hero_cardweight); err == nil {
|
|
if _configure, ok := v.(*cfg.GameDrawWeight); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
this.starW = make(map[int64]int32)
|
|
for _, v := range _configure.GetDataList() {
|
|
this.starW[(int64(v.Dtype)<<16)+int64(v.Key)] = v.Weight
|
|
}
|
|
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.NewGameDrawWeight", v)
|
|
}
|
|
})
|
|
|
|
// 卡池初始化
|
|
configure.RegisterConfigure(hero_cardpool, cfg.NewGameCardPool, func() {
|
|
if v, err := this.GetConfigure(hero_cardpool); err == nil {
|
|
if _configure, ok := v.(*cfg.GameCardPool); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
this.cardPool = make(map[string][]*cfg.GameCardPoolData)
|
|
for _, v := range _configure.GetDataList() {
|
|
this.cardPool[v.CardPoolType] = append(this.cardPool[v.CardPoolType], v)
|
|
}
|
|
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.NewGameCardPool", v)
|
|
}
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取英雄升星相关配置数据
|
|
func (this *configureComp) GetHeroStarupConfig(hid string, star int32) (conf *cfg.GameHeroStarupData, err error) {
|
|
var (
|
|
ok bool
|
|
par interface{}
|
|
)
|
|
if conf, ok = this.starMap[utils.ToInt64(hid)+int64(star)<<31]; !ok {
|
|
par = fmt.Errorf("hid:%s,phase:%d", hid, star)
|
|
err = comm.NewNotFoundConfErr("hero", hero_starup, par)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取当前英雄最高星级
|
|
func (this *configureComp) GetHeroMaxStar(hid string, curStar int32) int32 {
|
|
var star int32
|
|
for star = curStar; star < 100; star++ {
|
|
if v, ok := this.starMap[utils.ToInt64(hid)+int64(star+1)<<31]; !ok {
|
|
this.module.Debugf("%v", v)
|
|
return star
|
|
}
|
|
}
|
|
return star
|
|
}
|
|
|
|
// 获取觉醒配置
|
|
func (this *configureComp) GetHeroAwakenConfig(hid string, phase int32) (cfg *cfg.GameHeroAwakenData, err error) {
|
|
var (
|
|
ok bool
|
|
par interface{}
|
|
)
|
|
if cfg, ok = this.awakenMap[utils.ToInt64(hid)+int64(phase)<<31]; !ok {
|
|
par = fmt.Errorf("hid:%s,phase:%d", hid, phase)
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_awaken, par)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 抽卡配置表
|
|
// func (this *configureComp) SetHeroDrawConfig() {
|
|
// var (
|
|
// v interface{}
|
|
// err error
|
|
// )
|
|
// if v, err = this.GetConfigure(hero_drawcard); err == nil {
|
|
// if _configure, ok := v.(*cfg.GameDrawCard); ok {
|
|
// this.hlock.Lock()
|
|
// this.drawCardCfg = make(map[string]map[int32][]*cfg.GameDrawCardData, 0)
|
|
// for _, v := range _configure.GetDataList() {
|
|
// if _, ok := this.drawCardCfg[v.CardPoolType]; !ok {
|
|
// this.drawCardCfg[v.CardPoolType] = make(map[int32][]*cfg.GameDrawCardData, 0)
|
|
// }
|
|
// if _, ok := this.drawCardCfg[v.CardPoolType][v.Star]; !ok {
|
|
// this.drawCardCfg[v.CardPoolType][v.Star] = make([]*cfg.GameDrawCardData, 0)
|
|
// }
|
|
// this.drawCardCfg[v.CardPoolType][v.Star] = append(this.drawCardCfg[v.CardPoolType][v.Star], v)
|
|
// }
|
|
// this.hlock.Unlock()
|
|
// // this.module.Debug("update cfg.Game_drawCard over")
|
|
// return
|
|
// }
|
|
// }
|
|
// err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
|
|
// return
|
|
// }
|
|
|
|
// func (this *configureComp) GetPollByType(poosType string) (conf map[int32][]*cfg.GameDrawCardData, err error) {
|
|
// var ok bool
|
|
// if conf, ok = this.drawCardCfg[poosType]; !ok {
|
|
// err = comm.NewNotFoundConfErr(moduleName, hero_drawcard, poosType)
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
func (this *configureComp) GetHeroExp(hid string) (conf *cfg.GameHeroExpData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(hero_exp); err == nil {
|
|
if c, ok := v.(*cfg.GameHeroExp); ok {
|
|
if conf = c.Get(hid); conf != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_exp, hid)
|
|
return
|
|
}
|
|
|
|
// 获取英雄配置
|
|
func (this *configureComp) GetHeroConfig(heroCfgId string) (conf *cfg.GameHeroData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(new_hero); err == nil {
|
|
if configure, ok := v.(*cfg.GameHero); ok {
|
|
if conf, ok = configure.GetDataMap()[heroCfgId]; ok {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, new_hero, heroCfgId)
|
|
return
|
|
}
|
|
|
|
// 获取英雄星级配置
|
|
func (this *configureComp) GetHeroStar(star int32) *cfg.GameHeroStargrowData {
|
|
|
|
if v, err := this.GetConfigure(hero_stargrow); err == nil {
|
|
|
|
if configure, ok := v.(*cfg.GameHeroStargrow); ok {
|
|
return configure.Get(star)
|
|
}
|
|
}
|
|
this.module.Errorf(" GetHeroStar err : lv:%d", star)
|
|
return nil
|
|
}
|
|
|
|
// 获取英雄等级配置
|
|
func (this *configureComp) GetHeroLv(lv int32) *cfg.GameHeroLevelupData {
|
|
if v, err := this.GetConfigure(hero_levelup); err == nil {
|
|
if configure, ok := v.(*cfg.GameHeroLevelup); ok {
|
|
return configure.Get(lv)
|
|
}
|
|
}
|
|
|
|
this.module.Errorf(" GetHeroLv err : lv:%d", lv)
|
|
|
|
return nil
|
|
}
|
|
|
|
// 英雄成长配置
|
|
func (this *configureComp) GetHeroLvgrow(heroId string) *cfg.GameHeroLevelgrowData {
|
|
if v, err := this.GetConfigure(hero_levelgrow); err == nil {
|
|
if configure, ok := v.(*cfg.GameHeroLevelgrow); ok {
|
|
return configure.Get(heroId)
|
|
}
|
|
}
|
|
this.module.Errorf("cfg.GetHeroLvgrow :id = %s", heroId)
|
|
return nil
|
|
}
|
|
|
|
// 获取英雄技能升级相关信息
|
|
func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
|
|
if v, err = this.GetConfigure(hero_skillup); err == nil {
|
|
if conf, ok := v.(*cfg.GameHeroSkillLevel); ok {
|
|
if data = conf.Get(skillid); data != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_skillup, skillid)
|
|
return
|
|
}
|
|
|
|
// 获取英雄技能最大等级
|
|
func (this *configureComp) GetHeroSkillMaxLvConfig(skillId uint32) int32 {
|
|
|
|
if v, err := this.GetConfigure(game_skillatk); err == nil {
|
|
if configure, ok := v.(*cfg.GameSkillAtk); ok {
|
|
for _, v1 := range configure.GetDataList() {
|
|
if v1.Id == int32(skillId) {
|
|
return v1.MaxLV
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.module.Errorf("cfg.GetHeroSkillMaxLvConfig :id = %d", skillId)
|
|
return 0
|
|
}
|
|
|
|
func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(hero_talent); err == nil {
|
|
if configure, ok := v.(*cfg.GameHeroTalent); ok {
|
|
if data = configure.Get(id); data != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_talent, id)
|
|
return
|
|
}
|
|
|
|
// 天赋指定消耗
|
|
func (this *configureComp) GetHeroTalentBoxItem(heroid string) (itemid string) {
|
|
if v, err := this.GetConfigure(hero_talentbox); err == nil {
|
|
if configure, ok := v.(*cfg.GameTalentBox); ok {
|
|
itemid = configure.Get(heroid).Itemid
|
|
return
|
|
}
|
|
}
|
|
this.module.Errorf("cfg.GameItemBoxData GetHeroTalentBoxItem:skillId = %d", heroid)
|
|
return ""
|
|
}
|
|
|
|
// 读取商品
|
|
func (this *configureComp) GetShopItemsConfigure(key int32) (result *cfg.GameShopitemData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_shopitem); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameShopitem).GetDataMap()[key]; !ok {
|
|
err = fmt.Errorf("ShopConfigure not found:%d ", key)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb.DBUser) (result *cfg.GameShopitemData, err error) {
|
|
var (
|
|
v interface{}
|
|
table *cfg.GameShopitem
|
|
)
|
|
if v, err = this.GetConfigure(game_shopitem); err == nil {
|
|
table = v.(*cfg.GameShopitem)
|
|
for _, v := range table.GetDataMap() {
|
|
if v.Id == groupid &&
|
|
user.Lv >= v.Lvmin &&
|
|
user.Lv <= v.Lvmax &&
|
|
user.Vip >= v.Vip {
|
|
result = v
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, game_shopitem, groupid)
|
|
return
|
|
}
|
|
|
|
// 获取英雄升级属性变化相关配置数据
|
|
func (this *configureComp) GetEquipsuit(id int32) (configure *cfg.GameEquipSuitData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(equip_suit); err == nil {
|
|
if configure, ok = v.(*cfg.GameEquipSuit).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("%T no is *cfg.GameEquipSuit", v)
|
|
return
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetHeroSkillCost(star int32) (cost []*cfg.Gameatn) {
|
|
|
|
if v, err := this.GetConfigure(hero_skill); err == nil {
|
|
if configure, ok := v.(*cfg.GameHeroSkill); ok {
|
|
return configure.Get(star).Needgold
|
|
}
|
|
}
|
|
this.module.Errorf(" GetHeroSkillCost err : star:%d", star)
|
|
return
|
|
}
|
|
|
|
// 获取英雄最大等级
|
|
func (this *configureComp) GetHeroMaxLv(star int32) int32 {
|
|
|
|
if v, err := this.GetConfigure(hero_stargrow); err == nil {
|
|
if configure, ok := v.(*cfg.GameHeroStargrow); ok {
|
|
return configure.Get(star).Maxlevel
|
|
}
|
|
}
|
|
this.module.Errorf(" GetHeroMaxLv err : star:%d", star)
|
|
|
|
return 1
|
|
}
|
|
func (this *configureComp) GetHeroTalentMaxLv(heroid string) (maxlv int32) {
|
|
if v, err := this.GetConfigure(hero_talentbox); err == nil {
|
|
if configure, ok := v.(*cfg.GameTalentBox); ok {
|
|
return int32(len(configure.GetDataList()))
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
// id: 1新手卡池 2 表示普通抽 3表示阵营1 4表示阵营2 ...
|
|
func (this *configureComp) GetHeroDrawConfigByType(id int32) (data *cfg.GameDrawPoolData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
|
|
if v, err = this.GetConfigure(hero_draw); err == nil {
|
|
if conf, ok := v.(*cfg.GameDrawPool); ok {
|
|
if data = conf.Get(id); data != nil {
|
|
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_draw, id)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetHeroDrawWeightConfigById(dtype int32, key int32) int32 {
|
|
return this.starW[(int64(dtype)<<16)+int64(key)]
|
|
}
|
|
|
|
// 通过卡池获取 英雄
|
|
func (this *configureComp) GetHeroByPool(pool string) (hid string, err error) {
|
|
if v, ok := this.cardPool[pool]; ok {
|
|
var sz []int32
|
|
for _, v1 := range v {
|
|
sz = append(sz, v1.Weight)
|
|
}
|
|
if len(sz) == 0 { // 异常报错提醒
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_cardpool, pool)
|
|
return
|
|
}
|
|
hid = v[comm.GetRandW(sz)].Id
|
|
return
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, hero_cardpool, pool)
|
|
return
|
|
}
|