summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/Mill_ImprovementWindSpirits.cs
blob: 824352e791c292aa44224c1440427a079769a8af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Collections.Generic;
using UnityEngine;

public class Mill_ImprovementWindSpirits : MonoBehaviour, DayNightCycle.IDaytimeSensitive
{
	[SerializeField]
	private BuildSlot buildSlot;

	[SerializeField]
	private float blockIntervalLvl1 = 1f;

	[SerializeField]
	private float blockIntervalLvl2 = 0.5f;

	[SerializeField]
	private float blockIntervalLvl3 = 0.25f;

	public Mesh lvl2Mesh;

	public Mesh lvl3Mesh;

	private float blockInterval = 1f;

	[SerializeField]
	private float range = 30f;

	[SerializeField]
	private GameObject fxBlockArrow;

	private float cooldown;

	private TagManager tagManager;

	private List<TagManager.ETag> mustHaveTags = new List<TagManager.ETag>();

	private List<TagManager.ETag> mayNotHaveTags = new List<TagManager.ETag>();

	private void Start()
	{
		tagManager = TagManager.instance;
		cooldown = Random.value * blockInterval;
		mustHaveTags.Add(TagManager.ETag.BlockableEnemyProjectile);
		DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
	}

	private void Update()
	{
		cooldown -= Time.deltaTime;
		while (cooldown <= 0f)
		{
			BlockAnArrow();
			cooldown += blockInterval;
		}
	}

	private void BlockAnArrow()
	{
		TaggedObject taggedObject = tagManager.FindClosestTaggedObjectWithTags(base.transform.position, mustHaveTags, mayNotHaveTags);
		if (!(taggedObject == null) && (taggedObject.transform.position - base.transform.position).magnitude < range)
		{
			if ((bool)fxBlockArrow)
			{
				Object.Instantiate(fxBlockArrow, taggedObject.transform.position, Quaternion.identity);
			}
			Object.Destroy(taggedObject.gameObject);
		}
	}

	private void OnEnable()
	{
		buildSlot.upgrades[1].upgradeBranches[0].replacementMesh = lvl2Mesh;
		buildSlot.upgrades[2].upgradeBranches[0].replacementMesh = lvl3Mesh;
		SetCorrectWeapon();
	}

	public void OnDusk()
	{
		SetCorrectWeapon();
	}

	public void OnDawn_AfterSunrise()
	{
	}

	public void OnDawn_BeforeSunrise()
	{
	}

	private void SetCorrectWeapon()
	{
		if (buildSlot.Level == 1)
		{
			blockInterval = blockIntervalLvl1;
		}
		else if (buildSlot.Level == 2)
		{
			blockInterval = blockIntervalLvl2;
		}
		else if (buildSlot.Level == 3)
		{
			blockInterval = blockIntervalLvl3;
		}
	}
}