Exemplo n.º 1
0
        /// <summary>
        /// Get the equipment or accessory deformation set for a given item and race.
        /// Null if the set information doesn't exist.
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <param name="race"></param>
        /// <param name="accessory"></param>
        /// <returns></returns>
        private async Task <EquipmentDeformationParameterSet> GetEquipmentDeformationSet(int equipmentId, XivRace race, bool accessory = false)
        {
            var raw = await GetRawEquipmentDeformationParameters(equipmentId, race, accessory);

            if (raw == null)
            {
                return(null);
            }

            var set = new EquipmentDeformationParameterSet(accessory);

            var list = EquipmentDeformationParameterSet.SlotsAsList(accessory);

            // Pull the value apart two bits at a time.
            // Last 6 bits are not used.
            for (var idx = 0; idx < 5; idx++)
            {
                var entry = new EquipmentDeformationParameter();

                entry.bit0 = (raw & 1) != 0;
                raw        = (ushort)(raw >> 1);
                entry.bit1 = (raw & 1) != 0;
                raw        = (ushort)(raw >> 1);

                var key = list[idx];
                set.Parameters[key] = entry;
            }


            return(set);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all the available models for a given piece of equipment.
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <param name="accessory"></param>
        /// <returns></returns>
        public async Task <List <XivRace> > GetAvailableRacialModels(int equipmentId, string slot)
        {
            var isAccessory = EquipmentDeformationParameterSet.SlotsAsList(true).Contains(slot);

            if (!isAccessory)
            {
                var slotOk = EquipmentDeformationParameterSet.SlotsAsList(false).Contains(slot);
                if (!slotOk)
                {
                    throw new InvalidDataException("Attempted to get racial models for invalid slot.");
                }
            }

            var sets = await GetAllEquipmentDeformationSets(equipmentId, isAccessory);

            var races = new List <XivRace>();

            if (sets != null)
            {
                foreach (var kv in sets)
                {
                    var race  = kv.Key;
                    var set   = kv.Value;
                    var entry = set.Parameters[slot];

                    // Bit0 has unknown purpose currently.
                    if (entry.bit1)
                    {
                        races.Add(race);
                    }
                }
            }
            else
            {
                var _index = new Index(_gameDirectory);

                // Ok, at this point we're in a somewhat unusual item; it's an item that is effectively non-set.
                // It has an item set ID in the multiple thousands (ex. 5000/9000), so it does not use the EQDP table.
                // In these cases, there's nothing to do but hard check the model paths, until such a time as we know
                // how these are resolved.
                foreach (var race in DeformationAvailableRaces)
                {
                    var path = "";
                    if (!isAccessory)
                    {
                        path = String.Format(_EquipmentModelPathFormat, equipmentId.ToString().PadLeft(4, '0'), race.GetRaceCode(), slot);
                    }
                    else
                    {
                        path = String.Format(_AccessoryModelPathFormat, equipmentId.ToString().PadLeft(4, '0'), race.GetRaceCode(), slot);
                    }
                    if (await _index.FileExists(path))
                    {
                        races.Add(race);
                    }
                }
            }

            return(races);
        }