public bool HandleMessage(MessageReceivedEventArgs e) { object Obj; JsonObject Message; if (SimpleJson.SimpleJson.TryDeserializeObject(e.Message, out Obj)) Message = (JsonObject)Obj; else return false; if (!Message.ContainsKey("type")) return false; int p_id = 0; int c_id = 0; int l_id = 0; if (Message.ContainsKey("player_id")) p_id = Convert.ToInt32(Message["player_id"]); if (Message.ContainsKey("character_id")) c_id = Convert.ToInt32(Message["character_id"]); if (Message.ContainsKey("location_id")) l_id = Convert.ToInt32(Message["location_id"]); switch (Message["type"].ToString()) { case "text": //HANDLED AddLogEntry(Message["text"].ToString()); return true; case "character": //HANDLED AddLogEntry(Character.GetCharacter(c_id).Name + ": " + Message["text"].ToString()); return true; case "move": //HANDLED UpdatePlayerLocation(Players[p_id], l_id); AddLogEntry(Players[p_id].Name + " moved to " + Places.AllPlaces[l_id].Name); return true; case "next": //HANDLED CurrentPlayer = p_id; try { AddLogEntry("It is " + Players[p_id].Name + "'s turn"); } catch { } return true; case "question": //HANDLED JsonArray optionsBuf = (JsonArray)Message["options"]; string[] options = new string[optionsBuf.Count]; AddLogEntry(Players[p_id].Name + " has to decide on the following: " + Message["question"].ToString() +" These options are available for selection:"); for (int i = 0; i < optionsBuf.Count; i++) { options[i] = optionsBuf[i].ToString(); AddLogEntry(options[i]); } if (Array.Exists(Connection.ClientIDs, entry => entry == p_id)) { ActingOptionMenu = new ActingOptionMenu(p_id, c_id, Message["question"].ToString(), options, SendResponse); InitControlGroup(ActingOptionMenu); ActingOptionMenu.Visible = true; } return true; case "change_cards": //HANDLED // TODO: Replace Keys Resources ResourcesBUF = new Resources( Convert.ToInt32(Message["res1"]), Convert.ToInt32(Message["res2"]), Convert.ToInt32(Message["res3"]), Convert.ToInt32(Message["res4"])); Players[p_id].Resources += ResourcesBUF; AddLogEntry(Players[p_id].Name + " " + ResourcesBUF.ToString()); return true; case "item_gained": //HANDLED Players[p_id].AddItem(new Item(Message["item_name"].ToString())); AddLogEntry(Players[p_id].Name + " gained " + Message["item_name"].ToString()); return true; case "item_lost": //HANDLED Players[p_id].DeleteItem(new Item(Message["item_name"].ToString())); AddLogEntry(Players[p_id].Name + " lost " + Message["item_name"].ToString()); return true; case "win": AddLogEntry(Players[p_id].Name + " won."); return true; default: return false; } }
public bool HandleMessage(MessageReceivedEventArgs e) { object Obj; JsonObject Message; if (SimpleJson.SimpleJson.TryDeserializeObject(e.Message, out Obj)) { Message = (JsonObject)Obj; } else { return(false); } if (!Message.ContainsKey("type")) { return(false); } int p_id = 0; int c_id = 0; int l_id = 0; if (Message.ContainsKey("player_id")) { p_id = Convert.ToInt32(Message["player_id"]); } if (Message.ContainsKey("character_id")) { c_id = Convert.ToInt32(Message["character_id"]); } if (Message.ContainsKey("location_id")) { l_id = Convert.ToInt32(Message["location_id"]); } switch (Message["type"].ToString()) { case "text": //HANDLED AddLogEntry(Message["text"].ToString()); return(true); case "character": //HANDLED AddLogEntry(Character.GetCharacter(c_id).Name + ": " + Message["text"].ToString()); return(true); case "move": //HANDLED UpdatePlayerLocation(Players[p_id], l_id); AddLogEntry(Players[p_id].Name + " moved to " + Places.AllPlaces[l_id].Name); return(true); case "next": //HANDLED CurrentPlayer = p_id; try { AddLogEntry("It is " + Players[p_id].Name + "'s turn"); } catch { } return(true); case "question": //HANDLED JsonArray optionsBuf = (JsonArray)Message["options"]; string[] options = new string[optionsBuf.Count]; AddLogEntry(Players[p_id].Name + " has to decide on the following: " + Message["question"].ToString() + " These options are available for selection:"); for (int i = 0; i < optionsBuf.Count; i++) { options[i] = optionsBuf[i].ToString(); AddLogEntry(options[i]); } if (Array.Exists(Connection.ClientIDs, entry => entry == p_id)) { ActingOptionMenu = new ActingOptionMenu(p_id, c_id, Message["question"].ToString(), options, SendResponse); InitControlGroup(ActingOptionMenu); ActingOptionMenu.Visible = true; } return(true); case "change_cards": //HANDLED // TODO: Replace Keys Resources ResourcesBUF = new Resources( Convert.ToInt32(Message["res1"]), Convert.ToInt32(Message["res2"]), Convert.ToInt32(Message["res3"]), Convert.ToInt32(Message["res4"])); Players[p_id].Resources += ResourcesBUF; AddLogEntry(Players[p_id].Name + " " + ResourcesBUF.ToString()); return(true); case "item_gained": //HANDLED Players[p_id].AddItem(new Item(Message["item_name"].ToString())); AddLogEntry(Players[p_id].Name + " gained " + Message["item_name"].ToString()); return(true); case "item_lost": //HANDLED Players[p_id].DeleteItem(new Item(Message["item_name"].ToString())); AddLogEntry(Players[p_id].Name + " lost " + Message["item_name"].ToString()); return(true); case "win": AddLogEntry(Players[p_id].Name + " won."); return(true); default: return(false); } }