-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_spawn_trait.nss
268 lines (228 loc) · 7.79 KB
/
rand_spawn_trait.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
#include "rand_spawn_consts"
#include "rand_spawn_math"
// Core Trait Functions
//Determins which traits creature should have and stores them on the creature
void SetupTraits(object creature, int levelToAchieve);
//Applies special trait effects to creature
void DoTraits(object creature, int levelToAchieve);
//Applies specific trait to creature
void ApplyTrait(object creature, int trait, int levelToAchieve);
// Trait specific functions
// Applies damage scaled to levelToAchieve of type damageType
void DoDamageTrait(object creature, int levelToAchieve, int damageType);
// Applies damage resistance to levelToAchieve of type damageType
void DoDamageResistanceTrait(object creature, int levelToAchieve, int damageType);
// Applies damage reduction to creature scaled by levelToAchieve
void DoThickSkinnedTrait(object creature, int levelToAchieve);
//Bonus to Con equivalent to Stat Bonus, if Con primary attribute, HP/Fort
void DoToughTrait(object creature, int primaryAbility, float statBonus);
//+4 Str, -2 Dex
float DoBigTrait(object creature, int primaryAbility, float statBonus);
//+4 Dex, -2 Str
float DoSmallTrait(object creature, int primaryAbility, float statBonus);
// Helpers
//Gets if creature has a particular trait
int GetHasTrait(object creature, int trait);
//Returns the appropriate DAMAGE_BONUS_* for the specified amount
int TraitDamageBonusByAmount(int amount);
//Determins which traits creature should have and stores them on the creature
void SetupTraits(object creature, int levelToAchieve)
{
int areaTrait = 0;
int traitNum = 0;
do
{
traitNum++;
areaTrait = GetLocalInt(creature,"AREA_TRAIT_" + IntToString(traitNum));
if (areaTrait != 0)
SetLocalInt(creature,"CREATURE_TRAIT_" + IntToString(traitNum),areaTrait);
}
while (areaTrait != 0);
while (traitNum < 2)
{
SetLocalInt(creature,"CREATURE_TRAIT_" + IntToString(traitNum),Random(TOTAL_NUM_TRAITS) + 1);
traitNum++;
}
}
//Applies special trait effects to creature
void DoTraits(object creature, int levelToAchieve)
{
int creatureTrait = 0;
int traitNum = 0;
do
{
traitNum++;
creatureTrait = GetLocalInt(creature,"CREATURE_TRAIT_" + IntToString(traitNum));
if (creatureTrait != 0)
ApplyTrait(creature, creatureTrait, levelToAchieve);
}
while (creatureTrait != 0);
}
//Applies specific trait to creature
void ApplyTrait(object creature, int trait, int levelToAchieve)
{
switch (trait)
{
case TRAIT_FLAMING_WEAPONS:
DoDamageTrait(creature, levelToAchieve, DAMAGE_TYPE_FIRE);
break;
case TRAIT_FROST_WEAPONS:
DoDamageTrait(creature, levelToAchieve, DAMAGE_TYPE_COLD);
break;
case TRAIT_SHOCK_WEAPONS:
DoDamageTrait(creature, levelToAchieve, DAMAGE_TYPE_ELECTRICAL);
break;
case TRAIT_ACERBIC_WEAPONS:
DoDamageTrait(creature, levelToAchieve, DAMAGE_TYPE_ACID);
break;
case TRAIT_THUNDERING_WEAPONS:
DoDamageTrait(creature, levelToAchieve, DAMAGE_TYPE_SONIC);
break;
case TRAIT_FLAME_RETARDANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_FIRE);
break;
case TRAIT_FROST_RETARDANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_COLD);
break;
case TRAIT_WELL_GROUNDED:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_ELECTRICAL);
break;
case TRAIT_CORROSION_RESISTANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_ACID);
break;
case TRAIT_SONIC_INSULATION:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_SONIC);
break;
case TRAIT_THICK_SKINNED:
DoThickSkinnedTrait(creature,levelToAchieve);
break;
case TRAIT_PIERCING_RESISTANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_PIERCING);
break;
case TRAIT_SLASHING_RESISTANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_SLASHING);
break;
case TRAIT_BLUDGEONING_RESISTANT:
DoDamageResistanceTrait(creature, levelToAchieve, DAMAGE_TYPE_BLUDGEONING);
break;
}
}
// ********************************
// ** TRAIT SPECIFIC FUNCTIONS **
// ********************************
// Applies damage scaled to levelToAchieve / 2 of type damageType
void DoDamageTrait(object creature, int levelToAchieve, int damageType)
{
int damageBonus = TraitDamageBonusByAmount( (levelToAchieve + 1) / 2 );
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamageIncrease(damageBonus,damageType),creature);
}
// Applies damage resistance to levelToAchieve * 2 of type damageType
void DoDamageResistanceTrait(object creature, int levelToAchieve, int damageType)
{
int resistAmount = levelToAchieve * 2;
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamageResistance(damageType,resistAmount),creature);
}
// Applies damage reduction to creature scaled by levelToAchieve
void DoThickSkinnedTrait(object creature, int levelToAchieve)
{
int reducedAmount = (levelToAchieve + 1) / 2;
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamageReduction(reducedAmount,DR_TYPE_NONE),creature);
}
//Bonus to Con equivalent to Stat Bonus, if Con primary attribute, HP/Fort
void DoToughTrait(object creature, int primaryAbility, float statBonus)
{
if (primaryAbility == ABILITY_CONSTITUTION)
{
float tempHitPointAmount = statBonus * statBonus / (2.0f * PRIMARY_STAT_PROGRESS_PER_LEVEL);
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectTemporaryHitpoints(MathRound(tempHitPointAmount)),creature);
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectSavingThrowIncrease(SAVING_THROW_FORT, MathRound(statBonus / 2.0f)),creature);
}
else
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityIncrease(ABILITY_CONSTITUTION, MathRound(statBonus)),creature);
}
//+4 Str, -2 Dex
float DoBigTrait(object creature, int primaryAbility, float statBonus)
{
float returnedBonus = statBonus;
if (primaryAbility == ABILITY_DEXTERITY)
returnedBonus -= 2;
else
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityDecrease(ABILITY_DEXTERITY, 2),creature);
if (primaryAbility == ABILITY_STRENGTH)
returnedBonus += 4;
else
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityIncrease(ABILITY_STRENGTH, 4),creature);
return returnedBonus;
}
//+4 Dex, -2 Str
float DoSmallTrait(object creature, int primaryAbility, float statBonus)
{
float returnedBonus = statBonus;
if (primaryAbility == ABILITY_STRENGTH)
returnedBonus -= 2;
else
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityDecrease(ABILITY_STRENGTH, 2),creature);
if (primaryAbility == ABILITY_DEXTERITY)
returnedBonus += 4;
else
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectAbilityIncrease(ABILITY_DEXTERITY, 4),creature);
return returnedBonus;
}
// *******************************
// ** HELPERS **
// *******************************
//Gets if creature has a particular trait
int GetHasTrait(object creature, int trait)
{
int creatureTrait = 0;
int traitNum = 0;
do
{
traitNum++;
creatureTrait = GetLocalInt(creature,"CREATURE_TRAIT_" + IntToString(traitNum));
if (creatureTrait == trait)
return TRUE;
}
while (creatureTrait != 0);
return FALSE;
}
//Returns the appropriate DAMAGE_BONUS_* for the specified integer
int TraitDamageBonusByAmount(int amount)
{
switch (amount)
{
case 1:
return DAMAGE_BONUS_1;
break;
case 2:
return DAMAGE_BONUS_2;
break;
case 3:
return DAMAGE_BONUS_3;
break;
case 4:
return DAMAGE_BONUS_4;
break;
case 5:
return DAMAGE_BONUS_5;
break;
case 6:
return DAMAGE_BONUS_6;
break;
case 7:
return DAMAGE_BONUS_7;
break;
case 8:
return DAMAGE_BONUS_8;
break;
case 9:
return DAMAGE_BONUS_9;
break;
case 19:
return DAMAGE_BONUS_10;
break;
default:
return DAMAGE_BONUS_1;
}
return DAMAGE_BONUS_1;
}