You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.3 KiB
Go

package statistics
import (
"dcg/app/user_center/usercenter"
"dcg/game/manager"
pbGameZhg "dcg/game/pb/game/zhg"
"dcg/game/svc"
"git.noahlan.cn/northlan/ngs/component"
"git.noahlan.cn/northlan/ngs/session"
)
type PvP struct {
component.Base
svcCtx *svc.ServiceContext
}
func NewStatisticsPvP(svcCtx *svc.ServiceContext) *PvP {
return &PvP{
svcCtx: svcCtx,
}
}
func (p *PvP) CMD() string {
return "statistics"
}
func (p *PvP) Prefix() string {
return "pvp"
}
func (p *PvP) Init() {
}
func (p *PvP) Shutdown() {
}
// Report 战报
func (p *PvP) Report(s *session.Session, msg *pbGameZhg.StatPvPReportReq) error {
winItems := make([]*usercenter.StatPvPReportReq_Item, 0, len(msg.WinItems))
lostItems := make([]*usercenter.StatPvPReportReq_Item, 0, len(msg.LostItems))
for _, item := range msg.WinItems {
winItems = append(winItems, &usercenter.StatPvPReportReq_Item{
Uid: item.Uid,
Uname: item.Uname,
Damage: item.Damage,
DeDamage: item.DeDamage,
KillUnit: item.KillUnit,
DeKillUnit: item.DeKillUnit,
FirstBlood: item.FirstBlood,
DeFirstBlood: item.DeFirstBlood,
KillPlayer: item.KillPlayer,
DeKillPlayer: item.DeKillPlayer,
IsGeneral: item.IsGeneral,
})
}
for _, item := range msg.LostItems {
lostItems = append(lostItems, &usercenter.StatPvPReportReq_Item{
Uid: item.Uid,
Uname: item.Uname,
Damage: item.Damage,
DeDamage: item.DeDamage,
KillUnit: item.KillUnit,
DeKillUnit: item.DeKillUnit,
FirstBlood: item.FirstBlood,
DeFirstBlood: item.DeFirstBlood,
KillPlayer: item.KillPlayer,
DeKillPlayer: item.DeKillPlayer,
IsGeneral: item.IsGeneral,
})
}
// 战报
resp, err := p.svcCtx.UserCenterRpc.StatPvpReport(p.svcCtx.Ctx, &usercenter.StatPvPReportReq{
WinCamp: msg.WinCamp,
BattleId: manager.GameManager.BattleIdBySession(s),
WinItems: winItems,
LostItems: lostItems,
})
if err != nil {
return err
}
winItemsResp := make([]*pbGameZhg.StatPvPReportResp_Item, 0, len(resp.WinItems))
lostItemsResp := make([]*pbGameZhg.StatPvPReportResp_Item, 0, len(resp.LostItems))
for _, item := range resp.WinItems {
winItemsResp = append(winItemsResp, &pbGameZhg.StatPvPReportResp_Item{
Uid: item.Uid,
Uname: item.Uname,
Position: item.Position,
Score: item.Score,
Grade: &pbGameZhg.StatPvPReportResp_Grade{
Grade: item.Grade.Grade,
Level: item.Grade.Level,
Star: item.Grade.Star,
BravePoint: item.Grade.BravePoint,
},
GradeReason: pbGameZhg.StatPvPReportResp_GradeReason(item.GradeReason),
GradeResult: pbGameZhg.StatPvPReportResp_GradeResult(item.GradeResult),
})
}
for _, item := range resp.LostItems {
lostItemsResp = append(lostItemsResp, &pbGameZhg.StatPvPReportResp_Item{
Uid: item.Uid,
Uname: item.Uname,
Position: item.Position,
Score: item.Score,
Grade: &pbGameZhg.StatPvPReportResp_Grade{
Grade: item.Grade.Grade,
Level: item.Grade.Level,
Star: item.Grade.Star,
BravePoint: item.Grade.BravePoint,
},
GradeReason: pbGameZhg.StatPvPReportResp_GradeReason(item.GradeReason),
GradeResult: pbGameZhg.StatPvPReportResp_GradeResult(item.GradeResult),
})
}
return s.Response(&pbGameZhg.StatPvPReportResp{
WinItems: winItemsResp,
LostItems: lostItemsResp,
})
}