예제 #1
0
    private void OnClickDeleteButton()
    {
        // Get current character data.
        CharacterDataHolder characterData = PlayerManager.instance.selectedCharacterData;

        // Return if no character is selected.
        if (characterData == null)
        {
            return;
        }

        // Disable buttons.
        createButton.enabled     = false;
        deleteButton.enabled     = false;
        enterWorldButton.enabled = false;
        exitButton.enabled       = false;

        // Set text message to deleting character.
        textMessage.text = "Deleting character " + characterData.GetName() + "...";

        // Request info.
        waitingServer = true;
        NetworkManager.instance.ChannelSend(new CharacterDeletionRequest(characterData.GetSlot()));

        // Wait until server deletes the character.
        while (waitingServer)
        {
            // Make sure server has deleted the character.
        }

        // Reload everything.
        Destroy(characterSelected); // Destroy clone object.
        SceneFader.Fade("CharacterSelection", Color.white, 0.5f);
    }
    public static void Process(ReceivablePacket packet)
    {
        // Server information.
        long objectId = packet.ReadLong();
        CharacterDataHolder npcTemplate   = NpcData.GetNpc(packet.ReadInt());
        CharacterDataHolder characterData = new CharacterDataHolder();

        characterData.SetX(packet.ReadFloat());
        characterData.SetY(packet.ReadFloat());
        characterData.SetZ(packet.ReadFloat());
        characterData.SetHeading(packet.ReadFloat());
        characterData.SetCurrentHp(packet.ReadLong());
        // Client information.
        characterData.SetName(npcTemplate.GetName());
        characterData.SetRace(npcTemplate.GetRace());
        characterData.SetHeight(npcTemplate.GetHeight());
        characterData.SetBelly(npcTemplate.GetBelly());;
        characterData.SetHairType(npcTemplate.GetHairType());
        characterData.SetHairColor(npcTemplate.GetHairColor());
        characterData.SetSkinColor(npcTemplate.GetSkinColor());
        characterData.SetEyeColor(npcTemplate.GetEyeColor());
        characterData.SetHeadItem(npcTemplate.GetHeadItem());
        characterData.SetChestItem(npcTemplate.GetChestItem());
        characterData.SetLegsItem(npcTemplate.GetLegsItem());
        characterData.SetHandsItem(npcTemplate.GetHandsItem());
        characterData.SetFeetItem(npcTemplate.GetFeetItem());
        characterData.SetLeftHandItem(npcTemplate.GetLeftHandItem());
        characterData.SetRightHandItem(npcTemplate.GetRightHandItem());
        characterData.SetMaxHp(npcTemplate.GetMaxHp());
        characterData.SetTargetable(npcTemplate.IsTargetable());

        WorldManager.Instance.UpdateObject(objectId, characterData);
    }
예제 #3
0
    public void DeleteCharacter()
    {
        // Get current character data.
        CharacterDataHolder characterData = MainManager.Instance.GetSelectedCharacterData();

        // Return if no character is selected.
        if (characterData == null)
        {
            return;
        }

        // Set text message to deleting character.
        _textMessage.text = "Deleting character " + characterData.GetName() + "...";

        // Request info.
        _waitingServer = true;
        NetworkManager.ChannelSend(new CharacterDeletionRequest(characterData.GetSlot()));

        // Wait until server deletes the character.
        while (_waitingServer)
        {
            // Make sure server has deleted the character.
        }

        if (_characterSelected)
        {
            Destroy(_avatar.gameObject);
        }

        // Reload everything.
        MainManager.Instance.LoadScene(MainManager.CHARACTER_SELECTION_SCENE);
    }
예제 #4
0
    public void UpdateTargetInformation(WorldObject obj)
    {
        // Hide when object is null.
        if (obj == null)
        {
            HideTargetInformation();
            return;
        }
        // Show if hidden.
        if (!targetInformation.IsActive())
        {
            targetInformation.gameObject.SetActive(true);
            targetHpBar.gameObject.SetActive(true);
        }
        // Update information.
        CharacterDataHolder data = obj.characterData;

        if (data != null)
        {
            targetInformation.text = data.GetName();
            float progress = Mathf.Clamp01(data.GetCurrentHp() / data.GetMaxHp());
            targetHpBar.value    = progress;
            targetHpPercent.text = (int)(progress * 100f) + "%";
        }
    }
예제 #5
0
    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());
        }
    }
예제 #6
0
    public void UpdatePlayerInformation()
    {
        CharacterDataHolder data = MainManager.Instance.selectedCharacterData;

        playerInformation.text = data.GetName();
        float progress = Mathf.Clamp01(data.GetCurrentHp() / data.GetMaxHp());

        playerHpBar.value    = progress;
        playerHpPercent.text = (int)(progress * 100f) + "%";
    }
 public CharacterCreationRequest(CharacterDataHolder dataHolder)
 {
     WriteShort(3); // Packet id.
     WriteString(dataHolder.GetName());
     WriteByte(dataHolder.GetRace());
     WriteFloat(dataHolder.GetHeight());
     WriteFloat(dataHolder.GetBelly());
     WriteByte(dataHolder.GetHairType());
     WriteInt(dataHolder.GetHairColor());
     WriteInt(dataHolder.GetSkinColor());
     WriteInt(dataHolder.GetEyeColor());
 }
예제 #8
0
    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());
        }
    }