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

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

View File

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

View File

@ -20,7 +20,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
//切磋请求记录
//狗兔大战
type DBCanineRabbit struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -164,6 +164,7 @@ func (x *DBCanineRabbitRules) GetHeadstart() int32 {
return 0
}
//旗子
type DBCanineRabbitChess struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -241,7 +242,7 @@ type DBCanineRabbitRoomPlayer struct {
unknownFields protoimpl.UnknownFields
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"`
Score int32 `protobuf:"varint,4,opt,name=score,proto3" json:"score"`
Rabbitintegral int32 `protobuf:"varint,5,opt,name=rabbitintegral,proto3" json:"rabbitintegral"` //兔子积分
@ -287,11 +288,11 @@ func (x *DBCanineRabbitRoomPlayer) GetInfo() *BaseUserInfo {
return nil
}
func (x *DBCanineRabbitRoomPlayer) GetIsai() bool {
func (x *DBCanineRabbitRoomPlayer) GetCtype() int32 {
if x != nil {
return x.Isai
return x.Ctype
}
return false
return 0
}
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,
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,
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,
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,
0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x73, 0x61, 0x69, 0x18, 0x02, 0x20,
0x01, 0x28, 0x08, 0x52, 0x04, 0x69, 0x73, 0x61, 0x69, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x65, 0x61,
0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x12,
0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05,
0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x61, 0x62, 0x62, 0x69, 0x74, 0x69,
0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x72,
0x61, 0x62, 0x62, 0x69, 0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12, 0x24, 0x0a,
0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x06,
0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67,
0x72, 0x61, 0x6c, 0x22, 0xda, 0x01, 0x0a, 0x12, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65,
0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x2a, 0x0a, 0x05,
0x72, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42,
0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x75, 0x6c, 0x65,
0x73, 0x52, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x72, 0x65, 0x64, 0x18,
0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65,
0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72,
0x65, 0x61, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05,
0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x61, 0x62, 0x62, 0x69,
0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52,
0x0e, 0x72, 0x61, 0x62, 0x62, 0x69, 0x74, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12,
0x24, 0x0a, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c,
0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x68, 0x6f, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x74,
0x65, 0x67, 0x72, 0x61, 0x6c, 0x22, 0xda, 0x01, 0x0a, 0x12, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69,
0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x10, 0x0a, 0x03,
0x72, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x69, 0x64, 0x12, 0x2a,
0x0a, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e,
0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61, 0x62, 0x62, 0x69, 0x74, 0x52, 0x75,
0x6c, 0x65, 0x73, 0x52, 0x05, 0x72, 0x75, 0x6c, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x03, 0x72, 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, 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, 0x04,
0x62, 0x6c, 0x75, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x63, 0x68, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65, 0x52, 0x61,
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,
0x52, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x63, 0x68, 0x65, 0x73, 0x73, 0x18,
0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x6e, 0x69, 0x6e, 0x65,
0x52, 0x61, 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 (

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ type GameInviteQiecuoReq struct {
unknownFields protoimpl.UnknownFields
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"` //规则字符串
}