上传战斗接口

This commit is contained in:
liwei1dao 2022-09-06 11:37:29 +08:00
parent 8ab7ba0ed0
commit 583a482a3f
4 changed files with 91 additions and 49 deletions

View File

@ -130,4 +130,9 @@ type (
//推送消息到用户 //推送消息到用户
SendUserChat(msg *pb.DBChat) (code pb.ErrorCode) SendUserChat(msg *pb.DBChat) (code pb.ErrorCode)
} }
//战斗系统
IBattle interface {
CreatePveBattle(session IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, record *pb.DBBattleRecord)
}
) )

View File

@ -3,6 +3,7 @@ package battle
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "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 { if monst, err := this.module.configure.GetMonster(v1); err != nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
} else { } 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 return
} else { } else {
record.Buleflist[i].Team[i1].Property[comm.Hp] = int32(float32(record.Buleflist[i].Team[i1].Property[comm.Hp]) * mf.Hppro) 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 { if err := this.Add(record.Id, record); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
return
} }
return return
} }

View File

@ -43,17 +43,24 @@ func (this *Battle) OnInstallComp() {
this.modelBattle = this.RegisterComp(new(modelBattleComp)).(*modelBattleComp) this.modelBattle = this.RegisterComp(new(modelBattleComp)).(*modelBattleComp)
} }
func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, resp *pb.BattlePVEResp) { //创建pve战斗
var record *pb.DBBattleRecord 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 { if record, code = this.modelBattle.createpve(session, req); code != pb.ErrorCode_Success {
return return
} }
resp = &pb.BattlePVEResp{ this.pushbattle(session, &pb.BattleStartPush{
Id: record.Id, Id: record.Id,
Btype: record.Btype,
Ptype: record.Ptype,
RedCompId: record.RedCompId, RedCompId: record.RedCompId,
Redflist: record.Redflist, Redflist: record.Redflist,
BlueCompId: record.BlueCompId, BlueCompId: record.BlueCompId,
Buleflist: record.Buleflist, Buleflist: record.Buleflist,
} })
return return
} }
//推送战斗开始数据
func (this *Battle) pushbattle(session comm.IUserSession, resp *pb.BattleStartPush) {
session.SendMsg(string(this.GetType()), "start", resp)
}

View File

