This commit is contained in:
meixiongfeng 2023-11-01 19:33:56 +08:00
parent 2a633f9256
commit 8f4792ccb7
3 changed files with 183 additions and 51 deletions

View File

@ -38,25 +38,19 @@ type Room struct {
}
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
fmt.Printf("超时+++++%d\n", time.Now().Unix())
if this.operatetimer != nil {
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
}
if this.player1.Userinfo.Uid == this.curPower { // 给玩家2
this.player1.Ps--
if this.player1.Ps <= 0 { // 体力消耗完权限给下一个人
this.NexPower = this.player2.Userinfo.Uid
this.player2.Ps = MaxPs // 恢复体力
}
} else { // 权限给1号玩家
this.player2.Ps--
if this.player2.Ps <= 0 {
this.curPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs // 恢复体力
this.NexPower = this.player2.Userinfo.Uid
this.player2.Ps = MaxPs // 恢复体力
} else { // 权限给1号玩家
this.curPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs // 恢复体力
this.round++
this.round++
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
} // 回合+1
this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
}
}
var szMap []*pb.MapData
@ -87,6 +81,10 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
}
return
}
// 二号玩家是机器人
if len(this.szSession) == 1 {
this.AiOperator()
}
}
func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room {
@ -155,6 +153,10 @@ func (this *Room) AiOperator() {
this.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs
this.round++
if this.operatetimer != nil { // 开启新的定时器
timewheel.Remove(this.operatetimer)
}
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
}
// 校验下次是不是消除
if !this.chessboard.CheckAndRefreshPlat() {
@ -372,10 +374,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
this.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs
this.round++
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
}
}
}
for _, v := range szMap { //
@ -416,6 +415,13 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}
return
}
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
this.operatetimer = nil
}
if this.curPower != this.NexPower && len(this.szSession) > 1 {
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
}
// 变更权限
this.curPower = this.NexPower
if AIOperator { // AI操作
@ -454,6 +460,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()
@ -475,7 +482,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}, this.szSession...); err != nil {
this.module.Errorln(err)
}
this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
}
case "reconnect": // 重连

View File

