package hero import ( "fmt" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" "go_dreamfactory/lego/core" "go_dreamfactory/utils" ) const ( equip_suit = "game_equipsuit.json" //装备套装表 new_hero = "game_hero.json" //英雄 hero_stargrow = "game_herostargrow.json" //英雄品质系数 hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数 hero_starup = "game_herostarup.json" // 升星 hero_levelup = "game_herolevelup.json" //英雄等级基础属性 hero_exp = "game_heroexp.json" // 升级 hero_skillup = "game_heroskilllevel.json" // 英雄技能升级 game_skillatk = "game_skillatk.json" // 英雄技能 hero_awaken = "game_heroawaken.json" // 英雄觉醒 hero_drawcard = "game_drawcard.json" // 抽卡 hero_drawupdraw = "game_drawupdraw.json" // 抽卡概率调整 hero_drawcost = "game_drawcost.json" // 抽卡消耗 hero_fusion = "game_herofusion.json" // 卡牌融合 hero_starupsp = "game_herostarupsp.json" // 精灵升星 hero_talentskill = "game_talentskill.json" // 天赋 hero_talent = "game_herotalent.json" // 天赋详细数据 hero_itembox = "game_itembox.json" // 天赋详细数据 game_shopitem = "game_shopitem.json" hero_skill = "game_heroskill.json" ) ///配置管理组件 type configureComp struct { modules.MCompConfigure hlock sync.RWMutex drawCardCfg map[string]map[int32][]*cfg.GameDrawCardData // 第一个key 卡池id 第二个key 星级 awakenMap map[int64]*cfg.GameHeroAwakenData starMap map[int64]*cfg.GameHeroStarupData module *Hero } //组件初始化接口 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.(*Hero) err = this.LoadMultiConfigure(map[string]interface{}{ equip_suit: cfg.NewGameEquipSuit, new_hero: cfg.NewGameHero, hero_stargrow: cfg.NewGameHeroStargrow, hero_levelgrow: cfg.NewGameHeroLevelgrow, hero_levelup: cfg.NewGameHeroLevelup, hero_exp: cfg.NewGameHeroExp, hero_skillup: cfg.NewGameHeroSkillLevel, game_skillatk: cfg.NewGameSkillAtk, hero_drawcard: cfg.NewGameDrawCard, hero_fusion: cfg.NewGameHerofusion, hero_starupsp: cfg.NewGameHeroStarupSp, hero_talentskill: cfg.NewGameTalentSkill, hero_talent: cfg.NewGameHeroTalent, hero_itembox: cfg.NewGameItemBox, game_shopitem: cfg.NewGameShopitem, hero_skill: cfg.NewGameHeroSkill, }) this.drawCardCfg = make(map[string]map[int32][]*cfg.GameDrawCardData, 0) configure.RegisterConfigure(hero_drawcard, cfg.NewGameDrawCard, this.SetHeroDrawConfig) this.awakenMap = make(map[int64]*cfg.GameHeroAwakenData, 0) configure.RegisterConfigure(hero_awaken, cfg.NewGameHeroAwaken, func() { if v, err := this.GetConfigure(hero_awaken); err == nil { this.hlock.Lock() defer this.hlock.Unlock() if _configure, ok := v.(*cfg.GameHeroAwaken); ok { for _, v := range _configure.GetDataList() { this.awakenMap[int64(utils.ToInt32(v.Hid)<<8)+int64(v.Phase)] = v } return } } else { err = fmt.Errorf("%T no is *cfg.Game_drawCard", v) } }) // 升星 this.starMap = make(map[int64]*cfg.GameHeroStarupData, 0) configure.RegisterConfigure(hero_starup, cfg.NewGameHeroStarup, func() { if v, err := this.GetConfigure(hero_starup); err == nil { if _configure, ok := v.(*cfg.GameHeroStarup); ok { this.hlock.Lock() defer this.hlock.Unlock() for _, v := range _configure.GetDataList() { this.starMap[int64(utils.ToInt32(v.Id)<<8)+int64(v.Star)] = v } return } } else { err = fmt.Errorf("%T no is *cfg.Game_drawCard", v) } }) return } // 获取英雄升星相关配置数据 func (this *configureComp) GetHeroStarupConfig(hid string, star int32) *cfg.GameHeroStarupData { return this.starMap[int64(utils.ToInt32(hid)<<8)+int64(star)] } // 获取当前英雄最高星级 func (this *configureComp) GetHeroMaxStar(hid string, curStar int32) int32 { var star int32 for star = curStar; star < 100; star++ { if _, ok := this.starMap[int64(utils.ToInt32(hid)<<8)+int64(star+1)]; !ok { return star } } return star } func (this *configureComp) GetHeroAwakenConfig(hid string, phase int32) *cfg.GameHeroAwakenData { return this.awakenMap[int64(utils.ToInt32(hid)<<8)+int64(phase)] } // 抽卡配置表 func (this *configureComp) SetHeroDrawConfig() { var ( v interface{} err error ) if v, err = this.GetConfigure(hero_drawcard); err == nil { if _configure, ok := v.(*cfg.GameDrawCard); ok { this.hlock.Lock() this.drawCardCfg = make(map[string]map[int32][]*cfg.GameDrawCardData, 0) for _, v := range _configure.GetDataList() { if _, ok := this.drawCardCfg[v.CardPoolType]; !ok { this.drawCardCfg[v.CardPoolType] = make(map[int32][]*cfg.GameDrawCardData, 0) } if _, ok := this.drawCardCfg[v.CardPoolType][v.Star]; !ok { this.drawCardCfg[v.CardPoolType][v.Star] = make([]*cfg.GameDrawCardData, 0) } this.drawCardCfg[v.CardPoolType][v.Star] = append(this.drawCardCfg[v.CardPoolType][v.Star], v) } this.hlock.Unlock() this.module.Debug("update cfg.Game_drawCard over") return } } err = fmt.Errorf("%T no is *cfg.Game_drawCard", v) return } func (this *configureComp) GetPollByType(poosType string) map[int32][]*cfg.GameDrawCardData { return this.drawCardCfg[poosType] } func (this *configureComp) GetHeroExpConfig() (configure *cfg.GameHeroExp, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(hero_exp); err == nil { if configure, ok = v.(*cfg.GameHeroExp); !ok { err = fmt.Errorf("%T no is *cfg.GameHeroExp", v) return } } else { err = fmt.Errorf("%T no is *cfg.GameHeroExp", v) } return } func (this *configureComp) GetHeroExp(hid string) *cfg.GameHeroExpData { if v, err := this.GetConfigure(hero_exp); err == nil { if configure, ok := v.(*cfg.GameHeroExp); !ok { err = fmt.Errorf("%T no is *cfg.GameHeroExp", v) return nil } else { return configure.Get(hid) } } else { err = fmt.Errorf("%T no is *cfg.GameHeroExp", v) } return nil } //获取英雄配置 func (this *configureComp) GetHeroConfig(heroCfgId string) *cfg.GameHeroData { if v, err := this.GetConfigure(new_hero); err == nil { if configure, ok := v.(*cfg.GameHero); ok { if v, ok := configure.GetDataMap()[heroCfgId]; ok { return v } } } this.module.Errorf("config no is *cfg.GameHero heroid :%s", heroCfgId) return nil } //获取英雄星级配置 func (this *configureComp) GetHeroStar(star int32) *cfg.GameHeroStargrowData { if v, err := this.GetConfigure(hero_stargrow); err == nil { if configure, ok := v.(*cfg.GameHeroStargrow); ok { return configure.Get(star) } } this.module.Errorf(" GetHeroStar err : lv:%d", star) return nil } //获取英雄等级配置 func (this *configureComp) GetHeroLv(lv int32) *cfg.GameHeroLevelupData { if v, err := this.GetConfigure(hero_levelup); err == nil { if configure, ok := v.(*cfg.GameHeroLevelup); ok { return configure.Get(lv) } } this.module.Errorf(" GetHeroLv err : lv:%d", lv) return nil } //英雄成长配置 func (this *configureComp) GetHeroLvgrow(heroId string) *cfg.GameHeroLevelgrowData { if v, err := this.GetConfigure(hero_levelgrow); err == nil { if configure, ok := v.(*cfg.GameHeroLevelgrow); ok { return configure.Get(heroId) } } return nil } // 获取英雄技能升级相关信息 func (this *configureComp) GetHeroSkillUpConfig(skillid int32) (data *cfg.GameHeroSkillLevelData) { if v, err := this.GetConfigure(hero_skillup); err == nil { if conf, ok := v.(*cfg.GameHeroSkillLevel); ok { data = conf.Get(skillid) return } } return } // 获取英雄技能最大等级 func (this *configureComp) GetHeroSkillMaxLvConfig(skillId uint32) int32 { if v, err := this.GetConfigure(game_skillatk); err == nil { if configure, ok := v.(*cfg.GameSkillAtk); ok { for _, v1 := range configure.GetDataList() { if v1.Id == int32(skillId) { return v1.MaxLV } } } } return 0 } // 获取卡牌合成配置 func (this *configureComp) GetHeroFucionConfig(cid string) (data *cfg.GameHerofusionData) { if v, err := this.GetConfigure(hero_fusion); err == nil { if configure, ok := v.(*cfg.GameHerofusion); ok { data = configure.Get(cid) return } } this.module.Errorf("cfg.GameHerofusionData GetHeroFucionConfig:id = %s", cid) return } func (this *configureComp) GetHeroSpriteStar(cid string) (hid string) { if v, err := this.GetConfigure(hero_starupsp); err == nil { if configure, ok := v.(*cfg.GameHeroStarupSp); ok { hid = configure.Get(cid).Starid return } } this.module.Errorf("cfg.GameHeroStarupSpData GetHeroSpriteStar:id = %s", cid) return "" } func (this *configureComp) GetHeroTalent(id int32) (data *cfg.GameHeroTalentData) { if v, err := this.GetConfigure(hero_talent); err == nil { if configure, ok := v.(*cfg.GameHeroTalent); ok { data = configure.Get(id) return } } this.module.Errorf("cfg.GameHeroTalentData GetHeroTalent:id = %d", id) return nil } func (this *configureComp) GetHeroTalentSkill(skillId int32) (data *cfg.GameTalentSkillData) { if v, err := this.GetConfigure(hero_talentskill); err == nil { if configure, ok := v.(*cfg.GameTalentSkill); ok { data = configure.Get(skillId) return } } this.module.Errorf("cfg.GameTalentSkillData GetHeroTalentSkill:skillId = %d", skillId) return nil } // 天赋指定消耗 func (this *configureComp) GetHeroTalentBoxItem(heroid string) (itemid string) { if v, err := this.GetConfigure(hero_itembox); err == nil { if configure, ok := v.(*cfg.GameItemBox); ok { itemid = configure.Get(heroid).Itemid return } } this.module.Errorf("cfg.GameItemBoxData GetHeroTalentBoxItem:skillId = %d", heroid) return "" } //读取商品 func (this *configureComp) GetShopItemsConfigure(key int32) (result *cfg.GameShopitemData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) return } else { if result, ok = v.(*cfg.GameShopitem).GetDataMap()[key]; !ok { err = fmt.Errorf("ShopConfigure not found:%d ", key) this.module.Errorf("err:%v", err) return } } return } func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb.DBUser) (result *cfg.GameShopitemData, err error) { var ( v interface{} table *cfg.GameShopitem ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) return } else { table = v.(*cfg.GameShopitem) for _, v := range table.GetDataMap() { if v.Id == groupid && user.Lv >= v.Lvmin && user.Lv <= v.Lvmax && user.Vip >= v.Vip { result = v return } } } return } // 获取英雄升级属性变化相关配置数据 func (this *configureComp) GetEquipsuit(id int32) (configure *cfg.GameEquipSuitData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(equip_suit); err == nil { if configure, ok = v.(*cfg.GameEquipSuit).GetDataMap()[id]; !ok { err = fmt.Errorf("%T no is *cfg.GameEquipSuit", v) return } } return } func (this *configureComp) GetHeroSkillCost(star int32) (cost []*cfg.Gameatn) { if v, err := this.GetConfigure(hero_skill); err == nil { if configure, ok := v.(*cfg.GameHeroSkill); ok { return configure.Get(star).Needgold } } this.module.Errorf(" GetHeroSkillCost err : star:%d", star) return } // 获取英雄最大等级 func (this *configureComp) GetHeroMaxLv(star int32) int32 { if v, err := this.GetConfigure(hero_stargrow); err == nil { if configure, ok := v.(*cfg.GameHeroStargrow); ok { return configure.Get(star).Maxlevel } } this.module.Errorf(" GetHeroMaxLv err : star:%d", star) return 1 }