好友助战英雄列表

This commit is contained in:
wh_zcy 2022-10-21 11:15:41 +08:00
parent 30a1b1c409
commit 1c556e3e21
9 changed files with 277 additions and 42 deletions

View File

@ -82,6 +82,7 @@ var (
ff(comm.ModuleFriend, friend.FriendSubTypeGetreward): &formview.FriendGetrewardView{},
ff(comm.ModuleFriend, friend.FriendSubTypeAssistlist): &formview.FriendAssistListView{},
ff(comm.ModuleFriend, friend.FriendSubTypeAssistHero): &formview.FriendAssistHeroView{},
ff(comm.ModuleFriend, friend.FriendSubTypeAssistHeroList): &formview.FriendAssistHeroListView{},
// shop
ff(comm.ModuleShop, "getlist"): &formview.ShopListView{},
@ -180,6 +181,7 @@ var (
ff(comm.ModuleFriend, friend.FriendSubTypeGetreward),
ff(comm.ModuleFriend, friend.FriendSubTypeAssistHero),
ff(comm.ModuleFriend, friend.FriendSubTypeAssistlist),
ff(comm.ModuleFriend, friend.FriendSubTypeAssistHeroList),
},
"shop": {
ff(comm.ModuleShop, "getlist"),
@ -616,6 +618,13 @@ var (
SubType: friend.FriendSubTypeGetreward,
Enabled: true,
},
ff(comm.ModuleFriend, friend.FriendSubTypeAssistHeroList): {
NavLabel: "助战英雄列表",
Desc: "我的好友助战英雄列表",
MainType: string(comm.ModuleFriend),
SubType: friend.FriendSubTypeAssistHeroList,
Enabled: true,
},
//shop
string(comm.ModuleShop): {

View File

@ -0,0 +1,38 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
)
type FriendAssistHeroListView struct {
BaseformView
assistHeroList func()
}
func (this *FriendAssistHeroListView) CreateView(t *model.TestCase) fyne.CanvasObject {
this.assistHeroList = func() {
if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
&pb.FriendAssistHeroListReq{}); err != nil {
logrus.Error(err)
}
}
defer this.assistHeroList()
refreshBtn := widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
this.assistHeroList()
})
buttonBar := container.NewHBox(refreshBtn)
c := container.NewBorder(buttonBar, nil, nil, nil)
return c
}

View File

