84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package island
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.IsLandUpgradeReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.IsLandUpgradeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBIsland
|
|
conf *cfg.GamePuggsySkillData
|
|
front *cfg.GamePuggsySkillData
|
|
err error
|
|
)
|
|
if errdata = this.UpgradeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.model.getmodel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf, err = this.module.configure.getGamePuggsySkillData(req.Nid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf.CostItem != nil && len(conf.CostItem) > 0 { //可有升级
|
|
for _, _front := range conf.Front {
|
|
if _front > 0 {
|
|
if front, err = this.module.configure.getGamePuggsySkillData(_front); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if v, ok := info.Nodes[front.NodeId]; !ok || v < front.Lv {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "node Front no complete",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "The level has reached the upper limit",
|
|
}
|
|
return
|
|
}
|
|
if errdata = this.module.ConsumeRes(session, conf.CostItem, true); errdata != nil {
|
|
return
|
|
}
|
|
info.Nodes[conf.NodeId] = conf.Lv + 1
|
|
this.module.model.Change(session.GetUserId(), map[string]interface{}{
|
|
"nodes": info.Nodes,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "upgrade", &pb.IsLandUpgradeResp{Nid: conf.NodeId, Lv: info.Nodes[conf.NodeId]})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "IsLandUpgradeReq", conf.CostItem)
|
|
})
|
|
return
|
|
}
|