86 lines
2.6 KiB
Go
86 lines
2.6 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
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 *pb.ErrorData) {
|
|
var (
|
|
heroList []*pb.DBHero
|
|
chanegCard []*pb.DBHero // 推送属性变化
|
|
talentPoint int32 // 已经消耗的天赋点数
|
|
)
|
|
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.ModuleTools.GetGlobalConf().TalentReset, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
for k := range _talent.Talent {
|
|
if conf, err := this.module.configure.GetHeroTalent(k); err == nil {
|
|
talentPoint += conf.Point // 获取当前英雄的天赋点数
|
|
} else {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
data.Message = err.Error()
|
|
return
|
|
}
|
|
}
|
|
if t := this.module.configure.GetHeroTalentBoxItem(_talent.HeroId); t != "" {
|
|
res := &cfg.Gameatn{
|
|
A: "item",
|
|
T: t,
|
|
N: talentPoint,
|
|
}
|
|
this.module.Debugf("返还天赋的点数%d,itemID=%s", talentPoint, t)
|
|
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
|
|
this.module.Errorf("DispenseRes err,uid:%s,item:%v", session.GetUserId(), res)
|
|
} // 返还升级的天赋点数
|
|
}
|
|
|
|
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
|
|
}
|