Working on UI and job assignment, harvesting and depositing to TownHall working
This commit is contained in:
@@ -3,13 +3,21 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[System.Serializable]
|
||||
public class StorageConfig
|
||||
{
|
||||
public Resource.ResourceType resourceType;
|
||||
public int capacity;
|
||||
}
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
public enum BuildingType
|
||||
{
|
||||
House,
|
||||
Farm,
|
||||
Barracks
|
||||
Barracks,
|
||||
TownHall
|
||||
}
|
||||
public enum BuildingState
|
||||
{
|
||||
@@ -19,16 +27,37 @@ public class Building : MonoBehaviour
|
||||
Destroyed
|
||||
}
|
||||
[SerializeField] float constructionTime;
|
||||
[SerializeField] private Resource.ResourceType[] resourceTypes;
|
||||
[SerializeField] private Resource.ResourceType[] constructionResources;
|
||||
[SerializeField] private int[] constructionCost;
|
||||
private BuildingState buildingState;
|
||||
[SerializeField] private BuildingType buildingType;
|
||||
[SerializeField] private GameObject unbuiltModel, constructingModel, activeModel, destroyedModel;
|
||||
[SerializeField] private StorageConfig[] storageConfig = new StorageConfig[0];
|
||||
public Dictionary<Resource.ResourceType, int> resourcesToStore = new Dictionary<Resource.ResourceType, int>();
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
buildingState = BuildingState.Unbuilt;
|
||||
if (buildingType == BuildingType.TownHall)
|
||||
{
|
||||
buildingState = BuildingState.Active;
|
||||
}
|
||||
else
|
||||
{
|
||||
buildingState = BuildingState.Unbuilt;
|
||||
}
|
||||
|
||||
SetBuildingModel(buildingState);
|
||||
InitializeStorage();
|
||||
}
|
||||
|
||||
private void InitializeStorage()
|
||||
{
|
||||
resourcesToStore.Clear();
|
||||
foreach (StorageConfig config in storageConfig)
|
||||
{
|
||||
resourcesToStore[config.resourceType] = config.capacity;
|
||||
Debug.Log($"Storage capacity for {config.resourceType} set to {config.capacity}");
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -80,14 +109,14 @@ public class Building : MonoBehaviour
|
||||
if (buildingState != BuildingState.Unbuilt)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < resourceTypes.Length && i < constructionCost.Length; i++)
|
||||
for (int i = 0; i < constructionResources.Length && i < constructionCost.Length; i++)
|
||||
{
|
||||
if (GameManager.Instance.GetResource(resourceTypes[i]) < constructionCost[i])
|
||||
if (GameManager.Instance.GetResource(constructionResources[i]) < constructionCost[i])
|
||||
{
|
||||
Debug.Log("Not enough resources");
|
||||
return;
|
||||
}
|
||||
GameManager.Instance.AddResource(resourceTypes[i], -constructionCost[i]);
|
||||
GameManager.Instance.AddResource(constructionResources[i], -constructionCost[i]);
|
||||
}
|
||||
Debug.Log("Building Started");
|
||||
buildingState = BuildingState.Constructing;
|
||||
@@ -135,12 +164,32 @@ public class Building : MonoBehaviour
|
||||
case BuildingState.Active:
|
||||
//DestroyBuilding();
|
||||
var npcInventory = npcInteracting.GetInventory();
|
||||
foreach (KeyValuePair<Resource.ResourceType, int> entry in npcInventory)
|
||||
var entries = new List<KeyValuePair<Resource.ResourceType, int>>(npcInventory);
|
||||
foreach (KeyValuePair<Resource.ResourceType, int> entry in entries)
|
||||
{
|
||||
GameManager.Instance.AddResource(entry.Key, entry.Value);
|
||||
UIController.Instance.UpdateStats();
|
||||
npcInteracting.inventory.Remove(entry.Key);
|
||||
}
|
||||
break;
|
||||
case BuildingState.Destroyed:
|
||||
CancelBuilding();
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SetUpStore(StorageConfig[] configs)
|
||||
{
|
||||
if (configs == null)
|
||||
{
|
||||
Debug.LogWarning("SetUpStore received null config array.");
|
||||
return;
|
||||
}
|
||||
|
||||
resourcesToStore.Clear();
|
||||
foreach (StorageConfig config in configs)
|
||||
{
|
||||
resourcesToStore[config.resourceType] = config.capacity;
|
||||
Debug.Log($"Storage capacity for {config.resourceType} set to {config.capacity}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user