247 lines
7.3 KiB
Go
247 lines
7.3 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_pandamasbuff = "game_pandamasbuff.json" //熊猫buff
|
|
game_battletasktesting = "game_battletasktesting.json" //被动技能表
|
|
game_skillatk = "game_skillatk" //主技能表
|
|
game_skillafteratk = "game_skillafteratk" //子技能表
|
|
game_skillbuff = "game_skillbuff" //技能buff表
|
|
game_skillpassive = "game_skillpassive" //被动技能表
|
|
game_battleready_capskill = "game_battleready_capskill.json" //队长技能激活规则
|
|
)
|
|
|
|
///背包配置管理组件
|
|
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)
|
|
this.LoadConfigure(game_battletasktesting, cfg.NewGameBattletasktesting)
|
|
this.LoadConfigure(game_pandamasbuff, cfg.NewGamePandamasBuff)
|
|
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.Heroid != -1 {
|
|
this.mformat[v.Id][v.Pos-1] = v
|
|
}
|
|
}
|
|
}
|
|
this.mformatlock.Unlock()
|
|
})
|
|
this.LoadConfigure(game_battleready_capskill, cfg.NewGameBattleready_capskill)
|
|
// 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
|
|
// }
|
|
|
|
//获取全局buff
|
|
func (this *configureComp) getPandamasBuff(id int32) (configure *cfg.GamePandamasBuffData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_pandamasbuff); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GamePandamasBuff).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("not found:%d ", id)
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
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) GetBattlereadyCapskill(id int32) (result *cfg.GameBattleready_capskillData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_battleready_capskill); err != nil {
|
|
this.module.Errorln(err)
|
|
} else {
|
|
if result, ok = v.(*cfg.GameBattleready_capskill).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("on found BattlereadyCapskill:%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.Errorln(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.Errorln(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.Errorln(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.Errorln(err.Error())
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetBattleTask(battle int32) (result *cfg.GameBattletasktestingData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_battletasktesting); err != nil {
|
|
this.module.Errorln(err)
|
|
} else {
|
|
if result, ok = v.(*cfg.GameBattletasktesting).GetDataMap()[battle]; !ok {
|
|
err = fmt.Errorf("on found GetBattleTask battle:%d", battle)
|
|
this.module.Errorln(err.Error())
|
|
}
|
|
}
|
|
return
|
|
}
|