Scriptum/Assets/Scripts/REFACTORING/Models/Shop/ShopBuildModel.cs
2022-12-24 13:29:15 +01:00

55 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
[Serializable]
public class ShopBuildModel
{
[NonSerialized] public string ShopName; // npc name
[SerializeField] public List<IndexValuePair<Item>> Content = new List<IndexValuePair<Item>>();
public ShopBuildModel(string ownerName, List<IndexValuePair<EquippableItem>> shopContent)
{
ShopName = ownerName;
Content.Clear();
foreach (IndexValuePair<EquippableItem> item in shopContent)
{
Content.Add(
new IndexValuePair<Item>(item.Key, item.Value)
);
}
}
public Shop MapBuildModelToShop()
{
var shop = new Shop(
SceneManager.GetActiveScene().name,
ShopName
);
shop.Content = new List<IndexValuePair<int, EquippableItem>>();
foreach (var ChestElement in Content)
{
var castedObject = ChestElement.Value as EquippableItem;
if (castedObject == null)
shop.Content.Add(
new IndexValuePair<int, EquippableItem>(ChestElement.Key, new EquippableItem(ChestElement.Value))
);
else
shop.Content.Add(
new IndexValuePair<int, EquippableItem>(ChestElement.Key, castedObject)
);
}
return shop;
}
}