go_dreamfactory/modules/hero/configure_comp.go

435 lines
12 KiB
Go

package hero
import (
"fmt"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core"
"go_dreamfactory/utils"
)
const (
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_resonance = "game_heroresonance.json" // 英雄共鸣
hero_comatn = "game_comatn.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_starupsp = "game_herostarupsp.json" // 精灵升星
hero_talentskill = "game_talentskill.json" // 天赋
hero_talent = "game_herotalent.json" // 天赋详细数据
)
///配置管理组件
type configureComp struct {
modules.MCompConfigure
drawCardCfg map[string]map[int32][]*cfg.GameDrawCardData // 第一个key 卡池id 第二个key 星级
//map["base_pool1"]map[3]*cfg.Game_drawCardData
awakenMap map[int64]*cfg.GameHeroAwakenData
resonanceMap map[int64]*cfg.GameHeroResonanceData
starMap map[int64]*cfg.GameHeroStarupData
module *Hero
}
//组件初始化接口
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{}{
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_comatn: cfg.NewGameComAtn,
hero_drawcard: cfg.NewGameDrawCard,
hero_fusion: cfg.NewGameHerofusion,
hero_starupsp: cfg.NewGameHeroStarupSp,
hero_talentskill: cfg.NewGameTalentSkill,
hero_talent: cfg.NewGameHeroTalent,
})
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 {
if _configure, ok := v.(*cfg.GameHeroAwaken); ok {
for _, v := range _configure.GetDataList() {
this.awakenMap[int64(utils.ToInt32(v.Hid)<<8)+int64(v.Phase)] = v
}
return
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
}
})
// 共鸣
this.resonanceMap = make(map[int64]*cfg.GameHeroResonanceData, 0)
configure.RegisterConfigure(hero_resonance, cfg.NewGameHeroResonance, func() {
if v, err := this.GetConfigure(hero_resonance); err == nil {
if _configure, ok := v.(*cfg.GameHeroResonance); ok {
for _, v := range _configure.GetDataList() {
this.resonanceMap[int64(utils.ToInt32(v.Hid)<<8)+int64(v.Star)] = v
}
return
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_drawCard", 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 {
for _, v := range _configure.GetDataList() {
this.starMap[int64(utils.ToInt32(v.Id)<<8)+int64(v.Star)] = v
}
return
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
}
})
// 测试接口 功能完成后删
// _data := this.GetHeroTalentSkill(20101)
// _data1 := this.GetHeroTalent(1)
// this.module.Debugf("%v,%v", _data, _data1)
return
}
// 获取英雄升星相关配置数据
func (this *configureComp) GetHeroStarupConfig(hid string, star int32) *cfg.GameHeroStarupData {
return this.starMap[int64(utils.ToInt32(hid)<<8)+int64(star)]
}
// 通过英雄配置ID获取共鸣配置信息
func (this *configureComp) GetHeroResonanceConfig(hid string, star int32) *cfg.GameHeroResonanceData {
return this.resonanceMap[int64(utils.ToInt32(hid)<<8)+int64(star)]
}
func (this *configureComp) GetHeroAwakenConfig(hid string, phase int32) *cfg.GameHeroAwakenData {
return this.awakenMap[int64(utils.ToInt32(hid)<<8)+int64(phase)]
}
// 抽卡配置表
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 {
err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
return
} else {
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)
}
}
} else {
err = fmt.Errorf("%T no is *cfg.Game_drawCard", v)
}
return
}
func (this *configureComp) GetPollByType(poosType string) map[int32][]*cfg.GameDrawCardData {
return this.drawCardCfg[poosType]
}
// 获取英雄强化增加属性配置数据
func (this *configureComp) GetHeroStargrowConfig() (configure *cfg.GameHeroStargrow, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_stargrow); err == nil {
if configure, ok = v.(*cfg.GameHeroStargrow); !ok {
err = fmt.Errorf("%T no is *cfg.GameHero", v)
return
}
} else {
err = fmt.Errorf("%T no is *cfg.GameHero", v)
}
return
}
// 获取英雄升级属性变化相关配置数据
func (this *configureComp) GetHeroLevelgrowConfig() (configure *cfg.GameHeroLevelgrow, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_levelgrow); err == nil {
if configure, ok = v.(*cfg.GameHeroLevelgrow); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroLevelgrow", v)
return
}
}
return
}
// 获取英雄升级相关配置数据
func (this *configureComp) GetHeroLevelUpConfig() (configure *cfg.GameHeroLevelup, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_levelup); err == nil {
if configure, ok = v.(*cfg.GameHeroLevelup); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroLevelup", v)
return
}
} else {
err = fmt.Errorf("%T no is *cfg.GameHeroLevelup", v)
}
return
}
func (this *configureComp) GetHeroExpConfig() (configure *cfg.GameHeroExp, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_exp); err == nil {
if configure, ok = v.(*cfg.GameHeroExp); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroExp", v)
return
}
} else {
err = fmt.Errorf("%T no is *cfg.GameHeroExp", v)
}
return
}
func (this *configureComp) GetHeroExp(hid string) *cfg.GameHeroExpData {
if v, err := this.GetConfigure(hero_exp); err == nil {
if configure, ok := v.(*cfg.GameHeroExp); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroExp", v)
return nil
} else {
return configure.Get(hid)
}
} else {
err = fmt.Errorf("%T no is *cfg.GameHeroExp", v)
}
return nil
}
//英雄等级基础属性
func (this *configureComp) GetHeroLevelup() (configure *cfg.GameHeroLevelup, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_levelup); err != nil {
return
} else {
if configure, ok = v.(*cfg.GameHeroLevelup); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroLevelup", v)
return
}
}
return
}
//英雄品质系数
func (this *configureComp) GetHeroStargrow() (configure *cfg.GameHeroStargrow, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_stargrow); err != nil {
return
} else {
if configure, ok = v.(*cfg.GameHeroStargrow); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroStargrow", v)
return
}
}
return
}
//获取英雄配置
func (this *configureComp) GetHeroConfig(heroCfgId string) *cfg.GameHeroData {
if v, err := this.GetConfigure(new_hero); err == nil {
if configure, ok := v.(*cfg.GameHero); ok {
if v, ok := configure.GetDataMap()[heroCfgId]; ok {
return v
}
}
}
this.module.Errorf("config no is *cfg.GameHero")
return nil
}
//获取英雄星级配置
func (this *configureComp) GetHeroStar(star int32) *cfg.GameHeroStargrowData {
cfg, err := this.GetHeroStargrow()
if err != nil {
return nil
}
if v, ok := cfg.GetDataMap()[star]; ok {
return v
}
return nil
}
//获取英雄等级配置
func (this *configureComp) GetHeroLv(lv int32) *cfg.GameHeroLevelupData {
cfg, err := this.GetHeroLevelup()
if err != nil {
return nil
}
if v, ok := cfg.GetDataMap()[lv]; ok {
return v
}
return nil
}
// 英雄成长系数
func (this *configureComp) GetHeroLevelgrow() (configure *cfg.GameHeroLevelgrow, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hero_levelgrow); err != nil {
return
} else {
if configure, ok = v.(*cfg.GameHeroLevelgrow); !ok {
err = fmt.Errorf("%T no is *cfg.GameHeroLevelgrow", v)
return
}
}
return
}
//英雄成长配置
func (this *configureComp) GetHeroLvgrow(heroId string) *cfg.GameHeroLevelgrowData {
cfg, err := this.GetHeroLevelgrow()
if err != nil {
return nil
}
if v, ok := cfg.GetDataMap()[heroId]; ok {
return v
}
return nil
}
// 获取英雄技能升级相关信息
func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData) {
if v, err := this.GetConfigure(hero_skillup); err == nil {
if conf, ok := v.(*cfg.GameHeroSkillLevel); ok {
data = conf.Get(skillid)
return
}
}
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
}
}
}
}
return 0
}
func (this *configureComp) GetHeroResonanceRestConfig() (data *cfg.GameComAtnData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(hero_comatn); err == nil {
if configure, ok := v.(*cfg.GameComAtn); ok {
data = configure.Get("hero_reset")
return
}
}
this.module.Errorf("cfg.GameComAtnData GetHeroResonanceRestConfig:id = hero_reset")
return
}
// 获取卡牌合成配置
func (this *configureComp) GetHeroFucionConfig(cid string) (data *cfg.GameHerofusionData) {
if v, err := this.GetConfigure(hero_fusion); err == nil {
if configure, ok := v.(*cfg.GameHerofusion); ok {
data = configure.Get(cid)
return
}
}
this.module.Errorf("cfg.GameHerofusionData GetHeroFucionConfig:id = %s", cid)
return
}
func (this *configureComp) GetHeroSpriteStar(cid string) (hid string) {
if v, err := this.GetConfigure(hero_starupsp); err == nil {
if configure, ok := v.(*cfg.GameHeroStarupSp); !ok {
hid = configure.Get(cid).Starid
return
}
}
this.module.Errorf("cfg.GameHeroStarupSpData GetHeroSpriteStar:id = %s", cid)
return ""
}
func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData) {
if v, err := this.GetConfigure(hero_talent); err == nil {
if configure, ok := v.(*cfg.GameHeroTalent); ok {
data = configure.Get(id)
return
}
}
this.module.Errorf("cfg.GameHeroTalentData GetHeroTalent:id = %d", id)
return nil
}
func (this *configureComp) GetHeroTalentSkill(skillId int32) (data *cfg.GameTalentSkillData) {
if v, err := this.GetConfigure(hero_talentskill); err == nil {
if configure, ok := v.(*cfg.GameTalentSkill); ok {
data = configure.Get(skillId)
return
}
}
this.module.Errorf("cfg.GameTalentSkillData GetHeroTalentSkill:skillId = %d", skillId)
return nil
}