public void UpdateObject(long objectId, CharacterDataHolder characterdata)
    {
        lock (updateObjectLock) // Use lock to avoid adding duplicate gameObjects.
        {
            // Check for existing objects.
            if (gameObjects.ContainsKey(objectId))
            {
                // Update object info.
                ((IDictionary <long, CharacterDataHolder>)characterUpdateQueue).Remove(objectId);
                characterUpdateQueue.TryAdd(objectId, characterdata);
                return;
            }

            // Object is out of sight.
            if (CalculateDistance(new Vector3(characterdata.GetX(), characterdata.GetY(), characterdata.GetZ())) > VISIBILITY_RADIUS)
            {
                return;
            }

            // Add placeholder to game object list.
            gameObjects.GetOrAdd(objectId, (GameObject)null);

            // Queue creation.
            CharacterManager.Instance.characterCreationQueue.TryAdd(objectId, characterdata);
        }
    }
Пример #2
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());
        }
    }
    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());
        }
    }
Пример #4
0
 public DynamicCharacterAvatar CreateCharacter(CharacterDataHolder characterData)
 {
     return(CreateCharacter(characterData, characterData.GetX(), characterData.GetY(), characterData.GetZ(), characterData.GetHeading()));
 }