三消优化
This commit is contained in:
parent
866b768e96
commit
96d06af605
@ -36,6 +36,7 @@ type Room struct {
|
||||
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
|
||||
RoomType int32 // 房间类型 1 是好友创房
|
||||
MaxTime int32 // 操作时间
|
||||
Playtype int32 //当前房间玩法
|
||||
}
|
||||
|
||||
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
|
||||
this.NexPower = this.player2.Userinfo.Uid
|
||||
this.player2.Ps = MaxPs // 恢复体力
|
||||
|
||||
this.player1.Ps = 0
|
||||
} else { // 权限给1号玩家
|
||||
this.curPower = this.player1.Userinfo.Uid
|
||||
this.NexPower = this.player1.Userinfo.Uid
|
||||
this.player1.Ps = MaxPs // 恢复体力
|
||||
this.player2.Ps = 0
|
||||
this.round++
|
||||
|
||||
}
|
||||
|
||||
var 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{
|
||||
Mpadata: szMap,
|
||||
//Mpadata: szMap,
|
||||
Power: this.NexPower,
|
||||
Curpower: this.curPower,
|
||||
Score: 0,
|
||||
Round: this.round,
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Itype: 0,
|
||||
Itype: 9999,
|
||||
Curid: 0,
|
||||
Targetid: 0,
|
||||
}, 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 {
|
||||
var room *Room
|
||||
this.module = module
|
||||
this.chessboard = new(MapData)
|
||||
this.RandomPlayType()
|
||||
this.chessboard.InitMap(module) // 初始化棋盘
|
||||
if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok {
|
||||
this.module.PutUserSession(s1)
|
||||
@ -308,85 +324,101 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
return
|
||||
}
|
||||
oid1 = this.chessboard.Plat[req.Curid].Oid
|
||||
oid2 = this.chessboard.Plat[req.Targetid].Oid
|
||||
// 交换元素
|
||||
if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回
|
||||
Title: pb.ErrorCode_EntertainCantSwap.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 {
|
||||
// curScore += score
|
||||
szMap = append(szMap, m...)
|
||||
bAddPs = b
|
||||
} else { // 不能消除
|
||||
this.chessboard.SwapGirde(req.Targetid, req.Curid) // 换到原来的位置
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回
|
||||
Title: pb.ErrorCode_EntertainCantSwap.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 校验下次是不是消除
|
||||
if !this.chessboard.CheckAndRefreshPlat() {
|
||||
this.chessboard.RedsetPlatData()
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.chessboard.GetPalatData(),
|
||||
ChangeType: 1,
|
||||
})
|
||||
}
|
||||
if this.curPower == this.player1.Userinfo.Uid { //权限校验
|
||||
this.player1.Score += curScore
|
||||
this.player1.Ps--
|
||||
if bAddPs {
|
||||
this.player1.Ps++
|
||||
if this.player1.Ps > MaxPs {
|
||||
this.player1.Ps = MaxPs
|
||||
}
|
||||
}
|
||||
|
||||
if this.player1.Ps <= 0 {
|
||||
if req.Itype == 0 && req.Curid == 0 && req.Targetid == 0 {
|
||||
if this.curPower == this.player1.Userinfo.Uid {
|
||||
this.NexPower = this.player2.Userinfo.Uid
|
||||
if len(this.szSession) == 1 { // 校验2号玩家是不是AI
|
||||
AIOperator = true
|
||||
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
|
||||
oid2 = this.chessboard.Plat[req.Targetid].Oid
|
||||
// 交换元素
|
||||
if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回
|
||||
Title: pb.ErrorCode_EntertainCantSwap.ToString(),
|
||||
}
|
||||
this.player2.Ps = MaxPs
|
||||
return
|
||||
}
|
||||
|
||||
} else { // this.curPower == this.player2.Uid
|
||||
this.player2.Score += curScore
|
||||
this.player2.Ps--
|
||||
if bAddPs {
|
||||
this.player2.Ps++
|
||||
if this.player2.Ps > MaxPs {
|
||||
if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 {
|
||||
// curScore += score
|
||||
szMap = append(szMap, m...)
|
||||
bAddPs = b
|
||||
} else { // 不能消除
|
||||
this.chessboard.SwapGirde(req.Targetid, req.Curid) // 换到原来的位置
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回
|
||||
Title: pb.ErrorCode_EntertainCantSwap.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 校验下次是不是消除
|
||||
if !this.chessboard.CheckAndRefreshPlat() {
|
||||
this.chessboard.RedsetPlatData()
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.chessboard.GetPalatData(),
|
||||
ChangeType: 1,
|
||||
})
|
||||
}
|
||||
if this.curPower == this.player1.Userinfo.Uid { //权限校验
|
||||
this.player1.Score += curScore
|
||||
this.player1.Ps--
|
||||
if bAddPs {
|
||||
this.player1.Ps++
|
||||
if this.player1.Ps > MaxPs {
|
||||
this.player1.Ps = MaxPs
|
||||
}
|
||||
}
|
||||
|
||||
if this.player1.Ps <= 0 {
|
||||
this.NexPower = this.player2.Userinfo.Uid
|
||||
if len(this.szSession) == 1 { // 校验2号玩家是不是AI
|
||||
AIOperator = true
|
||||
}
|
||||
this.player2.Ps = MaxPs
|
||||
}
|
||||
}
|
||||
if this.player2.Ps <= 0 {
|
||||
this.NexPower = this.player1.Userinfo.Uid
|
||||
this.player1.Ps = MaxPs
|
||||
this.round++
|
||||
} else { // this.curPower == this.player2.Uid
|
||||
this.player2.Score += curScore
|
||||
this.player2.Ps--
|
||||
if bAddPs {
|
||||
this.player2.Ps++
|
||||
if this.player2.Ps > MaxPs {
|
||||
this.player2.Ps = MaxPs
|
||||
}
|
||||
}
|
||||
if this.player2.Ps <= 0 {
|
||||
this.NexPower = this.player1.Userinfo.Uid
|
||||
this.player1.Ps = MaxPs
|
||||
// this.round++
|
||||
|
||||
}
|
||||
}
|
||||
for _, v := range szMap { //
|
||||
curScore += v.CurSocre
|
||||
if color == 1 {
|
||||
this.player1.Score += v.CurSocre
|
||||
v.CurSocre = this.player1.Score
|
||||
this.player1.Energy += v.CurEnergy
|
||||
v.CurEnergy = this.player1.Energy
|
||||
} else {
|
||||
this.player2.Score += v.CurSocre
|
||||
v.CurSocre = this.player2.Score
|
||||
this.player2.Energy += v.CurEnergy
|
||||
v.CurEnergy = this.player2.Energy
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range szMap { //
|
||||
curScore += v.CurSocre
|
||||
if color == 1 {
|
||||
this.player1.Score += v.CurSocre
|
||||
v.CurSocre = this.player1.Score
|
||||
this.player1.Energy += v.CurEnergy
|
||||
v.CurEnergy = this.player1.Energy
|
||||
} else {
|
||||
this.player2.Score += v.CurSocre
|
||||
v.CurSocre = this.player2.Score
|
||||
this.player2.Energy += v.CurEnergy
|
||||
v.CurEnergy = this.player2.Energy
|
||||
}
|
||||
|
||||
if this.NexPower == this.player1.Userinfo.Uid && this.NexPower != this.curPower {
|
||||
this.round++
|
||||
}
|
||||
|
||||
// 广播消息
|
||||
@ -448,6 +480,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏
|
||||
bStartGame = true
|
||||
this.rd1 = false
|
||||
this.rd2 = false
|
||||
}
|
||||
}
|
||||
if bStartGame {
|
||||
@ -457,13 +491,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
} else {
|
||||
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime
|
||||
}
|
||||
//this.MaxTime = 5
|
||||
var weight []int32 // 权重
|
||||
// 开始随机玩法
|
||||
list := this.module.configure.GetGameConsumeIntegral()
|
||||
for _, v := range list {
|
||||
weight = append(weight, v.Weight)
|
||||
}
|
||||
this.MaxTime = 10
|
||||
|
||||
this.Status = 1
|
||||
this.round = 1
|
||||
@ -474,8 +502,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
Mpadata: &pb.MapData{Data: this.chessboard.Plat},
|
||||
Power: this.NexPower,
|
||||
Round: this.round,
|
||||
Roomid: this.Id, // 房间ID
|
||||
Playtype: list[comm.GetRandW(weight)].Key, // 通过权重随机一个玩法
|
||||
Roomid: this.Id, // 房间ID
|
||||
Playtype: this.Playtype, // 通过权重随机一个玩法
|
||||
}, this.szSession...); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
@ -525,13 +553,35 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
timewheel.Remove(this.operatetimer)
|
||||
this.operatetimer = nil
|
||||
}
|
||||
this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
|
||||
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
|
||||
Time: this.MaxTime,
|
||||
}, this.szSession...); err != nil {
|
||||
this.module.Errorln(err)
|
||||
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{
|
||||
Time: this.MaxTime,
|
||||
Power: this.curPower,
|
||||
}, this.szSession...); err != nil {
|
||||
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
|
||||
@ -596,7 +646,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
||||
}
|
||||
// 查看能不能获得箱子
|
||||
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.Color != 0 {
|
||||
box = &pb.BoxData{
|
||||
@ -638,6 +688,7 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room,
|
||||
this.player1 = p
|
||||
this.module = module
|
||||
this.chessboard = new(MapData)
|
||||
this.RandomPlayType()
|
||||
this.chessboard.InitMap(module) // 初始化棋盘
|
||||
if s1, ok := this.module.GetUserSession(p.Userinfo.Uid); !ok {
|
||||
this.module.PutUserSession(s1)
|
||||
|
@ -44,7 +44,6 @@ func GetRandType() int32 {
|
||||
|
||||
func (this *MapData) CreateGride(index int32) *pb.GirdeData {
|
||||
t := GetRandType()
|
||||
//fmt.Printf("create=====index: %d, color:%d \n", index, t)
|
||||
this.oid++
|
||||
return &pb.GirdeData{
|
||||
Oid: this.oid,
|
||||
@ -65,7 +64,7 @@ func (this *MapData) InitMap(module *Entertainment) {
|
||||
this.Plat[i] = this.CreateGride(int32(i))
|
||||
}
|
||||
this.SetIndelibilityPlat()
|
||||
this.SetMap() // 方便测试固定地图
|
||||
//this.SetMap() // 方便测试固定地图
|
||||
}
|
||||
|
||||
// 交换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
|
||||
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() {
|
||||
@ -2124,6 +2125,13 @@ func (x *EntertainStarTimerPush) GetTime() int32 {
|
||||
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_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,
|
||||
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, 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,
|
||||
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,
|
||||
0x74, 0x6f, 0x33,
|
||||
0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01,
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user