go_dreamfactory/modules/arena/configure.go
2023-08-28 16:12:30 +08:00

194 lines
5.5 KiB
Go

package arena
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_arenabuychallenge = "game_arenabuychallenge.json" //购买挑战记录
game_arenaactivereward = "game_arenaactivereward.json" //挑战奖励
game_arenarobot = "game_arenarobot.json" //ai配置表
game_arenarankreward = "game_arenarankreward.json" //比赛奖励配置
game_arenachallengenpc = "game_arenachallengenpc.json" //剧情表
game_monsterformat = "game_monsterformat.json" //整容表
game_monster = "game_monster.json" //怪物表
)
///竞技场配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Arena
lock sync.RWMutex
ais map[int32][]*cfg.GameArenaRobotData
mformatlock sync.RWMutex
mformat map[int32][]*cfg.GameMonsterFormatData //怪物阵营表
}
//组件初始化接口
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.(*Arena)
this.LoadConfigure(game_arenaactivereward, cfg.NewGameArenaActiveReward)
configure.RegisterConfigure(game_arenarobot, cfg.NewGameArenaRobot, this.updateArenaRobot)
this.LoadConfigure(game_arenarankreward, cfg.NewGameArenaRankReward)
this.LoadConfigure(game_arenachallengenpc, cfg.NewGameArenaChallengeNpc)
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_monster, cfg.NewGameMonster)
return
}
//查询积分段位信息
func (this *configureComp) getActiveReward(integral int32) (result *cfg.GameArenaActiveRewardData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_arenaactivereward); err != nil {
this.module.Errorln(err)
} else {
for _, v := range v.(*cfg.GameArenaActiveReward).GetDataMap() {
if integral >= v.ScoreLow && integral <= v.ScoreUp {
result = v
return
}
}
}
err = fmt.Errorf("未找到 匹配积分:%d段位配置", integral)
return
}
//查询积分段位信息
func (this *configureComp) getActiveRewardById(lv int32) (result *cfg.GameArenaActiveRewardData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_arenaactivereward); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameArenaActiveReward).GetDataMap()[lv]; !ok {
err = comm.NewNotFoundConfErr(moduleName, game_arenaactivereward, lv)
this.module.Errorln(err)
}
}
return
}
//更新ai数据表
func (this *configureComp) updateArenaRobot() {
if v, err := this.GetConfigure(game_arenarobot); err == nil {
if configure, ok := v.(*cfg.GameArenaRobot); ok {
this.lock.Lock()
defer this.lock.Unlock()
this.ais = make(map[int32][]*cfg.GameArenaRobotData)
for _, value := range configure.GetDataList() {
if _, ok = this.ais[value.LvId]; !ok {
this.ais[value.LvId] = make([]*cfg.GameArenaRobotData, 0)
}
this.ais[value.LvId] = append(this.ais[value.LvId], value)
}
return
}
} else {
this.module.Errorln(err)
}
}
func (this *configureComp) getArenaRobot(dan int32) (result []*cfg.GameArenaRobotData, err error) {
this.lock.RLock()
defer this.lock.RUnlock()
result = this.ais[dan]
if result == nil {
err = fmt.Errorf("未找到匹配段位:%d的ai配置", dan)
}
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 = comm.NewNotFoundConfErr(moduleName, game_monsterformat, 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 = comm.NewNotFoundConfErr(moduleName, game_monster, id)
this.module.Errorln(err)
}
}
return
}
//查询比赛奖励
func (this *configureComp) getRankReward() (result *cfg.GameArenaRankReward, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_arenarankreward); err != nil {
this.module.Errorln(err)
} else {
result = v.(*cfg.GameArenaRankReward)
}
return
}
//查询剧情npc系统
func (this *configureComp) getChallengenpc(id int32) (result *cfg.GameArenaChallengeNpcData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_arenachallengenpc); err != nil {
this.module.Errorln(err)
} else {
if result, ok = v.(*cfg.GameArenaChallengeNpc).GetDataMap()[id]; !ok {
// err = fmt.Errorf("on found getChallengenpc:%d", id)
err = comm.NewNotFoundConfErr(moduleName, game_arenachallengenpc, id)
this.module.Errorln(err)
}
}
return
}