120 lines
3.9 KiB
Go
120 lines
3.9 KiB
Go
package hero
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/pb"
|
||
cfg "go_dreamfactory/sys/configure/structs"
|
||
"go_dreamfactory/utils"
|
||
)
|
||
|
||
//参数校验
|
||
func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (errdata *pb.ErrorData) {
|
||
if req.HeroObjID == "" {
|
||
errdata = &pb.ErrorData{
|
||
Code: pb.ErrorCode_ReqParameterError,
|
||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
/// 英雄升星
|
||
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (errdata *pb.ErrorData) {
|
||
var (
|
||
starConf *cfg.GameHeroStarupData // 配置表目标升星英雄信息
|
||
_hero *pb.DBHero // 目标英雄
|
||
err error
|
||
)
|
||
if errdata = this.StrengthenUpStarCheck(session, req); errdata != nil {
|
||
return
|
||
}
|
||
if _hero, errdata = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID); errdata != nil {
|
||
return
|
||
}
|
||
|
||
// 校验指定英雄
|
||
if starConf, err = this.module.configure.GetHeroStarupConfig(_hero.HeroID, _hero.Star); err != nil {
|
||
errdata = &pb.ErrorData{
|
||
Code: pb.ErrorCode_ConfigNoFound,
|
||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||
Message: err.Error(),
|
||
}
|
||
return
|
||
}
|
||
if _, err = this.module.configure.GetHeroConfig(_hero.HeroID); err != nil {
|
||
errdata = &pb.ErrorData{
|
||
Code: pb.ErrorCode_ConfigNoFound,
|
||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||
Message: err.Error(),
|
||
}
|
||
return
|
||
}
|
||
nextHeroConfig, _ := this.module.configure.GetHeroStarupConfig(_hero.HeroID, _hero.Star+1)
|
||
if nextHeroConfig == nil {
|
||
errdata = &pb.ErrorData{
|
||
Code: pb.ErrorCode_HeroMaxStarLv,
|
||
Title: pb.ErrorCode_HeroMaxStarLv.ToString(),
|
||
}
|
||
return
|
||
}
|
||
|
||
if errdata = this.module.ConsumeRes(session, starConf.Needrace, true); errdata != nil {
|
||
return
|
||
}
|
||
|
||
// 加对应的天赋点数
|
||
if len(starConf.Starup) > 0 {
|
||
if errdata = this.module.DispenseRes(session, starConf.Starup, true); errdata != nil { // 加天赋点{
|
||
this.module.Errorf("DispenseRes err:uid:%s,res:%v", session.GetUserId(), starConf.Starup)
|
||
}
|
||
}
|
||
|
||
_hero.Star += 1
|
||
this.module.modelHero.PropertyCompute(_hero) // 重新计算属性
|
||
_heroMap := map[string]interface{}{
|
||
"star": _hero.Star,
|
||
"talentProperty": _hero.TalentProperty,
|
||
"property": _hero.Property,
|
||
"juexProperty": _hero.JuexProperty,
|
||
"horoscopeProperty": _hero.HoroscopeProperty,
|
||
}
|
||
|
||
// 保存数据
|
||
err = this.module.modelHero.ChangeList(session.GetUserId(), _hero.Id, _heroMap)
|
||
if err != nil {
|
||
errdata = &pb.ErrorData{
|
||
Code: pb.ErrorCode_DBError,
|
||
Title: pb.ErrorCode_DBError.ToString(),
|
||
Message: err.Error(),
|
||
}
|
||
this.module.Errorf("update hero star failed:%v", err)
|
||
}
|
||
|
||
session.SendMsg(string(this.module.GetType()), StrengthenUpStar, &pb.HeroStrengthenUpStarResp{Hero: _hero})
|
||
|
||
//英雄升星 【玩家名称】已将【英雄名称】培养至6星!
|
||
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
||
this.chat.SendSysChatToWorld(comm.ChatSystem8, nil, _hero.Lv, 0, user.Name, _hero.HeroID)
|
||
} else {
|
||
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
||
}
|
||
|
||
// 推送 世界任务消息
|
||
var szTask []*pb.BuriedParam
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype6, _hero.Star, utils.ToInt32(_hero.HeroID)))
|
||
szTask = append(szTask, comm.GetBuriedParam2(comm.Rtype25, _hero.HeroID, _hero.Star))
|
||
if _hero.Star == 4 {
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype26, 1))
|
||
|
||
} else if _hero.Star == 5 {
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype27, 1))
|
||
} else if _hero.Star == 6 {
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype28, 1))
|
||
}
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype114, _hero.Star, utils.ToInt32(_hero.HeroID)))
|
||
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype115, 1, _hero.Star))
|
||
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), szTask...)
|
||
return
|
||
}
|