go_dreamfactory/modules/practice/api_practice.go
2023-02-23 18:32:45 +08:00

95 lines
2.5 KiB
Go

package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"time"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) PracticeCheck(session comm.IUserSession, req *pb.PracticePracticeReq) (code pb.ErrorCode) {
return
}
///练功请求 练功
func (this *apiComp) Practice(session comm.IUserSession, req *pb.PracticePracticeReq) (code pb.ErrorCode, data proto.Message) {
var (
err error
room *pb.DBPracticeRoom
pillar *pb.DBPracticePillar
pillarconfigure *cfg.GamePandamasMzData
tconfigure *cfg.GamePandamasJxData
pconfigure *cfg.GamePandamasJxData
extra int32 = 0
filed string
)
if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
switch req.Index {
case 1:
pillar = room.Pillar1
filed = "pillar1"
break
case 2:
pillar = room.Pillar2
filed = "pillar2"
break
case 3:
pillar = room.Pillar3
filed = "pillar3"
break
case 4:
pillar = room.Pillarf
filed = "pillarf"
break
}
if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.ModuleHero.KungFuHero(session, req.Hero, true); code != pb.ErrorCode_Success {
return
}
if req.Teacher != "" {
if room.Knapsack[req.Teacher] == 1 { //已经被使用
code = pb.ErrorCode_ReqParameterError
return
}
room.Knapsack[req.Teacher] = 1
if tconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
extra += tconfigure.Duration
}
if req.Prop != "" {
if room.Knapsack[req.Prop] == 1 { //已经被使用
code = pb.ErrorCode_ReqParameterError
return
}
room.Knapsack[req.Prop] = 1
if pconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
extra += pconfigure.Duration
}
pillar.Hero = req.Hero
pillar.Start = configure.Now().Unix()
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
filed: pillar,
})
session.SendMsg(string(this.module.GetType()), "practice", &pb.PracticePracticeResp{Index: req.Index, Hero: req.Hero, Teacher: req.Teacher, Prop: req.Prop})
return
}