go_dreamfactory/modules/hero/api_talentreset.go
2023-11-13 17:20:35 +08:00

103 lines
3.0 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) (errdata *pb.ErrorData) {
if req.ObjId == "" {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
}
return
}
func (this *apiComp) TalentReset(session comm.IUserSession, req *pb.HeroTalentResetReq) (errdata *pb.ErrorData) {
var (
heroList []*pb.DBHero
chanegCard []*pb.DBHero // 推送属性变化
talentPoint int32 // 已经消耗的天赋点数
)
if errdata = this.TalentResetCheck(session, req); errdata != nil {
return
}
_talent, err1 := this.module.modelTalent.GetHerotalentByObjId(session.GetUserId(), req.ObjId) //根据对象id 获取数据
if err1 != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_TalentErrData,
Title: pb.ErrorCode_TalentErrData.ToString(),
}
return
}
if len(_talent.Talent) == 0 { // 已经是重置状态
errdata = &pb.ErrorData{
Code: pb.ErrorCode_TalentResetState,
Title: pb.ErrorCode_TalentResetState.ToString(),
}
return
}
chanegCard = make([]*pb.DBHero, 0)
// 检查消耗够不够
if errdata = this.module.ConsumeRes(session, this.module.ModuleTools.GetGlobalConf().TalentReset, true); errdata != nil {
return
}
for k := range _talent.Talent {
if conf, err := this.module.configure.GetHeroTalent(k); err == nil {
talentPoint += conf.Point // 获取当前英雄的天赋点数
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
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 errdata = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); errdata != nil {
this.module.Errorf("DispenseRes err,uid:%s,item:%v", session.GetUserId(), res)
} // 返还升级的天赋点数
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), "HeroTalentResetReq", 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) // 添加推送属性变化信息
}
}
}
if len(chanegCard) > 0 {
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: chanegCard})
}
session.SendMsg(string(this.module.GetType()), HeroTalentResetResp, &pb.HeroTalentResetResp{
Telnet: _talent,
})
return
}