Added the basic purchase multiplier for houses and to un/assign workers.

This commit is contained in:
4-Bit-Player
2024-08-20 12:58:10 +02:00
committed by Minz
parent 92e89222b2
commit 5b9766de50
5 changed files with 422 additions and 20 deletions

View File

@@ -5,11 +5,14 @@ using UnityEngine;
public class AssignableWorker : MonoBehaviour
{
private int workersAssigned = 0;
private TogglePurchaseAmount purchaseAmount;
private GameManager gameManager;
private int workerAmount = 0;
// Start is called before the first frame update
void Start()
{
purchaseAmount = GameObject.Find("PurchaseMultiplier").GetComponent<TogglePurchaseAmount>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
}
@@ -20,18 +23,23 @@ public class AssignableWorker : MonoBehaviour
public void AddWorker()
{
if(gameManager.GetResourceCount(Resource.WORKER) > 0)
workerAmount = purchaseAmount.GetPurchaseAmount();
if(gameManager.GetResourceCount(Resource.WORKER) >= workerAmount)
{
workersAssigned++;
gameManager.RemoveResource(Resource.WORKER, 1);
workersAssigned += workerAmount;
gameManager.RemoveResource(Resource.WORKER, workerAmount);
}
}
public bool RemoveWorker()
{
if (workersAssigned == 0) return false;
workersAssigned--;
gameManager.AddResource(Resource.WORKER, 1);
workerAmount = purchaseAmount.GetPurchaseAmount();
if (workersAssigned < workerAmount) return false;
workersAssigned -= workerAmount;
gameManager.AddResource(Resource.WORKER, workerAmount);
return true;
}
}

View File

@@ -9,28 +9,33 @@ public class HouseManager : MonoBehaviour
private float ttnw = 30; //Time to next worker
private float currentTtnw = 0;
private int workerPerHouse = 3;
private int purchaseMultiplier;
private TogglePurchaseAmount purchaseAmount;
private GameManager gameManager;
[SerializeField]
private GameObject mouseNotificationLabel;
//House cost: Brick Tile Plank
public int[] cost = new int[3] { 10, 5, 2 };
// public int[] cost = new int[3] { 10, 5, 2 };
public int[] cost = new int[3] { 2, 1, 1 };
[SerializeField]
private Transform notificationOrigin;
[SerializeField]
[SerializeField]
private TMP_Text houseReqLabel;
// Start is called before the first frame update
void Start()
{
purchaseAmount = GameObject.Find("PurchaseMultiplier").GetComponent<TogglePurchaseAmount>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
}
// Update is called once per frame
void Update()
{
houseReqLabel.text = $"{gameManager.GetResourceCount(Resource.BRICK)}/{cost[0]} Bricks\n" +
$"{gameManager.GetResourceCount(Resource.TILE)}/{cost[1]} Tiles\n" +
$"{gameManager.GetResourceCount(Resource.PLANKS)}/{cost[2]} Planks\n";
if (currentTtnw > 0)
purchaseMultiplier = purchaseAmount.GetPurchaseAmount();
houseReqLabel.text = $"{gameManager.GetResourceCount(Resource.BRICK)}/{cost[0] * purchaseMultiplier} Bricks\n" +
$"{gameManager.GetResourceCount(Resource.TILE)}/{cost[1] * purchaseMultiplier} Tiles\n" +
$"{gameManager.GetResourceCount(Resource.PLANKS)}/{cost[2] * purchaseMultiplier} Planks\n";
if (currentTtnw > 0)
{
currentTtnw -= Time.deltaTime;
} else
@@ -53,9 +58,9 @@ public class HouseManager : MonoBehaviour
public void BuildHouse()
{
if (gameManager.GetResourceCount(Resource.BRICK) < cost[0] ||
gameManager.GetResourceCount(Resource.TILE) < cost[1] ||
gameManager.GetResourceCount(Resource.PLANKS) < cost[2])
if (gameManager.GetResourceCount(Resource.BRICK) < cost[0] * purchaseMultiplier ||
gameManager.GetResourceCount(Resource.TILE) < cost[1] * purchaseMultiplier ||
gameManager.GetResourceCount(Resource.PLANKS) < cost[2] * purchaseMultiplier)
{
Debug.Log("Not enough resources to build house!");
GameObject infoLabel = Instantiate(mouseNotificationLabel, GameObject.Find("Canvas").transform);
@@ -64,9 +69,9 @@ public class HouseManager : MonoBehaviour
return;
}
gameManager.RemoveResource(Resource.BRICK, cost[0]);
gameManager.RemoveResource(Resource.TILE, cost[1]);
gameManager.RemoveResource(Resource.PLANKS, cost[2]);
gameManager.AddResource(Resource.HOUSE, 1);
gameManager.RemoveResource(Resource.BRICK, cost[0] * purchaseMultiplier);
gameManager.RemoveResource(Resource.TILE, cost[1] * purchaseMultiplier);
gameManager.RemoveResource(Resource.PLANKS, cost[2] * purchaseMultiplier);
gameManager.AddResource(Resource.HOUSE, 1 * purchaseMultiplier);
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Mime;
using UnityEngine;
using UnityEngine.UIElements;
using TMPro;
using Unity.VisualScripting;
public class TogglePurchaseAmount : MonoBehaviour
{
private int[] options= {1, 10, 100};
private int selected = 0;
public int purchaseAmount = 1;
TMP_Text displayThing;
// Start is called before the first frame update
void Start()
{
displayThing = GameObject.Find("PurchaseAmountText").GetComponent<TMP_Text>();
UpdateDisplayAmount();
}
// Update is called once per frame
void Update()
{
}
public void OnClick()
{
selected = (selected + 1) % options.Length;
purchaseAmount = options[selected];
UpdateDisplayAmount();
Debug.Log(purchaseAmount);
}
private void UpdateDisplayAmount()
{
displayThing.text = "Toggle Purchase Amount x " + purchaseAmount.ToString();
}
public int GetPurchaseAmount()
{
return purchaseAmount;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9980f1709cbec1e4db2c3690a04cfe4b