273 lines
7.8 KiB
Go
273 lines
7.8 KiB
Go
package integral
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_integralboss = "game_integralboss.json"
|
|
game_integralcondition = "game_integralcondition.json"
|
|
game_integralreward = "game_integralreward.json"
|
|
game_integraltime = "game_integraltime.json"
|
|
game_integralbuff = "game_integralbuff.json"
|
|
game_integralachieve = "game_integralachieve.json"
|
|
game_integralbuffgroup = "game_integralbuffgroup.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
hlock sync.RWMutex
|
|
modules.MCompConfigure
|
|
module *Integral
|
|
boss map[int32]*cfg.GameIntegralBossData
|
|
reward map[int32][]*cfg.GameIntegralRewardData
|
|
task map[int32]*cfg.GameIntegralConditionData
|
|
}
|
|
|
|
//组件初始化接口
|
|
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.(*Integral)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
game_integraltime: cfg.NewGameIntegralTime,
|
|
game_integralcondition: cfg.NewGameIntegralCondition,
|
|
game_integralbuff: cfg.NewGameIntegralBuff,
|
|
game_integralachieve: cfg.NewGameIntegralAchieve,
|
|
game_integralbuffgroup: cfg.NewGameIntegralBuffGroup,
|
|
})
|
|
configure.RegisterConfigure(game_integralboss, cfg.NewGameIntegralBoss, this.LoadStageBoss)
|
|
configure.RegisterConfigure(game_integralreward, cfg.NewGameIntegralReward, this.LoadIntegralReward)
|
|
configure.RegisterConfigure(game_integraltime, cfg.NewGameIntegralCondition, this.LoadIntegralCondition)
|
|
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) LoadStageBoss() {
|
|
if v, err := this.GetConfigure(game_integralboss); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralBoss); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
this.boss = make(map[int32]*cfg.GameIntegralBossData, 0)
|
|
for _, value := range configure.GetDataList() {
|
|
this.boss[value.Hdid<<8+value.Difficulty] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_integralboss conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过活动id 和难度获取
|
|
func (this *configureComp) GetStageBoss(hdid int32, nandu int32) (conf *cfg.GameIntegralBossData, err error) {
|
|
|
|
this.hlock.RLock()
|
|
conf = this.boss[hdid<<8+nandu]
|
|
this.hlock.RUnlock()
|
|
if conf == nil {
|
|
err = fmt.Errorf("not found game_integralboss:hid:%d,难度:%d", hdid, nandu)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 参数: boss类型 难度
|
|
func (this *configureComp) GetEnchantBossConfigData(bossId int32) (data []*cfg.GameEnchantBossData, err error) {
|
|
|
|
return
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v, nil)
|
|
if err != nil {
|
|
log.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralITime() (sz []*cfg.GameIntegralTimeData) {
|
|
if v, err := this.GetConfigure(game_integraltime); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralTime); ok {
|
|
return configure.GetDataList()
|
|
}
|
|
} else {
|
|
log.Errorf("get game_integraltime conf err:%v", err)
|
|
}
|
|
|
|
return
|
|
}
|
|
func (this *configureComp) LoadIntegralReward() {
|
|
|
|
if v, err := this.GetConfigure(game_integralreward); err == nil {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
this.reward = make(map[int32][]*cfg.GameIntegralRewardData)
|
|
if _configure, ok := v.(*cfg.GameIntegralReward); ok {
|
|
for _, v := range _configure.GetDataList() {
|
|
key := v.Hdid<<8 + v.Type
|
|
this.reward[key] = append(this.reward[key], v)
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.GameMonkeyReward", v)
|
|
}
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralReward(hid int32, itype int32) (result []*cfg.GameIntegralRewardData, err error) {
|
|
var (
|
|
ok bool
|
|
)
|
|
this.hlock.Lock()
|
|
result, ok = this.reward[hid<<8+itype]
|
|
this.hlock.Unlock()
|
|
if !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralreward, fmt.Sprintf("hid:%d,itype :%d", hid, itype))
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取积分boss debuff 条件
|
|
func (this *configureComp) GetIntegralCondition() (result []*cfg.GameIntegralConditionData) {
|
|
if v, err := this.GetConfigure(game_integralcondition); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralCondition); ok {
|
|
for _, v1 := range configure.GetDataList() {
|
|
if v1.IType == 1 {
|
|
result = append(result, v1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过id获取数据
|
|
func (this *configureComp) GetIntegralConditionByKey(id int32) (result *cfg.GameIntegralConditionData) {
|
|
if v, err := this.GetConfigure(game_integralcondition); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralCondition); ok {
|
|
return configure.Get(id)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralConditionByKeys(ids []int32) (result []int32) {
|
|
if v, err := this.GetConfigure(game_integralcondition); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralCondition); ok {
|
|
for _, id := range ids {
|
|
result = append(result, configure.Get(id).Skillid...)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) LoadIntegralCondition() {
|
|
|
|
if v, err := this.GetConfigure(game_integralcondition); err == nil {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
this.task = make(map[int32]*cfg.GameIntegralConditionData)
|
|
if _configure, ok := v.(*cfg.GameIntegralCondition); ok {
|
|
for _, v := range _configure.GetDataList() {
|
|
if v.IType == 1 {
|
|
this.task[v.TaskId] = v
|
|
}
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
err = fmt.Errorf("%T no is *cfg.game_integralcondition", v)
|
|
}
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralConditionByTask(taskid int32) (result *cfg.GameIntegralConditionData, err error) {
|
|
this.hlock.Lock()
|
|
result = this.task[taskid]
|
|
this.hlock.Unlock()
|
|
if result == nil {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralcondition, taskid)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralBuffByKey(skillId int32) (result *cfg.GameIntegralBuffData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_integralbuff); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralBuff); ok {
|
|
if result = configure.Get(skillId); result != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralbuff, skillId)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralAchieveByKey(id int32) (result *cfg.GameIntegralAchieveData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_integralachieve); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralAchieve); ok {
|
|
if result = configure.Get(id); result != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralachieve, id)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetIntegralBUff(group int32) (szSkillId []int32, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_integralbuffgroup); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralBuffGroup); ok {
|
|
if result := configure.Get(group); result != nil {
|
|
for _, v := range result.Skillid {
|
|
szSkillId = append(szSkillId, v)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralbuffgroup, group)
|
|
return
|
|
}
|
|
|
|
// 获取组数组
|
|
func (this *configureComp) GetIntegralBUffSkillGroup() (sz []int32, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_integralbuffgroup); err == nil {
|
|
if configure, ok := v.(*cfg.GameIntegralBuffGroup); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
sz = append(sz, v.Skillgroup)
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_integralbuffgroup, "")
|
|
return
|
|
}
|