//收到协议 public void OnMsgChoose(MsgBase msgBase) { MsgChoose msg = (MsgChoose)msgBase; if (msg.result == 0) { //提示 PanelManager.Open <TipPanel>("购买成功"); if (PanelManager.panels.ContainsKey("RoomListPanel") && PanelManager.panels["RoomListPanel"] != null) { RoomListPanel panel = (RoomListPanel)PanelManager.panels["RoomListPanel"]; panel.Major = msg.major; panel.Coin = msg.restCoin; } //关闭界面 Close(); } else if (msg.result == 1) { PanelManager.Open <TipPanel>("金币不足,购买失败"); } else { PanelManager.Open <TipPanel>("出现异常"); } }
//专业选择协议处理 public static void MsgChoose(ClientState c, MsgBase msgBase) { MsgChoose msg = (MsgChoose)msgBase; Player player = c.player; if (player == null) { return; } if (player.data.coin < msg.coin) { msg.result = 1; player.Send(msg); return; } if (player.data.major == msg.major) { msg.result = 2; Console.WriteLine("购买物品时出现bug,购买的系与现有的系相同"); } player.data.major = msg.major; player.data.coin -= msg.coin; msg.restCoin = player.data.coin; if (DbManager.UpdatePlayerData(player.id, player.data)) { msg.result = 0; } else { msg.result = 2; } player.Send(msg); }
/// <summary> /// 点击不同的购买按钮,发送choose协议 /// </summary> /// <param name="major">想要购买的按钮</param> private void BuyItem(Major major) { //发送 MsgChoose msg = new MsgChoose(); msg.major = (int)major; switch (major) { case Major.Chemistry: msg.coin = price[0]; break; case Major.Math: msg.coin = price[1]; break; case Major.ComputerScience: msg.coin = price[2]; break; } NetManager.Send(msg); }