public CharacterSelectionInfoResult(string accountName) { // Local data. List <CharacterDataHolder> characterList = new List <CharacterDataHolder>(); // Get data from database. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_QUERY, con); cmd.Parameters.AddWithValue("account", accountName); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { CharacterDataHolder characterData = new CharacterDataHolder(); characterData.SetName(reader.GetString("name")); characterData.SetSlot((byte)reader.GetInt16("slot")); // TODO: Remove cast? characterData.SetSelected(reader.GetBoolean("selected")); characterData.SetClassId((byte)reader.GetInt16("class_id")); // TODO: Remove cast? characterData.SetLocationName(reader.GetString("location_name")); characterData.SetX(reader.GetFloat("x")); characterData.SetY(reader.GetFloat("y")); characterData.SetZ(reader.GetFloat("z")); characterData.SetHeading(reader.GetFloat("heading")); characterData.SetExperience(reader.GetInt64("experience")); characterData.SetHp(reader.GetInt64("hp")); characterData.SetMp(reader.GetInt64("mp")); characterData.SetAccessLevel((byte)reader.GetInt16("access_level")); // TODO: Remove cast? characterList.Add(characterData); } con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Send the data. WriteShort(2); // Packet id. WriteByte(characterList.Count); foreach (CharacterDataHolder characterData in characterList) { WriteString(characterData.GetName()); WriteByte(characterData.GetSlot()); WriteByte(characterData.IsSelected() ? 1 : 0); WriteByte(characterData.GetClassId()); WriteString(characterData.GetLocationName()); WriteFloat(characterData.GetX()); WriteFloat(characterData.GetY()); WriteFloat(characterData.GetZ()); WriteFloat(characterData.GetHeading()); WriteLong(characterData.GetExperience()); WriteLong(characterData.GetHp()); WriteLong(characterData.GetMp()); WriteByte(characterData.GetAccessLevel()); } }
private void Start() { // Return if account name is empty. if (PlayerManager.instance == null || PlayerManager.instance.accountName == null) { return; } // Set instance. instance = this; // Schedule exit to login screen. StartCoroutine(ExitToLoginScreen()); // Show retrieving information message. textMessage.text = "Retrieving character information."; // Change music. MusicManager.instance.PlayMusic(MusicManager.instance.CharacterSelection); // Disable character select buttons. selectButtons[0].gameObject.SetActive(false); selectButtons[1].gameObject.SetActive(false); selectButtons[2].gameObject.SetActive(false); selectButtons[3].gameObject.SetActive(false); selectButtons[4].gameObject.SetActive(false); moveUpButtons[0].gameObject.SetActive(false); moveUpButtons[1].gameObject.SetActive(false); moveUpButtons[2].gameObject.SetActive(false); moveUpButtons[3].gameObject.SetActive(false); moveUpButtons[4].gameObject.SetActive(false); moveDownButtons[0].gameObject.SetActive(false); moveDownButtons[1].gameObject.SetActive(false); moveDownButtons[2].gameObject.SetActive(false); moveDownButtons[3].gameObject.SetActive(false); moveDownButtons[4].gameObject.SetActive(false); // Request info. waitingServer = true; NetworkManager.instance.ChannelSend(new CharacterSelectionInfoRequest()); // Wait until server sends existing player data. while (waitingServer) { // Make sure information from the server is received. } // Show last selected character. if (PlayerManager.instance.characterList.Count > 0) { for (int i = 0; i < PlayerManager.instance.characterList.Count; i++) { // Get current character data. CharacterDataHolder characterData = (CharacterDataHolder)PlayerManager.instance.characterList[i]; // Set select button text to character name. selectButtons[i].gameObject.SetActive(true); selectButtons[i].GetComponentInChildren <Text>().text = characterData.GetName(); // Enable move up / down buttons. moveUpButtons[i].gameObject.SetActive(true); moveDownButtons[i].gameObject.SetActive(true); if (characterData.IsSelected()) { PlayerManager.instance.selectedCharacterData = characterData; // Model 0-3 id is set from character class id. // characterModels[characterData.GetClassId()] characterSelected = Instantiate(GameObjectManager.instance.playerModels[characterData.GetClassId()], spawnLocation.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // TODO: Restore appearance when support is made. } } } else // In case of character deletion. { PlayerManager.instance.selectedCharacterData = null; } // Add button listeners. createButton.GetComponent <Button>().onClick.AddListener(OnClickCreateButton); deleteButton.GetComponent <Button>().onClick.AddListener(OnClickDeleteButton); enterWorldButton.GetComponent <Button>().onClick.AddListener(OnClickEnterButton); exitButton.GetComponent <Button>().onClick.AddListener(OnClickExitButton); selectButtons[0].GetComponent <Button>().onClick.AddListener(OnClickSelectCharacter1Button); selectButtons[1].GetComponent <Button>().onClick.AddListener(OnClickSelectCharacter2Button); selectButtons[2].GetComponent <Button>().onClick.AddListener(OnClickSelectCharacter3Button); selectButtons[3].GetComponent <Button>().onClick.AddListener(OnClickSelectCharacter4Button); selectButtons[4].GetComponent <Button>().onClick.AddListener(OnClickSelectCharacter5Button); moveUpButtons[1].GetComponent <Button>().onClick.AddListener(OnClickMoveUp2Button); moveUpButtons[2].GetComponent <Button>().onClick.AddListener(OnClickMoveUp3Button); moveUpButtons[3].GetComponent <Button>().onClick.AddListener(OnClickMoveUp4Button); moveUpButtons[4].GetComponent <Button>().onClick.AddListener(OnClickMoveUp5Button); moveDownButtons[0].GetComponent <Button>().onClick.AddListener(OnClickMoveDown1Button); moveDownButtons[1].GetComponent <Button>().onClick.AddListener(OnClickMoveDown2Button); moveDownButtons[2].GetComponent <Button>().onClick.AddListener(OnClickMoveDown3Button); moveDownButtons[3].GetComponent <Button>().onClick.AddListener(OnClickMoveDown4Button); // Hide retrieving information message. if (characterSelected == null) { textMessage.text = "Click the create button to make a new character."; } else { textMessage.text = ""; } }
private static readonly string VISIBLE_ITEMS_QUERY = "SELECT * FROM character_items WHERE owner=@owner AND slot_id>'0' AND slot_id<'8' ORDER BY slot_id ASC"; // Visible equipment slots are 1 to 7. public CharacterSelectionInfoResult(string accountName) { // Local data. List <CharacterDataHolder> characterList = new List <CharacterDataHolder>(); // Get data from database. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_QUERY, con); cmd.Parameters.AddWithValue("account", accountName); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { CharacterDataHolder characterData = new CharacterDataHolder(); string name = reader.GetString("name"); characterData.SetName(name); characterData.SetSlot((byte)reader.GetInt16("slot")); // TODO: Remove cast? characterData.SetSelected(reader.GetBoolean("selected")); characterData.SetRace((byte)reader.GetInt16("race")); // TODO: Remove cast? characterData.SetHeight(reader.GetFloat("height")); characterData.SetBelly(reader.GetFloat("belly")); characterData.SetHairType((byte)reader.GetInt16("hair_type")); // TODO: Remove cast? characterData.SetHairColor(reader.GetInt32("hair_color")); characterData.SetSkinColor(reader.GetInt32("skin_color")); characterData.SetEyeColor(reader.GetInt32("eye_color")); characterData.SetX(reader.GetFloat("x")); characterData.SetY(reader.GetFloat("y")); characterData.SetZ(reader.GetFloat("z")); characterData.SetHeading(reader.GetFloat("heading")); characterData.SetExperience(reader.GetInt64("experience")); characterData.SetHp(reader.GetInt64("hp")); characterData.SetMp(reader.GetInt64("mp")); characterData.SetAccessLevel((byte)reader.GetInt16("access_level")); // TODO: Remove cast? // Also get items for this character. try { MySqlConnection con2 = DatabaseManager.GetConnection(); MySqlCommand cmd2 = new MySqlCommand(VISIBLE_ITEMS_QUERY, con2); cmd2.Parameters.AddWithValue("owner", name); MySqlDataReader reader2 = cmd2.ExecuteReader(); while (reader2.Read()) { int slotId = reader2.GetInt32("slot_id"); int itemId = reader2.GetInt32("item_id"); switch (slotId) { case 1: characterData.SetHeadItem(itemId); break; case 2: characterData.SetChestItem(itemId); break; case 3: characterData.SetLegsItem(itemId); break; case 4: characterData.SetHandsItem(itemId); break; case 5: characterData.SetFeetItem(itemId); break; case 6: characterData.SetLeftHandItem(itemId); break; case 7: characterData.SetRightHandItem(itemId); break; } } con2.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Add gathered data to character list. characterList.Add(characterData); } con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Send the data. WriteShort(2); // Packet id. WriteByte(characterList.Count); foreach (CharacterDataHolder characterData in characterList) { WriteString(characterData.GetName()); WriteByte(characterData.GetSlot()); WriteByte(characterData.IsSelected() ? 1 : 0); WriteByte(characterData.GetRace()); WriteFloat(characterData.GetHeight()); WriteFloat(characterData.GetBelly()); WriteByte(characterData.GetHairType()); WriteInt(characterData.GetHairColor()); WriteInt(characterData.GetSkinColor()); WriteInt(characterData.GetEyeColor()); WriteInt(characterData.GetHeadItem()); WriteInt(characterData.GetChestItem()); WriteInt(characterData.GetLegsItem()); WriteInt(characterData.GetHandsItem()); WriteInt(characterData.GetFeetItem()); WriteInt(characterData.GetLeftHandItem()); WriteInt(characterData.GetRightHandItem()); WriteFloat(characterData.GetX()); WriteFloat(characterData.GetY()); WriteFloat(characterData.GetZ()); WriteFloat(characterData.GetHeading()); WriteLong(characterData.GetExperience()); WriteLong(characterData.GetHp()); WriteLong(characterData.GetMp()); WriteByte(characterData.GetAccessLevel()); } }