func DebugStack() { if x := recover(); x != nil { if _, ok := x.(string); ok { } else { base.DebugStack() } } }
func (yg *YGO) Loop() { defer func() { if x := recover(); x != nil { base.DebugStack() } }() //必要连锁初始化 yg.registerBothEvent(Summon) yg.registerBothEvent(SummonFlip) yg.registerBothEvent(SummonSpecial) yg.registerBothEvent(Declaration) yg.registerBothEvent(UseTrap) yg.registerBothEvent(UseSpell) //yg.registerMultiEvent(DP) yg.registerMultiEvent(SP) yg.registerMultiEvent(MP) yg.registerMultiEvent(BP) //yg.registerMultiEvent(EP) // 服务端初始化 for k, _ := range yg.players { yg.round = append(yg.round, k) } for k, v := range yg.round { ca := yg.players[v].camp yg.survival[ca] = yg.survival[ca] + 1 yg.players[v].index = k yg.players[v].game = yg yg.players[v].roundSize = 0 if yg.players[v].id == 0 || yg.players[v].name == "" { yg.players[v].name = "Guest" } } // 客户端初始化 gi := gameInitResponse{} for _, v := range yg.round { pi := playerInit{ //Hp: yg.Players[v].Hp, Name: yg.players[v].name, } gi.Users = append(gi.Users, pi) } for _, v := range yg.round { gi.Index = yg.players[v].index yg.players[v].call("init", gi) } //nap(10) // 牌组初始化 for _, v := range yg.round { yg.players[v].initDeck() } //nap(10) // 界面初始化 i := 31 for _, v := range yg.round { i++ yg.players[v].initPlayer(i) } nap(10) // 游戏开始 pl := yg.getPlayerForIndex(0) pl.Dispatch(Initiative) nap(10) yg.current = pl pl.Dispatch(First) yg.Room.LeaveEvent(func(sess *agent.Session) { pl := yg.players[sess.ToUint()] yg.current.MsgPub("msg.009", Arg{"rival": pl.name}) pl.Fail() }) loop: for { for _, v := range yg.round { nap(1) yg.current = yg.players[v] yg.current.round() yg.forEachPlayer(func(pl *Player) { if pl.IsFail() { yg.Over = true } }) if yg.Over { break loop } } } yg.GameOver() return }