diff --git a/go.mod b/go.mod index 163bbcc84..b1b0e2fe1 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( bright v0.0.0 github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 + github.com/dengsgo/math-engine v0.0.0-20220213125415-0351c3c75eca github.com/go-playground/validator/v10 v10.10.1 github.com/go-redis/redis/v8 v8.11.5 github.com/golang-jwt/jwt v3.2.2+incompatible @@ -43,7 +44,6 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cheekybits/genny v1.0.0 // indirect - github.com/dengsgo/math-engine v0.0.0-20220213125415-0351c3c75eca // indirect github.com/dgryski/go-jump v0.0.0-20211018200510-ba001c3ffce0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/edwingeng/doublejump v0.0.0-20210724020454-c82f1bcb3280 // indirect diff --git a/modules/equipment/api_upgrade.go b/modules/equipment/api_upgrade.go index efc41fca5..055c645c7 100644 --- a/modules/equipment/api_upgrade.go +++ b/modules/equipment/api_upgrade.go @@ -118,7 +118,7 @@ func (this *Api_Comp) Upgrade(session comm.IUserSession, agrs map[string]interfa //已装备 重新计算属性 if equipment.HeroId != "" { - if hero, code = this.module.hero.GetHero(equipment.HeroId); code != pb.ErrorCode_Success { + if hero, code = this.module.hero.GetHero(session.GetUserId(), equipment.HeroId); code != pb.ErrorCode_Success { log.Errorf("Upgrade code:%d", code) return } diff --git a/modules/hero/api_heroStrengthen.go b/modules/hero/api_heroStrengthen.go index 8d71f9d43..1528ef679 100644 --- a/modules/hero/api_heroStrengthen.go +++ b/modules/hero/api_heroStrengthen.go @@ -3,7 +3,6 @@ package hero import ( "go_dreamfactory/comm" "go_dreamfactory/pb" - "log" ) //参数校验 @@ -31,8 +30,8 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He var costGold int32 // 当前需要消耗金币的数量 var addExp int32 // 需要增加的经验 // 查询 本次消耗会获得多少经验 - expConf, err1 := this.module.configure_comp.GetHeroExpConByHeroid(_expHero.HeroID) - if err1 != nil { + expConf := this.module.configure_comp.GetHeroExp(_expHero.HeroID) + if expConf != nil { addExp = expConf.Heroexp * req.Amount } if _expHero.Count <= req.Amount { // 消耗经验卡片数量不足 @@ -45,7 +44,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He code.Code = pb.ErrorCode_HeroMaxLv return } - if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil { + if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil { costGold += _data.Gold[0].N curExp += addExp // 先把经验加上 // 当前升级需要消耗的经验 @@ -54,7 +53,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He curExp = _data.Heroexp[0].N if curExp >= 0 { // 大于下一级经验 curLv += 1 // 经验够了 那么等级+1 - if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil { + if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil { if _data.Heroexp[0].N > curExp { // 经验不足则 直接返回 break } @@ -88,12 +87,5 @@ func (this *Api_Comp) StrengthenUplv(session comm.IUserSession, agrs map[string] } }() - if configure, err := this.module.configure_comp.GetHeroConfigure(); err != nil { - _data := configure.GetDataMap() - for key, value := range _data { - log.Fatalf("%d,%v", key, value) - } - } - return } diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index cb46637b1..cf72ca460 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -9,12 +9,12 @@ import ( ) const ( - game_hero = "game_newhero.json" - game_heroStargrow = "game_heroStargrow.json" - game_heroLevelgrow = "game_heroLevelgrow.json" - game_heroStarup = "game_heroStarup.json" - game_heroLevelup = "game_heroLevelup.json" - game_heroExp = "game_exp.json" + new_hero = "game_newhero.json" //英雄 + hero_stargrow = "game_herostargrow.json" //英雄品质系数 + hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数 + hero_starup = "game_herostarup.json" // + hero_levelup = "game_herolevelup.json" //英雄等级基础属性 + hero_exp = "game_exp.json" ) ///配置管理组件 @@ -24,28 +24,33 @@ type Configure_Comp struct { //组件初始化接口 func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.ModuleCompBase.Init(service, module, comp, options) - this.LoadConfigure(game_hero, cfg.NewGame_newHero) - this.LoadConfigure(game_heroStargrow, cfg.NewGame_heroStargrow) - this.LoadConfigure(game_heroLevelgrow, cfg.NewGame_heroLevelgrow) - this.LoadConfigure(game_heroStarup, cfg.NewGame_heroStarup) - this.LoadConfigure(game_heroLevelup, cfg.NewGame_heroLevelup) - this.LoadConfigure(game_heroExp, cfg.NewGame_heroExp) + + err = this.MComp_Configure.Init(service, module, comp, options) + err = this.LoadMultiConfigure(map[string]interface{}{ + new_hero: cfg.NewGame_newHero, + hero_stargrow: cfg.NewGame_heroStargrow, + hero_levelgrow: cfg.NewGame_heroLevelgrow, + hero_starup: cfg.NewGame_heroStarup, + hero_levelup: cfg.NewGame_heroLevelup, + hero_exp: cfg.NewGame_heroExp, + }) + return } //获取英雄配置数据 -func (this *Configure_Comp) GetHeroConfigure() (configure *cfg.Game_newHero, err error) { +func (this *Configure_Comp) getHeroConfigure() (configure *cfg.Game_newHero, err error) { var ( v interface{} ok bool ) - if v, err = this.GetConfigure(game_hero); err == nil { + + if v, err = this.GetConfigure(new_hero); err != nil { + return + } else { if configure, ok = v.(*cfg.Game_newHero); !ok { err = fmt.Errorf("%T no is *cfg.Game_hero", v) } - } else { - err = fmt.Errorf("%T no is *cfg.Game_hero", v) } return } @@ -56,7 +61,7 @@ func (this *Configure_Comp) GetHeroStargrowCon() (configure *cfg.Game_heroStargr v interface{} ok bool ) - if v, err = this.GetConfigure(game_heroStargrow); err == nil { + if v, err = this.GetConfigure(hero_stargrow); err == nil { if configure, ok = v.(*cfg.Game_heroStargrow); !ok { err = fmt.Errorf("%T no is *cfg.Game_hero", v) return @@ -74,7 +79,7 @@ func (this *Configure_Comp) GetHeroLevelgrowCon() (configure *cfg.Game_heroLevel v interface{} ok bool ) - if v, err = this.GetConfigure(game_heroLevelgrow); err == nil { + if v, err = this.GetConfigure(hero_levelgrow); err == nil { if configure, ok = v.(*cfg.Game_heroLevelgrow); !ok { err = fmt.Errorf("%T no is *cfg.Game_heroLevelgrow", v) return @@ -90,7 +95,7 @@ func (this *Configure_Comp) GetHeroStarupCon() (configure *cfg.Game_heroStarup, v interface{} ok bool ) - if v, err = this.GetConfigure(game_heroStarup); err == nil { + if v, err = this.GetConfigure(hero_starup); err == nil { if configure, ok = v.(*cfg.Game_heroStarup); !ok { err = fmt.Errorf("%T no is *cfg.Game_heroStarup", v) return @@ -107,7 +112,7 @@ func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup v interface{} ok bool ) - if v, err = this.GetConfigure(game_heroLevelup); err == nil { + if v, err = this.GetConfigure(hero_levelup); err == nil { if configure, ok = v.(*cfg.Game_heroLevelup); !ok { err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) return @@ -118,29 +123,12 @@ func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup return } -// 获取英雄升级相关配置数据 -func (this *Configure_Comp) GetHeroLevelUpByLv(lv int32) (data *cfg.Game_heroLevelupData, err error) { - - if v, err1 := this.GetConfigure(game_heroLevelup); err1 == nil { - if configure, ok := v.(*cfg.Game_heroLevelup); !ok { - err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) - return - - } else { - data = configure.Get(lv) - } - } else { - err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) - } - return -} - func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err error) { var ( v interface{} ok bool ) - if v, err = this.GetConfigure(game_heroExp); err == nil { + if v, err = this.GetConfigure(hero_exp); err == nil { if configure, ok = v.(*cfg.Game_heroExp); !ok { err = fmt.Errorf("%T no is *cfg.Game_heroExp", v) return @@ -150,21 +138,117 @@ func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err er } return } +func (this *Configure_Comp) GetHeroExp(hid int32) *cfg.Game_heroExpData { -func (this *Configure_Comp) GetHeroExpConByHeroid(hid int32) (data *cfg.Game_heroExpData, err error) { - var ( - v interface{} - ) - if v, err = this.GetConfigure(game_heroExp); err == nil { + if v, err := this.GetConfigure(hero_exp); err == nil { if configure, ok := v.(*cfg.Game_heroExp); !ok { err = fmt.Errorf("%T no is *cfg.Game_heroExp", v) - - return + return nil } else { - data = configure.Get(hid) + return configure.Get(hid) } } else { err = fmt.Errorf("%T no is *cfg.Game_heroExp", v) } + return nil +} + +//英雄等级基础属性 +func (this *Configure_Comp) GetHeroLevelup() (configure *cfg.Game_heroLevelup, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(hero_levelup); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_heroLevelup); !ok { + err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) + return + } + } return } + +//英雄品质系数 +func (this *Configure_Comp) GetHeroStargrow() (configure *cfg.Game_heroStargrow, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(hero_stargrow); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_heroStargrow); !ok { + err = fmt.Errorf("%T no is *cfg.Game_heroStargrow", v) + return + } + } + return +} + +//获取英雄配置 +func (this *Configure_Comp) GetHero(heroId int32) *cfg.Game_newHeroData { + cfg, err := this.getHeroConfigure() + if err != nil { + return nil + } + if v, ok := cfg.GetDataMap()[heroId]; ok { + return v + } + return nil +} + +//获取英雄星级配置 +func (this *Configure_Comp) GetHeroStar(star int32) *cfg.Game_heroStargrowData { + cfg, err := this.GetHeroStargrow() + if err != nil { + return nil + } + + if v, ok := cfg.GetDataMap()[star]; ok { + return v + } + return nil +} + +//获取英雄等级配置 +func (this *Configure_Comp) GetHeroLv(lv int32) *cfg.Game_heroLevelupData { + cfg, err := this.GetHeroLevelup() + if err != nil { + return nil + } + if v, ok := cfg.GetDataMap()[lv]; ok { + return v + } + return nil +} + +// 英雄成长系数 +func (this *Configure_Comp) GetHeroLevelgrow() (configure *cfg.Game_heroLevelgrow, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(hero_levelgrow); err != nil { + return + } else { + if configure, ok = v.(*cfg.Game_heroLevelgrow); !ok { + err = fmt.Errorf("%T no is *cfg.Game_heroLevelgrow", v) + return + } + } + return +} + +//英雄成长配置 +func (this *Configure_Comp) GetHeroLvgrow(heroId int32) *cfg.Game_heroLevelgrowData { + cfg, err := this.GetHeroLevelgrow() + if err != nil { + return nil + } + if v, ok := cfg.GetDataMap()[heroId]; ok { + return v + } + return nil +} diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 124671d8e..2e9ae8819 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -36,7 +36,7 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData { newHero := &pb.DB_HeroData{ Id: objId, Uid: uid, - HeroID: heroCfg.Id, + HeroID: heroCfg.Hid, Star: heroCfg.Star, Lv: 1, //初始等级 NormalSkill: []*pb.SkillData{},