74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package uigame
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) PuzzleGridCheck(session comm.IUserSession, req *pb.UiGamePuzzleGridReq) (errdata *pb.ErrorData) {
|
|
if req.Hdid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 点击某个格子进行拼图
|
|
func (this *apiComp) PuzzleGrid(session comm.IUserSession, req *pb.UiGamePuzzleGridReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.PuzzleGridCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
var (
|
|
atno []*pb.UserAtno
|
|
res []*cfg.Gameatn
|
|
)
|
|
list, _ := this.module.modelPuzzle.getPuzzleList(session.GetUserId(), req.Hdid)
|
|
if _, ok := list.Puzzle[req.Grid]; ok { // 重复拼图
|
|
return
|
|
}
|
|
|
|
// 校验消耗
|
|
if conf, err := this.module.configure.GetPuzzleConsumConf(); err == nil {
|
|
if conf.Cost.N > 0 {
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{conf.Cost}, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
if len(conf.Costget) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Costget, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
if len(conf.Costget) > 0 {
|
|
res = append(res, conf.Costget...)
|
|
}
|
|
if c, err := this.module.configure.GetMinerConf(req.Grid); err == nil {
|
|
res = append(res, c.Itemid)
|
|
}
|
|
if len(res) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
list.Puzzle[req.Grid] = 1
|
|
update := make(map[string]interface{}, 0)
|
|
update["puzzle"] = list.Puzzle
|
|
this.module.modelPuzzle.modifyPuzzleListByObjId(session.GetUserId(), update) // 修改进度
|
|
session.SendMsg(string(this.module.GetType()), "puzzlegrid", &pb.UiGamePuzzleGridResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "UiGamePuzzleGridReq", atno)
|
|
})
|
|
return
|
|
}
|