Пример #1
0
    public IEnumerator CustomizeCharacterAppearance(CharacterDataHolder characterData, DynamicCharacterAvatar newAvatar)
    {
        // Hide avatar until delay ends.
        newAvatar.gameObject.SetActive(false);

        // Unfortunately UMA needs a small delay to initialize.
        yield return(new WaitForSeconds(0.25f));

        // Delay ended. Show avatar.
        newAvatar.gameObject.SetActive(true);

        // Customize character.
        int hairType = characterData.GetHairType();

        if (characterData.GetRace() == 0)
        {
            newAvatar.ChangeRace("HumanMaleDCS");
            if (hairType != 0)
            {
                newAvatar.SetSlot("Hair", _hairModelsMale[characterData.GetHairType()]);
            }
        }
        if (characterData.GetRace() == 1)
        {
            newAvatar.ChangeRace("HumanFemaleDCS");
            if (hairType != 0)
            {
                newAvatar.SetSlot("Hair", _hairModelsFemale[characterData.GetHairType()]);
            }
        }

        // Set colors.
        newAvatar.SetColor("Hair", Util.IntToColor(characterData.GetHairColor()));
        newAvatar.SetColor("Skin", Util.IntToColor(characterData.GetSkinColor()));
        newAvatar.SetColor("Eyes", Util.IntToColor(characterData.GetEyeColor()));
        newAvatar.UpdateColors(true);

        Dictionary <string, DnaSetter> dna = newAvatar.GetDNA();

        dna["height"].Set(characterData.GetHeight());
        dna["belly"].Set(characterData.GetBelly());
        newAvatar.BuildCharacter(false);

        // Set visible equipable armor items.
        EquipItem(newAvatar, characterData.GetHeadItem());
        EquipItem(newAvatar, characterData.GetChestItem());
        EquipItem(newAvatar, characterData.GetLegsItem());
        EquipItem(newAvatar, characterData.GetHandsItem());
        EquipItem(newAvatar, characterData.GetFeetItem());

        // Without this delay, sometimes, we cannot not see mounted weapons.
        yield return(new WaitForSeconds(0.25f));

        // Set visible equipable left and right hand items.
        EquipItem(newAvatar, characterData.GetLeftHandItem());
        EquipItem(newAvatar, characterData.GetRightHandItem());
    }
    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 DynamicCharacterAvatar CreateCharacter(CharacterDataHolder characterData, float posX, float posY, float posZ, float heading)
    {
        // Setting race on Instantiate, because even we set it at CustomizeCharacterAppearance, we could not mount items for female characters.
        Vector3 newPosition = new Vector3(posX, posY, posZ);
        DynamicCharacterAvatar avatarTemplate = characterData.GetRace() == 0 ? _avatarMale : _avatarFemale;
        DynamicCharacterAvatar newAvatar      = Instantiate(avatarTemplate, newPosition, Quaternion.identity) as DynamicCharacterAvatar;

        // Set heading early, to avoid inconsistencies with template heading that are
        // sometimes visible before CustomizeCharacterAppearance starts on character selection scene.
        SetAvatarHeading(newAvatar, heading);

        // Prevent UMA bone error.
        newAvatar.BuildCharacter(false);

        // Add a new Capsule Collider to prevent falling.
        CapsuleCollider capsuleCollider = newAvatar.gameObject.AddComponent <CapsuleCollider>();

        capsuleCollider.radius = 0.15f;
        capsuleCollider.height = 1.71f;
        capsuleCollider.center = new Vector3(0, 0.82f, 0);

        // Add AudioSource.
        newAvatar.gameObject.AddComponent <AudioSource>();

        // Customize character.
        StartCoroutine(CustomizeCharacterAppearance(characterData, newAvatar));
        StartCoroutine(InitializeLocation(newAvatar, newPosition, heading));

        // Return GameObject.
        return(newAvatar);
    }
Пример #4
0
    public DynamicCharacterAvatar CreateCharacter(CharacterDataHolder characterData, float posX, float posY, float posZ)
    {
        // Setting race on Instantiate, because even we set it at CustomizeCharacterAppearance, we could not mount items for female characters.
        DynamicCharacterAvatar newAvatar = Instantiate(characterData.GetRace() == 0 ? avatarMale : avatarFemale, new Vector3(posX, posY, posZ), Quaternion.identity) as DynamicCharacterAvatar;

        newAvatar.BuildCharacter(); // Prevent UMA bone error.

        // Add a new Capsule Collider to prevent falling.
        CapsuleCollider capsuleCollider = newAvatar.gameObject.AddComponent <CapsuleCollider>();

        capsuleCollider.radius = 0.15f;
        capsuleCollider.height = 1.71f;
        capsuleCollider.center = new Vector3(0, 0.82f, 0);

        // Customize character.
        StartCoroutine(CustomizeCharacterAppearance(characterData, newAvatar));

        // Add AudioSource.
        newAvatar.gameObject.AddComponent <AudioSource>();

        // Disable avatar until race customization ends.
        newAvatar.gameObject.SetActive(false);

        // Return GameObject.
        return(newAvatar);
    }
 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());
 }
    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());
        }
    }