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
105
106
107
108
109
110
111
|
using UnityEngine;
public class HauntedHouse : IncomeGenerator, IBuildable
{
[SerializeField]
private LayerMask graveLayerMask;
[SerializeField]
private GameObject UIObject;
[SerializeField]
private int goldBackOnDemolish;
private bool isGathering;
private int graveCount;
private int manaUsed;
private float timer;
private SimpleUI myUI;
protected override void Start()
{
base.Start();
DetectGraves();
}
private void Update()
{
if (myUI != null && isGathering)
{
string text = "Mana used: " + manaUsed;
text = text + "\nNearby graves: x" + graveCount;
text = text + "\nTax efficiency: x" + GameManager.instance.hauntedHouseEfficiency;
text = text + "\nDeath tax due: " + Mathf.Max((int)Mathf.Sqrt(manaUsed * GameManager.instance.hauntedHouseEfficiency * graveCount), 1) + "g";
text = text + "\nNet tax collected: " + base.netGold + "g.";
myUI.SetDiscriptionText(text);
}
if (!isGathering || !SpawnManager.instance.combat)
{
return;
}
if (timer <= 0f)
{
if (ResourceManager.instance.CheckMana(1))
{
ResourceManager.instance.SpendMana(1);
manaUsed++;
timer = 1f;
}
}
else
{
timer -= Time.deltaTime;
}
}
public override void GenerateIncome()
{
incomePerRound = Mathf.Max((int)Mathf.Sqrt(manaUsed * GameManager.instance.hauntedHouseEfficiency * graveCount), 1);
base.GenerateIncome();
manaUsed = 0;
incomePerRound = 1;
}
public void SetStats()
{
}
private void DetectGraves()
{
if (Physics.Raycast(base.transform.position + new Vector3(1f, 1f, 0f), -base.transform.up, out var hitInfo, 1f, graveLayerMask, QueryTriggerInteraction.Ignore))
{
CheckGrave(hitInfo);
}
if (Physics.Raycast(base.transform.position + new Vector3(-1f, 1f, 0f), -base.transform.up, out hitInfo, 1f, graveLayerMask, QueryTriggerInteraction.Ignore))
{
CheckGrave(hitInfo);
}
if (Physics.Raycast(base.transform.position + new Vector3(0f, 1f, 1f), -base.transform.up, out hitInfo, 1f, graveLayerMask, QueryTriggerInteraction.Ignore))
{
CheckGrave(hitInfo);
}
if (Physics.Raycast(base.transform.position + new Vector3(0f, 1f, -1f), -base.transform.up, out hitInfo, 1f, graveLayerMask, QueryTriggerInteraction.Ignore))
{
CheckGrave(hitInfo);
}
}
private void CheckGrave(RaycastHit hit)
{
if (hit.collider.GetComponent<Grave>() != null && (double)Mathf.Abs(hit.collider.transform.position.y - base.transform.position.y) <= 0.001)
{
graveCount++;
isGathering = true;
}
}
public void SpawnUI()
{
myUI = Object.Instantiate(UIObject, base.transform.position, Quaternion.identity).GetComponent<SimpleUI>();
myUI.SetDemolishable(base.gameObject, goldBackOnDemolish);
}
public void Demolish()
{
RemoveIncomeGeneration();
}
}
|