优化英雄经验变化

This commit is contained in:
liwei1dao 2023-12-22 11:15:14 +08:00
parent 93f21dfa02
commit 1937244a37
7 changed files with 253 additions and 207 deletions

View File

@ -1164,5 +1164,6 @@ const (
//session Session 临时数据key //session Session 临时数据key
const ( const (
Session_User = "user" Session_User = "user"
Session_UserExpand = "userexpand"
) )

View File

@ -311,16 +311,15 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
heroRecord.Cur = szCards heroRecord.Cur = szCards
update["selectcount"] = heroRecord.Selectcount update["selectcount"] = heroRecord.Selectcount
update["cur"] = heroRecord.Cur update["cur"] = heroRecord.Cur
} else { // 非模拟抽不发奖
this.module.DispenseAtno(session, allres, true)
} }
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
if req.DrawType != 1 { if req.DrawType != 1 {
if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil { // 发放许愿石奖励 allres = append(allres, reward...)
return
} }
if errdata, atno = this.module.DispenseAtno(session, allres, true); errdata != nil { //同意发送奖励
return
} }
session.SendMsg(string(this.module.GetType()), DrawCard, rsp) session.SendMsg(string(this.module.GetType()), DrawCard, rsp)

View File

@ -86,7 +86,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
return 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 return
} }
// 消耗金币 // 消耗金币

View File

@ -169,6 +169,15 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
return hero 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) { 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 ( var (
preLv int32 //加经验之前的等级 tasks []*pb.BuriedParam
curExp int32 // 加经验之后的经验 changeupdate map[string]interface{} = make(map[string]interface{})
curLv int32 // 加经验之后的等级 maxlvhero *pb.DBHero
update map[string]interface{} // 属性变化
) )
if hero == nil { curAddExp = make([]int32, len(heros))
errdata = &pb.ErrorData{ for i, hero := range heros {
Code: pb.ErrorCode_HeroNoExist, var (
Title: pb.ErrorCode_HeroNoExist.ToString(), preLv int32 //加经验之前的等级
} curExp int32 // 加经验之后的经验
return curLv int32 // 加经验之后的等级
} update map[string]interface{} // 属性变化
update = make(map[string]interface{}, 0) )
curExp = hero.Exp if hero == nil {
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)
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_HeroNoExist,
Title: pb.ErrorCode_DBError.ToString(), Title: pb.ErrorCode_HeroNoExist.ToString(),
Message: err.Error(),
} }
return
} }
} else { update = make(map[string]interface{}, 0)
if err := this.ChangeList(session.GetUserId(), hero.Id, update); err != nil { curExp = hero.Exp
this.module.Errorf("add hero exp failed ChangeList %v", err) curLv = hero.Lv
errdata = &pb.ErrorData{ preLv = curLv
Code: pb.ErrorCode_DBError, var maxLv int32 // 校验等级达到上限
Title: pb.ErrorCode_DBError.ToString(), maxLv = this.module.configure.GetHeroMaxLv(hero.Star)
Message: err.Error(), // 校验玩家等级
} 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 // 英雄最大等级限制
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)))
}
} }
} }
} }
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) { _data := this.module.configure.GetHeroLv(curLv)
this.module.passon.HeroUpLv(session, hero.HeroID, curLv) if _data == nil {
this.module.ModuleBuried.TriggerBuried(session, tasks...) 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 return
} }

View File

@ -830,44 +830,67 @@ func (this *Hero) CheckPeachReward(session comm.IUserSession, ctime int64) {
} }
return return
} }
func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp int32) (curAddExp []int32, errdata *pb.ErrorData) { func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp int32) (curAddExp []int32, errdata *pb.ErrorData) {
var ( var (
_hero *pb.DBHero ids []string = make([]string, 0)
_changeHero []*pb.DBHero // 变化的英雄 heros []*pb.DBHero
addExp int32 changeHero []*pb.DBHero // 变化的英雄
addExp []int32
err error
) )
for _, heroObjID := range heroObjs { curAddExp = make([]int32, len(heroObjs))
if heroObjID == "" { for _, v := range heroObjs {
continue 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 { if this.IsCross() {
session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: _changeHero}) 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 return
} }

View File

@ -157,6 +157,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh
} }
return return
} }
session.SetMate(comm.Session_User, user)
if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(conf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 { 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 { if errdata, atno = this.module.DispenseAtno(session, lotteryward, true); errdata != nil {
this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward) this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward)

View File

@ -477,32 +477,30 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn
temp *pb.UserAtno temp *pb.UserAtno
err error err error
) )
if ok, userMate := session.GetMate(comm.Session_User); ok {
user, err = this.GetUser(uid) user = userMate.(*pb.DBUser)
if err != nil { } else {
errdata = &pb.ErrorData{ if user, err = this.GetUser(session.GetUserId()); err != nil {
Code: pb.ErrorCode_UserSessionNobeing, errdata = &pb.ErrorData{
Title: pb.ErrorCode_UserSessionNobeing.ToString(), Code: pb.ErrorCode_UserSessionNobeing,
Message: err.Error(), 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 { if ok, userMate := session.GetMate(comm.Session_UserExpand); ok {
errdata = &pb.ErrorData{ userEx = userMate.(*pb.DBUserExpand)
Code: pb.ErrorCode_UserSessionNobeing, } else {
Title: pb.ErrorCode_UserSessionNobeing.ToString(), 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{ change = &pb.UserResChangedPush{