146 lines
4.1 KiB
Go
146 lines
4.1 KiB
Go
package uigame
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) LatticeGridCheck(session comm.IUserSession, req *pb.UiGameLatticeGridReq) (errdata *pb.ErrorData) {
|
|
if req.Hdid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 走迷宫格子
|
|
func (this *apiComp) LatticeGrid(session comm.IUserSession, req *pb.UiGameLatticeGridReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.LatticeGridCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
var (
|
|
latticeConf *cfg.GameUiGameLatticeData
|
|
err error
|
|
atno []*pb.UserAtno
|
|
conf *cfg.GameUiGameConsumData
|
|
)
|
|
update := make(map[string]interface{}, 0)
|
|
list, _ := this.module.modelLattice.getLatticeList(session.GetUserId(), req.Hdid)
|
|
|
|
if latticeConf, err = this.module.configure.GetLatticeConf(list.Floor); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if list.Floor > 1 { // 移动到出生点 直接去上一层
|
|
if latticeConf.Bornpos == req.Grid {
|
|
list.Floor -= 1
|
|
update["floor"] = list.Floor
|
|
list.Curpos = 0
|
|
update["curpos"] = list.Curpos
|
|
this.module.modelLattice.modifyLatticeListByObjId(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), "latticegrid", &pb.UiGameLatticeGridResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
return
|
|
}
|
|
}
|
|
if v1, ok := list.Lattice[list.Floor]; ok {
|
|
if _, ok := v1.Data[req.Grid]; ok {
|
|
list.Curpos = req.Grid
|
|
if req.Grid == latticeConf.Outpos { // 宝箱关
|
|
list.Floor += 1
|
|
// 校验是不是达到最大层数
|
|
if _, e := this.module.configure.GetLatticeConf(list.Floor); e != nil {
|
|
list.Floor -= 1
|
|
} else {
|
|
list.Curpos = 0
|
|
}
|
|
update["floor"] = list.Floor
|
|
if list.Total < list.Floor {
|
|
list.Total = list.Floor
|
|
update["total"] = list.Total
|
|
}
|
|
}
|
|
|
|
update["curpos"] = list.Curpos
|
|
this.module.modelLattice.modifyLatticeListByObjId(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), "latticegrid", &pb.UiGameLatticeGridResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
return
|
|
}
|
|
list.Lattice[list.Floor].Data[req.Grid] = 1
|
|
} else {
|
|
list.Lattice[list.Floor] = &pb.LatticeData{
|
|
Data: map[int32]int32{req.Grid: 1},
|
|
}
|
|
}
|
|
// 校验消耗
|
|
if conf, err = this.module.configure.GetLatticeConsumConf(); err != nil {
|
|
if conf.Cost.N > 0 {
|
|
if errdata = this.module.CheckRes(session, []*cfg.Gameatn{conf.Cost}); errdata != nil { // 消耗校验
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, v := range latticeConf.Chestspos {
|
|
if v == req.Grid { // 发现是宝箱
|
|
if errdata, atno = this.module.DispenseAtno(session, latticeConf.Chestsward, true); errdata != nil {
|
|
return
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if len(atno) == 0 { // 普通格子奖励
|
|
if len(conf.Costget) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Costget, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{conf.Cost}, true); errdata != nil {
|
|
return
|
|
}
|
|
update["lattice"] = list.Lattice
|
|
// 如果是下一关
|
|
if req.Grid == latticeConf.Outpos {
|
|
list.Floor += 1
|
|
// 校验是不是达到最大层数
|
|
if _, e := this.module.configure.GetLatticeConf(list.Floor); e != nil {
|
|
list.Floor -= 1
|
|
} else {
|
|
req.Grid = 0 // 重置出生点
|
|
}
|
|
update["floor"] = list.Floor
|
|
if list.Total < list.Floor {
|
|
list.Total = list.Floor
|
|
update["total"] = list.Total
|
|
}
|
|
}
|
|
|
|
list.Curpos = req.Grid
|
|
update["curpos"] = list.Curpos
|
|
this.module.modelLattice.modifyLatticeListByObjId(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), "latticegrid", &pb.UiGameLatticeGridResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "UiGameLatticeGridReq", atno)
|
|
})
|
|
return
|
|
}
|