la config des ennemis influencait la config des alliés, ce qui était un bug maintenant, il y a une config différente pour les alliés et les ennemis. l'animation d'attaque ne se terminait pas à temps pour faire le dégat, il a donc fallu multiplier la vitesse d'animation par le attack speed quand on attaque j'en ai profité pour faire la même chose pour le walk animation et le speed j'ai changé l'attribut des unités "attack speed" pour un "attack interval", pour que ça représente mieux son utilisation. Le multiplicateur reste sur la vitesse, et non sur l'interval. Les configs pour les ressources sont les valeurs des ressources directement (pas des multiplicateurs)
84 lines
2.6 KiB
C#
84 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static Extensions;
|
|
|
|
[CreateAssetMenu(menuName = project_name + "/" + nameof(ResourceTile))]
|
|
public class ResourceTile : LevelTile
|
|
{
|
|
[SerializeField]
|
|
[Tooltip("the prefab of the currency that will be spawned when mining this resource")]
|
|
private GameObject _yieldPrefab;
|
|
|
|
public GameObject YieldPrefab => _yieldPrefab;
|
|
private string YieldPrefabName => _yieldPrefab.name;
|
|
|
|
[SerializeField]
|
|
[Range(0.0f, 5.0f)]
|
|
private float _randomPositionConfig = 0.5f;
|
|
private float _yieldCounter = 0;
|
|
|
|
public override void LevelStart()
|
|
{
|
|
base.LevelStart();
|
|
ResetYieldDuration();
|
|
}
|
|
public override void LevelUpdate()
|
|
{
|
|
//check if there is an harvester unit on top
|
|
var hasFarmer = LevelManager.Instance.Get<Harvester>(x => x.Position.IsContainedIn(Position));
|
|
if (!hasFarmer) return;
|
|
|
|
_yieldCounter -= Time.deltaTime;
|
|
if (_yieldCounter > 0) return;
|
|
|
|
ResetYieldDuration();
|
|
|
|
if (_yieldPrefab != null)
|
|
{
|
|
YieldResource();
|
|
}
|
|
}
|
|
private void YieldResource()
|
|
{
|
|
float rangeConfig = 0.5f + _randomPositionConfig;
|
|
Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z);
|
|
var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity);
|
|
yielded.transform.SetParent(LevelManager.Instance.LevelTransform);
|
|
}
|
|
private void ResetYieldDuration()
|
|
{
|
|
_yieldCounter = 0;
|
|
var config = GlobalConfig.Instance.Current;
|
|
if (!config) return;
|
|
|
|
if (config.useRandomHarvestDuration)
|
|
{
|
|
float min = config.randomHarvestDurationMinimum,
|
|
max = config.randomHarvestDurationMaximum;
|
|
_yieldCounter = Random.Range(min, max);
|
|
}
|
|
else
|
|
{
|
|
_yieldCounter = config.harvestDuration;
|
|
}
|
|
}
|
|
public override bool Equals(ILevelObject other)
|
|
{
|
|
return other is ResourceTile otherRes
|
|
&& base.Equals(otherRes)
|
|
&& _yieldPrefab == otherRes._yieldPrefab;
|
|
}
|
|
public override Dictionary<string, object> ToDictionary()
|
|
{
|
|
var dict = base.ToDictionary();
|
|
|
|
dict[nameof(YieldPrefabName)] = YieldPrefabName;
|
|
return dict;
|
|
}
|
|
public override void LoadDictionary(Dictionary<string, object> dict)
|
|
{
|
|
base.LoadDictionary(dict);
|
|
var prefabName = dict[nameof(YieldPrefabName)].ToString();
|
|
_yieldPrefab = Database.Instance.Prefabs[prefabName];
|
|
}
|
|
} |