98 lines
3.3 KiB
Go
98 lines
3.3 KiB
Go
package hero
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/pb"
|
||
cfg "go_dreamfactory/sys/configure/structs"
|
||
"go_dreamfactory/utils"
|
||
|
||
"google.golang.org/protobuf/proto"
|
||
)
|
||
|
||
//参数校验
|
||
func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode) {
|
||
if req.HeroObjID == "" {
|
||
code = pb.ErrorCode_ReqParameterError
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
/// 英雄升星
|
||
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode, data proto.Message) {
|
||
var (
|
||
starConf *cfg.GameHeroStarupData // 配置表目标升星英雄信息
|
||
_hero *pb.DBHero // 目标英雄
|
||
)
|
||
|
||
code = this.StrengthenUpStarCheck(session, req) // check
|
||
if code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID)
|
||
if code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
|
||
// 校验指定英雄
|
||
starConf = this.module.configure.GetHeroStarupConfig(_hero.HeroID, _hero.Star)
|
||
if starConf == nil {
|
||
code = pb.ErrorCode_ReqParameterError
|
||
return
|
||
}
|
||
heroConf := this.module.configure.GetHeroConfig(_hero.HeroID)
|
||
nextHeroConfig := this.module.configure.GetHeroStarupConfig(_hero.HeroID, _hero.Star+1)
|
||
if nextHeroConfig == nil && heroConf.Type != comm.CardTypeStar {
|
||
code = pb.ErrorCode_HeroMaxStarLv
|
||
return
|
||
}
|
||
|
||
if code = this.module.ConsumeRes(session, starConf.Needrace, true); code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
|
||
// 加对应的天赋点数
|
||
if len(starConf.Starup) > 0 {
|
||
if code = this.module.DispenseRes(session, starConf.Starup, true); code != pb.ErrorCode_Success { // 加天赋点{
|
||
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.Property,
|
||
"property": _hero.TalentProperty,
|
||
"juexProperty": _hero.JuexProperty,
|
||
"horoscopeProperty": _hero.HoroscopeProperty,
|
||
}
|
||
|
||
// 保存数据
|
||
err := this.module.modelHero.ChangeList(session.GetUserId(), _hero.Id, _heroMap)
|
||
if err != nil {
|
||
code = pb.ErrorCode_DBError
|
||
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())
|
||
}
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype6, utils.ToInt32(_hero.HeroID), _hero.Star)
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype25, 1, utils.ToInt32(_hero.HeroID), _hero.Star)
|
||
if _hero.Star == 4 {
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype26, 1)
|
||
} else if _hero.Star == 5 {
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype27, 1)
|
||
} else if _hero.Star == 6 {
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype28, 1)
|
||
}
|
||
this.module.ModuleRtask.SendToRtask(session, comm.Rtype115, utils.ToInt32(_hero.HeroID), _hero.Star)
|
||
return
|
||
}
|