go_dreamfactory/modules/reputation/api_upgrade.go
2023-04-20 14:40:55 +08:00

71 lines
1.7 KiB
Go

package reputation
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
// 天赋树升级
func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.ReputationUpgradeReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.ReputationUpgradeReq) (code pb.ErrorCode, data *pb.ErrorData) {
//
uid := session.GetUserId()
rsp := &pb.ReputationUpgradeResp{}
talentCfg := this.module.configure.getTalentNodeCfg(req.NodeId)
if talentCfg == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
reputation := this.module.modelReputation.getDBReputation(uid)
if reputation == nil {
code = pb.ErrorCode_DataNotFound
return
}
camp, ok := reputation.Camps[talentCfg.Type]
if !ok {
reputation.Camps[talentCfg.Type] = &pb.Camp{}
}
if code = this.module.CheckRes(session, talentCfg.IconCos); code != pb.ErrorCode_Success {
return
}
if camp != nil {
if len(camp.Nodes) == 0 {
camp.Nodes = append(camp.Nodes, &pb.TalentNode{
Nid: req.NodeId,
})
} else {
for _, v := range camp.Nodes {
//判断是否满级
if req.NodeId == v.Nid && v.Status == 2 {
code = pb.ErrorCode_ReputationTalentFull
return
} else if req.NodeId == v.Nid {
//消耗
if c := this.module.ConsumeRes(session, talentCfg.IconCos, true); c == pb.ErrorCode_Success {
v.Status = 1
camp.CampAttr = this.module.modelReputation.computeAttr(camp.CampAttr, talentCfg.Attribute)
}
break
}
}
}
update := map[string]interface{}{
"camps": reputation.Camps,
}
this.module.modelReputation.updateDBReputation(uid, update)
}
session.SendMsg(string(this.module.GetType()), "upgrade", rsp)
return
}