private MahjongClientRoom __InitRoom() { IEnumerable <Node> nodes = __client == null ? null : __client.nodes; if (nodes != null) { MahjongClientPlayer player; foreach (Node node in nodes) { player = node as MahjongClientPlayer; if (player != null) { player.Clear(); } } } MahjongClientRoom room = MahjongClientRoom.instance; if (room != null) { if (__shuffleMessage != null) { int count = __shuffleMessage.point0 + __shuffleMessage.point1; room.Init(__shuffleMessage.tileCount, (((count + 1) & 3) * ((__shuffleMessage.tileCount + 4) >> 3) + count + __shuffleMessage.point2 + __shuffleMessage.point3) << 1); } } return(room); }
private void __OnReady() { MahjongClientRoom room = MahjongClientRoom.instance; if (room != null) { if (room.finish.root != null) { room.finish.root.SetActive(false); } if (room.finish.normal.root != null) { room.finish.normal.root.SetActive(false); } if (room.finish.win.root != null) { room.finish.win.root.SetActive(false); } } Node node = localPlayer as Node; if (node != null) { node.Ready(); } }
private void __ClearReady() { CancelInvoke("__ClearReady"); MahjongClientPlayer player = localPlayer as MahjongClientPlayer; if (player != null) { player.Unselect(); } MahjongClientRoom room = MahjongClientRoom.instance; if (room == null) { return; } if (room.pass != null) { room.pass.onClick = null; GameObject gameObject = room.pass.gameObject; if (gameObject != null) { gameObject.SetActive(false); } } if (room.show != null) { room.show.onClick = null; GameObject gameObject = room.show.gameObject; if (gameObject != null) { gameObject.SetActive(false); } } if (room.hide != null) { room.hide.onClick = null; GameObject gameObject = room.hide.gameObject; if (gameObject != null) { gameObject.SetActive(false); } } }
private void __OnShuffle(NetworkMessage message) { __shuffleMessage = message == null ? null : message.ReadMessage <MahjongShuffleMessage>(); if (__shuffleMessage == null) { return; } MahjongClientRoom room = __InitRoom(); if (room != null) { room.Play(__shuffleMessage.point0, __shuffleMessage.point1, __shuffleMessage.point2, __shuffleMessage.point3); } }
private void __OnRoom(NetworkMessage message) { __client.UnregisterHandler((short)MahjongNetworkMessageType.Room); NameMessage nameMessage = message == null ? null : message.ReadMessage <NameMessage>(); __coroutine = StartCoroutine(__LoadScene(roomSceneBuildIndex, delegate() { MahjongClientRoom room = __InitRoom(); if (room != null) { if (room.name != null) { room.name.text = nameMessage.name; } } __client.onRegistered += __OnRegistered; __client.Register(new RegisterMessage(__uid, nameMessage.name)); }, __coroutine)); }
void OnDisable() { instance = null; }
void OnEnable() { instance = this; }
private void __OnNotReady(int roomIndex, int count) { if (count == 0) { MahjongClientRoom room = MahjongClientRoom.instance; if (room != null) { if ((room.finish.normal.root == null || !room.finish.normal.root.activeSelf) && (room.finish.win.root == null || !room.finish.win.root.activeSelf)) { if (room.finish.root != null) { room.finish.root.SetActive(true); } if (room.finish.button != null) { Button.ButtonClickedEvent onClick = room.finish.button.onClick; if (onClick == null) { onClick = new Button.ButtonClickedEvent(); } else { onClick.RemoveAllListeners(); } onClick.AddListener(__OnReady); } } if (room.finish.normal.ready != null) { Button.ButtonClickedEvent onClick = room.finish.normal.ready.onClick; if (onClick == null) { onClick = new Button.ButtonClickedEvent(); } else { onClick.RemoveAllListeners(); } onClick.AddListener(__OnReady); } if (room.finish.win.ready != null) { Button.ButtonClickedEvent onClick = room.finish.win.ready.onClick; if (onClick == null) { onClick = new Button.ButtonClickedEvent(); } else { onClick.RemoveAllListeners(); } onClick.AddListener(__OnReady); } } } }
private void __OnRuleNodes(NetworkMessage message) { MahjongRuleMessage ruleMessage = message == null ? null : message.ReadMessage <MahjongRuleMessage>(); if (ruleMessage == null || ruleMessage.ruleNodes == null) { return; } MahjongClientRoom room = MahjongClientRoom.instance; if (room == null) { return; } int index = 0; List <int> chowIndices = null, pongIndices = null, kongIndices = null, winIndices = null; foreach (Mahjong.RuleNode ruleNode in ruleMessage.ruleNodes) { switch (ruleNode.type) { case Mahjong.RuleType.Chow: if (chowIndices == null) { chowIndices = new List <int>(); } chowIndices.Add(index); break; case Mahjong.RuleType.Pong: if (pongIndices == null) { pongIndices = new List <int>(); } pongIndices.Add(index); break; case Mahjong.RuleType.Kong: case Mahjong.RuleType.HiddenKong: case Mahjong.RuleType.MeldedKong: if (kongIndices == null) { kongIndices = new List <int>(); } kongIndices.Add(index); break; case Mahjong.RuleType.Win: case Mahjong.RuleType.SelfDraw: case Mahjong.RuleType.BreakKong: case Mahjong.RuleType.OverKong: if (winIndices == null) { winIndices = new List <int>(); } winIndices.Add(index); break; } ++index; } bool isSetEvent = false; if (chowIndices != null) { isSetEvent = __SetEvent(ruleMessage.ruleNodes, chowIndices.AsReadOnly(), room.chow) || isSetEvent; } if (pongIndices != null) { isSetEvent = __SetEvent(ruleMessage.ruleNodes, pongIndices.AsReadOnly(), room.pong) || isSetEvent; } if (kongIndices != null) { isSetEvent = __SetEvent(ruleMessage.ruleNodes, kongIndices.AsReadOnly(), room.kong) || isSetEvent; } if (winIndices != null) { isSetEvent = __SetEvent(ruleMessage.ruleNodes, winIndices.AsReadOnly(), room.win) || isSetEvent; } if (isSetEvent) { GameObject gameObject = room.pass.gameObject; if (gameObject != null) { gameObject.SetActive(true); } Button.ButtonClickedEvent buttonClickedEvent = new Button.ButtonClickedEvent(); room.pass.onClick = buttonClickedEvent; buttonClickedEvent.AddListener(__PassTry); Invoke("__ClearTry", tryTime); } }
private void __OnReadyHand(NetworkMessage message) { MahjongReadyHandMessage readyHandMessage = message == null ? null : message.ReadMessage <MahjongReadyHandMessage>(); if (readyHandMessage == null) { return; } MahjongClientRoom room = MahjongClientRoom.instance; if (room == null) { return; } GameObject gameObject = room.pass.gameObject; if (gameObject != null) { gameObject.SetActive(true); } Button.ButtonClickedEvent buttonClickedEvent = new Button.ButtonClickedEvent(); room.pass.onClick = buttonClickedEvent; buttonClickedEvent.AddListener(__PassReady); if (room.show != null) { gameObject = room.show.gameObject; if (gameObject != null) { gameObject.SetActive(true); } int count = readyHandMessage.indices == null ? 0 : readyHandMessage.indices.Count; buttonClickedEvent = new Button.ButtonClickedEvent(); room.show.onClick = buttonClickedEvent; UnityAction handler = delegate() { MahjongClientPlayer player = localPlayer as MahjongClientPlayer; for (int i = 0; i < count; ++i) { int index = i; player.Select(readyHandMessage.indices[i], delegate() { player.Ready((byte)((index << 2) | (int)MahjongReadyType.Show)); __ClearReady(); }); } }; buttonClickedEvent.AddListener(handler); } if (room.hide != null) { gameObject = room.hide.gameObject; if (gameObject != null) { gameObject.SetActive(true); } int count = readyHandMessage.indices == null ? 0 : readyHandMessage.indices.Count; buttonClickedEvent = new Button.ButtonClickedEvent(); room.hide.onClick = buttonClickedEvent; UnityAction handler = delegate() { MahjongClientPlayer player = localPlayer as MahjongClientPlayer; for (int i = 0; i < count; ++i) { int index = i; player.Select(readyHandMessage.indices[i], delegate() { player.Ready((byte)((index << 2) | (int)MahjongReadyType.Hide)); __ClearReady(); }); } }; buttonClickedEvent.AddListener(handler); } Invoke("__ClearReady", readyTime); }