go_dreamfactory/modules/practice/api_practice.go
2023-07-04 10:55:43 +08:00

236 lines
7.3 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
heroconf *cfg.GameHeroData
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 heroconf, err = this.module.ModuleTools.GetHeroConfig(hero.HeroID); 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(),
Message: "pillar is no unlock",
}
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(),
Message: "pillar usenum to Limitation",
}
return
}
if req.Teacher != "" {
if room.Knapsack[req.Teacher].State == 1 { //已经被使用
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher:%s is working", req.Teacher),
}
return
}
room.Knapsack[req.Teacher].State = 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 !utils.IsToday(room.Knapsack[req.Teacher].Lastusetime) {
room.Knapsack[req.Teacher].Usenum = 0
}
if room.Knapsack[req.Teacher].Usenum >= tconfigure.Limitation {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher:%s use to Limit", req.Teacher),
}
return
}
room.Knapsack[req.Teacher].Usenum++
if tconfigure.Race != heroconf.Race {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher race:%d and the herorace:%d is race no can use", tconfigure.Race, heroconf.Race),
}
}
if tconfigure.Job != heroconf.Job {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher job:%d and the hero job:%d is race no can use", tconfigure.Job, heroconf.Job),
}
}
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 += int32(float64(pillarconfigure.PlacementDuration) * float64(tconfigure.Duration) / float64(1000))
pillar.Teacher = req.Teacher
}
if req.Prop != "" {
if room.Knapsack[req.Prop].State == 1 { //已经被使用
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
room.Knapsack[req.Prop].State = 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
}
if !utils.IsToday(room.Knapsack[req.Prop].Lastusetime) {
room.Knapsack[req.Teacher].Usenum = 0
}
if room.Knapsack[req.Prop].Usenum >= tconfigure.Limitation {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the prop:%s use to Limit", req.Prop),
}
return
}
room.Knapsack[req.Prop].Usenum++
if pconfigure.Race != heroconf.Race {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher race:%d and the herorace:%d is race no can use", tconfigure.Race, heroconf.Race),
}
}
if pconfigure.Job != heroconf.Job {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("the teacher job:%d and the hero job:%d is race no can use", tconfigure.Job, heroconf.Job),
}
}
extra += int32(float64(pillarconfigure.PlacementDuration) * float64(pconfigure.Duration) / float64(1000))
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
}