@ -105,6 +105,13 @@ func (this *MapData) Check5X() (bEliminate bool, xiaochu []int, s map[int]int) {
//var xiaochu []int // 即将消除的key
s = make(map[int]int)
for k, v := range this.Plat {
// b := false
// for _, e := range this.operElem {
// if e == int32(k) {
// b = true
// break
// }
// }
if v.Cid == 0 {
continue
}
@ -158,6 +165,13 @@ func (this *MapData) Check4X() (bEliminate bool, xiaochu []int, s map[int]int) {
//var xiaochu []int // 即将消除的key
for k, v := range this.Plat {
// b := false
// for _, e := range this.operElem {
// if e == int32(k) {
// b = true
// break
// }
// }
if v.Cid == 0 {
continue
}
@ -232,6 +246,13 @@ func (this *MapData) Check4X() (bEliminate bool, xiaochu []int, s map[int]int) {
func (this *MapData) Check3X() (bEliminate bool, xiaochu []int) {
//var xiaochu []int // 即将消除的key
for k, v := range this.Plat {
// b := false
// for _, e := range this.operElem {
// if e == int32(k) {
// b = true
// break
// }
// }
if v.Cid == 0 {
continue
}
@ -545,13 +566,20 @@ func (this *MapData) CheckInitPlat() {
func (this *MapData) SetMap() {
sz2 := []int32{
1, 4, 2, 5, 4, 5, 2,
3, 2, 3, 1, 2, 1, 4,
2, 1, 5, 4, 6, 4, 1,
3, 1, 3, 5, 2, 6, 3,
4, 5, 4, 2, 4, 1, 1,
5, 3, 1, 5, 3, 3, 4,
4, 2, 4, 1, 2, 3, 4,
5, 5, 4, 1, 1, 2, 5,
3, 6, 3, 4, 6, 2, 1,
3, 5, 6, 3, 1, 6, 1,
1, 2, 6, 5, 4, 1, 3,
4, 4, 3, 5, 4, 6, 4,
5, 6, 1, 4, 3, 3, 6,
5, 3, 5, 3, 6, 1, 5,
// 1, 4, 2, 5, 4, 5, 2,
// 3, 2, 3, 5, 2, 1, 4,
// 2, 5, 5, 4, 5, 4, 1,
// 3, 1, 3, 5, 2, 6, 3,
// 4, 5, 4, 2, 4, 1, 1,
// 5, 3, 1, 5, 3, 3, 4,
// 4, 2, 4, 1, 2, 3, 4,
}
var pos int
for index := Width - 1; index >= 0; index-- {
@ -561,7 +589,8 @@ func (this *MapData) SetMap() {
pos++
}
}
this.SetIndelibilityPlat()
this.CheckAndRefreshPlat()
// this.SetIndelibilityPlat()
}
@ -574,12 +603,19 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
}
x := int32(k % Height) // x
y := int32(k / Height) // y
if x+2 < Height {
if x+2 < Height { // 上
k1 := this.Plat[k].Color
k2 := this.Plat[k+1].Color
if k1 == k2 { // 校验k3 左边和右边
if true {
pos := k + 2
if pos/Width-1 >= 0 { // 右
p := this.Plat[pos-Width].Color
if p == k1 {
bEliminate = true
return
}
}
if pos/Width+1 < Width { // 右
p := this.Plat[pos+Width].Color
if p == k1 {
@ -595,9 +631,34 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
}
}
}
// xia
pos := k - 1
if pos%Height > 0 { // 左右
if pos/Width-1 >= 0 { //左
p := this.Plat[pos-Width].Color
if p == k1 {
bEliminate = true
return
}
}
if pos/Width+1 < Width { // 右
p := this.Plat[pos+Width].Color
if p == k1 {
bEliminate = true
return
}
}
}
if pos%Height-1 >= 0 {
p := this.Plat[pos-1].Color
if p == k1 {
bEliminate = true
return
}
}
}
}
if y+2 < Height {
if y+2 < Height { // 左
k1 := this.Plat[k].Color
k2 := this.Plat[k+Width].Color
@ -618,6 +679,40 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
return
}
}
if pos%Height-1 >= 0 {
p := this.Plat[pos-1].Color
if p == k1 {
bEliminate = true
return
}
}
}
if true {
pos := k - Width
if pos >= 0 {
if pos%Height+1 < Width { // 上
p := this.Plat[pos+1].Color
if p == k1 {
bEliminate = true
return
}
}
if pos%Height-1 >= 0 { // 下
p := this.Plat[pos-1].Color
if p == k1 {
bEliminate = true
return
}
}
}
if pos/Height-1 >= 0 {
p := this.Plat[pos-Height].Color
if p == k1 {
bEliminate = true
return
}
}
}
}
}
@ -639,6 +734,13 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
return
}
}
if pos%Height-1 >= 0 {
p := this.Plat[pos-1].Color
if p == k1 {
bEliminate = true
return
}
}
}
}
}
@ -659,10 +761,21 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
return
}
}
if pos/Height-1 >= 0 { // 右
p := this.Plat[pos-Width].Color
if p == k1 {
bEliminate = true
return
}
}
}
}
}
}
if !bEliminate {
this.Debugf()
}
return
}
@ -680,14 +793,19 @@ func (this *MapData) SetIndelibilityPlat() {
k3 := this.Plat[k+2].Color
if k1 == k2 && k2 == k3 {
if this.Plat[k+2].Special == 0 {
this.Plat[k+2].Cid = (k3+1)%5 + 1
this.Plat[k+2].Color = (k3+1)%5 + 1
} else if this.Plat[k+1].Special == 0 {
this.Plat[k+1].Cid = (k3+1)%5 + 1
this.Plat[k+1].Color = (k3+1)%5 + 1
} else if this.Plat[k].Special == 0 {
this.Plat[k].Cid = (k3+1)%5 + 1
this.Plat[k].Color = (k3+1)%5 + 1
newId := k + 2
oldId := Total - 1
for i := 0; i < Total; i++ {
if this.Plat[oldId].Color == k3 { // 找到颜色不一样的
oldId -= 1
} else {
break
}
}
tmp := new(pb.GirdeData)
*tmp = *this.Plat[newId]
this.Plat[newId] = this.Plat[oldId]
this.Plat[oldId] = tmp
}
}
}
@ -698,15 +816,20 @@ func (this *MapData) SetIndelibilityPlat() {
k3 := this.Plat[k+2*Width].Color
if k1 == k2 && k2 == k3 {
if this.Plat[k+2*Width].Special == 0 {
this.Plat[k+2*Width].Cid = (k3+1)%5 + 1
this.Plat[k+2*Width].Color = (k3+1)%5 + 1
} else if this.Plat[k+Width].Special == 0 {
this.Plat[k+Width].Cid = (k3+1)%5 + 1
this.Plat[k+Width].Color = (k3+1)%5 + 1
} else if this.Plat[k].Special == 0 {
this.Plat[k].Cid = (k3+1)%5 + 1
this.Plat[k].Color = (k3+1)%5 + 1
if this.Plat[k+2*Width].Special == 0 { // 找最后一个交换
newId := k + 2*Width
oldId := Total - 1
for i := 0; i < Total; i++ {
if this.Plat[oldId].Color == k3 { // 找到颜色不一样的
oldId -= 1
} else {
break
}
}
tmp := new(pb.GirdeData)
*tmp = *this.Plat[newId]
this.Plat[newId] = this.Plat[oldId]
this.Plat[oldId] = tmp
}
}
}
@ -715,6 +838,7 @@ func (this *MapData) SetIndelibilityPlat() {
// 重新洗牌
func (this *MapData) RedsetPlatData() {
for i := 0; i < Total-1; i++ {
targetId := comm.GetRandNum(0, Total-1)
if i == int(targetId) {
@ -727,4 +851,5 @@ func (this *MapData) RedsetPlatData() {
}
this.SetIndelibilityPlat()
this.Debugf()
}

View File

@ -116,8 +116,8 @@ func (this *apiComp) GetAllMailAttachment(session comm.IUserSession, req *pb.Mai
}
this.module.modelMail.MailGetAttachmentMail(mailIds)
session.SendMsg(string(this.module.GetType()), "getallmailattachment", &pb.MailGetAllMailAttachmentResp{
Res: atno,
Ids: mailIds,
Reward: atno,
Ids: mailIds,
})
return
}