go_dreamfactory/modules/caninerabbit/room.go
2023-10-26 17:42:56 +08:00

65 lines
1.4 KiB
Go

package caninerabbit
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"time"
"google.golang.org/protobuf/proto"
)
type Room struct {
module *CanineRabbit
data *pb.DBCanineRabbitRoom
sessions []comm.IUserSession
starttime time.Time
currside int32
currindex int32
}
func (this *Room) GameStart() (err error) {
this.starttime = configure.Now()
if err = this.Broadcast("gameready", &pb.CanineRabbitGameReadyPush{
ServicePath: fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId()),
Room: this.data,
Countdown: 60,
}); err != nil {
this.module.Errorln(err)
}
return
}
func (this *Room) PlayerLoadEnd(uid string) (err error) {
if uid == this.data.Red.Info.Uid {
this.data.Red.Ready = true
} else {
this.data.Blue.Ready = true
}
if this.data.Red.Ready && this.data.Blue.Ready { //两个人都准备了
this.currside = 1
if err = this.Broadcast("gamestart", &pb.DColorGameStartPush{
Roomid: this.data.Rid,
Side: 1,
}); err != nil {
this.module.Errorln(err)
}
}
return
}
//玩家操作
func (this *Room) PlayerHandle(uid string, handle *pb.CanineRabbitHandleReq) (err error) {
return
}
func (this *Room) Broadcast(stype string, msg proto.Message) (err error) {
if err = this.module.SendMsgToSession(string(this.module.GetType()), stype, msg, this.sessions...); err != nil {
this.module.Errorln(err)
}
return
}