go_dreamfactory/modules/battle/configure.go
2022-11-14 13:53:47 +08:00

188 lines
5.5 KiB
Go

package battle
import (
"fmt"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_equipsuit = "game_equipsuit.json" //套装技能表
game_monsterformat = "game_monsterformat.json" //整容表
game_monster = "game_monster.json" //怪物表
game_skillatk = "game_skillatk" //主技能表
game_skillafteratk = "game_skillafteratk" //子技能表
game_skillbuff = "game_skillbuff" //技能buff表
game_skillpassive = "game_skillpassive" //被动技能表
)
///背包配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Battle
mformatlock sync.RWMutex
mformat map[int32][]*cfg.GameMonsterFormatData //怪物阵营表
skillatklock sync.RWMutex
skillatk map[int32]map[int32]*cfg.GameSkillAtkData //主动技能表
}
//组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*Battle)
// this.LoadConfigure(game_equipsuit, cfg.NewGameEquipSuit)
// this.LoadConfigure(game_monster, cfg.NewGameMonster)
// configure.RegisterConfigure(game_monsterformat, cfg.NewGameMonsterFormat, func() {
// this.mformatlock.Lock()
// if v, err := this.GetConfigure(game_monsterformat); err != nil {
// this.module.Errorf("err:%v", err)
// return
// } else {
// this.mformat = make(map[int32][]*cfg.GameMonsterFormatData)
// for _, v := range v.(*cfg.GameMonsterFormat).GetDataList() {
// if this.mformat[v.Id] == nil {
// this.mformat[v.Id] = make([]*cfg.GameMonsterFormatData, 5)
// }
// if v.Monster != -1 {
// this.mformat[v.Id][v.Pos-1] = v
// }
// }
// }
// this.mformatlock.Unlock()
// })
// configure.RegisterConfigure(game_skillatk, cfg.NewGameSkillAtk, func() {
// this.skillatklock.Lock()
// if v, err := this.GetConfigure(game_skillatk); err != nil {
// this.module.Errorf("err:%v", err)
// return
// } else {
// this.skillatk = make(map[int32]map[int32]*cfg.GameSkillAtkData)
// for _, v := range v.(*cfg.GameSkillAtk).GetDataList() {
// if this.skillatk[v.Id] == nil {
// this.skillatk[v.Id] = make(map[int32]*cfg.GameSkillAtkData)
// }
// this.skillatk[v.Id][v.Level] = v
// }
// }
// this.skillatklock.Unlock()
// })
// this.LoadConfigure(game_skillafteratk, cfg.NewGameSkillAfteratk)
// this.LoadConfigure(game_skillbuff, cfg.NewGameSkillBuff)
// this.LoadConfigure(game_skillpassive, cfg.NewGameSkillPassive)
return
}
//查询阵容表
func (this *configureComp) GetMonsterFormat(id int32) (result []*cfg.GameMonsterFormatData, err error) {
this.mformatlock.RLock()
defer this.mformatlock.RUnlock()
var (
ok bool
)
if result, ok = this.mformat[id]; ok {
return
}
err = fmt.Errorf("GetMonsterFormat no found :%d", id)
this.module.Errorln(err)
return
}
//查询怪物表
func (this *configureComp) GetMonster(id int32) (result *cfg.GameMonsterData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_monster); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameMonster).GetDataMap()[id]; !ok {
err = fmt.Errorf("on found GameMonster:%d", id)
this.module.Errorln(err)
}
}
return
}
//查询装备套装表
func (this *configureComp) Getequipsuit(id int32) (result *cfg.GameEquipSuitData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_equipsuit); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameEquipSuit).GetDataMap()[id]; !ok {
err = fmt.Errorf("on found Getequipsuit:%d", id)
this.module.Errorln(err)
}
}
return
}
///获取主动技能配置表
func (this *configureComp) GetSkillAtk(skillId int32, skillLv int32) (result *cfg.GameSkillAtkData, err error) {
if skills, ok := this.skillatk[skillId]; ok {
if result, ok = skills[skillLv]; ok {
return
}
}
err = fmt.Errorf("no found SkillAtk skillId:%d skillLv%d", skillId, skillLv)
this.module.Error(err.Error())
return
}
//获取子技能配置表
func (this *configureComp) GetSkillAfteratk(skillId int32) (result *cfg.GameSkillAfteratkData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_skillafteratk); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameSkillAfteratk).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
}
}
return
}
//获取buff表
func (this *configureComp) GetSkillBuff(skillId int32) (result *cfg.GameSkillBuffData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_skillbuff); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameSkillBuff).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
}
}
return
}
//获取被动技能表
func (this *configureComp) GetSkillPassive(skillId int32) (result *cfg.GameSkillPassiveData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_skillpassive); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameSkillPassive).GetDataMap()[skillId]; !ok {
err = fmt.Errorf("on found SkillAfteratk skillId:%d", skillId)
this.module.Error(err.Error())
}
}
return
}