Shop - allow to trade non equippable items
This commit is contained in:
parent
2280e5fc15
commit
7de447ac73
@ -16,6 +16,9 @@ public class NpcShopManager : MonoBehaviour
|
||||
public Dialogue Dialogue;
|
||||
|
||||
[SerializeField]
|
||||
public ShopBuildModel shopModel;
|
||||
|
||||
[NonSerialized]
|
||||
public Shop shop;
|
||||
|
||||
bool CanShopBeOpened = false;
|
||||
@ -51,7 +54,7 @@ public class NpcShopManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
shop = ShopUIManager.Instance.GetList().Where(shop => {
|
||||
return shop.Npc == gameObject.GetComponent<NPC>().name && shop.Map == SceneManager.GetActiveScene().name;
|
||||
return shopModel.ShopName == gameObject.GetComponent<NPC>().name && shop.Map == SceneManager.GetActiveScene().name;
|
||||
}).First();
|
||||
|
||||
IsRegistered = true;
|
||||
@ -118,19 +121,15 @@ public class NpcShopManager : MonoBehaviour
|
||||
public void RegisterShop()
|
||||
{
|
||||
// 1. Set owner name
|
||||
shop.Npc = gameObject.name;
|
||||
shopModel.ShopName = gameObject.GetComponent<NPC>().Name;
|
||||
|
||||
// 2. Create new Shop instance in scene registry list
|
||||
((SceneShopDataManager)SceneShopDataManager.Instance)
|
||||
.RegisterShop(
|
||||
new Shop(
|
||||
SceneManager.GetActiveScene().name,
|
||||
gameObject.name,
|
||||
shop.GetContent()
|
||||
)
|
||||
shopModel.MapBuildModelToShop()
|
||||
);
|
||||
|
||||
Debug.Log($"Shop {shop.Npc} registered");
|
||||
Debug.Log($"Shop {shopModel.ShopName} registered");
|
||||
}
|
||||
|
||||
public void OpenShop()
|
||||
|
55
Assets/Scripts/REFACTORING/Models/Shop/ShopBuildModel.cs
Normal file
55
Assets/Scripts/REFACTORING/Models/Shop/ShopBuildModel.cs
Normal file
@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0818080ca77517949aba932b1af1e100
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user