-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourceNode.cs
196 lines (162 loc) · 4.34 KB
/
ResourceNode.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class ResourceNode : MonoBehaviour {
[Header("Debug?")]
public ManageDebug DebugManager;
[Header("Item Data")]
public Item_Data dataController;
public ITEMS TYPES;
[Header("Node Info")]
[SerializeField]
private int ID;
[SerializeField]
private new string name;
public bool RichNode;
[Header("Respawn Info")]
[SerializeField]
private int resource_left;
public bool NodeHarvestable = false;
public bool StartRespawnTimer = false;
public float respawnTimer;
[SerializeField]
private bool respawn;
public float resetTime = 5f;
[Header("Resource Info")]
private int min_ATM; // min gather amount per node
private int max_ATM; // max gather amount per node
[SerializeField]
private Item resource;
public ResourceNode(int id, string n, int time, bool r, int min, int max, Item item)
{
ID = id;
name = n;
respawnTimer = time;
respawn = r;
min_ATM = min;
max_ATM = max;
resource = item;
}
// Use this for initialization
void Start ()
{
ID = dataController.getIdData(TYPES);
name = dataController.getNameData(TYPES);
//resource = dataController.
hideChildren();
RespawnNode();
}
// Update is called once per frame
void Update () {
if(respawn)
{
respawnTimer -= Time.deltaTime;
if (respawnTimer <= 0)
{
RichNode = false;
RespawnNode();
}
}
}
void RespawnNode()
{
//Determines if the node is a Rich Node, which is high in resources
int richChance = Random.Range(1, 11);
if (richChance > 8) // 20% chance of being a rich node
RichNode = true;
ResourceFloor();
ResourceCeiling();
resource_left = max_ATM;
NodeHarvestable = true;
respawn = false;
respawnTimer = resetTime;
if(DebugManager.debugResourceNodes)
Debug.Log("Respawned");
}
public void Harvest()
{
if(NodeHarvestable)
{
resource_left--;
if (DebugManager.debugResourceNodes)
Debug.Log("Harvested <1> <" + name + ">");
}
if(resource_left == 0)
{
NodeHarvestable = false;
if (DebugManager.debugResourceNodes)
Debug.Log("Out of Resources");
respawn = true;
}
}
void ResourceFloor()
{
if (RichNode)
min_ATM = Random.Range(3, 6);
else
min_ATM = Random.Range(1, 4);
}
void ResourceCeiling()
{
if (RichNode)
max_ATM = Random.Range(5, 9);
else
max_ATM = Random.Range(3, 6);
}
void hideChildren()
{
for(int i = 0; i < this.transform.childCount; i ++)
{
this.transform.GetChild(i).gameObject.SetActive(false);
}
}
public void spawnItems()
{
int spawnAMT = Random.Range(1, 11);
if (DebugManager.debugResourceNodes)
Debug.Log(spawnAMT);
for(int i = 0; i < spawnAMT; i ++)
{
this.transform.GetChild(i).gameObject.SetActive(true);
}
}
public int getID()
{
return ID;
}
public string getName()
{
return name;
}
public ITEMS getType()
{
return TYPES;
}
public Item getItemType()
{
return resource;
}
public ITEMS determineItemData()
{
if (ID == 0)
return ITEMS.STONE;
else if (ID == 1)
return ITEMS.FLINT;
else if (ID == 2)
return ITEMS.LOG;
else if (ID == 3)
return ITEMS.STICK;
else if (ID == 4)
return ITEMS.HERB;
else if (ID == 5)
return ITEMS.WATER;
else if (ID == 6)
return ITEMS.BERRY;
else if (ID == 7)
return ITEMS.RAW_MEAT;
else if (ID == 8)
return ITEMS.COOKED_MEAT;
return ITEMS.Default;
}
}