65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package egghunt
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.EgghuntAwardReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Award(session comm.IUserSession, req *pb.EgghuntAwardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameRepeatAllData
|
|
info *pb.DBEgghunt
|
|
atno []*pb.UserAtno
|
|
err error
|
|
)
|
|
if errdata = this.AwardCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameRepeatAllData(req.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.model.getModel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if int32(configure.Now().Sub(time.Unix(info.Egg[conf.Key], 0)).Seconds()) < conf.Cdtime {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "in cd!",
|
|
}
|
|
return
|
|
}
|
|
|
|
info.Egg[conf.Key] = configure.Now().Unix()
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.TriggerTwo, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
this.module.model.Change(session.GetUserId(), map[string]interface{}{
|
|
"egg": info.Egg,
|
|
})
|
|
|
|
session.SendMsg(string(this.module.GetType()), "award", &pb.EgghuntAwardResp{Id: req.Id, Award: atno})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "EgghuntAwardReq", atno)
|
|
})
|
|
return
|
|
}
|