private static Dictionary <Guid, Item> ConvertItemsForPlaying(SaveData.SerializableItemDictionary itemSdos) { var items = new Dictionary <Guid, Item>(); foreach (var sdo in itemSdos) { Item item; switch (sdo.Value.ItemCategory.ToLower()) { case "armor": item = ArmorSdo.ConvertToArmor((ArmorSdo)sdo.Value); break; case "weapon": item = WeaponSdo.ConvertToWeapon((WeaponSdo)sdo.Value); break; case "consumable": throw new NotImplementedException(); default: Debug.Log($@"Item Category {sdo.Value.ItemCategory.ToLower()} not found. Converting to Item."); item = ItemSdo.ConvertToItem(sdo.Value); break; } items.Add(item.Id, item); } return(items); }
private static SaveData.SerializableItemDictionary ConvertItemsForSaving(Dictionary <Guid, Item> items) { if (items == null) { return(null); } var sdos = new SaveData.SerializableItemDictionary(); foreach (var item in items) { try { ItemSdo sdo; switch (item.Value.ItemCategory.ToLower()) { case "armor": sdo = ArmorSdo.ConvertToArmorSdo((Armor)item.Value); break; case "weapon": sdo = WeaponSdo.ConvertToWeaponSdo((Weapon)item.Value); break; case "consumable": throw new NotImplementedException(); default: Debug.Log($@"Item Category {item.Value.ItemCategory.ToLower()} not found. Converting to ItemSdo."); sdo = ItemSdo.ConvertToItemSdo(item.Value); break; } sdos.Add(sdo.Id, sdo); } catch (Exception e) { Debug.Log($"Error converting {item.Value.ItemName}: {e.Message}"); } } return(sdos); }
public static Weapon ConvertToWeapon(WeaponSdo sdo) { var weapon = new Weapon(); weapon.Type = sdo.Type; weapon.Range = sdo.Range; weapon.Rarity = sdo.Rarity; weapon.EquipmentSlotType = sdo.EquipmentSlotType; weapon.EquipmentSlots = sdo.EquipmentSlots; weapon.ItemType = sdo.ItemType; weapon.ItemCategory = sdo.ItemCategory; weapon.Id = sdo.Id; weapon.ItemDice = sdo.ItemDice; weapon.ItemName = sdo.ItemName; weapon.Properties = sdo.Properties; if (sdo.AOEType != null) { weapon.AOE = AOEStore.GetAOEByType((AoeType)sdo.AOEType); } return(weapon); }