110 lines
2.7 KiB
Go
110 lines
2.7 KiB
Go
package reputation
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 天赋树升级
|
|
func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.ReputationUpgradeReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.ReputationUpgradeReq) (errdata *pb.ErrorData) {
|
|
|
|
uid := session.GetUserId()
|
|
rsp := &pb.ReputationUpgradeResp{}
|
|
|
|
reputation := this.module.modelReputation.getDBReputation(uid)
|
|
if reputation == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DataNotFound,
|
|
Title: pb.ErrorCode_DataNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
camp, ok := reputation.Camps[req.RaceType]
|
|
if !ok {
|
|
reputation.Camps[req.RaceType] = &pb.Camp{}
|
|
}
|
|
|
|
var nodeLv int32
|
|
if len(camp.Nodes) == 0 {
|
|
nodeLv = 1
|
|
} else {
|
|
for _, n := range camp.Nodes {
|
|
if n.Nid == req.NodeId {
|
|
nodeLv = n.Lv + 1
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
talentCfg := this.module.configure.getTalentNodeCfgBy(req.NodeId, nodeLv)
|
|
if talentCfg == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.CheckRes(session, talentCfg.IconCos); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if camp != nil {
|
|
if len(camp.Nodes) == 0 {
|
|
//消耗
|
|
if c := this.module.ConsumeRes(session, talentCfg.IconCos, true); c == nil {
|
|
camp.Nodes = append(camp.Nodes, &pb.TalentNode{
|
|
Nid: req.NodeId,
|
|
Lv: 1,
|
|
Status: 1,
|
|
})
|
|
camp.CampAttr = this.module.modelReputation.computeAttr(camp.CampAttr, talentCfg.Attribute)
|
|
}
|
|
} else {
|
|
for _, v := range camp.Nodes {
|
|
//判断是否满级
|
|
if req.NodeId == v.Nid && v.Status == 2 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReputationTalentFull,
|
|
Title: pb.ErrorCode_ReputationTalentFull.ToString(),
|
|
}
|
|
return
|
|
} else if req.NodeId == v.Nid {
|
|
if !this.module.modelReputation.isReachPreNode(reputation, req.RaceType, talentCfg.PreNode, talentCfg.PreNodeLv) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReputationNoPreNodeLv,
|
|
Title: pb.ErrorCode_ReputationNoPreNodeLv.ToString(),
|
|
}
|
|
return
|
|
}
|
|
//消耗
|
|
if c := this.module.ConsumeRes(session, talentCfg.IconCos, true); c == nil {
|
|
|
|
v.Lv++
|
|
camp.CampAttr = this.module.modelReputation.computeAttr(camp.CampAttr, talentCfg.Attribute)
|
|
if talentCfg.NodeLv == v.Lv {
|
|
v.Status = 2
|
|
} else {
|
|
v.Status = 1
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
update := map[string]interface{}{
|
|
"camps": reputation.Camps,
|
|
}
|
|
this.module.modelReputation.updateDBReputation(uid, update)
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "upgrade", rsp)
|
|
|
|
return
|
|
}
|