95 lines
2.5 KiB
Go
95 lines
2.5 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 (
|
|
consum *cfg.Gameatn // 获取消耗
|
|
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 _, ok := list.Gotarr[req.Grid]; ok {
|
|
session.SendMsg(string(this.module.GetType()), "latticegrid", &pb.UiGameLatticeGridResp{Data: list})
|
|
return
|
|
}
|
|
// 校验消耗
|
|
if conf, err = this.module.configure.GetLatticeConsumConf(); err != nil {
|
|
consum = &cfg.Gameatn{
|
|
A: conf.Itemget.A,
|
|
T: conf.Itemget.T,
|
|
N: 1,
|
|
}
|
|
}
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{consum}, true); errdata != nil {
|
|
return
|
|
}
|
|
// 校验 是否是宝箱
|
|
latticeConf, err = this.module.configure.GetLatticeConf(list.Val)
|
|
if err != 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, latticeConf.Chestsward, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// 如果是下一关
|
|
if req.Grid == latticeConf.Outpos {
|
|
list.Val += 1
|
|
// 校验是不是达到最大层数
|
|
if _, e := this.module.configure.GetLatticeConf(list.Val); e == nil {
|
|
list.Val -= 1
|
|
}
|
|
update["val"] = list.Val
|
|
if list.Total < list.Val {
|
|
list.Total = list.Val
|
|
update["total"] = list.Total
|
|
}
|
|
}
|
|
list.Gotarr[req.Grid] = 1
|
|
|
|
update["gotarr"] = list.Gotarr
|
|
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), update) // 修改进度
|
|
session.SendMsg(string(this.module.GetType()), "latticegrid", &pb.UiGameLatticeGridResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
return
|
|
}
|