Merge branch 'develop' of git.pogorockgames.com:mango-games/server/game into develop
This commit is contained in:
commit
0855fc58f4
|
|
@ -30,6 +30,8 @@ const (
|
|||
ClawDollSceneBilledTimeout = time.Second * 2 //结算
|
||||
ClawDollSceneWaitPayCoinimeout = time.Second * 10 //等待下一局投币
|
||||
|
||||
ClawDollSceneGrapTimeOut = time.Second * 5 //下抓防卡死强制变状态倒计时
|
||||
ClawDollScenePayCoinTimeOut = time.Second * 2 //投币防卡死强制变状态倒计时
|
||||
)
|
||||
|
||||
// 玩家操作
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"mongo.games.com/game/protocol/machine"
|
||||
"mongo.games.com/goserver/core/logger"
|
||||
"mongo.games.com/goserver/core/netlib"
|
||||
"mongo.games.com/goserver/core/timer"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
|
@ -74,8 +75,9 @@ func MSDollMachineoCoinResultHandler(session *netlib.Session, packetId int, data
|
|||
|
||||
switch msg.TypeId {
|
||||
case 1:
|
||||
logger.Logger.Tracef("ClawDoll OnPlayerOp payCoin response, SnId= %v", p.SnId)
|
||||
if msg.Result == 1 {
|
||||
logger.Logger.Tracef("上分成功!!!!!!!!!!!!snid = ", msg.Snid)
|
||||
logger.Logger.Tracef("上分成功!!!!!!!!!!!!snid = %v", msg.Snid)
|
||||
|
||||
sceneEx.playingSnid = p.SnId
|
||||
|
||||
|
|
@ -91,22 +93,29 @@ func MSDollMachineoCoinResultHandler(session *netlib.Session, packetId int, data
|
|||
ClawdollBroadcastPlayingInfo(s)
|
||||
|
||||
} else {
|
||||
logger.Logger.Tracef("上分失败!!!!!!!!!!!!snid = ", msg.Snid)
|
||||
logger.Logger.Tracef("上分失败!!!!!!!!!!!!snid = %v", msg.Snid)
|
||||
}
|
||||
|
||||
case 2:
|
||||
if msg.Result == 1 {
|
||||
// 获得娃娃卡
|
||||
logger.Logger.Tracef("下抓成功!!!!!!!!!!!!snid = ", msg.Snid)
|
||||
logger.Logger.Tracef("下抓成功!!!!!!!!!!!!snid = %v", msg.Snid)
|
||||
} else {
|
||||
logger.Logger.Tracef("下抓失败!!!!!!!!!!!!snid = ", msg.Snid)
|
||||
logger.Logger.Tracef("下抓失败!!!!!!!!!!!!snid = %v", msg.Snid)
|
||||
}
|
||||
|
||||
logger.Logger.Tracef("ClawDoll StatePlayGame OnPlayerOp Grab response, SnId= %v", msg.Snid)
|
||||
|
||||
s.ChangeSceneState(rule.ClawDollSceneStateBilled)
|
||||
sceneEx.SetPlayingState(int32(rule.ClawDollSceneStateBilled))
|
||||
|
||||
ClawdollBroadcastRoomState(s)
|
||||
ClawdollSendPlayerInfo(s)
|
||||
|
||||
if sceneEx.grabTimerHandle != timer.TimerHandle(0) {
|
||||
timer.StopTimer(sceneEx.grabTimerHandle)
|
||||
sceneEx.grabTimerHandle = timer.TimerHandle(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ type SceneEx struct {
|
|||
machineId int //娃娃机ID
|
||||
machineConn *netlib.Session //娃娃机链接
|
||||
machineStatus int32 //娃娃机链接状态 0:离线 1:在线
|
||||
|
||||
payCoinTimeHandle timer.TimerHandle //上分投币托管handle
|
||||
grabTimerHandle timer.TimerHandle //下抓托管handle
|
||||
}
|
||||
|
||||
// 游戏是否能开始
|
||||
|
|
@ -392,6 +395,7 @@ func (this *SceneEx) TimeOutPlayGrab() bool {
|
|||
if playerEx != nil {
|
||||
grapType := this.GetPlayGrabType(playerEx)
|
||||
this.OnPlayerSMGrabOp(this.playingSnid, int32(this.machineId), grapType)
|
||||
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
@ -431,6 +435,34 @@ func (this *SceneEx) SendToMachine(pid int, msg interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
// 下抓托管handle
|
||||
func (this *SceneEx) GrabTimerHandle() {
|
||||
if this.grabTimerHandle != timer.TimerHandle(0) {
|
||||
timer.StopTimer(this.grabTimerHandle)
|
||||
this.grabTimerHandle = timer.TimerHandle(0)
|
||||
}
|
||||
|
||||
this.grabTimerHandle, _ = timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
|
||||
|
||||
logger.Logger.Tracef("ClawDoll SceneEx GrabTimerHandle: TimeOut: %v", rule.ClawDollSceneGrapTimeOut)
|
||||
this.TimeOutPlayGrab()
|
||||
return true
|
||||
}), nil, rule.ClawDollSceneGrapTimeOut, 1)
|
||||
}
|
||||
|
||||
// 上分投币托管handle
|
||||
func (this *SceneEx) PayCoinTimeHandle() {
|
||||
if this.payCoinTimeHandle != timer.TimerHandle(0) {
|
||||
timer.StopTimer(this.payCoinTimeHandle)
|
||||
this.payCoinTimeHandle = timer.TimerHandle(0)
|
||||
}
|
||||
|
||||
this.payCoinTimeHandle, _ = timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
|
||||
logger.Logger.Tracef("ClawDoll SceneEx PayCoinTimeHandle: TimeOut: %v", rule.ClawDollScenePayCoinTimeOut)
|
||||
return true
|
||||
}), nil, rule.ClawDollScenePayCoinTimeOut, 1)
|
||||
}
|
||||
|
||||
// actionType : 1 禁止推流 ForbidRTCStream
|
||||
// actionType : 2 恢复推流 ResumeRTCStream
|
||||
func operateTask(sceneEx *SceneEx, times int, actionType int, platform string) {
|
||||
|
|
|
|||
|
|
@ -530,6 +530,8 @@ func (this *StateWait) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, par
|
|||
// 1-前 2-后 3-左 4-右 5-投币
|
||||
sceneEx.OnPlayerSMPerateOp(p.SnId, int32(sceneEx.machineId), rule.ButtonPayCoin)
|
||||
|
||||
logger.Logger.Trace("(ClawDoll this *StateWait) OnPlayerOp payCoin, sceneId=", s.GetSceneId(), " player=", p.SnId, " machineId=", sceneEx.machineId)
|
||||
|
||||
//sceneEx.OnPlayerSCOp(p, opcode, clawdoll.OpResultCode_OPRC_Success, params)
|
||||
}
|
||||
}
|
||||
|
|
@ -575,6 +577,8 @@ func (this *StateStart) OnTick(s *base.Scene) {
|
|||
this.BaseState.OnTick(s)
|
||||
if sceneEx, ok := s.ExtraData.(*SceneEx); ok {
|
||||
if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollSceneStartTimeout {
|
||||
|
||||
logger.Logger.Trace("ClawDoll StateStart OnTick ChangeSceneState:", rule.ClawDollSceneStatePlayGame)
|
||||
//切换到等待操作状态
|
||||
s.ChangeSceneState(rule.ClawDollSceneStatePlayGame)
|
||||
sceneEx.SetPlayingState(int32(rule.ClawDollSceneStatePlayGame))
|
||||
|
|
@ -636,7 +640,7 @@ func (this *PlayGame) OnEnter(s *base.Scene) {
|
|||
|
||||
func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, params []int64) bool {
|
||||
|
||||
logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params)
|
||||
logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params)
|
||||
|
||||
if this.BaseState.OnPlayerOp(s, p, opcode, params) {
|
||||
return true
|
||||
|
|
@ -664,7 +668,7 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para
|
|||
|
||||
grapType := sceneEx.GetPlayGrabType(playerEx)
|
||||
|
||||
logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " grapType: ", grapType)
|
||||
logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp Grab-----SnId:", p.SnId, " grapType: ", grapType)
|
||||
//1-弱力抓 2 -强力抓
|
||||
sceneEx.OnPlayerSMGrabOp(p.SnId, int32(sceneEx.machineId), grapType)
|
||||
|
||||
|
|
@ -681,7 +685,7 @@ func (this *PlayGame) OnPlayerOp(s *base.Scene, p *base.Player, opcode int, para
|
|||
}
|
||||
|
||||
if params[0] < rule.ButtonFront || params[0] > rule.ButtonRight {
|
||||
logger.Logger.Trace("StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params)
|
||||
logger.Logger.Trace("ClawDoll StatePlayGame OnPlayerOp-----SnId:", p.SnId, " opcode: ", opcode, " params:", params)
|
||||
return false
|
||||
}
|
||||
// 1-前 2-后 3-左 4-右 5-投币
|
||||
|
|
@ -696,9 +700,11 @@ func (this *PlayGame) OnTick(s *base.Scene) {
|
|||
if sceneEx, ok := s.ExtraData.(*SceneEx); ok {
|
||||
if time.Now().Sub(sceneEx.StateStartTime) > rule.ClawDollScenePlayTimeout {
|
||||
|
||||
if sceneEx.TimeOutPlayGrab() {
|
||||
if sceneEx.Gaming && sceneEx.TimeOutPlayGrab() {
|
||||
sceneEx.Gaming = false
|
||||
logger.Logger.Trace("PlayGame OnTick TimeOutPlayGrab SnId", sceneEx.playingSnid, " machineId:", sceneEx.machineId)
|
||||
logger.Logger.Trace("PlayGame OnTick TimeOutPlayGrab SnId: ", sceneEx.playingSnid, " machineId:", sceneEx.machineId)
|
||||
|
||||
sceneEx.GrabTimerHandle()
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
|||
|
|
@ -77,7 +77,11 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
|||
|
||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||
if !ok || conn == nil {
|
||||
return nil
|
||||
fmt.Println("移动,创建链接!!!!!!!!!!!!!")
|
||||
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
if conn == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.Perate {
|
||||
|
|
@ -119,6 +123,7 @@ func SMDollMachinePerateHandler(session *netlib.Session, packetId int, data inte
|
|||
Process(conn, f1, f2)
|
||||
case 5:
|
||||
//投币
|
||||
conn := machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
fmt.Println("===========玩家投币===========", conn)
|
||||
go DollMachineGrabResult(conn, msg.Snid, msg.GetId())
|
||||
machinedoll.Coin(conn)
|
||||
|
|
@ -137,7 +142,11 @@ func SMDollMachineGrabHandler(session *netlib.Session, packetId int, data interf
|
|||
|
||||
conn, ok := machinedoll.MachineMgr.ConnMap[int(msg.GetId())]
|
||||
if !ok || conn == nil {
|
||||
return nil
|
||||
fmt.Println("下抓,创建链接!!!!!!!!!!!!!")
|
||||
conn = machinedoll.MachineMgr.CreateConn(int(msg.GetId()))
|
||||
if conn == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.GetTypeId() {
|
||||
|
|
@ -198,6 +207,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
|||
Result: 0,
|
||||
TypeId: 2,
|
||||
})
|
||||
//删除娃娃机链接
|
||||
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||
err := conn.Conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("关闭与娃娃机链接")
|
||||
return
|
||||
}
|
||||
if bytes.Contains(part, instruction1) && num != 1 {
|
||||
|
|
@ -215,6 +231,13 @@ func DollMachineGrabResult(conn *machinedoll.Conn, snid, id int32) {
|
|||
Result: 1,
|
||||
TypeId: 2,
|
||||
})
|
||||
//删除娃娃机链接
|
||||
//delete(machinedoll.MachineMgr.ConnMap, conn.Id)
|
||||
err := conn.Conn.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println("关闭与娃娃机链接")
|
||||
return
|
||||
}
|
||||
//上分成功
|
||||
|
|
|
|||
|
|
@ -87,6 +87,47 @@ func (this *MachineManager) Init() {
|
|||
|
||||
}
|
||||
|
||||
// 创建娃娃机链接
|
||||
func (this *MachineManager) CreateConn(key int) *Conn {
|
||||
fmt.Println("新建与娃娃机链接")
|
||||
var serverAddrs []string
|
||||
programDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
logger.Logger.Error("Error getting working directory:", err)
|
||||
return nil
|
||||
}
|
||||
configFile := filepath.Join(programDir, "machineIPConfig.json")
|
||||
logger.Logger.Trace("构建配置文件的路径", configFile)
|
||||
fileData, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
logger.Logger.Error("Read robot account file error:", err)
|
||||
return nil
|
||||
} else {
|
||||
if err = json.Unmarshal(fileData, &serverAddrs); err != nil {
|
||||
logger.Logger.Error("Unmarshal robot account data error:", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//与娃娃机创建连接
|
||||
// 遍历每个服务器地址,建立连接
|
||||
for i, addr := range serverAddrs {
|
||||
if i+1 == key {
|
||||
conn, err := net.DialTimeout("tcp", addr, 5*time.Second)
|
||||
if err != nil {
|
||||
logger.Logger.Error("Failed to connect to server:", err)
|
||||
continue
|
||||
}
|
||||
this.ConnMap[i+1] = &Conn{
|
||||
Id: i + 1,
|
||||
Conn: conn,
|
||||
Addr: addr,
|
||||
}
|
||||
return this.ConnMap[i+1]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *MachineManager) Update() {
|
||||
//向游戏服发送心跳包
|
||||
pack := &machine.MSDollMachineHeartBeat{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue