go_dreamfactory/modules/practice/api_practice.go
2023-07-03 11:22:55 +08:00

174 lines
4.9 KiB
Go

package practice
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"time"
)
// 参数校验
func (this *apiComp) PracticeCheck(session comm.IUserSession, req *pb.PracticePracticeReq) (errdata *pb.ErrorData) {
return
}
// /练功请求 练功
func (this *apiComp) Practice(session comm.IUserSession, req *pb.PracticePracticeReq) (errdata *pb.ErrorData) {
var (
err error
room *pb.DBPracticeRoom
hero *pb.DBHero
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 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if hero, err = this.module.ModuleHero.QueryCrossHeroinfo(req.Hero); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: fmt.Sprintf("no found hero:%s", req.Hero),
}
return
}
if tconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
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 pillar.Isunlock != 2 { //柱子未解锁
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if utils.IsToday(pillar.Lastusetime) { //上一次训练不是今天
pillar.Usenum = 0
}
if pillar.Usenum >= pillarconfigure.Limitation {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_PracticeUseLimit,
Title: pb.ErrorCode_PracticeUseLimit.ToString(),
}
return
}
if req.Teacher != "" {
if room.Knapsack[req.Teacher] == 1 { //已经被使用
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
room.Knapsack[req.Teacher] = 1
if tconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if tconfigure.BanHero == hero.HeroID { //禁止使用
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("teacher:%s and hero:%s no can together", req.Teacher, hero.HeroID),
}
return
}
extra += tconfigure.Duration
pillar.Teacher = req.Teacher
}
if req.Prop != "" {
if room.Knapsack[req.Prop] == 1 { //已经被使用
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
room.Knapsack[req.Prop] = 1
if pconfigure, err = this.module.configure.getGamePandamasJx(req.Prop); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
extra += pconfigure.Duration
pillar.Prop = req.Prop
}
pillar.Hero = req.Hero
if errdata = this.module.ModuleHero.KungFuHero(session, req.Hero, true, ""); errdata != nil {
return
}
pillar.Start = configure.Now().Unix()
if extra >= 0 {
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
} else {
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
}
pillar.Usenum++
pillar.Lastusetime = configure.Now().Unix()
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
filed: pillar,
})
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype149, 1))
session.SendMsg(string(this.module.GetType()), "practice", &pb.PracticePracticeResp{Pillar: pillar})
return
}