-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_spawn_heartbeat.nss
138 lines (106 loc) · 3.56 KB
/
rand_spawn_heartbeat.nss
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
#include "rand_spawn_consts"
#include "rand_spawn_setup_area"
//rand_spawn_heartbeat
//This function serves as a pseudoheartbeat
void RSSHeartbeat();
//Returns TRUE if the area has any creatures in it
int DoesAreaHaveCreatures(object area);
//Returns TRUE if the area has had enough camps killed to be cleared. Also reactivates spawns in the area.
int IsAreaCleared(object area);
//Returns the chance out of a 100 that this area should be set up to spawn creatures
int GetSpawnChance(object area);
//Returns the chance out of a 100 that this area should be torn down to despawn creatures
int GetDespawnChance(object area);
// Returns the percentage of spawns in the area that must be killed for it to be considered cleared
float GetAreaClearedPercentage(object area);
void main()
{
RSSHeartbeat();
}
void RSSHeartbeat()
{
if (GetLocalInt(OBJECT_SELF, "AREA_SPAWN_READY"))
{
int despawnArea = FALSE;
//Has area been cleared?
//void IsAreaClear(OBJECT_SELF)
//Should we despawn?
if (d100(1) <= GetDespawnChance(OBJECT_SELF))
despawnArea = TRUE;
if (despawnArea == TRUE)
TeardownAreaForRSS(OBJECT_SELF);
}
else
{
//Should we spawn?
if (d100(1) <= GetSpawnChance(OBJECT_SELF))
SetupAreaForRSS(OBJECT_SELF);
}
//float timeUntilNextBeat = 2700 + Random(1800); // 60 min +- 15 min
float timeUntilNextBeat = 60.0f; // Short duration for testing
DelayCommand(timeUntilNextBeat, RSSHeartbeat());
}
//Returns the chance out of a 100 that this area should be set up to spawn creatures
int GetSpawnChance(object area)
{
int chanceOfSpawn = GetLocalInt(area, "AREA_SPAWN_CHANCE");
if (chanceOfSpawn == AREA_USES_DEFAULT_SPAWN_CHANCE)
chanceOfSpawn = DEFAULT_CHANCE_OF_SPAWN;
if (chanceOfSpawn == NO_SPAWN)
chanceOfSpawn = 0;
return chanceOfSpawn;
}
//Returns the chance out of a 100 that this area should be torn down to despawn creatures
int GetDespawnChance(object area)
{
int chanceOfDespawn = GetLocalInt(area, "AREA_DESPAWN_CHANCE");
if (chanceOfDespawn == AREA_USES_DEFAULT_DESPAWN_CHANCE)
chanceOfDespawn = DEFAULT_CHANCE_OF_DESPAWN;
if (chanceOfDespawn == NO_DESPAWN)
chanceOfDespawn = 0;
return chanceOfDespawn;
}
//Returns TRUE if the area has any creatures in it
int DoesAreaHaveCreatures(object area)
{
object areaObject = GetFirstObjectInArea(area);
while (GetIsObjectValid(areaObject))
{
if (GetObjectType(areaObject) == OBJECT_TYPE_CREATURE)
return TRUE;
areaObject = GetNextObjectInArea(area);
}
return FALSE;
}
//Returns TRUE if the area has had enough camps killed to be cleared. Also reactivates spawns in the area.
int IsAreaCleared(object area)
{
object areaObject = GetFirstObjectInArea(area);
int clearedCount = 0;
int totalCount = 0;
while (GetIsObjectValid(areaObject))
{
if (GetObjectType(areaObject) == OBJECT_TYPE_WAYPOINT)
{
totalCount++;
if (GetLocalInt(curObj, "SpawnDeactivated"))
{
clearedCount++;
GetLocalInt(curObj, "SpawnDeactivated", FALSE);
}
}
areaObject = GetNextObjectInArea(area);
}
float clearedPercentage = IntToFloat(clearedCount) / IntToFloat(totalCount + clearedCount) * 100.0f;
if (clearedPercentage >= GetAreaClearedPercentage(area))
return TRUE;
return FALSE;
}
// Returns the percentage of spawns in the area that must be killed for it to be considered cleared
float GetAreaClearedPercentage(object area)
{
int clearPercentage = GetLocalInt(area, "AREA_CLEAR_PERCENTAGE");
if (clearPercentage == 0)
return DEFAULT_CLEAR_PERCENTAGE
return clearPercentage;
}