Felix Boucher b54627196c population mechanic with art
- added art for house and UI
- put population in ResourceManager
- create house prefab
- added code for adding and removing pop depending on entity
- refactor harvesters so they inherit from ally
- modify placeholders and buttons so that only units cost population
- add events for population and resources changing
- add population relative configs to global config
- add start resources values to Levels
- add debug feature for generating resources for free
2023-10-29 19:12:32 -04:00

59 lines
1.9 KiB
C#

using UnityEngine;
using System.Collections.Generic;
using static Enum;
public class Harvester : Ally
{
[SerializeField] [Tooltip("helps choose the right skin for the harvester depending on resource")]
private List<HarvesterResourcePair> _harvesterResourcePairs;
protected ResourceChoice ResourceChoice => _resourceChoice;
public override Vector2 RangeMultiplier { get; }
public override float HpMultiplier { get; }
public override float SpeedMultiplier { get; }
public override float DamageMultiplier { get; }
public override float AttackSpeedMultiplier { get; }
[SerializeField]
private ResourceChoice _resourceChoice;
public override sealed void Start()
{
base.Start();
ChooseSkinForHarvester();
}
/// <summary>
/// changes the harvester's appearance depending on the resource they're harvesting
/// </summary>
private void ChooseSkinForHarvester()
{
//get the tile we're on
var tile = LevelManager.Instance.Get<ResourceTile>(t => t.Position == Position);
if (tile == default) return;
//get the resource of the tile we're on
var yieldPrefab = tile.YieldPrefab;
if (!yieldPrefab) return;
var resourceMaker = yieldPrefab.GetComponent<ResourceMaker>();
if (!resourceMaker) return;
//if we already have the right harvester for the resource, no need to change
var resourceChoice = resourceMaker.ResourceChoice;
if (resourceChoice == this.ResourceChoice) return;
//get the right pair for the resource we're on
var harvResPair = _harvesterResourcePairs.Find(hrp => hrp.Resource == resourceChoice);
if (harvResPair == null) return;
//exchange harvesters
var newHarvester = Instantiate(harvResPair.HarvesterPrefab, transform.position, Quaternion.identity);
newHarvester.transform.SetParent(transform.parent);
Destroy(gameObject);
}
}