diff --git a/comm/imodule.go b/comm/imodule.go index 5bdad5ca5..4452cf6f1 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -130,4 +130,9 @@ type ( //推送消息到用户 SendUserChat(msg *pb.DBChat) (code pb.ErrorCode) } + + //战斗系统 + IBattle interface { + CreatePveBattle(session IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, record *pb.DBBattleRecord) + } ) diff --git a/modules/battle/modelBattle.go b/modules/battle/modelBattle.go index e92e33651..dde3d8c39 100644 --- a/modules/battle/modelBattle.go +++ b/modules/battle/modelBattle.go @@ -3,6 +3,7 @@ package battle import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -68,7 +69,9 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, req *pb.Battle if monst, err := this.module.configure.GetMonster(v1); err != nil { code = pb.ErrorCode_ConfigNoFound } else { - if record.Buleflist[i].Team[i1], code = this.module.ModuleHero.CreateMonster(monst.HeroId, monst.Star, mf.Lv); code != pb.ErrorCode_Success { + if record.Buleflist[i].Team[i1] = this.module.ModuleHero.CreateMonster(monst.HeroId, monst.Star, mf.Lv); record.Buleflist[i].Team[i1] == nil { + log.Error("on found battle req data", log.Field{Key: "HeroId", Value: monst.HeroId}) + code = pb.ErrorCode_ReqParameterError return } else { record.Buleflist[i].Team[i1].Property[comm.Hp] = int32(float32(record.Buleflist[i].Team[i1].Property[comm.Hp]) * mf.Hppro) @@ -82,6 +85,8 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, req *pb.Battle } if err := this.Add(record.Id, record); err != nil { this.module.Errorln(err) + return } + return } diff --git a/modules/battle/module.go b/modules/battle/module.go index de9f69372..66a4fc4e0 100644 --- a/modules/battle/module.go +++ b/modules/battle/module.go @@ -43,17 +43,24 @@ func (this *Battle) OnInstallComp() { this.modelBattle = this.RegisterComp(new(modelBattleComp)).(*modelBattleComp) } -func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, resp *pb.BattlePVEResp) { - var record *pb.DBBattleRecord +//创建pve战斗 +func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, record *pb.DBBattleRecord) { if record, code = this.modelBattle.createpve(session, req); code != pb.ErrorCode_Success { return } - resp = &pb.BattlePVEResp{ + this.pushbattle(session, &pb.BattleStartPush{ Id: record.Id, + Btype: record.Btype, + Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, - } + }) return } + +//推送战斗开始数据 +func (this *Battle) pushbattle(session comm.IUserSession, resp *pb.BattleStartPush) { + session.SendMsg(string(this.GetType()), "start", resp) +} diff --git a/pb/battle_msg.pb.go b/pb/battle_msg.pb.go index f6a064fa2..217961794 100644 --- a/pb/battle_msg.pb.go +++ b/pb/battle_msg.pb.go @@ -20,6 +20,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// pve 战斗创建请求 (此请求 为服务端间使用 客户端可忽略) type BattlePVEReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -99,20 +100,23 @@ func (x *BattlePVEReq) GetMformat() []int32 { return nil } -type BattlePVEResp struct { +//战斗开始推送 +type BattleStartPush struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id"` //战斗id - RedCompId string `protobuf:"bytes,5,opt,name=redCompId,proto3" json:"redCompId"` //红方阵营id - Redflist []*DBBattleFormt `protobuf:"bytes,6,rep,name=redflist,proto3" json:"redflist"` //红方阵型列表 - BlueCompId string `protobuf:"bytes,7,opt,name=blueCompId,proto3" json:"blueCompId"` //蓝方阵营id - Buleflist []*DBBattleFormt `protobuf:"bytes,8,rep,name=buleflist,proto3" json:"buleflist"` //红方阵型列表 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"` //战斗id + Btype BattleType `protobuf:"varint,2,opt,name=btype,proto3,enum=BattleType" json:"btype"` //战斗类型 + Ptype PlayType `protobuf:"varint,3,opt,name=ptype,proto3,enum=PlayType" json:"ptype"` //玩法类型 + RedCompId string `protobuf:"bytes,4,opt,name=redCompId,proto3" json:"redCompId"` //红方阵营id + Redflist []*DBBattleFormt `protobuf:"bytes,5,rep,name=redflist,proto3" json:"redflist"` //红方阵型列表 + BlueCompId string `protobuf:"bytes,6,opt,name=blueCompId,proto3" json:"blueCompId"` //蓝方阵营id + Buleflist []*DBBattleFormt `protobuf:"bytes,7,rep,name=buleflist,proto3" json:"buleflist"` //红方阵型列表 } -func (x *BattlePVEResp) Reset() { - *x = BattlePVEResp{} +func (x *BattleStartPush) Reset() { + *x = BattleStartPush{} if protoimpl.UnsafeEnabled { mi := &file_battle_battle_msg_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -120,13 +124,13 @@ func (x *BattlePVEResp) Reset() { } } -func (x *BattlePVEResp) String() string { +func (x *BattleStartPush) String() string { return protoimpl.X.MessageStringOf(x) } -func (*BattlePVEResp) ProtoMessage() {} +func (*BattleStartPush) ProtoMessage() {} -func (x *BattlePVEResp) ProtoReflect() protoreflect.Message { +func (x *BattleStartPush) ProtoReflect() protoreflect.Message { mi := &file_battle_battle_msg_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -138,40 +142,54 @@ func (x *BattlePVEResp) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use BattlePVEResp.ProtoReflect.Descriptor instead. -func (*BattlePVEResp) Descriptor() ([]byte, []int) { +// Deprecated: Use BattleStartPush.ProtoReflect.Descriptor instead. +func (*BattleStartPush) Descriptor() ([]byte, []int) { return file_battle_battle_msg_proto_rawDescGZIP(), []int{1} } -func (x *BattlePVEResp) GetId() string { +func (x *BattleStartPush) GetId() string { if x != nil { return x.Id } return "" } -func (x *BattlePVEResp) GetRedCompId() string { +func (x *BattleStartPush) GetBtype() BattleType { + if x != nil { + return x.Btype + } + return BattleType_nil +} + +func (x *BattleStartPush) GetPtype() PlayType { + if x != nil { + return x.Ptype + } + return PlayType_mainline +} + +func (x *BattleStartPush) GetRedCompId() string { if x != nil { return x.RedCompId } return "" } -func (x *BattlePVEResp) GetRedflist() []*DBBattleFormt { +func (x *BattleStartPush) GetRedflist() []*DBBattleFormt { if x != nil { return x.Redflist } return nil } -func (x *BattlePVEResp) GetBlueCompId() string { +func (x *BattleStartPush) GetBlueCompId() string { if x != nil { return x.BlueCompId } return "" } -func (x *BattlePVEResp) GetBuleflist() []*DBBattleFormt { +func (x *BattleStartPush) GetBuleflist() []*DBBattleFormt { if x != nil { return x.Buleflist } @@ -193,20 +211,24 @@ var file_battle_battle_msg_proto_rawDesc = []byte{ 0x6c, 0x65, 0x61, 0x64, 0x70, 0x6f, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x69, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x69, 0x64, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x05, 0x20, 0x03, - 0x28, 0x05, 0x52, 0x07, 0x6d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0xb7, 0x01, 0x0a, 0x0d, - 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x50, 0x56, 0x45, 0x52, 0x65, 0x73, 0x70, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, - 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x08, 0x72, - 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, - 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x74, 0x52, 0x08, 0x72, - 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x43, - 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x6c, 0x75, - 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x12, 0x2c, 0x0a, 0x09, 0x62, 0x75, 0x6c, 0x65, 0x66, - 0x6c, 0x69, 0x73, 0x74, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x42, - 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x74, 0x52, 0x09, 0x62, 0x75, 0x6c, 0x65, - 0x66, 0x6c, 0x69, 0x73, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x05, 0x52, 0x07, 0x6d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0xfd, 0x01, 0x0a, 0x0f, + 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x21, 0x0a, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0b, + 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x62, 0x74, 0x79, + 0x70, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x70, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x09, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x70, 0x74, + 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, + 0x64, 0x12, 0x2a, 0x0a, 0x08, 0x72, 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, + 0x72, 0x6d, 0x74, 0x52, 0x08, 0x72, 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x0a, + 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x12, 0x2c, 0x0a, + 0x09, 0x62, 0x75, 0x6c, 0x65, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x74, + 0x52, 0x09, 0x62, 0x75, 0x6c, 0x65, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -223,20 +245,23 @@ func file_battle_battle_msg_proto_rawDescGZIP() []byte { var file_battle_battle_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_battle_battle_msg_proto_goTypes = []interface{}{ - (*BattlePVEReq)(nil), // 0: BattlePVEReq - (*BattlePVEResp)(nil), // 1: BattlePVEResp - (PlayType)(0), // 2: PlayType - (*DBBattleFormt)(nil), // 3: DBBattleFormt + (*BattlePVEReq)(nil), // 0: BattlePVEReq + (*BattleStartPush)(nil), // 1: BattleStartPush + (PlayType)(0), // 2: PlayType + (BattleType)(0), // 3: BattleType + (*DBBattleFormt)(nil), // 4: DBBattleFormt } var file_battle_battle_msg_proto_depIdxs = []int32{ 2, // 0: BattlePVEReq.ptype:type_name -> PlayType - 3, // 1: BattlePVEResp.redflist:type_name -> DBBattleFormt - 3, // 2: BattlePVEResp.buleflist:type_name -> DBBattleFormt - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 3, // 1: BattleStartPush.btype:type_name -> BattleType + 2, // 2: BattleStartPush.ptype:type_name -> PlayType + 4, // 3: BattleStartPush.redflist:type_name -> DBBattleFormt + 4, // 4: BattleStartPush.buleflist:type_name -> DBBattleFormt + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_battle_battle_msg_proto_init() } @@ -259,7 +284,7 @@ func file_battle_battle_msg_proto_init() { } } file_battle_battle_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*BattlePVEResp); i { + switch v := v.(*BattleStartPush); i { case 0: return &v.state case 1: