79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
package monkey
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) UpdateStarCheck(session comm.IUserSession, req *pb.MonkeyUpdateStarReq) (errdata *pb.ErrorData) {
|
|
if req.Stage == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取猴拳章节信息
|
|
func (this *apiComp) UpdateStar(session comm.IUserSession, req *pb.MonkeyUpdateStarReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
info *pb.DBMonkey
|
|
conf *cfg.GameMonkeyMainData
|
|
update map[string]interface{}
|
|
)
|
|
update = make(map[string]interface{}, 0)
|
|
if errdata = this.UpdateStarCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameMonkeyData(req.Stage); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.model.getMonkeyData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info.Data[conf.Chapter] == nil {
|
|
info.Data[conf.Chapter] = &pb.ChapterData{
|
|
Award: map[int32]int32{
|
|
req.Stage: req.Star,
|
|
},
|
|
}
|
|
update["data"] = info.Data
|
|
} else {
|
|
if info.Data[conf.Chapter].Award[req.Stage] != req.Star {
|
|
curStar := info.Data[conf.Chapter].Award[req.Stage] // 当前的星
|
|
info.Data[conf.Chapter].Award[req.Stage] = (req.Star ^ curStar) // 做异或操作
|
|
update["data"] = info.Data
|
|
}
|
|
}
|
|
if len(update) > 0 {
|
|
if err = this.module.model.changeMonkeyData(session.GetUserId(), update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "updatestar", &pb.MonkeyUpdateStarResp{
|
|
Star: req.Star,
|
|
})
|
|
|
|
return
|
|
}
|