go_dreamfactory/modules/library/api_activationfetter.go
2023-06-19 18:25:34 +08:00

61 lines
1.7 KiB
Go

package library
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
//参数校验
func (this *apiComp) ActivationFetterCheck(session comm.IUserSession, req *pb.LibraryActivationFetterReq) (errdata *pb.ErrorData) {
if req.Oid == "" {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
}
return
}
func (this *apiComp) ActivationFetter(session comm.IUserSession, req *pb.LibraryActivationFetterReq) (errdata *pb.ErrorData) {
if errdata = this.ActivationFetterCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
rsp := &pb.LibraryActivationFetterResp{}
fetter := this.module.modelLibrary.getOneLibrary(session.GetUserId(), req.Oid)
if fetter == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_LibraryNoData,
Title: pb.ErrorCode_LibraryNoData.ToString(),
}
return
}
if fetter.Fidlv != 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_LibraryActivation,
Title: pb.ErrorCode_LibraryActivation.ToString(),
}
return
}
// 检查是否有这几个英雄
c, _ := this.module.configure.GetFriendData(fetter.Fid, 1)
if len(fetter.Herofetter) != len(c) {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_LibraryNoData,
Title: fmt.Sprintf("羁绊英雄数据数量不足,needLen :%d,curLen :%d", len(c), len(fetter.Herofetter)),
}
return
}
fetter.Fidlv = 1
mapData := make(map[string]interface{}, 0)
mapData["fidlv"] = fetter.Fidlv
this.module.modelLibrary.modifyLibraryDataByObjId(session.GetUserId(), fetter.Id, mapData)
rsp.Data = fetter
session.SendMsg(string(this.module.GetType()), LibraryActivationFetterResp, rsp)
return
}