68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package uigame
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) MinerKeyCheck(session comm.IUserSession, req *pb.UiGameMinerKeyReq) (errdata *pb.ErrorData) {
|
|
if req.Hdid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 点击某个格子进行拼图
|
|
func (this *apiComp) MinerKey(session comm.IUserSession, req *pb.UiGameMinerKeyReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.MinerKeyCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
var (
|
|
atno []*pb.UserAtno
|
|
res []*cfg.Gameatn
|
|
)
|
|
list, _ := this.module.modelMiner.getMinerList(session.GetUserId(), req.Hdid)
|
|
if _, ok := list.Gotarr[req.Cid]; ok { // 重复拼图
|
|
return
|
|
}
|
|
|
|
// 校验消耗
|
|
if conf, err := this.module.configure.GetMinerConsumConf(); 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 {
|
|
res = append(res, conf.Costget...)
|
|
}
|
|
if c, err := this.module.configure.GetMinerConf(req.Cid); err == nil {
|
|
res = append(res, c.Itemid)
|
|
}
|
|
if len(res) > 0 {
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
list.Gotarr[req.Cid] = 1
|
|
update := make(map[string]interface{}, 0)
|
|
update["gotarr"] = list.Gotarr
|
|
this.module.modelMiner.modifyMinerListByObjId(session.GetUserId(), update) // 修改进度
|
|
session.SendMsg(string(this.module.GetType()), "minerkey", &pb.UiGameMinerKeyResp{
|
|
Data: list,
|
|
Atno: atno,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "UiGameMinerKeyReq", atno)
|
|
})
|
|
return
|
|
}
|