void TransferItem(DaggerfallUnityItem item, ItemCollection from, ItemCollection to) { // Block transfer of horse or cart if (item.IsOfTemplate(ItemGroups.Transportation, (int)Transportation.Horse) || item.IsOfTemplate(ItemGroups.Transportation, (int)Transportation.Small_cart)) { return; } // When transferring gold to player simply add to player's gold count if (item.IsOfTemplate(ItemGroups.Currency, (int)Currency.Gold_pieces) && PlayerEntity.Items == to) { playerEntity.GoldPieces += item.stackCount; from.RemoveItem(item); Refresh(false); return; } to.Transfer(item, from, preferredOrder); Refresh(false); }
void EquipItem(DaggerfallUnityItem item) { // Bows not currently supported if (item.IsOfTemplate((int)Weapons.Long_Bow) || item.IsOfTemplate((int)Weapons.Short_Bow)) { DaggerfallUI.MessageBox(HardStrings.bowsNotImplemented); return; } playerEntity.ItemEquipTable.EquipItem(item); Refresh(); }
/// <summary> /// Gets inventory/equip image for specified item. /// Image will be cached based on material and hand for faster subsequent fetches. /// </summary> /// <param name="item">Item to fetch image for.</param> /// <param name="removeMask">Removes mask index (e.g. around helmets) from final image.</param> /// <param name="forPaperDoll">Image is for paper doll.</param> /// <returns>ImageData.</returns> public ImageData GetItemImage(DaggerfallUnityItem item, bool removeMask = false, bool forPaperDoll = false) { // Get colour int color = (int)item.dyeColor; // Get archive and record indices int archive = item.InventoryTextureArchive; int record = item.InventoryTextureRecord; // Paper doll handling if (forPaperDoll) { // 1H Weapons in right hand need record + 1 if (item.ItemGroup == ItemGroups.Weapons && item.EquipSlot == EquipSlots.RightHand) { if (ItemEquipTable.GetItemHands(item) == ItemHands.Either) record += 1; } } else { // Katanas need +1 for inventory image as they use right-hand image instead of left if (item.IsOfTemplate(ItemGroups.Weapons, (int)Weapons.Katana)) record += 1; } // Gold pieces use world texture indices if (item.ItemGroup == ItemGroups.Currency && item.TemplateIndex == (int)Currency.Gold_pieces) { archive = item.ItemTemplate.worldTextureArchive; record = item.ItemTemplate.worldTextureRecord; } // Get unique key int key = MakeImageKey(color, archive, record, removeMask); // Get existing icon if in cache if (itemImages.ContainsKey(key)) return itemImages[key]; // Load image data string filename = TextureFile.IndexToFileName(archive); ImageData data = ImageReader.GetImageData(filename, record, 0, true, false); if (data.type == ImageTypes.None) throw new Exception("GetItemImage() could not load image data."); // Remove mask if requested if (removeMask) data.dfBitmap = ImageProcessing.ChangeMask(data.dfBitmap); // Change dye or just update texture ItemGroups group = item.ItemGroup; DyeColors dye = (DyeColors)color; if (group == ItemGroups.Weapons || group == ItemGroups.Armor) data = ChangeDye(data, dye, DyeTargets.WeaponsAndArmor); else if (item.ItemGroup == ItemGroups.MensClothing || item.ItemGroup == ItemGroups.WomensClothing) data = ChangeDye(data, dye, DyeTargets.Clothing); else ImageReader.UpdateTexture(ref data); // Add to cache itemImages.Add(key, data); return data; }
/// <summary> /// Determines if item is stackable. /// Currently very simple - only ingredients and gold pieces are stackable. /// </summary> /// <param name="item">Item to check if stackable.</param> /// <returns>True if item stackable.</returns> bool IsStackable(DaggerfallUnityItem item) { if (item.IsIngredient) return true; else if (item.IsOfTemplate(ItemGroups.Currency, (int)Currency.Gold_pieces)) return true; else return false; }
static void SetVariant(DaggerfallUnityItem item, int variant) { // Range check int totalVariants = item.ItemTemplate.variants; if (variant < 0 || variant >= totalVariants) return; // Clamp to appropriate variant based on material family if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Cuirass)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) variant = 0; else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) variant = 4; else variant = Mathf.Clamp(variant, 1, 3); } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Greaves)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) variant = Mathf.Clamp(variant, 0, 1); else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) variant = 6; else variant = Mathf.Clamp(variant, 2, 5); } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Left_Pauldron) || item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Right_Pauldron)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) variant = 0; else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) variant = 4; else variant = Mathf.Clamp(variant, 1, 3); } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Gauntlets)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) variant = 0; else variant = 1; } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Boots)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) variant = 0; else variant = Mathf.Clamp(variant, 1, 2); } // Store variant item.CurrentVariant = variant; }
static void SetVariant(DaggerfallUnityItem item, int variant) { // Range check int totalVariants = item.ItemTemplate.variants; if (variant < 0 || variant >= totalVariants) { return; } // Clamp to appropriate variant based on material family if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Cuirass)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) { variant = 0; } else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) { variant = 4; } else { variant = Mathf.Clamp(variant, 1, 3); } } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Greaves)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) { variant = Mathf.Clamp(variant, 0, 1); } else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) { variant = 6; } else { variant = Mathf.Clamp(variant, 2, 5); } } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Left_Pauldron) || item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Right_Pauldron)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) { variant = 0; } else if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain || item.nativeMaterialValue == (int)ArmorMaterialTypes.Chain2) { variant = 4; } else { variant = Mathf.Clamp(variant, 1, 3); } } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Gauntlets)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) { variant = 0; } else { variant = 1; } } else if (item.IsOfTemplate(ItemGroups.Armor, (int)Armor.Boots)) { if (item.nativeMaterialValue == (int)ArmorMaterialTypes.Leather) { variant = 0; } else { variant = 1; } } // Store variant item.CurrentVariant = variant; }
/// <summary> /// Gets inventory/equip image for specified item. /// Image will be cached based on material and hand for faster subsequent fetches. /// </summary> /// <param name="item">Item to fetch image for.</param> /// <param name="removeMask">Removes mask index (e.g. around helmets) from final image.</param> /// <param name="forPaperDoll">Image is for paper doll.</param> /// <returns>ImageData.</returns> public ImageData GetItemImage(DaggerfallUnityItem item, bool removeMask = false, bool forPaperDoll = false) { // Get colour int color = (int)item.dyeColor; // Get archive and record indices int archive = item.InventoryTextureArchive; int record = item.InventoryTextureRecord; // Paper doll handling if (forPaperDoll) { // 1H Weapons in right hand need record + 1 if (item.ItemGroup == ItemGroups.Weapons && item.EquipSlot == EquipSlots.RightHand) { if (ItemEquipTable.GetItemHands(item) == ItemHands.Either) { record += 1; } } } else { // Katanas need +1 for inventory image as they use right-hand image instead of left if (item.IsOfTemplate(ItemGroups.Weapons, (int)Weapons.Katana)) { record += 1; } } // Gold pieces use world texture indices if (item.ItemGroup == ItemGroups.Currency && item.TemplateIndex == (int)Currency.Gold_pieces) { archive = item.ItemTemplate.worldTextureArchive; record = item.ItemTemplate.worldTextureRecord; } // Get unique key int key = MakeImageKey(color, archive, record, removeMask); // Get existing icon if in cache if (itemImages.ContainsKey(key)) { return(itemImages[key]); } // Load image data string filename = TextureFile.IndexToFileName(archive); ImageData data = ImageReader.GetImageData(filename, record, 0, true, false); if (data.type == ImageTypes.None) { throw new Exception("GetItemImage() could not load image data."); } // Fix items with known incorrect paper doll offsets if (archive == 237 && (record == 52 || record == 54)) { // "Short shirt" template index 202 variants 2 and 5 for human female data.offset = new DaggerfallConnect.Utility.DFPosition(237, 43); } // Remove mask if requested if (removeMask) { data.dfBitmap = ImageProcessing.ChangeMask(data.dfBitmap); } // Change dye or just update texture ItemGroups group = item.ItemGroup; DyeColors dye = (DyeColors)color; if (group == ItemGroups.Weapons || group == ItemGroups.Armor) { data = ChangeDye(data, dye, DyeTargets.WeaponsAndArmor); } else if (item.ItemGroup == ItemGroups.MensClothing || item.ItemGroup == ItemGroups.WomensClothing) { data = ChangeDye(data, dye, DyeTargets.Clothing); } else { ImageReader.UpdateTexture(ref data); } // Add to cache itemImages.Add(key, data); return(data); }