-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_spawn_level_helpers.nss
270 lines (221 loc) · 9.06 KB
/
rand_spawn_level_helpers.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "x2_inc_itemprop"
#include "rand_spawn_math"
#include "rand_spawn_consts"
#include "rand_spawn_trait"
//Changes the creature's FirstName to that of the local tribe name.
void DoTribeName(object creature);
//Levels creature up to levelToAchieve based on class in position 1
void DoLevelUp(object creature, int levelToAchieve);
//Levels up the creature based on what is in position 1
void LevelUpCreatureDefault(object creature);
//Levels up the creature based on its tag returns FALSE if no level up took place
//set justCheck to TRUE if you want to avoid leveling the creature up.
int LevelUpCreatureSpecial(object creature, int justCheck=FALSE);
//Adds an armor bonus to the creature based on levelToAchieve
void DoArmorBonus(object creature, int levelToAchieve);
//Adds a bonus to the creature's primary stat based on levelToAchieve
void DoStatBonus(object creature, int levelToAchieve);
//Adds a bonus to the creature's weapons based on levelToAchieve
void DoWeaponBonus(object creature, int levelToAchieve);
// Returns highest ability score, favors STR>DEX>CON>INT>WIS>CHA
int GetPrimaryAbility(object targetCreature);
//Changes the creature's FirstName to that of the local tribe name.
void DoTribeName(object creature)
{
string tribeName = GetLocalString(GetArea(creature),"AREA_CREATURE_TRIBE");
SetFirstName(creature, tribeName);
}
//Levels creature up to levelToAchieve based on class in position 1
void DoLevelUp(object creature, int levelToAchieve)
{
int isSpecial = LevelUpCreatureSpecial(creature, TRUE);
int i;
for (i = GetHitDice(creature); i < levelToAchieve; i++)
{
if (isSpecial)
LevelUpCreatureSpecial(creature);
else
LevelUpCreatureDefault(creature);
}
}
//Levels up the creature based on its tag returns FALSE if no level up took place
//set justCheck to TRUE if you want to avoid leveling the creature up.
int LevelUpCreatureSpecial(object creature, int justCheck)
{
//Determine which class we're leveling up. TODO: Make custom leveling sequences
string creatureTag = GetTag(creature);
// KOBOLD DRAGON DISCIPLE
if (creatureTag == "c_kobold_rand_disciple")
{
if (justCheck) return TRUE;
//Level up Dragon Disciple when bard has reached level 5 and we have not finished the class
if (GetLevelByPosition(1) >= 5 && GetLevelByPosition(2) < 10)
LevelUpHenchman(creature, CLASS_TYPE_DRAGONDISCIPLE, TRUE, PACKAGE_DRAGON_DISCIPLE);
else
LevelUpHenchman(creature, CLASS_TYPE_BARD, TRUE, PACKAGE_BARD_BLADE);
return TRUE;
}
if (creatureTag == "c_orc_rand_berserker")
{
if (justCheck) return TRUE;
//Level up Frenzied Berserker when barbarian has reached level 6 and we have not finished the class
if (GetLevelByPosition(1) >= 6 && GetLevelByPosition(2) < 10)
LevelUpHenchman(creature, CLASS_TYPE_FRENZIEDBERSERKER, TRUE, 135); //Base Frenzied Berserker Package
else
LevelUpHenchman(creature, CLASS_TYPE_BARBARIAN, TRUE, 18); //Barbarian, Berserker
return TRUE;
}
if (creatureTag == "c_drow_rand_archer")
{
if (justCheck) return TRUE;
//Level up Wizard when we have reached Ranger 6 and have no wizard levels
if (GetLevelByPosition(1) == 6 && GetLevelByPosition(2) == 0)
LevelUpHenchman(creature, CLASS_TYPE_WIZARD, TRUE, PACKAGE_WIZARDGENERALIST);
else
{ //Level up Arcane Archer when we reached Ranger 6 / Wizard 1 and have not completed the class
if (GetLevelByPosition(1) >= 6 && GetLevelByPosition(3) < 10)
LevelUpHenchman(creature, CLASS_TYPE_ARCANE_ARCHER, TRUE, PACKAGE_ARCANE_ARCHER);
else //Otherwise level up Ranger
LevelUpHenchman(creature, CLASS_TYPE_RANGER, TRUE, PACKAGE_RANGER_ARCANEARCHER);
}
return TRUE;
}
return FALSE;
}
//Levels up the creature based on what is in position 1
void LevelUpCreatureDefault(object creature)
{
//Default class leveling
switch (GetClassByPosition(1))
{
case CLASS_TYPE_FIGHTER :
if (GetPrimaryAbility(creature) == ABILITY_DEXTERITY)
LevelUpHenchman(creature, CLASS_TYPE_FIGHTER, TRUE, 151); //NPC_SHANDRA package
else
LevelUpHenchman(creature, CLASS_TYPE_FIGHTER, TRUE, PACKAGE_FIGHTER);
break;
case CLASS_TYPE_BARBARIAN :
LevelUpHenchman(creature, CLASS_TYPE_BARBARIAN, TRUE, PACKAGE_BARBARIAN);
break;
case CLASS_TYPE_RANGER :
LevelUpHenchman(creature, CLASS_TYPE_RANGER, TRUE, PACKAGE_RANGER);
break;
case CLASS_TYPE_ROGUE :
LevelUpHenchman(creature, CLASS_TYPE_ROGUE, TRUE, PACKAGE_ROGUE);
break;
case CLASS_TYPE_DRUID :
LevelUpHenchman(creature, CLASS_TYPE_DRUID, TRUE, PACKAGE_DRUID);
break;
case CLASS_TYPE_CLERIC :
LevelUpHenchman(creature, CLASS_TYPE_CLERIC, TRUE, PACKAGE_CLERIC);
break;
case CLASS_TYPE_SPIRIT_SHAMAN :
LevelUpHenchman(creature, CLASS_TYPE_SPIRIT_SHAMAN, TRUE, 181); //Spirit Shaman Elementalist
break;
case CLASS_TYPE_SORCERER :
LevelUpHenchman(creature, CLASS_TYPE_SORCERER, TRUE, PACKAGE_SORCERER_EVOCATION);
break;
case CLASS_TYPE_WIZARD :
LevelUpHenchman(creature, CLASS_TYPE_WIZARD, TRUE, PACKAGE_WIZARD_EVOCATION);
break;
case CLASS_TYPE_BARD :
LevelUpHenchman(creature, CLASS_TYPE_BARD, TRUE, PACKAGE_BARD);
break;
case CLASS_TYPE_ANIMAL:
LevelUpHenchman(creature, CLASS_TYPE_ANIMAL, TRUE, PACKAGE_ANIMAL);
break;
case CLASS_TYPE_HUMANOID :
LevelUpHenchman(creature, CLASS_TYPE_HUMANOID, TRUE, PACKAGE_HUMANOID);
break;
case CLASS_TYPE_VERMIN :
LevelUpHenchman(creature, CLASS_TYPE_VERMIN, TRUE, PACKAGE_VERMIN);
break;
case CLASS_TYPE_MAGICAL_BEAST :
LevelUpHenchman(creature, CLASS_TYPE_MAGICAL_BEAST, TRUE, PACKAGE_MAGICBEAST);
break;
case CLASS_TYPE_OOZE :
LevelUpHenchman(creature,CLASS_TYPE_OOZE, TRUE, 68); // General Ooze Package
break;
case CLASS_TYPE_SHAPECHANGER :
LevelUpHenchman(creature,CLASS_TYPE_SHAPECHANGER, TRUE, PACKAGE_SHAPECHANGER);
break;
default:
LevelUpHenchman(creature, CLASS_TYPE_FIGHTER, TRUE, PACKAGE_FIGHTER);
}
}
//Adds an armor bonus to the creature based on levelToAchieve
void DoArmorBonus(object creature, int levelToAchieve)
{
float armorBonus = ARMOR_PROGRESS_PER_LEVEL * IntToFloat(levelToAchieve);
//Apply armor bonus instantly so it can't be removed
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectACIncrease(MathRound(armorBonus)),creature);
}
//Adds a bonus to the creature's primary stat based on levelToAchieve
void DoStatBonus(object creature, int levelToAchieve)
{
float statBonus = PRIMARY_STAT_PROGRESS_PER_LEVEL * IntToFloat(levelToAchieve);
int primaryAbility = GetPrimaryAbility(creature);
//Traits
if (GetHasTrait(creature, TRAIT_TOUGH))
DoToughTrait(creature,primaryAbility,statBonus);
if (GetHasTrait(creature, TRAIT_BIG))
statBonus = DoBigTrait(creature,primaryAbility,statBonus);
if (GetHasTrait(creature, TRAIT_SMALL))
statBonus = DoSmallTrait(creature,primaryAbility,statBonus);
//Apply ability bonus instantly so it can't be removed
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityIncrease(primaryAbility, MathRound(statBonus)),creature);
}
//Adds a bonus to the creature's weapons based on levelToAchieve
void DoWeaponBonus(object creature, int levelToAchieve)
{
float weaponBonus = WEAPON_PROGRESS_PER_LEVEL * IntToFloat(levelToAchieve);
//Cycle through inventory
int bFoundWeapon = FALSE;
object curItem = GetFirstItemInInventory(creature);
while (GetIsObjectValid(curItem))
{
// Attack bonus to our melee weapons
if (IPGetIsMeleeWeapon(curItem))
{
AddItemProperty(DURATION_TYPE_PERMANENT, ItemPropertyEnhancementBonus(MathRound(weaponBonus)),curItem);
bFoundWeapon = TRUE;
}
//Attack bonus to our ranged weapons
if (GetWeaponRanged(curItem))
{
AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyAttackBonus(MathRound(weaponBonus)),curItem);
bFoundWeapon = TRUE;
}
//Damage bonus to our arrows and bolts and such
if (IPGetIsProjectile(curItem))
{
AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_PIERCING,MathRound(weaponBonus)),curItem);
}
curItem = GetNextItemInInventory(creature);
}
//No items? Buff its natural attack
if (bFoundWeapon == FALSE)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAttackIncrease(MathRound(weaponBonus)),creature);
}
}
// Returns highest ability score, favors STR>DEX>CON>INT>WIS>CHA
int GetPrimaryAbility(object targetCreature)
{
//setup to start
int curHighestAbility = ABILITY_STRENGTH;
int curHighestScore = GetAbilityScore(targetCreature,ABILITY_STRENGTH,TRUE);
//loop through the rest looking for our best choice. Ability scores are numerally from 0 to 5
int i, testScore = 0;
for (i = 1; i < 6; i++)
{
testScore = GetAbilityScore(targetCreature,i,TRUE);
// Check to see the current ability score we are looking at is higher than what has come before
if (testScore > curHighestScore)
{
curHighestAbility = i;
curHighestScore = testScore;
}
}
return curHighestAbility;
}