104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) LvRewardCheck(session comm.IUserSession, req *pb.HeroLvRewardReq) (errdata *pb.ErrorData) {
|
|
if req.Heroid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "Heroid is Empty",
|
|
}
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// / 英雄觉醒
|
|
func (this *apiComp) LvReward(session comm.IUserSession, req *pb.HeroLvRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
hero *pb.DBHero
|
|
confs []*cfg.GameHeroLeveluprewardData
|
|
conf *cfg.GameHeroLeveluprewardData
|
|
give []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
ok bool
|
|
err error
|
|
)
|
|
if hero, errdata = this.module.GetHeroByObjID(session.GetUserId(), req.Heroid); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if req.Index == 0 {
|
|
|
|
if confs, err = this.module.configure.GetHeroLvUpWardDatas(hero.Star); err == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, conf = range confs {
|
|
if conf.Level <= hero.Lv {
|
|
if _, ok = hero.Lvreward[conf.Level]; !ok {
|
|
give = append(give, conf.Starup...)
|
|
hero.Lvreward[conf.Level] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
} else {
|
|
if req.Index > hero.Lv {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "index more than the hero.Lv",
|
|
}
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.GetHeroLvUpWardData(hero.Star, req.Index); err == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if _, ok = hero.Lvreward[req.Index]; !ok {
|
|
give = append(give, conf.Starup...)
|
|
hero.Lvreward[req.Index] = true
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "Received",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if errdata, atno = this.module.DispenseAtno(session, give, true); errdata != nil {
|
|
return
|
|
}
|
|
// 保存数据
|
|
if err = this.module.modelHero.ChangeList(session.GetUserId(), hero.Id, map[string]interface{}{
|
|
"lvreward": hero.Lvreward,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "lvreward", &pb.HeroLvRewardResp{
|
|
Heroid: req.Heroid,
|
|
Lvreward: hero.Lvreward,
|
|
Atno: atno,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "HeroLvRewardResp", atno)
|
|
})
|
|
return
|
|
}
|