go_dreamfactory/modules/exclusive/api_addexp.go
2024-02-27 14:17:15 +08:00

63 lines
1.6 KiB
Go

package exclusive
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
func (this *apiComp) AddExpCheck(session comm.IUserSession, req *pb.ExclusiveAddExpReq) (errdata *pb.ErrorData) {
return
}
///获取用户装备列表
func (this *apiComp) AddExp(session comm.IUserSession, req *pb.ExclusiveAddExpReq) (errdata *pb.ErrorData) {
var (
info *pb.DB_Exclusive
confs map[string]*cfg.GameExclusiveItemData = make(map[string]*cfg.GameExclusiveItemData)
conf *cfg.GameExclusiveItemData
need []*cfg.Gameatn = make([]*cfg.Gameatn, 0)
err error
)
if info, err = this.module.model.getExclusivesById(session.GetUserId(), req.Oid); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
for k, n := range req.Items {
if conf, err = this.module.configure.GetGameExclusiveItem(k); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Message: err.Error(),
}
return
}
confs[k] = conf
need = append(need, &cfg.Gameatn{
A: comm.ItemType,
T: k,
N: n,
})
info.Exp += conf.Exp * n
}
if errdata = this.module.ConsumeRes(session, need, true); errdata != nil {
return
}
if err = this.module.model.updateExclusive(session.GetUserId(), info); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
this.module.equipmentsChangePush(session, []*pb.DB_Exclusive{info})
session.SendMsg(string(this.module.GetType()), "addExp", &pb.ExclusiveAddExpResp{Exclusives: info})
return
}