172 lines
4.9 KiB
Go
172 lines
4.9 KiB
Go
package battle
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
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
|
|
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)
|
|
this.LoadConfigure(game_monsterformat, cfg.NewGameMonsterFormat)
|
|
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) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_monsterformat); err != nil {
|
|
this.module.Errorln(err)
|
|
} else {
|
|
if result, ok = v.(*cfg.GameMonsterFormat).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("on found MonsterFormat:%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
|
|
}
|