go_dreamfactory/modules/entertainment/configure.go
2024-01-22 18:43:43 +08:00

413 lines
10 KiB
Go

package entertainment
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
"go_dreamfactory/lego/core"
)
const (
game_block = "game_block.json"
game_consumehero = "game_consumehero.json"
game_integral = "game_integral.json"
game_consumeIntegral = "game_consumeintegral.json"
game_playingmethod = "game_playingmethod.json"
consume_box = "game_consumebox.json"
game_playerskill = "game_playerskill.json"
game_passcheck = "game_passcheck.json"
game_consumetask = "game_consumetask.json"
consume_rank = "game_consumerank.json"
)
// /配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Entertainment
lock sync.RWMutex
block map[int32]*cfg.GameBlockData
order map[int32][]*cfg.GamePassCheckData //战令
resetScore int32 // 重置积分
}
const moduleName = "entertainment"
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.(*Entertainment)
err = this.LoadMultiConfigure(map[string]interface{}{
game_consumehero: cfg.NewGameConsumeHero,
game_integral: cfg.NewGameIntegral,
game_consumeIntegral: cfg.NewGameConsumeIntegral,
game_playingmethod: cfg.NewGamePlayingMethod,
consume_box: cfg.NewGameConsumeBox,
game_playerskill: cfg.NewGamePlayerSkill,
game_consumetask: cfg.NewGameConsumeTask,
consume_rank: cfg.NewGameConsumeRank,
})
configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock)
configure.RegisterConfigure(game_passcheck, cfg.NewGamePassCheck, this.updatePassCheck)
configure.RegisterConfigure(game_consumeIntegral, cfg.NewGameConsumeIntegral, this.loadConsumeIntegral)
return
}
func (this *configureComp) LoadGameBlock() {
var (
v interface{}
configure *cfg.GameBlock
err error
ok bool
)
if v, err = this.GetConfigure(game_block); err != nil {
this.module.Errorln(err)
return
}
block := make(map[int32]*cfg.GameBlockData)
if configure, ok = v.(*cfg.GameBlock); ok {
for _, v := range configure.GetDataList() {
if v.Belongto == 2 {
continue
}
key := v.Color<<8 + v.Type
block[key] = v
}
}
this.lock.Lock()
this.block = block
this.lock.Unlock()
return
}
func (this *configureComp) GetGameBlock(color int32, iType int32) (conf *cfg.GameBlockData, err error) {
var (
ok bool
key int32
)
key = color<<8 + iType
this.lock.RLock()
defer this.lock.RUnlock()
if conf, ok = this.block[key]; !ok {
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_block, fmt.Sprintf("color:%d,itype:%d", color, key))
}
return
}
func (this *configureComp) GetGameConsumeHero(heroid string) (conf *cfg.GameConsumeHeroData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_consumehero); err == nil {
if configure, ok := v.(*cfg.GameConsumeHero); ok {
if conf = configure.Get(heroid); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_consumehero, heroid)
return
}
func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameIntegralData, err error) {
var (
v interface{}
configure *cfg.GameIntegral
ok bool
)
if v, err = this.GetConfigure(game_integral); err == nil {
if configure, ok = v.(*cfg.GameIntegral); ok {
for pos, v := range configure.GetDataList() {
if v.Key >= key {
if pos == 0 {
conf = configure.GetDataList()[1]
return
}
conf = v
return
}
}
}
}
if configure.GetDataList()[len(configure.GetDataList())-1].Key < key { // 设置最大值
conf = configure.GetDataList()[len(configure.GetDataList())-1]
return
}
err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
return
}
func (this *configureComp) GetRobotGameConsumeHero() (cardid string) {
if v, err := this.GetConfigure(game_consumehero); err == nil {
if configure, ok := v.(*cfg.GameConsumeHero); ok {
for _, v := range configure.GetDataList() {
cardid = v.Key
break
}
}
}
return
}
func (this *configureComp) GetInitGameConsumeHero() (cardid []string) {
if v, err := this.GetConfigure(game_consumehero); err == nil {
if configure, ok := v.(*cfg.GameConsumeHero); ok {
for _, v := range configure.GetDataList() {
if v.Type == 1 {
cardid = append(cardid, v.Key)
}
}
}
}
return
}
func (this *configureComp) GetGameConsumeIntegral() (itype []*cfg.GamePlayingMethodData) {
if v, err := this.GetConfigure(game_playingmethod); err == nil {
if configure, ok := v.(*cfg.GamePlayingMethod); ok {
for _, v := range configure.GetDataList() {
if v.Type == 2 {
itype = append(itype, v)
}
}
}
}
return
}
func (this *configureComp) GetGameConsumeIntegralByKey(key int32) (conf *cfg.GamePlayingMethodData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_playingmethod); err == nil {
if configure, ok := v.(*cfg.GamePlayingMethod); ok {
if conf = configure.Get(key); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_playingmethod, key)
return
}
func (this *configureComp) GetGameConsumeBoxConf(boxid int32) (conf *cfg.GameConsumeBoxData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(consume_box); err == nil {
if configure, ok := v.(*cfg.GameConsumeBox); ok {
if conf = configure.Get(boxid); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, consume_box, boxid)
return
}
func (this *configureComp) GetGameRandomConsumeBoxConf() (conf *cfg.GameConsumeBoxData, err error) {
var (
v interface{}
szWeight []int32
boxid []int32
)
if v, err = this.GetConfigure(consume_box); err == nil {
if configure, ok := v.(*cfg.GameConsumeBox); ok {
for _, v1 := range configure.GetDataList() {
szWeight = append(szWeight, v1.Weight)
boxid = append(boxid, v1.Boxid)
}
}
}
conf, err = this.GetGameConsumeBoxConf(boxid[comm.GetRandW(szWeight)])
return
}
func (this *configureComp) GetGameBlockByKey(key int32) (conf *cfg.GameBlockData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_block); err == nil {
if configure, ok := v.(*cfg.GameBlock); ok {
if conf = configure.Get(key); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_block, key)
return
}
// 通过权重获取一个普通元素
func (this *configureComp) GetGameNormalElem() (rd int32) {
var (
v interface{}
szWeight []int32
err error
)
if v, err = this.GetConfigure(game_block); err == nil {
if configure, ok := v.(*cfg.GameBlock); ok {
for _, v := range configure.GetDataList() {
if v.Key > 6 {
break
}
szWeight = append(szWeight, v.Weight)
}
}
}
rd = comm.GetRandW(szWeight) + 1
return
}
func (this *configureComp) GetGamePlaySkill(skillid string) (conf *cfg.GamePlayerSkillData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_playerskill); err == nil {
if configure, ok := v.(*cfg.GamePlayerSkill); ok {
if conf = configure.Get(skillid); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_playerskill, skillid)
return
}
// 更新任务配置表
func (this *configureComp) updatePassCheck() {
gwt, err := this.getPassCheckCfg()
if err != nil {
this.module.Error("世界任务配置表异常!")
return
}
orderConf := make(map[int32][]*cfg.GamePassCheckData)
for _, v := range gwt.GetDataList() {
if _, ok := orderConf[v.PasscheckType]; !ok {
orderConf[v.PasscheckType] = make([]*cfg.GamePassCheckData, 0)
}
orderConf[v.PasscheckType] = append(orderConf[v.PasscheckType], v)
}
this.lock.Lock()
this.order = orderConf
this.lock.Unlock()
}
func (this *configureComp) getorder(wtype int32) (results []*cfg.GamePassCheckData, err error) {
this.lock.RLock()
defer this.lock.RUnlock()
var ok bool
if results, ok = this.order[wtype]; !ok {
err = fmt.Errorf("no found wtype:%d", wtype)
}
return
}
// 读取任务配置表
func (this *configureComp) getPassCheckCfg() (data *cfg.GamePassCheck, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_passcheck); err != nil {
return
} else {
if data, ok = v.(*cfg.GamePassCheck); !ok {
err = fmt.Errorf("%T is *cfg.GameWorldTask", v)
return
}
}
return
}
func (this *configureComp) GetInitGameConsumeSkill() (skill []string) {
if v, err := this.GetConfigure(game_playerskill); err == nil {
if configure, ok := v.(*cfg.GamePlayerSkill); ok {
for _, v := range configure.GetDataList() {
if v.Number == 1 {
skill = append(skill, v.Key)
}
}
}
}
return
}
// 获取任务
func (this *configureComp) GetConsumeTaskData() (conf []*cfg.GameConsumeTaskData) {
if v, err := this.GetConfigure(game_consumetask); err == nil {
if configure, ok := v.(*cfg.GameConsumeTask); ok {
conf = configure.GetDataList()
}
}
return
}
func (this *configureComp) GetGameConsumeReward() (conf []*cfg.GameIntegralData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_integral); err == nil {
if configure, ok := v.(*cfg.GameIntegral); ok {
if conf = configure.GetDataList(); len(conf) != 0 {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_integral, nil)
return
}
func (this *configureComp) loadConsumeIntegral() {
var (
v interface{}
configure *cfg.GameConsumeIntegral
err error
ok bool
)
if v, err = this.GetConfigure(game_consumeIntegral); err != nil {
this.module.Errorln(err)
return
}
if configure, ok = v.(*cfg.GameConsumeIntegral); ok {
for _, v := range configure.GetDataList() {
if v.Type == 2 {
this.resetScore = v.Key
break
}
}
}
return
}
func (this *configureComp) GetConsumeResetIntegral() (score int32) {
return this.resetScore
}
//查询比赛奖励
func (this *configureComp) getRankReward() (result *cfg.GameConsumeRank, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(consume_rank); err == nil {
if result, ok = v.(*cfg.GameConsumeRank); ok {
return
}
}
err = comm.NewNotFoundConfErr(moduleName, consume_rank, nil)
return
}