119 lines
3.3 KiB
Go
119 lines
3.3 KiB
Go
// package 设置助战英雄
|
|
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 设置助战英雄
|
|
|
|
func (this *apiComp) AssistheroCheck(session comm.IUserSession, req *pb.FriendAssistheroReq) (errdata *pb.ErrorData) {
|
|
if req.HeroObjId == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
this.module.Error("设置助战英雄参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssistheroReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.AssistheroCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
// 获取英雄
|
|
hero, err := this.module.ModuleHero.QueryCrossHeroinfo(req.HeroObjId)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("查询英雄数据 QueryCrossHeroinfo",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.HeroObjId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
if hero == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_HeroNoExist,
|
|
Title: pb.ErrorCode_HeroNoExist.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取玩家自己好友数据
|
|
self := this.module.modelFriend.GetFriend(uid)
|
|
if self == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSelfNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"assistHeroId": req.HeroObjId,
|
|
"hero": hero,
|
|
}
|
|
|
|
received := self.Received
|
|
if received == 0 {
|
|
update["received"] = 1 //设置可领取状态
|
|
}
|
|
|
|
if err := this.module.modelFriend.Change(self.Uid, update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendApplyError,
|
|
Title: pb.ErrorCode_FriendApplyError.ToString(),
|
|
}
|
|
this.module.Error("设置助战英雄",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.HeroObjId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
rsp := &pb.FriendAssistheroResp{HeroObjId: req.HeroObjId, Received: received}
|
|
if err := session.SendMsg(string(this.module.GetType()), FriendSubTypeAssistHero, rsp); err != nil {
|
|
return
|
|
}
|
|
|
|
// 有好友时再推送
|
|
if len(self.FriendIds) > 0 {
|
|
//把设置的助战英雄推送给好友
|
|
push := &pb.FriendAssistHeroUpdatePush{
|
|
Friend: &pb.FriendBase{
|
|
UserId: self.Uid,
|
|
HeroObjId: req.HeroObjId,
|
|
},
|
|
}
|
|
|
|
this.module.Debug("设置的助战英雄推送给好友",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "friendIds", Value: self.FriendIds},
|
|
log.Field{Key: "heroObjId", Value: req.HeroObjId},
|
|
)
|
|
if err := this.module.SendMsgToUsers(string(this.module.GetType()), "assistheroupdate", push, self.FriendIds...); err != nil {
|
|
this.module.Error("推送助战英雄列表",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "friends", Value: self.FriendIds},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
}
|
|
}
|
|
|
|
// 随机任务Rtype13
|
|
// this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype13, 1)
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype13, 1))
|
|
return
|
|
}
|