go_dreamfactory/modules/troll/api_getReward.go
2022-11-07 22:52:03 +08:00

52 lines
1.4 KiB
Go

package troll
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) NpcRewardCheck(session comm.IUserSession, req *pb.TrollNpcRewardReq) (code pb.ErrorCode) {
return
}
///美食城领取奖励
func (this *apiComp) NpcReward(session comm.IUserSession, req *pb.TrollNpcRewardReq) (code pb.ErrorCode, data proto.Message) {
var (
update map[string]interface{}
)
code = this.NpcRewardCheck(session, req)
_troll, err := this.module.modelTroll.getTrollList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
conf := this.module.configure.GetTrollLv(req.RewardId)
if conf == nil {
code = pb.ErrorCode_ReqParameterError
}
if confLv := this.configure.GetTrollLv(req.RewardId); confLv != nil {
if _troll.TotalEarn >= int64(confLv.Money) {
if _, ok := _troll.NpcReward[req.RewardId]; !ok {
if code = this.module.DispenseRes(session, conf.Reword, true); code != pb.ErrorCode_Success {
return
}
_troll.NpcReward[req.RewardId] = 1
update = make(map[string]interface{}, 0)
update["npcReward"] = _troll.NpcReward
this.module.ModifyTrollData(session.GetUserId(), update)
} else {
code = pb.ErrorCode_TrollRepeatedReward
return
}
}
}
session.SendMsg(string(this.module.GetType()), TrollNpcRewardResp, &pb.TrollNpcRewardResp{Data: _troll})
return
}