优化英雄经验变化

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

@ -1165,4 +1165,5 @@ 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,7 +398,14 @@ 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 (
tasks []*pb.BuriedParam
changeupdate map[string]interface{} = make(map[string]interface{})
maxlvhero *pb.DBHero
)
curAddExp = make([]int32, len(heros))
for i, hero := range heros {
var ( var (
preLv int32 //加经验之前的等级 preLv int32 //加经验之前的等级
curExp int32 // 加经验之后的经验 curExp int32 // 加经验之后的经验
@ -430,7 +446,7 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
var maxExp int32 var maxExp int32
maxExp = _data.Heroexp maxExp = _data.Heroexp
if maxLv <= curLv && curExp >= maxExp { // 加经验之前校验是否达到最大等级 if maxLv <= curLv && curExp >= maxExp { // 加经验之前校验是否达到最大等级
curAddExp = 0 // 已经满级的时候 curAddExp[i] = 0 // 已经满级的时候
//code = pb.ErrorCode_HeroMaxLv // //code = pb.ErrorCode_HeroMaxLv //
this.module.Debugf("英雄已经满级 不需要升级heroid:%s,addexp:%d", hero.Id, exp) this.module.Debugf("英雄已经满级 不需要升级heroid:%s,addexp:%d", hero.Id, exp)
return return
@ -438,13 +454,13 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
curExp += exp // 先把经验加上 curExp += exp // 先把经验加上
for { // 死循环判断一键升级 for { // 死循环判断一键升级
if _data.Heroexp == 0 { if _data.Heroexp == 0 {
curAddExp = exp - (curExp - maxExp) // 减去超过部分的经验 curAddExp[i] = exp - (curExp - maxExp) // 减去超过部分的经验
curExp = 0 curExp = 0
break break
} }
maxExp = _data.Heroexp maxExp = _data.Heroexp
if maxLv <= curLv && curExp >= maxExp { // 设置最大经验和等级 if maxLv <= curLv && curExp >= maxExp { // 设置最大经验和等级
curAddExp = exp - (curExp - maxExp) // 减去超过部分的经验 curAddExp[i] = exp - (curExp - maxExp) // 减去超过部分的经验
curLv = maxLv curLv = maxLv
curExp = maxExp curExp = maxExp
break break
@ -462,8 +478,8 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
} }
} }
if curAddExp != 0 { if curAddExp[i] != 0 {
curAddExp = exp // 真正加的经验 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) 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)
@ -473,34 +489,17 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
hero.Lv = curLv hero.Lv = curLv
hero.Exp = curExp hero.Exp = curExp
if curLv-preLv > 0 { // 升级了 统计任务 if curLv-preLv > 0 { // 升级了 统计任务
if maxlvhero == nil || curLv > maxlvhero.Lv {
maxlvhero = hero
}
this.PropertyCompute(hero) this.PropertyCompute(hero)
update["property"] = hero.Property update["property"] = hero.Property
update["horoscopeProperty"] = hero.HoroscopeProperty update["horoscopeProperty"] = hero.HoroscopeProperty
update["talentProperty"] = hero.TalentProperty update["talentProperty"] = hero.TalentProperty
update["juexProperty"] = hero.JuexProperty update["juexProperty"] = hero.JuexProperty
} }
if model != nil { changeupdate[hero.Id] = update
if err := model.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(),
}
}
} 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 { // 升级了 统计任务 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.Rtype147, utils.ToInt32(hero.HeroID), curLv-preLv))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, curLv)) 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.GetBuriedParam(comm.Rtype4, hero.Lv, utils.ToInt32(hero.HeroID)))
@ -538,12 +537,37 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype113, 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.Rtype33, 1, 1, hero.Lv))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype118, hero.Lv, hero.JuexingLv)) 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) { go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.passon.HeroUpLv(session, hero.HeroID, curLv) if maxlvhero != nil {
this.module.passon.HeroUpLv(session, maxlvhero.HeroID, maxlvhero.Lv)
}
this.module.ModuleBuried.TriggerBuried(session, tasks...) 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() { if this.IsCross() {
_hero = &pb.DBHero{}
if model, err := this.GetDBModelByUid(session.GetUserId(), this.modelHero.TableName); err == nil { if model, err := this.GetDBModelByUid(session.GetUserId(), this.modelHero.TableName); err == nil {
if err := model.GetListObj(session.GetUserId(), heroObjID, _hero); err != nil { if err := model.GetListObjs(session.GetUserId(), ids, &heros); err != nil {
this.Errorf("err:%v", err) this.Errorf("err:%v", err)
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return return
} }
addExp, errdata = this.modelHero.AddCardExp(session, _hero, exp, model) if addExp, errdata = this.modelHero.AddCardExp(session, heros, exp, model); errdata != nil {
if errdata == nil { return
curAddExp = append(curAddExp, addExp)
} }
for i, v := range heros {
for n, id := range heroObjs {
if v.Id == id {
curAddExp[n] = addExp[i]
}
}
}
changeHero = append(changeHero, heros...)
} }
} else { } else {
_hero, errdata = this.GetHeroByObjID(session.GetUserId(), heroObjID) if heros, err = this.modelHero.getHeros(session.GetUserId(), ids); err != nil {
if errdata != nil { errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return return
} }
addExp, errdata = this.modelHero.AddCardExp(session, _hero, exp, nil) if addExp, errdata = this.modelHero.AddCardExp(session, heros, exp, nil); errdata != nil {
if errdata != nil { return
curAddExp = append(curAddExp, addExp) }
for i, v := range heros {
for n, id := range heroObjs {
if v.Id == id {
curAddExp[n] = addExp[i]
} }
} }
_changeHero = append(_changeHero, _hero) // 升级后的英雄 hero id 不变
} }
changeHero = append(changeHero, heros...)
if len(_changeHero) > 0 { }
session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: _changeHero}) 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,9 +477,10 @@ 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 {
if user, err = this.GetUser(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing, Code: pb.ErrorCode_UserSessionNobeing,
Title: pb.ErrorCode_UserSessionNobeing.ToString(), Title: pb.ErrorCode_UserSessionNobeing.ToString(),
@ -487,8 +488,12 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn
} }
return return
} }
userEx, err = this.GetUserExpand(uid) }
if err != nil {
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{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserExpandNull, Code: pb.ErrorCode_UserExpandNull,
Title: pb.ErrorCode_UserExpandNull.ToString(), Title: pb.ErrorCode_UserExpandNull.ToString(),
@ -496,13 +501,6 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn
} }
return return
} }
if user == nil || userEx == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserSessionNobeing,
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
}
return
} }
change = &pb.UserResChangedPush{ change = &pb.UserResChangedPush{