go_dreamfactory/modules/practice/api_loot.go
2023-04-11 13:54:50 +08:00

105 lines
3.3 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) LootCheck(session comm.IUserSession, req *pb.PracticeLootReq) (code pb.ErrorCode) {
return
}
///练功请求 蹭馆
func (this *apiComp) Loot(session comm.IUserSession, req *pb.PracticeLootReq) (code pb.ErrorCode, data proto.Message) {
var (
err error
froom *pb.DBPracticeRoom
room *pb.DBPracticeRoom
pillarconfigure *cfg.GamePandamasMzData
tconfigure *cfg.GamePandamasJxData
pconfigure *cfg.GamePandamasJxData
extra int32 = 0
)
if froom, err = this.module.modelPandata.queryUserMartialhall(req.Friend); err != nil {
code = pb.ErrorCode_DBError
return
}
if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
if froom.Pillarf.Hero != "" {
code = pb.ErrorCode_ReqParameterError
}
if pillarconfigure, err = this.module.configure.getGamePandamasMz(froom.Pillarf.Lv); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.ModuleHero.KungFuHero(session, req.Hero, true, req.Friend); 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
froom.Pillarf.Teacher = req.Teacher
}
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
froom.Pillarf.Prop = req.Prop
}
froom.Pillarf.Uid = session.GetUserId()
froom.Pillarf.Hero = req.Hero
froom.Pillarf.Start = configure.Now().Unix()
if extra >= 0 {
froom.Pillarf.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
froom.Pillarf.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
} else {
froom.Pillarf.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
froom.Pillarf.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
}
this.module.modelPandata.Change(req.Friend, map[string]interface{}{
"pillarf": froom.Pillarf,
})
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
})
if _session, ok := this.module.GetUserSession(req.Friend); ok {
_session.SendMsg(string(this.module.GetType()), "rommchange", &pb.PracticeRommChangePush{Info: froom})
if err = _session.Push(); err != nil {
this.module.Errorln(err)
}
this.module.PutUserSession(_session)
} else {
this.module.PutUserSession(_session)
}
session.SendMsg(string(this.module.GetType()), "loot", &pb.PracticeLootResp{Friend: req.Friend, Pillar: froom.Pillarf})
return
}