/// <summary> /// Sets item from group and index. /// Resets item data from new template. /// Retains existing UID. /// </summary> /// <param name="itemGroup">Item group.</param> /// <param name="groupIndex">Item group index.</param> public void SetItem(ItemGroups itemGroup, int groupIndex) { // Get template data ItemTemplate itemTemplate = DaggerfallUnity.Instance.ItemHelper.GetItemTemplate(itemGroup, groupIndex); // Assign new data shortName = itemTemplate.name; this.itemGroup = itemGroup; this.groupIndex = groupIndex; playerTextureArchive = itemTemplate.playerTextureArchive; playerTextureRecord = itemTemplate.playerTextureRecord; worldTextureArchive = itemTemplate.worldTextureArchive; worldTextureRecord = itemTemplate.worldTextureRecord; nativeMaterialValue = 0; dyeColor = DyeColors.Unchanged; weightInKg = itemTemplate.baseWeight; drawOrder = itemTemplate.drawOrderOrEffect; currentVariant = 0; value1 = itemTemplate.basePrice; value2 = itemTemplate.basePrice; hits1 = itemTemplate.hitPoints; hits2 = itemTemplate.hitPoints; hits3 = itemTemplate.hitPoints; enchantmentPoints = itemTemplate.enchantmentPoints; message = 0; stackCount = 1; // Fix leather helms ItemBuilder.FixLeatherHelm(this); }
/// <summary> /// Sets item from group and index. /// Resets item data from new template. /// Retains existing UID. /// </summary> /// <param name="itemGroup">Item group.</param> /// <param name="groupIndex">Item group index.</param> public void SetItem(ItemGroups itemGroup, int groupIndex) { // Hand off for artifacts if (itemGroup == ItemGroups.Artifacts) { SetArtifact(itemGroup, groupIndex); return; } // Get template data ItemTemplate itemTemplate = DaggerfallUnity.Instance.ItemHelper.GetItemTemplate(itemGroup, groupIndex); // Assign new data shortName = itemTemplate.name; this.itemGroup = itemGroup; this.groupIndex = groupIndex; playerTextureArchive = itemTemplate.playerTextureArchive; playerTextureRecord = itemTemplate.playerTextureRecord; worldTextureArchive = itemTemplate.worldTextureArchive; worldTextureRecord = itemTemplate.worldTextureRecord; nativeMaterialValue = 0; dyeColor = DyeColors.Unchanged; weightInKg = itemTemplate.baseWeight; drawOrder = itemTemplate.drawOrderOrEffect; currentVariant = 0; value = itemTemplate.basePrice; unknown = 0; flags = 0; currentCondition = itemTemplate.hitPoints; maxCondition = itemTemplate.hitPoints; unknown2 = 0; typeDependentData = 0; enchantmentPoints = itemTemplate.enchantmentPoints; message = 0; stackCount = 1; // Fix leather helms ItemBuilder.FixLeatherHelm(this); }
/// <summary> /// Create from native save ItemRecord data. /// </summary> void FromItemRecord(ItemRecord itemRecord) { // Get template data ItemGroups group = (ItemGroups)itemRecord.ParsedData.group; int index = itemRecord.ParsedData.index; ItemTemplate itemTemplate = DaggerfallUnity.Instance.ItemHelper.GetItemTemplate(group, index); // Get player image int playerBitfield = (int)itemRecord.ParsedData.image1; int playerArchive = playerBitfield >> 7; int playerRecord = (playerBitfield & 0x7f); // Get world image int worldBitfield = (int)itemRecord.ParsedData.image2; int worldArchive = worldBitfield >> 7; int worldRecord = (worldBitfield & 0x7f); // Assign new data shortName = itemRecord.ParsedData.name; itemGroup = group; groupIndex = index; playerTextureArchive = playerArchive; playerTextureRecord = playerRecord; worldTextureArchive = worldArchive; worldTextureRecord = worldRecord; nativeMaterialValue = itemRecord.ParsedData.material; dyeColor = (DyeColors)itemRecord.ParsedData.color; weightInKg = (float)itemRecord.ParsedData.weight * 0.25f; drawOrder = itemTemplate.drawOrderOrEffect; value = (int)itemRecord.ParsedData.value; unknown = itemRecord.ParsedData.unknown; flags = itemRecord.ParsedData.flags; currentCondition = itemRecord.ParsedData.currentCondition; maxCondition = itemRecord.ParsedData.maxCondition; unknown2 = itemRecord.ParsedData.unknown2; typeDependentData = itemRecord.ParsedData.typeDependentData; // If item is an arrow, typeDependentData is the stack count if ((itemGroup == ItemGroups.Weapons) && (groupIndex == 18)) // index 18 is for arrows { stackCount = itemRecord.ParsedData.typeDependentData; } else { stackCount = 1; } currentVariant = 0; enchantmentPoints = itemRecord.ParsedData.enchantmentPoints; message = (int)itemRecord.ParsedData.message; // Assign current variant if (itemTemplate.variants > 0) { if (IsCloak()) { currentVariant = playerRecord - (itemTemplate.playerTextureRecord + 1); } else { currentVariant = playerRecord - itemTemplate.playerTextureRecord; } } // Assign legacy magic effects array bool foundEnchantment = false; if (itemRecord.ParsedData.magic != null) { legacyMagic = new int[itemRecord.ParsedData.magic.Length]; for (int i = 0; i < itemRecord.ParsedData.magic.Length; i++) { legacyMagic[i] = itemRecord.ParsedData.magic[i]; if (legacyMagic[i] != 0xffff) { foundEnchantment = true; } } } // Discard list if no enchantment found if (!foundEnchantment) { legacyMagic = null; } // TEST: Force dye color to match material of imported weapons & armor // This is to fix cases where dye colour may be set incorrectly on imported item dyeColor = DaggerfallUnity.Instance.ItemHelper.GetDyeColor(this); // Fix leather helms ItemBuilder.FixLeatherHelm(this); }