This commit is contained in:
meixiongfeng 2023-11-01 11:48:36 +08:00
commit d675f2099e
5 changed files with 525 additions and 436 deletions

View File

@ -63,11 +63,12 @@ func (this *CanineRabbit) OnInstallComp() {
func (this *CanineRabbit) CreateRoom(sessions []comm.IUserSession, rulesStr string) (roomid string, err error) { func (this *CanineRabbit) CreateRoom(sessions []comm.IUserSession, rulesStr string) (roomid string, err error) {
var ( var (
rules *pb.DBCanineRabbitRules = &pb.DBCanineRabbitRules{} rules *pb.DBCanineRabbitRules = &pb.DBCanineRabbitRules{}
chess []*pb.DBCanineRabbitChess chess []*pb.DBCanineRabbitChess
red *pb.DBUser red *pb.DBUser
blue *pb.DBUser redtype, bluetype int32
room *Room blue *pb.DBUser
room *Room
) )
if err = json.Unmarshal([]byte(rulesStr), rules); err != nil { if err = json.Unmarshal([]byte(rulesStr), rules); err != nil {
@ -114,13 +115,23 @@ func (this *CanineRabbit) CreateRoom(sessions []comm.IUserSession, rulesStr stri
Y: 2, Y: 2,
}) })
if rules.RedType == 0 {
redtype = 0
bluetype = 1
} else {
redtype = 1
bluetype = 0
}
if room, err = this.rooms.newRoom(&pb.DBCanineRabbitRoom{ if room, err = this.rooms.newRoom(&pb.DBCanineRabbitRoom{
Rid: roomid, Rid: roomid,
Red: &pb.DBCanineRabbitRoomPlayer{ Red: &pb.DBCanineRabbitRoomPlayer{
Info: comm.GetUserBaseInfo(red), Info: comm.GetUserBaseInfo(red),
Ctype: redtype,
}, },
Blue: &pb.DBCanineRabbitRoomPlayer{ Blue: &pb.DBCanineRabbitRoomPlayer{
Info: comm.GetUserBaseInfo(blue), Info: comm.GetUserBaseInfo(blue),
Ctype: bluetype,
}, },
Chess: chess, Chess: chess,
}, sessions); err != nil { }, sessions); err != nil {

View File

@ -15,7 +15,7 @@ type Room struct {
data *pb.DBCanineRabbitRoom data *pb.DBCanineRabbitRoom
sessions []comm.IUserSession sessions []comm.IUserSession
starttime time.Time starttime time.Time
currside int32 currside string
currindex int32 currindex int32
} }
@ -28,6 +28,7 @@ func (this *Room) GameStart() (err error) {
}); err != nil { }); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
} }
return return
} }
@ -39,10 +40,22 @@ func (this *Room) PlayerLoadEnd(uid string) (err error) {
} }
if this.data.Red.Ready && this.data.Blue.Ready { //两个人都准备了 if this.data.Red.Ready && this.data.Blue.Ready { //两个人都准备了
this.currside = 1 if this.data.Rules.Headstart == 0 {
if err = this.Broadcast("gamestart", &pb.DColorGameStartPush{ if this.data.Red.Ctype == 0 { //红方先手
Roomid: this.data.Rid, this.currside = this.data.Red.Info.Uid
Side: 1, } else {
this.currside = this.data.Blue.Info.Uid
}
} else {
if this.data.Red.Ctype == 0 { //红方先手
this.currside = this.data.Blue.Info.Uid
} else {
this.currside = this.data.Red.Info.Uid
}
}
if err = this.Broadcast("gamestart", &pb.CanineRabbitGameStartPush{
Roomid: this.data.Rid,
Currplayer: this.currside,
}); err != nil { }); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
} }
@ -58,10 +71,15 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CanineRabbitHandleReq) (er
v.Y = handle.Chess.Y v.Y = handle.Chess.Y
} }
} }
if this.currside == 1 { if this.currside == uid {
this.currside = 2 if this.currside == this.data.Red.Info.Uid {
this.currside = this.data.Blue.Info.Uid
} else {
this.currside = this.data.Red.Info.Uid
}
} else { } else {
this.currside = 1 err = fmt.Errorf("It's not you who shoot!")
return
} }
if err = this.Broadcast("gamehandle", &pb.CanineRabbitGameHandlePush{ if err = this.Broadcast("gamehandle", &pb.CanineRabbitGameHandlePush{
Roomid: this.data.Rid, Roomid: this.data.Rid,
@ -75,11 +93,12 @@ func (this *Room) PlayerHandle(uid string, handle *pb.CanineRabbitHandleReq) (er
//玩家操作 //玩家操作
func (this *Room) PlayerWin(uid string, handle *pb.CanineRabbitWinReq) (err error) { func (this *Room) PlayerWin(uid string, handle *pb.CanineRabbitWinReq) (err error) {
var (
winuid string = uid
)
if handle.Iswin { if handle.Iswin {
if this.currside == 1 { if this.currside != this.data.Red.Info.Uid {
this.data.Red.Score = 1 if this.data.Red.Ctype == 0 {
if this.data.Rules.RedType == 0 {
this.data.Red.Rabbitintegral += 1 this.data.Red.Rabbitintegral += 1
} else { } else {
this.data.Red.Houndintegral += 1 this.data.Red.Houndintegral += 1
@ -88,28 +107,58 @@ func (this *Room) PlayerWin(uid string, handle *pb.CanineRabbitWinReq) (err erro
"rabbitintegral": this.data.Red.Rabbitintegral, "rabbitintegral": this.data.Red.Rabbitintegral,
"houndintegral": this.data.Red.Houndintegral, "houndintegral": this.data.Red.Houndintegral,
}) })
} else { } else {
this.data.Blue.Score = 1 if this.data.Blue.Ctype == 0 {
if this.data.Rules.RedType == 0 {
this.data.Blue.Rabbitintegral += 1 this.data.Blue.Rabbitintegral += 1
} else { } else {
this.data.Blue.Houndintegral += 1 this.data.Blue.Houndintegral += 1
} }
this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{ this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{
"rabbitintegral": this.data.Red.Rabbitintegral, "rabbitintegral": this.data.Blue.Rabbitintegral,
"houndintegral": this.data.Red.Houndintegral, "houndintegral": this.data.Blue.Houndintegral,
}) })
} }
if err = this.Broadcast("gameover", &pb.CanineRabbitGameOverPush{ if err = this.Broadcast("gameover", &pb.CanineRabbitGameOverPush{
Winside: this.currside, Winuid: winuid,
RedIntegral: this.data.Red.Score, Admitdefeat: false,
BlueIntegral: this.data.Blue.Score, Red: this.data.Red,
Blue: this.data.Blue,
}); err != nil {
this.module.Errorln(err)
}
} else {
if uid != this.data.Red.Info.Uid {
winuid = this.data.Red.Info.Uid
if this.data.Red.Ctype == 0 {
this.data.Red.Rabbitintegral += 1
} else {
this.data.Red.Houndintegral += 1
}
this.module.model.Change(this.data.Red.Info.Uid, map[string]interface{}{
"rabbitintegral": this.data.Red.Rabbitintegral,
"houndintegral": this.data.Red.Houndintegral,
})
} else {
winuid = this.data.Blue.Info.Uid
if this.data.Blue.Ctype == 0 {
this.data.Blue.Rabbitintegral += 1
} else {
this.data.Blue.Houndintegral += 1
}
this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{
"rabbitintegral": this.data.Blue.Rabbitintegral,
"houndintegral": this.data.Blue.Houndintegral,
})
}
if err = this.Broadcast("gameover", &pb.CanineRabbitGameOverPush{
Winuid: winuid,
Admitdefeat: true,
Red: this.data.Red,
Blue: this.data.Blue,
}); err != nil { }); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
} }
} }
return return
} }
func (this *Room) Broadcast(stype string, msg proto.Message) (err error) { func (this *Room) Broadcast(stype string, msg proto.Message) (err error) {

View File

@ -20,7 +20,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
//切磋请求记录 //狗兔大战
type DBCanineRabbit struct { type DBCanineRabbit struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -164,6 +164,7 @@ func (x *DBCanineRabbitRules) GetHeadstart() int32 {
return 0 return 0
} }
//旗子
type DBCanineRabbitChess struct { type DBCanineRabbitChess struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -240,8 +241,8 @@ type DBCanineRabbitRoomPlayer struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Info *BaseUserInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info"` //发起者信息 Info *BaseUserInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info"` //发起者信息
Isai bool `protobuf:"varint,2,opt,name=isai,proto3" json:"isai"` Ctype int32 `protobuf:"varint,2,opt,name=ctype,proto3" json:"ctype"` //0兔子 1猎犬
Ready bool `protobuf:"varint,3,opt,name=ready,proto3" json:"ready"` Ready bool `protobuf:"varint,3,opt,name=ready,proto3" json:"ready"`
Score int32 `protobuf:"varint,4,opt,name=score,proto3" json:"score"` Score int32 `protobuf:"varint,4,opt,name=score,proto3" json:"score"`
Rabbitintegral int32 `protobuf:"varint,5,opt,name=rabbitintegral,proto3" json:"rabbitintegral"` //兔子积分 Rabbitintegral int32 `protobuf:"varint,5,opt,name=rabbitintegral,proto3" json:"rabbitintegral"` //兔子积分
@ -287,11 +288,11 @@ func (x *DBCanineRabbitRoomPlayer) GetInfo() *BaseUserInfo {
return nil return nil
} }
func (x *DBCanineRabbitRoomPlayer) GetIsai() bool { func (x *DBCanineRabbitRoomPlayer) GetCtype() int32 {
if x != nil { if x != nil {
return x.Isai return x.Ctype
} }
return false return 0
} }
func (x *DBCanineRabbitRoomPlayer) GetReady() bool { func (x *DBCanineRabbitRoomPlayer) GetReady() bool {
@ -435,34 +436,35 @@ var file_caninerabbit_caninerabbit_db_proto_rawDesc = []byte{
0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x03, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x03,
0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x04, 0x20, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x04, 0x20, 0x01,
0x28, 0x05, 0x52, 0x01, 0x79, 0x22, 0xcb, 0x01, 0x0a, 0x18, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x28, 0x05, 0x52, 0x01, 0x79, 0x22, 0xcd, 0x01, 0x0a, 0x18, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69,
0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79,
0x65, 0x72, 0x12, 0x21, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0d, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x32, 0x0d, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x73, 0x61, 0x69, 0x18, 0x02, 0x20, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02,
0x01, 0x28, 0x08, 0x52, 0x04, 0x69, 0x73, 0x61, 0x69, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72,
0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x12, 0x65, 0x61, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64,
0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05,
0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x61, 0x62, 0x62, 0x69, 0x74, 0x69, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x61, 0x62, 0x62, 0x69,
0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x72, 0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52,
0x61, 0x62, 0x62, 0x69, 0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12, 0x24, 0x0a, 0x0e, 0x72, 0x61, 0x62, 0x62, 0x69, 0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12,
0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x06, 0x24, 0x0a, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c,
0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74,
0x72, 0x61, 0x6c, 0x22, 0xda, 0x01, 0x0a, 0x12, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x22, 0xda, 0x01, 0x0a, 0x12, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69,
0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x10, 0x0a, 0x03,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x2a, 0x0a, 0x05, 0x72, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x2a,
0x72, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42, 0x0a, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e,
0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x75, 0x6c, 0x65, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x75,
0x73, 0x52, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x72, 0x65, 0x64, 0x18, 0x6c, 0x65, 0x73, 0x52, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x72, 0x65,
0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69,
0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79,
0x65, 0x72, 0x52, 0x03, 0x72, 0x65, 0x64, 0x12, 0x2d, 0x0a, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x18,
0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65,
0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72,
0x52, 0x03, 0x72, 0x65, 0x64, 0x12, 0x2d, 0x0a, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x52, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x63, 0x68, 0x65, 0x73, 0x73, 0x18,
0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65,
0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x52, 0x04, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x43, 0x68, 0x65, 0x73, 0x73, 0x52, 0x05, 0x63, 0x68, 0x65,
0x62, 0x6c, 0x75, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x63, 0x68, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x73, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x6f, 0x33,
0x62, 0x62, 0x69, 0x74, 0x43, 0x68, 0x65, 0x73, 0x73, 0x52, 0x05, 0x63, 0x68, 0x65, 0x73, 0x73,
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ type GameInviteQiecuoReq struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Fid string `protobuf:"bytes,1,opt,name=fid,proto3" json:"fid"` //游戏邀请对象 Fid string `protobuf:"bytes,1,opt,name=fid,proto3" json:"fid"` //游戏邀请对象
Gtype int32 `protobuf:"varint,2,opt,name=gtype,proto3" json:"gtype"` //游戏类型 Gtype int32 `protobuf:"varint,2,opt,name=gtype,proto3" json:"gtype"` //游戏类型 1 武馆切磋 2 犬兔大战 3 猜颜色
Rules string `protobuf:"bytes,3,opt,name=rules,proto3" json:"rules"` //规则字符串 Rules string `protobuf:"bytes,3,opt,name=rules,proto3" json:"rules"` //规则字符串
} }