三消优化
This commit is contained in:
parent
866b768e96
commit
96d06af605
@ -36,6 +36,7 @@ type Room struct {
|
|||||||
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
|
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
|
||||||
RoomType int32 // 房间类型 1 是好友创房
|
RoomType int32 // 房间类型 1 是好友创房
|
||||||
MaxTime int32 // 操作时间
|
MaxTime int32 // 操作时间
|
||||||
|
Playtype int32 //当前房间玩法
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||||
@ -46,27 +47,29 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
|||||||
if this.player1.Userinfo.Uid == this.curPower { // 给玩家2
|
if this.player1.Userinfo.Uid == this.curPower { // 给玩家2
|
||||||
this.NexPower = this.player2.Userinfo.Uid
|
this.NexPower = this.player2.Userinfo.Uid
|
||||||
this.player2.Ps = MaxPs // 恢复体力
|
this.player2.Ps = MaxPs // 恢复体力
|
||||||
|
this.player1.Ps = 0
|
||||||
} else { // 权限给1号玩家
|
} else { // 权限给1号玩家
|
||||||
this.curPower = this.player1.Userinfo.Uid
|
this.NexPower = this.player1.Userinfo.Uid
|
||||||
this.player1.Ps = MaxPs // 恢复体力
|
this.player1.Ps = MaxPs // 恢复体力
|
||||||
|
this.player2.Ps = 0
|
||||||
this.round++
|
this.round++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var szMap []*pb.MapData
|
var szMap []*pb.MapData
|
||||||
szMap = append(szMap, &pb.MapData{
|
szMap = append(szMap, &pb.MapData{
|
||||||
Data: this.chessboard.Plat,
|
Data: this.chessboard.GetPalatData(),
|
||||||
})
|
})
|
||||||
|
fmt.Printf("===超时棋盘=============\n")
|
||||||
|
this.chessboard.Debugf()
|
||||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||||
Mpadata: szMap,
|
//Mpadata: szMap,
|
||||||
Power: this.NexPower,
|
Power: this.NexPower,
|
||||||
Curpower: this.curPower,
|
Curpower: this.curPower,
|
||||||
Score: 0,
|
Score: 0,
|
||||||
Round: this.round,
|
Round: this.round,
|
||||||
User1: this.player1,
|
User1: this.player1,
|
||||||
User2: this.player2,
|
User2: this.player2,
|
||||||
Itype: 0,
|
Itype: 9999,
|
||||||
Curid: 0,
|
Curid: 0,
|
||||||
Targetid: 0,
|
Targetid: 0,
|
||||||
}, this.szSession...); err != nil {
|
}, this.szSession...); err != nil {
|
||||||
@ -88,10 +91,23 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 随机一个玩法
|
||||||
|
func (this *Room) RandomPlayType() {
|
||||||
|
var weight []int32 // 权重
|
||||||
|
// 开始随机玩法
|
||||||
|
list := this.module.configure.GetGameConsumeIntegral()
|
||||||
|
for _, v := range list {
|
||||||
|
weight = append(weight, v.Weight)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Playtype = list[comm.GetRandW(weight)].Key
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room {
|
func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room {
|
||||||
var room *Room
|
var room *Room
|
||||||
this.module = module
|
this.module = module
|
||||||
this.chessboard = new(MapData)
|
this.chessboard = new(MapData)
|
||||||
|
this.RandomPlayType()
|
||||||
this.chessboard.InitMap(module) // 初始化棋盘
|
this.chessboard.InitMap(module) // 初始化棋盘
|
||||||
if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok {
|
if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok {
|
||||||
this.module.PutUserSession(s1)
|
this.module.PutUserSession(s1)
|
||||||
@ -308,6 +324,18 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if req.Itype == 0 && req.Curid == 0 && req.Targetid == 0 {
|
||||||
|
if this.curPower == this.player1.Userinfo.Uid {
|
||||||
|
this.NexPower = this.player2.Userinfo.Uid
|
||||||
|
this.player2.Ps = 2
|
||||||
|
this.player1.Ps = 0
|
||||||
|
}
|
||||||
|
if this.curPower == this.player2.Userinfo.Uid {
|
||||||
|
this.NexPower = this.player1.Userinfo.Uid
|
||||||
|
this.player1.Ps = 2
|
||||||
|
this.player2.Ps = 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
oid1 = this.chessboard.Plat[req.Curid].Oid
|
oid1 = this.chessboard.Plat[req.Curid].Oid
|
||||||
oid2 = this.chessboard.Plat[req.Targetid].Oid
|
oid2 = this.chessboard.Plat[req.Targetid].Oid
|
||||||
// 交换元素
|
// 交换元素
|
||||||
@ -357,7 +385,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
}
|
}
|
||||||
this.player2.Ps = MaxPs
|
this.player2.Ps = MaxPs
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // this.curPower == this.player2.Uid
|
} else { // this.curPower == this.player2.Uid
|
||||||
this.player2.Score += curScore
|
this.player2.Score += curScore
|
||||||
this.player2.Ps--
|
this.player2.Ps--
|
||||||
@ -370,7 +397,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
if this.player2.Ps <= 0 {
|
if this.player2.Ps <= 0 {
|
||||||
this.NexPower = this.player1.Userinfo.Uid
|
this.NexPower = this.player1.Userinfo.Uid
|
||||||
this.player1.Ps = MaxPs
|
this.player1.Ps = MaxPs
|
||||||
this.round++
|
// this.round++
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -388,6 +415,11 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
v.CurEnergy = this.player2.Energy
|
v.CurEnergy = this.player2.Energy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if this.NexPower == this.player1.Userinfo.Uid && this.NexPower != this.curPower {
|
||||||
|
this.round++
|
||||||
|
}
|
||||||
|
|
||||||
// 广播消息
|
// 广播消息
|
||||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||||
@ -448,6 +480,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
}
|
}
|
||||||
if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏
|
if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏
|
||||||
bStartGame = true
|
bStartGame = true
|
||||||
|
this.rd1 = false
|
||||||
|
this.rd2 = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bStartGame {
|
if bStartGame {
|
||||||
@ -457,13 +491,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
} else {
|
} else {
|
||||||
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime
|
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime
|
||||||
}
|
}
|
||||||
//this.MaxTime = 5
|
this.MaxTime = 10
|
||||||
var weight []int32 // 权重
|
|
||||||
// 开始随机玩法
|
|
||||||
list := this.module.configure.GetGameConsumeIntegral()
|
|
||||||
for _, v := range list {
|
|
||||||
weight = append(weight, v.Weight)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Status = 1
|
this.Status = 1
|
||||||
this.round = 1
|
this.round = 1
|
||||||
@ -475,7 +503,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
Power: this.NexPower,
|
Power: this.NexPower,
|
||||||
Round: this.round,
|
Round: this.round,
|
||||||
Roomid: this.Id, // 房间ID
|
Roomid: this.Id, // 房间ID
|
||||||
Playtype: list[comm.GetRandW(weight)].Key, // 通过权重随机一个玩法
|
Playtype: this.Playtype, // 通过权重随机一个玩法
|
||||||
}, this.szSession...); err != nil {
|
}, this.szSession...); err != nil {
|
||||||
this.module.Errorln(err)
|
this.module.Errorln(err)
|
||||||
}
|
}
|
||||||
@ -525,13 +553,35 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
timewheel.Remove(this.operatetimer)
|
timewheel.Remove(this.operatetimer)
|
||||||
this.operatetimer = nil
|
this.operatetimer = nil
|
||||||
}
|
}
|
||||||
this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
|
if this.player1.Userinfo.Uid == session.GetUserId() {
|
||||||
|
this.rd1 = true
|
||||||
|
} else if this.player2.Userinfo.Uid == session.GetUserId() {
|
||||||
|
this.rd2 = true
|
||||||
|
}
|
||||||
|
if len(this.szSession) == 1 {
|
||||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
|
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
|
||||||
Time: this.MaxTime,
|
Time: this.MaxTime,
|
||||||
|
Power: this.curPower,
|
||||||
}, this.szSession...); err != nil {
|
}, this.szSession...); err != nil {
|
||||||
this.module.Errorln(err)
|
this.module.Errorln(err)
|
||||||
}
|
}
|
||||||
|
if this.curPower == this.player2.Userinfo.Uid {
|
||||||
|
this.AiOperator()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏
|
||||||
|
this.rd1 = false
|
||||||
|
this.rd2 = false
|
||||||
|
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
|
||||||
|
Time: this.MaxTime,
|
||||||
|
Power: this.curPower,
|
||||||
|
}, this.szSession...); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -596,7 +646,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
|||||||
}
|
}
|
||||||
// 查看能不能获得箱子
|
// 查看能不能获得箱子
|
||||||
if list, err := this.module.model.getEntertainmList(winner.Userinfo.Uid); err == nil {
|
if list, err := this.module.model.getEntertainmList(winner.Userinfo.Uid); err == nil {
|
||||||
if len(list.Box) <= 3 { // 可以获得一个宝箱
|
if len(list.Box) < 3 { // 可以获得一个宝箱
|
||||||
if c, err := this.module.configure.GetGameRandomConsumeBoxConf(); err == nil {
|
if c, err := this.module.configure.GetGameRandomConsumeBoxConf(); err == nil {
|
||||||
if c.Color != 0 {
|
if c.Color != 0 {
|
||||||
box = &pb.BoxData{
|
box = &pb.BoxData{
|
||||||
@ -638,6 +688,7 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room,
|
|||||||
this.player1 = p
|
this.player1 = p
|
||||||
this.module = module
|
this.module = module
|
||||||
this.chessboard = new(MapData)
|
this.chessboard = new(MapData)
|
||||||
|
this.RandomPlayType()
|
||||||
this.chessboard.InitMap(module) // 初始化棋盘
|
this.chessboard.InitMap(module) // 初始化棋盘
|
||||||
if s1, ok := this.module.GetUserSession(p.Userinfo.Uid); !ok {
|
if s1, ok := this.module.GetUserSession(p.Userinfo.Uid); !ok {
|
||||||
this.module.PutUserSession(s1)
|
this.module.PutUserSession(s1)
|
||||||
|
@ -44,7 +44,6 @@ func GetRandType() int32 {
|
|||||||
|
|
||||||
func (this *MapData) CreateGride(index int32) *pb.GirdeData {
|
func (this *MapData) CreateGride(index int32) *pb.GirdeData {
|
||||||
t := GetRandType()
|
t := GetRandType()
|
||||||
//fmt.Printf("create=====index: %d, color:%d \n", index, t)
|
|
||||||
this.oid++
|
this.oid++
|
||||||
return &pb.GirdeData{
|
return &pb.GirdeData{
|
||||||
Oid: this.oid,
|
Oid: this.oid,
|
||||||
@ -65,7 +64,7 @@ func (this *MapData) InitMap(module *Entertainment) {
|
|||||||
this.Plat[i] = this.CreateGride(int32(i))
|
this.Plat[i] = this.CreateGride(int32(i))
|
||||||
}
|
}
|
||||||
this.SetIndelibilityPlat()
|
this.SetIndelibilityPlat()
|
||||||
this.SetMap() // 方便测试固定地图
|
//this.SetMap() // 方便测试固定地图
|
||||||
}
|
}
|
||||||
|
|
||||||
// 交换2个元素(参数 oid )
|
// 交换2个元素(参数 oid )
|
||||||
@ -896,6 +895,10 @@ func (this *MapData) SetIndelibilityPlat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if b, _ := this.Check3X(); b {
|
||||||
|
fmt.Printf("plat init\n")
|
||||||
|
this.CheckMap(0, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新洗牌
|
// 重新洗牌
|
||||||
|
@ -2082,7 +2082,8 @@ type EntertainStarTimerPush struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Time int32 `protobuf:"varint,1,opt,name=time,proto3" json:"time"`
|
Time int32 `protobuf:"varint,1,opt,name=time,proto3" json:"time"` // 定时时间 单位s
|
||||||
|
Power string `protobuf:"bytes,2,opt,name=power,proto3" json:"power"` // 当前谁操作
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *EntertainStarTimerPush) Reset() {
|
func (x *EntertainStarTimerPush) Reset() {
|
||||||
@ -2124,6 +2125,13 @@ func (x *EntertainStarTimerPush) GetTime() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *EntertainStarTimerPush) GetPower() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Power
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
var File_entertain_entertain_msg_proto protoreflect.FileDescriptor
|
var File_entertain_entertain_msg_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_entertain_entertain_msg_proto_rawDesc = []byte{
|
var file_entertain_entertain_msg_proto_rawDesc = []byte{
|
||||||
@ -2323,11 +2331,12 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{
|
|||||||
0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x52, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x22, 0x1b, 0x0a, 0x19, 0x45, 0x6e, 0x74, 0x65,
|
0x52, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x22, 0x1b, 0x0a, 0x19, 0x45, 0x6e, 0x74, 0x65,
|
||||||
0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x4f, 0x76, 0x65,
|
0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x4f, 0x76, 0x65,
|
||||||
0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x2c, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61,
|
0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x42, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61,
|
||||||
0x69, 0x6e, 0x53, 0x74, 0x61, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12,
|
0x69, 0x6e, 0x53, 0x74, 0x61, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12,
|
||||||
0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74,
|
0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74,
|
||||||
0x69, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01,
|
||||||
0x74, 0x6f, 0x33,
|
0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70,
|
||||||
|
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user