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;
|
public Dialogue Dialogue;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
public ShopBuildModel shopModel;
|
||||||
|
|
||||||
|
[NonSerialized]
|
||||||
public Shop shop;
|
public Shop shop;
|
||||||
|
|
||||||
bool CanShopBeOpened = false;
|
bool CanShopBeOpened = false;
|
||||||
@ -51,7 +54,7 @@ public class NpcShopManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
shop = ShopUIManager.Instance.GetList().Where(shop => {
|
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();
|
}).First();
|
||||||
|
|
||||||
IsRegistered = true;
|
IsRegistered = true;
|
||||||
@ -118,19 +121,15 @@ public class NpcShopManager : MonoBehaviour
|
|||||||
public void RegisterShop()
|
public void RegisterShop()
|
||||||
{
|
{
|
||||||
// 1. Set owner name
|
// 1. Set owner name
|
||||||
shop.Npc = gameObject.name;
|
shopModel.ShopName = gameObject.GetComponent<NPC>().Name;
|
||||||
|
|
||||||
// 2. Create new Shop instance in scene registry list
|
// 2. Create new Shop instance in scene registry list
|
||||||
((SceneShopDataManager)SceneShopDataManager.Instance)
|
((SceneShopDataManager)SceneShopDataManager.Instance)
|
||||||
.RegisterShop(
|
.RegisterShop(
|
||||||
new Shop(
|
shopModel.MapBuildModelToShop()
|
||||||
SceneManager.GetActiveScene().name,
|
|
||||||
gameObject.name,
|
|
||||||
shop.GetContent()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Debug.Log($"Shop {shop.Npc} registered");
|
Debug.Log($"Shop {shopModel.ShopName} registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenShop()
|
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