go_dreamfactory/modules/hero/api_talentreset.go
2022-11-08 15:06:22 +08:00

65 lines
1.8 KiB
Go

package hero
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) TalentResetCheck(session comm.IUserSession, req *pb.HeroTalentResetReq) (code pb.ErrorCode) {
if req.ObjId == "" {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) TalentReset(session comm.IUserSession, req *pb.HeroTalentResetReq) (code pb.ErrorCode, data proto.Message) {
var (
heroList []*pb.DBHero
chanegCard []*pb.DBHero // 推送属性变化
)
if code = this.TalentResetCheck(session, req); code != pb.ErrorCode_Success {
return
}
_talent, err1 := this.module.modelTalent.GetHerotalentByObjId(session.GetUserId(), req.ObjId) //根据对象id 获取数据
if err1 != nil {
code = pb.ErrorCode_TalentErrData
return
}
if len(_talent.Talent) == 0 { // 已经是重置状态
code = pb.ErrorCode_TalentResetState
return
}
chanegCard = make([]*pb.DBHero, 0)
// 检查消耗够不够
if code = this.module.ConsumeRes(session, this.module.configure.GetGlobalConf().TalentReset, true); code != pb.ErrorCode_Success {
return
}
if len(_talent.Talent) > 0 {
update := make(map[string]interface{}, 0)
szTalent := map[int32]int32{}
update["talent"] = szTalent
_talent.Talent = szTalent
this.module.modelTalent.ChangeHeroTalent(_talent, update)
heroList = this.module.GetHeroList(session.GetUserId())
for _, hero := range heroList {
if hero.HeroID == _talent.HeroId {
this.module.modelHero.cleanTalentProperty(hero)
chanegCard = append(chanegCard, hero) // 添加推送属性变化信息
}
}
}
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: chanegCard})
session.SendMsg(string(this.module.GetType()), HeroTalentResetResp, &pb.HeroTalentResetResp{
Telnet: _talent,
})
return
}