From 1937244a376c6816e56cb2c9d1a25e7a08018655 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 22 Dec 2023 11:15:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8B=B1=E9=9B=84=E7=BB=8F?= =?UTF-8?q?=E9=AA=8C=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 +- modules/hero/api_drawCard.go | 11 +- modules/hero/api_strengthenUplv.go | 2 +- modules/hero/model_hero.go | 314 ++++++++++++++------------ modules/hero/module.go | 87 ++++--- modules/mainline/api_challengeover.go | 1 + modules/user/module.go | 42 ++-- 7 files changed, 253 insertions(+), 207 deletions(-) diff --git a/comm/const.go b/comm/const.go index 0361aa694..e4b4d8738 100644 --- a/comm/const.go +++ b/comm/const.go @@ -1164,5 +1164,6 @@ const ( //session Session 临时数据key const ( - Session_User = "user" + Session_User = "user" + Session_UserExpand = "userexpand" ) diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 22b80a320..7a36bac4a 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -311,16 +311,15 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq heroRecord.Cur = szCards update["selectcount"] = heroRecord.Selectcount update["cur"] = heroRecord.Cur - } else { // 非模拟抽不发奖 - - this.module.DispenseAtno(session, allres, true) } this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) if req.DrawType != 1 { - if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil { // 发放许愿石奖励 - return - } + allres = append(allres, reward...) + + } + if errdata, atno = this.module.DispenseAtno(session, allres, true); errdata != nil { //同意发送奖励 + return } session.SendMsg(string(this.module.GetType()), DrawCard, rsp) diff --git a/modules/hero/api_strengthenUplv.go b/modules/hero/api_strengthenUplv.go index 7f8a86e30..9e867d2cd 100644 --- a/modules/hero/api_strengthenUplv.go +++ b/modules/hero/api_strengthenUplv.go @@ -86,7 +86,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren return } // 执行升级逻辑 - if _, errdata = this.module.modelHero.AddCardExp(session, _hero, addExp, nil); errdata != nil { // 加经验 + if _, errdata = this.module.modelHero.AddCardExp(session, []*pb.DBHero{_hero}, addExp, nil); errdata != nil { // 加经验 return } // 消耗金币 diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index e7c253765..460423cca 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -169,6 +169,15 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero { return hero } +// 获取一个英雄(参数唯一objID) +func (this *ModelHero) getHeros(uid string, heroIds []string) (heros []*pb.DBHero, err error) { + heros = make([]*pb.DBHero, 0) + if err = this.GetListObjs(uid, heroIds, &heros); err != nil { + return + } + return +} + // 消耗英雄卡 func (this *ModelHero) consumeHeroCard(uid string, hero *pb.DBHero) (err error) { @@ -389,161 +398,176 @@ func (this *ModelHero) cleanData(uid string) { } } -func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, exp int32, model *db.DBModel) (curAddExp int32, errdata *pb.ErrorData) { +func (this *ModelHero) AddCardExp(session comm.IUserSession, heros []*pb.DBHero, exp int32, model *db.DBModel) (curAddExp []int32, errdata *pb.ErrorData) { var ( - preLv int32 //加经验之前的等级 - curExp int32 // 加经验之后的经验 - curLv int32 // 加经验之后的等级 - update map[string]interface{} // 属性变化 + tasks []*pb.BuriedParam + changeupdate map[string]interface{} = make(map[string]interface{}) + maxlvhero *pb.DBHero ) - if hero == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_HeroNoExist, - Title: pb.ErrorCode_HeroNoExist.ToString(), - } - return - } - update = make(map[string]interface{}, 0) - curExp = hero.Exp - curLv = hero.Lv - preLv = curLv - var maxLv int32 // 校验等级达到上限 - maxLv = this.module.configure.GetHeroMaxLv(hero.Star) - // 校验玩家等级 - if _user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { - if expConf := this.module.configure.GetPlayerlvConf(_user.Lv); expConf != nil { - if maxLv > expConf.HeroLv { - maxLv = expConf.HeroLv // 英雄最大等级限制 - } - } - } - - _data := this.module.configure.GetHeroLv(curLv) - if _data == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ConfigNoFound, - Title: pb.ErrorCode_ConfigNoFound.ToString(), - } - return - } - - var maxExp int32 - maxExp = _data.Heroexp - if maxLv <= curLv && curExp >= maxExp { // 加经验之前校验是否达到最大等级 - curAddExp = 0 // 已经满级的时候 - //code = pb.ErrorCode_HeroMaxLv // - this.module.Debugf("英雄已经满级 不需要升级heroid:%s,addexp:%d", hero.Id, exp) - return - } - curExp += exp // 先把经验加上 - for { // 死循环判断一键升级 - if _data.Heroexp == 0 { - curAddExp = exp - (curExp - maxExp) // 减去超过部分的经验 - curExp = 0 - break - } - maxExp = _data.Heroexp - if maxLv <= curLv && curExp >= maxExp { // 设置最大经验和等级 - curAddExp = exp - (curExp - maxExp) // 减去超过部分的经验 - curLv = maxLv - curExp = maxExp - break - } - if maxExp > curExp { // 经验不够升级则不能执行升级操作 - break - } else { // 升级操作 - curExp -= maxExp - curLv += 1 // 经验够了 那么等级+1 - _data = this.module.configure.GetHeroLv(curLv) - if _data == nil { // 等级加失败了 回到原来的等级 - curLv -= 1 - break - } - } - } - - if curAddExp != 0 { - curAddExp = exp // 真正加的经验 - } - - this.module.Debugf("add hero exp :old lv:%d,old exp:%d,new lv:%d,new exp:%d,addexp:%d", hero.Lv, hero.Exp, curLv, curExp, exp) - update["lv"] = curLv - update["exp"] = curExp - - hero.Lv = curLv - hero.Exp = curExp - if curLv-preLv > 0 { // 升级了 统计任务 - this.PropertyCompute(hero) - update["property"] = hero.Property - update["horoscopeProperty"] = hero.HoroscopeProperty - update["talentProperty"] = hero.TalentProperty - update["juexProperty"] = hero.JuexProperty - } - if model != nil { - if err := model.ChangeList(session.GetUserId(), hero.Id, update); err != nil { - this.module.Errorf("add hero exp failed ChangeList %v", err) + curAddExp = make([]int32, len(heros)) + for i, hero := range heros { + var ( + preLv int32 //加经验之前的等级 + curExp int32 // 加经验之后的经验 + curLv int32 // 加经验之后的等级 + update map[string]interface{} // 属性变化 + ) + if hero == nil { errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), + Code: pb.ErrorCode_HeroNoExist, + Title: pb.ErrorCode_HeroNoExist.ToString(), } + return } - } else { - if err := this.ChangeList(session.GetUserId(), hero.Id, update); err != nil { - this.module.Errorf("add hero exp failed ChangeList %v", err) - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), - } - } - } - - if curLv-preLv > 0 { // 升级了 统计任务 - var tasks []*pb.BuriedParam - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype147, utils.ToInt32(hero.HeroID), curLv-preLv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, curLv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype4, hero.Lv, utils.ToInt32(hero.HeroID))) - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype23, hero.HeroID, hero.Star, hero.Lv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype24, curLv-preLv)) - // szTask = append(szTask, comm.GetBuriedParam(comm.Rtype29, 1, hero.Lv, utils.ToInt32(hero.HeroID))) - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype23, hero.HeroID, hero.Star, hero.Lv)) - if cfg, _ := this.module.configure.GetHeroConfig(hero.HeroID); cfg != nil { - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype32, hero.HeroID, cfg.Color, hero.Lv)) - //xx英雄满级、共鸣、觉醒至最高状态 - nextAwaken, _ := this.module.configure.GetHeroAwakenConfig(hero.HeroID, hero.JuexingLv+1) - if nextAwaken == nil { // 达到满级觉醒 - if hero.Lv == this.module.configure.GetHeroMaxLv(hero.Star) { - var _l int32 - talent, err := this.module.modelTalent.GetHerotalent(session.GetUserId()) - if err == nil { - for _, v := range talent { - if v.HeroId == hero.HeroID { - _l = int32(len(v.Talent)) - break - } - } - } - if this.module.configure.GetHeroTalentMaxLv(hero.HeroID) == _l { - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype37, hero.HeroID, cfg.Color)) - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype38, hero.HeroID)) - iHeroId, _ := strconv.Atoi(hero.HeroID) - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype243, hero.HeroID, int32(iHeroId))) - } + update = make(map[string]interface{}, 0) + curExp = hero.Exp + curLv = hero.Lv + preLv = curLv + var maxLv int32 // 校验等级达到上限 + maxLv = this.module.configure.GetHeroMaxLv(hero.Star) + // 校验玩家等级 + if _user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { + if expConf := this.module.configure.GetPlayerlvConf(_user.Lv); expConf != nil { + if maxLv > expConf.HeroLv { + maxLv = expConf.HeroLv // 英雄最大等级限制 } } } - tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype111, hero.HeroID, hero.Lv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype112, 1, hero.Lv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, hero.Lv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype33, 1, 1, hero.Lv)) - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype118, hero.Lv, hero.JuexingLv)) - go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { - this.module.passon.HeroUpLv(session, hero.HeroID, curLv) - this.module.ModuleBuried.TriggerBuried(session, tasks...) - }) + _data := this.module.configure.GetHeroLv(curLv) + if _data == nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + } + return + } + + var maxExp int32 + maxExp = _data.Heroexp + if maxLv <= curLv && curExp >= maxExp { // 加经验之前校验是否达到最大等级 + curAddExp[i] = 0 // 已经满级的时候 + //code = pb.ErrorCode_HeroMaxLv // + this.module.Debugf("英雄已经满级 不需要升级heroid:%s,addexp:%d", hero.Id, exp) + return + } + curExp += exp // 先把经验加上 + for { // 死循环判断一键升级 + if _data.Heroexp == 0 { + curAddExp[i] = exp - (curExp - maxExp) // 减去超过部分的经验 + curExp = 0 + break + } + maxExp = _data.Heroexp + if maxLv <= curLv && curExp >= maxExp { // 设置最大经验和等级 + curAddExp[i] = exp - (curExp - maxExp) // 减去超过部分的经验 + curLv = maxLv + curExp = maxExp + break + } + if maxExp > curExp { // 经验不够升级则不能执行升级操作 + break + } else { // 升级操作 + curExp -= maxExp + curLv += 1 // 经验够了 那么等级+1 + _data = this.module.configure.GetHeroLv(curLv) + if _data == nil { // 等级加失败了 回到原来的等级 + curLv -= 1 + break + } + } + } + + if curAddExp[i] != 0 { + curAddExp[i] = exp // 真正加的经验 + } + + this.module.Debugf("add hero exp :old lv:%d,old exp:%d,new lv:%d,new exp:%d,addexp:%d", hero.Lv, hero.Exp, curLv, curExp, exp) + update["lv"] = curLv + update["exp"] = curExp + + hero.Lv = curLv + hero.Exp = curExp + if curLv-preLv > 0 { // 升级了 统计任务 + if maxlvhero == nil || curLv > maxlvhero.Lv { + maxlvhero = hero + } + this.PropertyCompute(hero) + update["property"] = hero.Property + update["horoscopeProperty"] = hero.HoroscopeProperty + update["talentProperty"] = hero.TalentProperty + update["juexProperty"] = hero.JuexProperty + } + changeupdate[hero.Id] = update + if curLv-preLv > 0 { // 升级了 统计任务 + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype147, utils.ToInt32(hero.HeroID), curLv-preLv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, curLv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype4, hero.Lv, utils.ToInt32(hero.HeroID))) + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype23, hero.HeroID, hero.Star, hero.Lv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype24, curLv-preLv)) + // szTask = append(szTask, comm.GetBuriedParam(comm.Rtype29, 1, hero.Lv, utils.ToInt32(hero.HeroID))) + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype23, hero.HeroID, hero.Star, hero.Lv)) + if cfg, _ := this.module.configure.GetHeroConfig(hero.HeroID); cfg != nil { + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype32, hero.HeroID, cfg.Color, hero.Lv)) + //xx英雄满级、共鸣、觉醒至最高状态 + nextAwaken, _ := this.module.configure.GetHeroAwakenConfig(hero.HeroID, hero.JuexingLv+1) + if nextAwaken == nil { // 达到满级觉醒 + if hero.Lv == this.module.configure.GetHeroMaxLv(hero.Star) { + var _l int32 + talent, err := this.module.modelTalent.GetHerotalent(session.GetUserId()) + if err == nil { + for _, v := range talent { + if v.HeroId == hero.HeroID { + _l = int32(len(v.Talent)) + break + } + } + } + if this.module.configure.GetHeroTalentMaxLv(hero.HeroID) == _l { + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype37, hero.HeroID, cfg.Color)) + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype38, hero.HeroID)) + iHeroId, _ := strconv.Atoi(hero.HeroID) + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype243, hero.HeroID, int32(iHeroId))) + } + } + } + } + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype111, hero.HeroID, hero.Lv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype112, 1, hero.Lv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, hero.Lv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype33, 1, 1, hero.Lv)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype118, hero.Lv, hero.JuexingLv)) + } } + + if model != nil { + if err := model.ChangeLists(session.GetUserId(), changeupdate); err != nil { + this.module.Errorln(err) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + } else { + if err := this.ChangeLists(session.GetUserId(), changeupdate); err != nil { + this.module.Errorln(err) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + } + + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + if maxlvhero != nil { + this.module.passon.HeroUpLv(session, maxlvhero.HeroID, maxlvhero.Lv) + } + this.module.ModuleBuried.TriggerBuried(session, tasks...) + }) return } diff --git a/modules/hero/module.go b/modules/hero/module.go index 678f9a0ce..5eac964e1 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -830,44 +830,67 @@ func (this *Hero) CheckPeachReward(session comm.IUserSession, ctime int64) { } return } + func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp int32) (curAddExp []int32, errdata *pb.ErrorData) { var ( - _hero *pb.DBHero - _changeHero []*pb.DBHero // 变化的英雄 - addExp int32 + ids []string = make([]string, 0) + heros []*pb.DBHero + changeHero []*pb.DBHero // 变化的英雄 + addExp []int32 + err error ) - for _, heroObjID := range heroObjs { - if heroObjID == "" { - continue + curAddExp = make([]int32, len(heroObjs)) + for _, v := range heroObjs { + if v != "" { + ids = append(ids, v) } - if this.IsCross() { - _hero = &pb.DBHero{} - if model, err := this.GetDBModelByUid(session.GetUserId(), this.modelHero.TableName); err == nil { - if err := model.GetListObj(session.GetUserId(), heroObjID, _hero); err != nil { - this.Errorf("err:%v", err) - return - } - addExp, errdata = this.modelHero.AddCardExp(session, _hero, exp, model) - if errdata == nil { - curAddExp = append(curAddExp, addExp) - } - } - } else { - _hero, errdata = this.GetHeroByObjID(session.GetUserId(), heroObjID) - if errdata != nil { - return - } - - addExp, errdata = this.modelHero.AddCardExp(session, _hero, exp, nil) - if errdata != nil { - curAddExp = append(curAddExp, addExp) - } - } - _changeHero = append(_changeHero, _hero) // 升级后的英雄 hero id 不变 } - if len(_changeHero) > 0 { - session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: _changeHero}) + if this.IsCross() { + if model, err := this.GetDBModelByUid(session.GetUserId(), this.modelHero.TableName); err == nil { + if err := model.GetListObjs(session.GetUserId(), ids, &heros); err != nil { + this.Errorf("err:%v", err) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Message: err.Error(), + } + return + } + if addExp, errdata = this.modelHero.AddCardExp(session, heros, exp, model); errdata != nil { + return + } + for i, v := range heros { + for n, id := range heroObjs { + if v.Id == id { + curAddExp[n] = addExp[i] + } + } + } + changeHero = append(changeHero, heros...) + } + } else { + if heros, err = this.modelHero.getHeros(session.GetUserId(), ids); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Message: err.Error(), + } + return + } + + if addExp, errdata = this.modelHero.AddCardExp(session, heros, exp, nil); errdata != nil { + return + } + for i, v := range heros { + for n, id := range heroObjs { + if v.Id == id { + curAddExp[n] = addExp[i] + } + } + } + changeHero = append(changeHero, heros...) + } + if len(changeHero) > 0 { + session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: changeHero}) } return } diff --git a/modules/mainline/api_challengeover.go b/modules/mainline/api_challengeover.go index 60dddde97..191c7de5d 100644 --- a/modules/mainline/api_challengeover.go +++ b/modules/mainline/api_challengeover.go @@ -157,6 +157,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh } return } + session.SetMate(comm.Session_User, user) if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(conf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 { if errdata, atno = this.module.DispenseAtno(session, lotteryward, true); errdata != nil { this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward) diff --git a/modules/user/module.go b/modules/user/module.go index 5d0f67762..7dabc323b 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -477,32 +477,30 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn temp *pb.UserAtno err error ) - - user, err = this.GetUser(uid) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_UserSessionNobeing, - Title: pb.ErrorCode_UserSessionNobeing.ToString(), - Message: err.Error(), + if ok, userMate := session.GetMate(comm.Session_User); ok { + user = userMate.(*pb.DBUser) + } else { + if user, err = this.GetUser(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_UserSessionNobeing, + Title: pb.ErrorCode_UserSessionNobeing.ToString(), + Message: err.Error(), + } + return } - return - } - userEx, err = this.GetUserExpand(uid) - if err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_UserExpandNull, - Title: pb.ErrorCode_UserExpandNull.ToString(), - Message: err.Error(), - } - return } - if user == nil || userEx == nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_UserSessionNobeing, - Title: pb.ErrorCode_UserSessionNobeing.ToString(), + if ok, userMate := session.GetMate(comm.Session_UserExpand); ok { + userEx = userMate.(*pb.DBUserExpand) + } else { + if userEx, err = this.GetUserExpand(uid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_UserExpandNull, + Title: pb.ErrorCode_UserExpandNull.ToString(), + Message: err.Error(), + } + return } - return } change = &pb.UserResChangedPush{