package arena import ( "fmt" "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_arenaarobot = "game_arenaarobot.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 } //组件初始化接口 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_arenabuychallenge, cfg.NewGameArenaBuyChallenge) this.LoadConfigure(game_arenaactivereward, cfg.NewGameArenaActiveReward) this.LoadConfigure(game_arenaarobot, cfg.NewGameArenaRobot) configure.RegisterConfigure(game_arenaarobot, cfg.NewGameArenaRobot, this.updateArenaRobot) this.LoadConfigure(game_arenarankreward, cfg.NewGameArenaRankReward) this.LoadConfigure(game_arenachallengenpc, cfg.NewGameArenaChallengeNpc) this.LoadConfigure(game_monsterformat, cfg.NewGameMonsterFormat) this.LoadConfigure(game_monster, cfg.NewGameMonster) return } ///获取月之秘境触购买表 func (this *configureComp) GetchallengeData(buynum int32) (result *cfg.GameArenaBuyChallengeData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_arenabuychallenge); err != nil { this.module.Errorln(err) return } else { result = v.(*cfg.GameArenaBuyChallenge).GetDataMap()[buynum] } 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 = fmt.Errorf("未找到段位:%d配置", lv) this.module.Errorln(err) } } return } //更新ai数据表 func (this *configureComp) updateArenaRobot() { if v, err := this.GetConfigure(game_arenaarobot); err == nil { if configure, ok := v.(*cfg.GameArenaRobot); ok { this.lock.Lock() defer this.lock.Unlock() 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) { 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 }