package battle 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_equipsuit = "game_equipsuit.json" //套装技能表 game_monsterformat = "game_monsterformat.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" //队长技能激活规则 game_battleready = "game_battleready.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) this.LoadConfigure(game_battleready, cfg.NewGameBattleReady) return } func (this *configureComp) GetBattleReady(id int32) (conf *cfg.GameBattleReadyData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_battleready); err != nil { this.module.Errorln(err) return } else { if conf, ok = v.(*cfg.GameBattleReady).GetDataMap()[id]; !ok { // err = fmt.Errorf("not found:%d ", id) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_battleready, id) this.module.Errorln(err) return } } 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), 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 = 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) // err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_pandamasbuff, id) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_pandamasbuff, 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_equipsuit, 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_battleready_capskill, 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 = comm.NewNotFoundConfErr(string(this.module.GetType()), game_skillafteratk, skillId) 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_skillafteratk, 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_skillbuff, 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) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_skillpassive, 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 = comm.NewNotFoundConfErr(string(this.module.GetType()), game_battletasktesting, battle) this.module.Errorln(err.Error()) } } return }