go_dreamfactory/modules/practice/api_gymrefresh.go
2023-06-06 11:08:14 +08:00

86 lines
2.3 KiB
Go

package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
)
//参数校验
func (this *apiComp) GymRefreshCheck(session comm.IUserSession, req *pb.PracticeGymRefreshReq) (errdata *pb.ErrorData) {
return
}
///练功请求
func (this *apiComp) GymRefresh(session comm.IUserSession, req *pb.PracticeGymRefreshReq) (errdata *pb.ErrorData) {
var (
err error
room *pb.DBPracticeRoom
confs []*cfg.GamePandamasMrylData
temp []*cfg.GamePandamasMrylData
refreshAtns []*cfg.Gameatn
atn *cfg.Gameatn
)
if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
refreshAtns = this.module.ModuleTools.GetGlobalConf().MrylFlushed
if len(refreshAtns) == 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if int(room.Gymrefresh) < len(refreshAtns) {
atn = refreshAtns[room.Gymrefresh]
} else {
atn = refreshAtns[len(refreshAtns)-1]
}
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{atn}, true); errdata != nil {
return
}
if confs, err = this.module.configure.getGamePandamasMryls(); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
temp = make([]*cfg.GamePandamasMrylData, 0)
//过滤掉当前的buff
for _, v := range confs {
if v.Id != room.Gymaction {
temp = append(temp, v)
}
}
if len(confs) == 0 {
code = pb.ErrorCode_ConfigurationException
return
}
r := rand.New(rand.NewSource(configure.Now().Unix()))
room.Gymaction = temp[r.Perm(len(temp))[0]].Id
room.Gymrefresh++
room.Lastrefresh = configure.Now().Unix()
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"gymaction": room.Gymaction,
"gymrefresh": room.Gymrefresh,
"lastrefresh": room.Lastrefresh,
})
session.SendMsg(string(this.module.GetType()), "gymrefresh", &pb.PracticeGymRefreshResp{Lastaction: room.Gymaction, Refreshnum: room.Gymrefresh})
return
}