@ -24,6 +24,7 @@ const (
FriendSubTypeDel = "del"
FriendSubTypeAssistlist = "assistlist"
FriendSubTypeGetreward = "getreward"
FriendSubTypeAssistHeroList = "assistherolist"
)
type apiComp struct {

View File

@ -65,18 +65,19 @@ func (this *apiComp) Assisthero(session comm.IUserSession, req *pb.FriendAssisth
return
}
//推送
push := &pb.FriendAssistHeroListPush{}
for _, fId := range self.FriendIds {
d := this.moduleFriend.modelFriend.GetFriend(fId)
push.Friends = append(push.Friends, &pb.FriendBase{
HeroObjId: d.AssistHeroId,
})
// 有好友时再推送
if len(self.FriendIds) > 0 {
//把设置的助战英雄推送给好友
push := &pb.FriendAssistHeroListPush{
Friend: &pb.FriendBase{
HeroObjId: req.HeroObjId,
},
}
if err := this.moduleFriend.SendMsgToUsers(string(this.moduleFriend.GetType()), "AssistHeroList",
&pb.FriendAssistHeroListPush{}, self.FriendIds...); err != nil {
if err := this.moduleFriend.SendMsgToUsers(string(this.moduleFriend.GetType()), "assistherolist", push, self.FriendIds...); err != nil {
this.moduleFriend.Errorf("push AssistHeroList err:", err)
}
}
// 随机任务Rtype13
this.moduleFriend.ModuleRtask.SendToRtask(session, comm.Rtype13, 1)

View File

@ -0,0 +1,39 @@
package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 好友助战英雄列表
func (this *apiComp) AssistHeroListCheck(session comm.IUserSession, req *pb.FriendAssistHeroListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) AssistHeroList(session comm.IUserSession, req *pb.FriendAssistHeroListReq) (code pb.ErrorCode, data proto.Message) {
//获取玩家自己好友数据
self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil {
code = pb.ErrorCode_FriendSelfNoData
return
}
rsp := &pb.FriendAssistHeroListResp{}
for _, v := range self.FriendIds {
f := this.moduleFriend.modelFriend.GetFriend(v)
rsp.Friends = append(rsp.Friends, &pb.FriendBase{
HeroObjId: f.AssistHeroId,
})
}
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAssistHeroList, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -2,9 +2,11 @@ package friend
import (
"context"
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"time"
"go_dreamfactory/lego/base"
@ -104,10 +106,25 @@ func (this *Friend) UseAssistHero(uid, friendId string) (*pb.DBHero, error) {
for _, fId := range friend.FriendIds {
// 判断uid是否在指定玩家的好友列表中
if fId == uid {
//好友没有设置助战英雄
if friend.AssistHeroId == "" {
break
}
//遍历助战记录
for _, r := range friend.Record {
if r.AssistHeroId == friend.AssistHeroId {
if utils.IsToday(r.Zhuzhantime) {
log.Warnf("今日已助战 uid:%v friendId:%v heroId:%v", uid, friendId, r.AssistHeroId)
return nil, errors.New("今日已助战")
}
}
}
//更新助战记录和助战分数
friend.ZhuzhanScore++
// 设置助战记录
friend.Record = append(friend.Record, &pb.ZhuZhanRecord{
Uid: uid,
AssistHeroId: friend.AssistHeroId,
Zhuzhantime: time.Now().Unix(),
})
update := map[string]interface{}{
@ -117,5 +134,6 @@ func (this *Friend) UseAssistHero(uid, friendId string) (*pb.DBHero, error) {
return friend.Hero, this.modelFriend.Change(friendId, update)
}
}
return nil, nil
log.Errorf("[friendId:%v]不是你[uid:%v]的好友", uid, friendId)
return nil, errors.New("非好友")
}

View File

@ -163,6 +163,7 @@ type ZhuZhanRecord struct {
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //好友Id
Zhuzhantime int64 `protobuf:"varint,2,opt,name=zhuzhantime,proto3" json:"zhuzhantime" bson:"zhuzhanTime"` //上次助战时间
AssistHeroId string `protobuf:"bytes,3,opt,name=assistHeroId,proto3" json:"assistHeroId" bson:"assistHeroId"` //助战英雄
}
func (x *ZhuZhanRecord) Reset() {
@ -211,6 +212,13 @@ func (x *ZhuZhanRecord) GetZhuzhantime() int64 {
return 0
}
func (x *ZhuZhanRecord) GetAssistHeroId() string {
if x != nil {
return x.AssistHeroId
}
return ""
}
var File_friend_friend_db_proto protoreflect.FileDescriptor
var file_friend_friend_db_proto_rawDesc = []byte{
@ -240,12 +248,14 @@ var file_friend_friend_db_proto_rawDesc = []byte{
0x75, 0x7a, 0x68, 0x61, 0x6e, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x72, 0x65,
0x63, 0x6f, 0x72, 0x64, 0x18, 0x0c, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x5a, 0x68, 0x75,
0x5a, 0x68, 0x61, 0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x06, 0x72, 0x65, 0x63, 0x6f,
0x72, 0x64, 0x22, 0x43, 0x0a, 0x0d, 0x5a, 0x68, 0x75, 0x5a, 0x68, 0x61, 0x6e, 0x52, 0x65, 0x63,
0x72, 0x64, 0x22, 0x67, 0x0a, 0x0d, 0x5a, 0x68, 0x75, 0x5a, 0x68, 0x61, 0x6e, 0x52, 0x65, 0x63,
0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x7a, 0x68, 0x75, 0x7a, 0x68, 0x61, 0x6e,
0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x7a, 0x68, 0x75, 0x7a,
0x68, 0x61, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x68, 0x61, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x61, 0x73, 0x73, 0x69, 0x73,
0x74, 0x48, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x61,
0x73, 0x73, 0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e,
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -1866,13 +1866,13 @@ func (x *FriendGetrewardResp) GetReceived() int32 {
return 0
}
// 助战英雄列表推送
// 助战英雄更新推送
type FriendAssistHeroListPush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"` //好友列表
Friend *FriendBase `protobuf:"bytes,1,opt,name=friend,proto3" json:"friend"` //好友
}
func (x *FriendAssistHeroListPush) Reset() {
@ -1907,7 +1907,93 @@ func (*FriendAssistHeroListPush) Descriptor() ([]byte, []int) {
return file_friend_friend_msg_proto_rawDescGZIP(), []int{37}
}
func (x *FriendAssistHeroListPush) GetFriends() []*FriendBase {
func (x *FriendAssistHeroListPush) GetFriend() *FriendBase {
if x != nil {
return x.Friend
}
return nil
}
//好友助战英雄列表
type FriendAssistHeroListReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *FriendAssistHeroListReq) Reset() {
*x = FriendAssistHeroListReq{}
if protoimpl.UnsafeEnabled {
mi := &file_friend_friend_msg_proto_msgTypes[38]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *FriendAssistHeroListReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FriendAssistHeroListReq) ProtoMessage() {}
func (x *FriendAssistHeroListReq) ProtoReflect() protoreflect.Message {
mi := &file_friend_friend_msg_proto_msgTypes[38]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use FriendAssistHeroListReq.ProtoReflect.Descriptor instead.
func (*FriendAssistHeroListReq) Descriptor() ([]byte, []int) {
return file_friend_friend_msg_proto_rawDescGZIP(), []int{38}
}
type FriendAssistHeroListResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"`
}
func (x *FriendAssistHeroListResp) Reset() {
*x = FriendAssistHeroListResp{}
if protoimpl.UnsafeEnabled {
mi := &file_friend_friend_msg_proto_msgTypes[39]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *FriendAssistHeroListResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FriendAssistHeroListResp) ProtoMessage() {}
func (x *FriendAssistHeroListResp) ProtoReflect() protoreflect.Message {
mi := &file_friend_friend_msg_proto_msgTypes[39]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use FriendAssistHeroListResp.ProtoReflect.Descriptor instead.
func (*FriendAssistHeroListResp) Descriptor() ([]byte, []int) {
return file_friend_friend_msg_proto_rawDescGZIP(), []int{39}
}
func (x *FriendAssistHeroListResp) GetFriends() []*FriendBase {
if x != nil {
return x.Friends
}
@ -2053,12 +2139,18 @@ var file_friend_friend_msg_proto_rawDesc = []byte{
0x22, 0x31, 0x0a, 0x13, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x47, 0x65, 0x74, 0x72, 0x65, 0x77,
0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69,
0x76, 0x65, 0x64, 0x22, 0x41, 0x0a, 0x18, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73,
0x76, 0x65, 0x64, 0x22, 0x3f, 0x0a, 0x18, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73,
0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12,
0x25, 0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x0b, 0x2e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66,
0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x23, 0x0a, 0x06, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0b, 0x2e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x06, 0x66, 0x72,
0x69, 0x65, 0x6e, 0x64, 0x22, 0x19, 0x0a, 0x17, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73,
0x73, 0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22,
0x41, 0x0a, 0x18, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41, 0x73, 0x73, 0x69, 0x73, 0x74, 0x48,
0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x07, 0x66,
0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x46,
0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e,
0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
}
var (
@ -2073,7 +2165,7 @@ func file_friend_friend_msg_proto_rawDescGZIP() []byte {
return file_friend_friend_msg_proto_rawDescData
}
var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 38)
var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 40)
var file_friend_friend_msg_proto_goTypes = []interface{}{
(*FriendBase)(nil), // 0: FriendBase
(*FriendListReq)(nil), // 1: FriendListReq
@ -2113,7 +2205,9 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{
(*FriendGetrewardReq)(nil), // 35: FriendGetrewardReq
(*FriendGetrewardResp)(nil), // 36: FriendGetrewardResp
(*FriendAssistHeroListPush)(nil), // 37: FriendAssistHeroListPush
(*ZhuZhanRecord)(nil), // 38: ZhuZhanRecord
(*FriendAssistHeroListReq)(nil), // 38: FriendAssistHeroListReq
(*FriendAssistHeroListResp)(nil), // 39: FriendAssistHeroListResp
(*ZhuZhanRecord)(nil), // 40: ZhuZhanRecord
}
var file_friend_friend_msg_proto_depIdxs = []int32{
0, // 0: FriendListResp.list:type_name -> FriendBase
@ -2123,13 +2217,14 @@ var file_friend_friend_msg_proto_depIdxs = []int32{
0, // 4: FriendBlackListResp.friends:type_name -> FriendBase
0, // 5: FriendZanlistResp.list:type_name -> FriendBase
0, // 6: FriendAssistlistResp.list:type_name -> FriendBase
38, // 7: FriendAssistlistResp.record:type_name -> ZhuZhanRecord
0, // 8: FriendAssistHeroListPush.friends:type_name -> FriendBase
9, // [9:9] is the sub-list for method output_type
9, // [9:9] is the sub-list for method input_type
9, // [9:9] is the sub-list for extension type_name
9, // [9:9] is the sub-list for extension extendee
0, // [0:9] is the sub-list for field type_name
40, // 7: FriendAssistlistResp.record:type_name -> ZhuZhanRecord
0, // 8: FriendAssistHeroListPush.friend:type_name -> FriendBase
0, // 9: FriendAssistHeroListResp.friends:type_name -> FriendBase
10, // [10:10] is the sub-list for method output_type
10, // [10:10] is the sub-list for method input_type
10, // [10:10] is the sub-list for extension type_name
10, // [10:10] is the sub-list for extension extendee
0, // [0:10] is the sub-list for field type_name
}
func init() { file_friend_friend_msg_proto_init() }
@ -2595,6 +2690,30 @@ func file_friend_friend_msg_proto_init() {
return nil
}
}
file_friend_friend_msg_proto_msgTypes[38].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FriendAssistHeroListReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_friend_friend_msg_proto_msgTypes[39].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FriendAssistHeroListResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -2602,7 +2721,7 @@ func file_friend_friend_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_friend_friend_msg_proto_rawDesc,
NumEnums: 0,
NumMessages: 38,
NumMessages: 40,
NumExtensions: 0,
NumServices: 0,
},