@ -20,6 +20,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
// pve 战斗创建请求 (此请求 为服务端间使用 客户端可忽略)
type BattlePVEReq struct { type BattlePVEReq struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -99,20 +100,23 @@ func (x *BattlePVEReq) GetMformat() []int32 {
return nil return nil
} }
type BattlePVEResp struct { //战斗开始推送
type BattleStartPush struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id"` //战斗id Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id"` //战斗id
RedCompId string `protobuf:"bytes,5,opt,name=redCompId,proto3" json:"redCompId"` //红方阵营id Btype BattleType `protobuf:"varint,2,opt,name=btype,proto3,enum=BattleType" json:"btype"` //战斗类型
Redflist []*DBBattleFormt `protobuf:"bytes,6,rep,name=redflist,proto3" json:"redflist"` //红方阵型列表 Ptype PlayType `protobuf:"varint,3,opt,name=ptype,proto3,enum=PlayType" json:"ptype"` //玩法类型
BlueCompId string `protobuf:"bytes,7,opt,name=blueCompId,proto3" json:"blueCompId"` //蓝方阵营id RedCompId string `protobuf:"bytes,4,opt,name=redCompId,proto3" json:"redCompId"` //红方阵营id
Buleflist []*DBBattleFormt `protobuf:"bytes,8,rep,name=buleflist,proto3" json:"buleflist"` //红方阵型列表 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() { func (x *BattleStartPush) Reset() {
*x = BattlePVEResp{} *x = BattleStartPush{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_battle_battle_msg_proto_msgTypes[1] mi := &file_battle_battle_msg_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 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) 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] mi := &file_battle_battle_msg_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -138,40 +142,54 @@ func (x *BattlePVEResp) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use BattlePVEResp.ProtoReflect.Descriptor instead. // Deprecated: Use BattleStartPush.ProtoReflect.Descriptor instead.
func (*BattlePVEResp) Descriptor() ([]byte, []int) { func (*BattleStartPush) Descriptor() ([]byte, []int) {
return file_battle_battle_msg_proto_rawDescGZIP(), []int{1} return file_battle_battle_msg_proto_rawDescGZIP(), []int{1}
} }
func (x *BattlePVEResp) GetId() string { func (x *BattleStartPush) GetId() string {
if x != nil { if x != nil {
return x.Id return x.Id
} }
return "" 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 { if x != nil {
return x.RedCompId return x.RedCompId
} }
return "" return ""
} }
func (x *BattlePVEResp) GetRedflist() []*DBBattleFormt { func (x *BattleStartPush) GetRedflist() []*DBBattleFormt {
if x != nil { if x != nil {
return x.Redflist return x.Redflist
} }
return nil return nil
} }
func (x *BattlePVEResp) GetBlueCompId() string { func (x *BattleStartPush) GetBlueCompId() string {
if x != nil { if x != nil {
return x.BlueCompId return x.BlueCompId
} }
return "" return ""
} }
func (x *BattlePVEResp) GetBuleflist() []*DBBattleFormt { func (x *BattleStartPush) GetBuleflist() []*DBBattleFormt {
if x != nil { if x != nil {
return x.Buleflist 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, 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, 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, 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, 0x28, 0x05, 0x52, 0x07, 0x6d, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0xfd, 0x01, 0x0a, 0x0f,
0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x50, 0x56, 0x45, 0x52, 0x65, 0x73, 0x70, 0x12, 0x0e, 0x0a, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12,
0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x21, 0x0a, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0b,
0x52, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x08, 0x72, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x62, 0x74, 0x79,
0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x65, 0x12, 0x1f, 0x0a, 0x05, 0x70, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x74, 0x52, 0x08, 0x72, 0x0e, 0x32, 0x09, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x70, 0x74,
0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x43, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64,
0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x62, 0x6c, 0x75, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6d, 0x70, 0x49,
0x65, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x12, 0x2c, 0x0a, 0x09, 0x62, 0x75, 0x6c, 0x65, 0x66, 0x64, 0x12, 0x2a, 0x0a, 0x08, 0x72, 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20,
0x6c, 0x69, 0x73, 0x74, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x42, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f,
0x61, 0x74, 0x74, 0x6c, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x74, 0x52, 0x09, 0x62, 0x75, 0x6c, 0x65, 0x72, 0x6d, 0x74, 0x52, 0x08, 0x72, 0x65, 0x64, 0x66, 0x6c, 0x69, 0x73, 0x74, 0x12, 0x1e, 0x0a,
0x66, 0x6c, 0x69, 0x73, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x43, 0x6f, 0x6d, 0x70, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28,
0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@ -224,19 +246,22 @@ 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_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_battle_battle_msg_proto_goTypes = []interface{}{ var file_battle_battle_msg_proto_goTypes = []interface{}{
(*BattlePVEReq)(nil), // 0: BattlePVEReq (*BattlePVEReq)(nil), // 0: BattlePVEReq
(*BattlePVEResp)(nil), // 1: BattlePVEResp (*BattleStartPush)(nil), // 1: BattleStartPush
(PlayType)(0), // 2: PlayType (PlayType)(0), // 2: PlayType
(*DBBattleFormt)(nil), // 3: DBBattleFormt (BattleType)(0), // 3: BattleType
(*DBBattleFormt)(nil), // 4: DBBattleFormt
} }
var file_battle_battle_msg_proto_depIdxs = []int32{ var file_battle_battle_msg_proto_depIdxs = []int32{
2, // 0: BattlePVEReq.ptype:type_name -> PlayType 2, // 0: BattlePVEReq.ptype:type_name -> PlayType
3, // 1: BattlePVEResp.redflist:type_name -> DBBattleFormt 3, // 1: BattleStartPush.btype:type_name -> BattleType
3, // 2: BattlePVEResp.buleflist:type_name -> DBBattleFormt 2, // 2: BattleStartPush.ptype:type_name -> PlayType
3, // [3:3] is the sub-list for method output_type 4, // 3: BattleStartPush.redflist:type_name -> DBBattleFormt
3, // [3:3] is the sub-list for method input_type 4, // 4: BattleStartPush.buleflist:type_name -> DBBattleFormt
3, // [3:3] is the sub-list for extension type_name 5, // [5:5] is the sub-list for method output_type
3, // [3:3] is the sub-list for extension extendee 5, // [5:5] is the sub-list for method input_type
0, // [0:3] is the sub-list for field type_name 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() } 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{} { 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: case 0:
return &v.state return &v.state
case 1: case 1: