forked from VortexQuake2/Vortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v_items.c
1283 lines (1071 loc) · 35.1 KB
/
v_items.c
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "g_local.h"
void spawnNorm(edict_t *rune, int targ_level, int type);
void spawnCombo(edict_t *rune, int targ_level);
void spawnClassRune(edict_t *rune, int targ_level);
qboolean spawnUnique(edict_t *rune, int index);
//************************************************************************************************
//************************************************************************************************
qboolean V_HiddenMod(edict_t *ent, item_t *rune, imodifier_t *mod)
{
//Check to see if this is a hidden mod
if (mod->set == 0)
return false;
//Do we have enough set items equipped?
if (eqSetItems(ent, rune) > mod->set)
return false;
else return true;
}
//************************************************************************************************
int eqSetItems(edict_t *ent, item_t *rune)
{
int i;
int count = 0;
//Better safe than sorry
if (rune->setCode == 0)
return 0;
for (i=0; i < 3; ++i) //loop through only the equip slots
{
if ((ent->myskills.items[i].itemtype != TYPE_NONE) && (ent->myskills.items[i].setCode == rune->setCode))
count++;
}
//Return number of matching items
return count;
}
//************************************************************************************************
int V_GetRuneWeaponPts(edict_t *ent, item_t *rune)
{
int i, points=0;
for (i = 0; i < MAX_VRXITEMMODS; ++i)
{
//Ignore mods with no mod type
if (rune->modifiers[i].type == TYPE_NONE)
continue;
//Ignore hidden mods if they don't have enough set items equipped
if (V_HiddenMod(ent, rune, &rune->modifiers[i]))
continue;
if (rune->modifiers[i].type & TYPE_WEAPON)
points += rune->modifiers[i].value;
}
if (points < 0)
return 0;
return points;
}
int V_GetRuneAbilityPts(edict_t *ent, item_t *rune)
{
int i, points=0;
for (i = 0; i < MAX_VRXITEMMODS; ++i)
{
//Ignore mods with no mod type
if (rune->modifiers[i].type == TYPE_NONE)
continue;
//Ignore hidden mods if they don't have enough set items equipped
if (V_HiddenMod(ent, rune, &rune->modifiers[i]))
continue;
if (rune->modifiers[i].type & TYPE_ABILITY)
points += rune->modifiers[i].value;
}
if (points < 0)
return 0;
return points;
}
void V_ApplyRune(edict_t *ent, item_t *rune)
{
int i;
if(!rune->itemtype) //rune equipped? (double checking in some cases)
return;
for (i = 0; i < MAX_VRXITEMMODS; ++i)
{
//Ignore mods with no mod type
if (rune->modifiers[i].type == TYPE_NONE)
continue;
//Ignore hidden mods if they don't have enough set items equipped
if (V_HiddenMod(ent, rune, &rune->modifiers[i]))
continue;
//The only rune mods to worry about are weapon and ability mods
if (rune->modifiers[i].type & TYPE_WEAPON)
{
int weapon, mod;
//Which weapon mod is this?
weapon = (rune->modifiers[i].index / 100) - 10;
mod = rune->modifiers[i].index % 100;
//Better safe than sorry
if ((mod < 0) || (weapon < 0))
continue;
if ((mod < MAX_WEAPONMODS) && (weapon < MAX_WEAPONS))
{
//Increase the player's current level
weaponskill_t *wepmod = &(ent->myskills.weapons[weapon].mods[mod]);
wepmod->current_level += rune->modifiers[i].value;
//Cap current_level to the hard maximum
if ((wepmod->hard_max) && (wepmod->current_level > wepmod->hard_max))
wepmod->current_level = wepmod->hard_max;
}
}
else if (rune->modifiers[i].type & TYPE_ABILITY)
{
int ability;
ability = rune->modifiers[i].index;
//Better safe than sorry
if (ability < 0)
continue;
if (ability < MAX_ABILITIES)
{
//Increase the player's current level
upgrade_t *abilitymod = &(ent->myskills.abilities[ability]);
abilitymod->current_level += rune->modifiers[i].value;
//Cap current_level to the hard maximum (2 * max for abilities)
if (abilitymod->current_level > abilitymod->hard_max)
abilitymod->current_level = abilitymod->hard_max;
}
}
}
}
//************************************************************************************************
//************************************************************************************************
void adminSpawnRune(edict_t *self, int type, int index)
{
gitem_t *item;
edict_t *rune;
item = FindItem("Rune"); // get the item properties
rune = Drop_Item(self, item); // create the entity that holds those properties
V_ItemClear(&rune->vrxitem); // initialize the rune
rune->vrxitem.quantity = 1;
switch(type)
{
case ITEM_WEAPON: spawnNorm(rune, index, ITEM_WEAPON); return;
case ITEM_ABILITY: spawnNorm(rune, index, ITEM_ABILITY); return;
case ITEM_COMBO: spawnCombo(rune, index); return;
case ITEM_CLASSRUNE: spawnClassRune(rune, index); return;
//Try to spawn a unique (or a random one if it fails to find one at the index)
case ITEM_UNIQUE: if (!spawnUnique(rune, index)) spawnNorm(rune, index, 0); return;
}
//Randomize id
strcpy(rune->vrxitem.id, GetRandomString(16));
//Free the ent (if no rune was spawned)
G_FreeEdict(rune);
}
//************************************************************************************************
//************************************************************************************************
void V_TossRune (edict_t *rune, float h_vel, float v_vel)
{
vec3_t forward;
rune->s.angles[YAW] = GetRandom(0, 360);
AngleVectors(rune->s.angles, forward, NULL, NULL);
VectorClear(rune->velocity);
VectorScale (forward, h_vel, rune->velocity);
rune->velocity[2] = v_vel;
}
/* az- This function is for avoiding redundant abilities within a rune. */
void fixRuneIndexes(edict_t *rune, int i)
{
int b_i;
// do a backward's iteration, if we find the ability then..
for (b_i = (i - 1); b_i > -1; b_i--)
{
// so we already have one of these?
// add onto it then, discard this one.
if (rune->vrxitem.modifiers[b_i].index == rune->vrxitem.modifiers[i].index &&
rune->vrxitem.modifiers[b_i].type == rune->vrxitem.modifiers[i].type)
{
if (rune->vrxitem.modifiers[b_i].type == TYPE_ABILITY) // It's an ability?
{
// invalidate this modifier.
rune->vrxitem.modifiers[i].index = 0;
rune->vrxitem.modifiers[i].type = TYPE_NONE;
if (GetAbilityUpgradeCost(rune->vrxitem.modifiers[b_i].index) > 1)
{
// sum the modifiers.
rune->vrxitem.modifiers[b_i].value += rune->vrxitem.modifiers[i].value;
}
rune->vrxitem.modifiers[i].value = 0;
}
}
}
}
/* az- With this, our rune generation woes are finished, finally! */
abildefinition_t *getRandomAbility();
void V_CreateAbilityModifier(edict_t* rune, qboolean is_class, int i)
{
abildefinition_t *ability; // Get ability description
int hard_max;
if (is_class)
ability = getClassRuneStat(rune->vrxitem.classNum);
else
{
ability = getRandomAbility();
while (!ability)
ability = getRandomAbility();
}
if (ability->index < 0 || ability->index > MAX_ABILITIES-1)
return; // we can't use this ability, it's invalid due to its index
// alright so we got a valid ability
rune->vrxitem.modifiers[i].index = ability->index;
// Assign it a type
rune->vrxitem.modifiers[i].type = TYPE_ABILITY;
if (GetAbilityUpgradeCost(ability->index) > 1) // No runes that have cost 2+ stuff should get over...
{
// for class runes, having this kind of abilities that are one-pointed or more is stupid
if (!ability->start || generalabmode->value || !is_class)
rune->vrxitem.modifiers[i].value = 1;
else
{
// if it has a starting value then we must invalidate this modifier. It's pointless to have it.
rune->vrxitem.modifiers[i].index = 0;
rune->vrxitem.modifiers[i].value = 0;
rune->vrxitem.modifiers[i].type = TYPE_NONE;
}
}
else
{
rune->vrxitem.modifiers[i].value = GetRandom(1, RUNE_ABILITY_MAXVALUE);
}
hard_max = getHardMax(ability->index, !is_class, 0);
if (rune->vrxitem.modifiers[i].value > hard_max) // this ability goes way too high? trim it
rune->vrxitem.modifiers[i].value = hard_max;
rune->vrxitem.itemLevel += rune->vrxitem.modifiers[i].value;
fixRuneIndexes(rune, i);
}
edict_t *V_SpawnRune (edict_t *self, edict_t *attacker, float base_drop_chance, float levelmod)
{
int iRandom;
int targ_level;
float temp = 0;
gitem_t *item;
edict_t *rune;
attacker = G_GetClient(attacker);
if (!attacker || !attacker->client)
return NULL;
if(!self->client && self->activator && self->svflags & SVF_MONSTER)
{
temp = (float) (self->monsterinfo.level + 1) / (attacker->myskills.level + 1);
if (base_drop_chance * temp < random())
return NULL;
//set target level
targ_level = (self->monsterinfo.level + attacker->myskills.level) / 2;
// don't allow runes higher than attacker's level
if (targ_level > attacker->myskills.level)
targ_level = attacker->myskills.level;
}
else if (attacker != self && attacker != world)
{
//boss has a greater chance of dropping a rune
if (attacker->myskills.boss > 0)
temp = (float)attacker->myskills.boss / 5.0;
else
temp = (float) (self->myskills.level + 1) / (attacker->myskills.level + 1);
// miniboss has greater chance of dropping a rune
if (IsNewbieBasher(self))
temp *= 2;
//boss has a greater chance of dropping a rune
temp *= 1.0 + ((float)self->myskills.boss / 2.0);
if (base_drop_chance * temp < random())
return NULL;
//set target level
targ_level = (self->myskills.level + attacker->myskills.level) / 2;
}
else
return NULL;
item = FindItem("Rune"); // get the item properties
rune = Drop_Item(self, item); // create the entity that holds those properties
V_ItemClear(&rune->vrxitem); // initialize the rune
if (levelmod)
targ_level *= levelmod;
rune->vrxitem.quantity = 1;
//Spawn a random rune
iRandom = GetRandom(0, 1000);
if (iRandom < CHANCE_UNIQUE)
{
//spawn a unique
// vrx chile 1.4 no uniques until someone makes them
if (!spawnUnique(rune, 0))
spawnNorm(rune, targ_level, 0);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS)
{
//spawn a class-specific rune
spawnClassRune(rune, targ_level);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS + CHANCE_COMBO)
{
//spawn a combo rune
spawnCombo(rune, targ_level);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS + CHANCE_COMBO + CHANCE_NORM)
{
//spawn a normal rune
spawnNorm(rune, targ_level, 0);
}
else
{
G_FreeEdict(rune);
return NULL;
}
//Randomize id
strcpy(rune->vrxitem.id, GetRandomString(16));
return rune;
}
void SpawnRune (edict_t *self, edict_t *attacker, qboolean debug)
{
int iRandom;
int targ_level = 0;
float temp = 0;
gitem_t *item;
edict_t *rune;
attacker = G_GetClient(attacker);
if (!attacker)
return;
if(!self->client)
{
// is this a world monster?
if (self->mtype && (self->svflags & SVF_MONSTER) && self->activator && !self->activator->client)
{
if (IsABoss(self) || (self->mtype == M_COMMANDER))
//boss has a 100% chance to spawn a rune
temp = (float) (self->monsterinfo.level + 1) / (attacker->myskills.level + 1) * 100.0;
else if (self->monsterinfo.bonus_flags & BF_UNIQUE_LIGHTNING
|| self->monsterinfo.bonus_flags & BF_UNIQUE_FIRE)
// unique monsters have a 50% chance to spawn a rune
temp = (float) (self->monsterinfo.level + 1) / (attacker->myskills.level + 1) * 75.0;
else if (self->monsterinfo.bonus_flags & BF_CHAMPION)
// champion monsters have a 15% chance to spawn a rune
temp = (float) (self->monsterinfo.level + 1) / (attacker->myskills.level + 1) * 15.0; // from 2%
else
// monsters have a 5% chance to spawn a rune NOP MONSTERS DON'T DROP RUNES
//temp = (float) (self->monsterinfo.level + 1) / (attacker->myskills.level + 1) * 5.0; // from 0.2%
temp = 1; // 1% to drop runes.
//gi.dprintf("%.3f\n", temp*RUNE_SPAWN_BASE);
if (RUNE_SPAWN_BASE * temp < random())
return;
//set target level
targ_level = (self->monsterinfo.level + attacker->myskills.level) / 2;
// don't allow runes higher than attacker's level
if (targ_level > attacker->myskills.level)
targ_level = attacker->myskills.level;
}
else
return;
}
else if (attacker != self)
{
//boss has a greater chance of dropping a rune
if (attacker->myskills.boss > 0)
temp = (float)attacker->myskills.boss * 5;
else
temp = (float) (self->myskills.level + 1) * 5.0 / (attacker->myskills.level + 1);
// miniboss has greater chance of dropping a rune
if (IsNewbieBasher(self))
temp *= 2;
//boss has a greater chance of dropping a rune
temp *= 1.0 + ((float)self->myskills.boss / 2.0);
if (RUNE_SPAWN_BASE * temp < random())
return;
//set target level
targ_level = (self->myskills.level + attacker->myskills.level) / 2;
}
else if (debug == false)
return;
item = FindItem("Rune"); // get the item properties
rune = Drop_Item(self, item); // create the entity that holds those properties
V_ItemClear(&rune->vrxitem); // initialize the rune
//set target level to 20 if we are debugging
if (debug == true)
targ_level = 20;
rune->vrxitem.quantity = 1;
//Spawn a random rune
iRandom = GetRandom(0, 1000);
if (iRandom < CHANCE_UNIQUE)
{
//spawn a unique
#ifdef ENABLE_UNIQUES
if (!spawnUnique(rune, 0))
#endif
spawnNorm(rune, targ_level, 0);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS)
{
//spawn a class-specific rune
spawnClassRune(rune, targ_level);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS + CHANCE_COMBO)
{
//spawn a combo rune
spawnCombo(rune, targ_level);
}
else if (iRandom < CHANCE_UNIQUE + CHANCE_CLASS + CHANCE_COMBO + CHANCE_NORM)
{
//spawn a normal rune
spawnNorm(rune, targ_level, 0);
}
else
{
G_FreeEdict(rune);
return;
}
//Randomize id
strcpy(rune->vrxitem.id, GetRandomString(16));
}
//************************************************************************************************
int GetAbilityUpgradeCost(int index);
void spawnNorm(edict_t *rune, int targ_level, int type)
{
int x = GetRandom(1, 100);
int i;
int max_mods, num_mods;
//Admins can control the type of rune
if (type > 0)
{
switch(type)
{
case ITEM_WEAPON: x = 100; break;
case ITEM_ABILITY: x = 0; break;
}
}
if (x > 50) //weapon rune
{
int weaponIndex = GetRandom(0, MAX_WEAPONS-1); // random weapon
rune->vrxitem.itemtype = ITEM_WEAPON;
max_mods = 1 + (0.25 * targ_level); //This means lvl 16+ can get all 5 mods
if (max_mods > MAX_WEAPONMODS)
max_mods = MAX_WEAPONMODS;
num_mods = GetRandom(0, max_mods);
//set the weapon type (just in case there were 0 mods)
rune->vrxitem.modifiers[0].index = ((weaponIndex + 10) * 100);
for (i = 0; i < num_mods; ++i)
{
int modIndex = i;
//25% chance for rune mod not to show up
if (GetRandom(0, 4) == 0)
continue;
rune->vrxitem.modifiers[i].value = GetRandom(1, RUNE_WEAPON_MAXVALUE);
rune->vrxitem.modifiers[i].index = ((weaponIndex + 10) * 100) + modIndex; // ex: 1800 = rg damage
rune->vrxitem.modifiers[i].type = TYPE_WEAPON;
//Fix 1 time upgrades to 1 pt
if ((modIndex > 3) || ((modIndex > 2) && (weaponIndex != WEAPON_SWORD)))
{
if (rune->vrxitem.modifiers[i].value > 1)
rune->vrxitem.modifiers[i].value = 1;
}
rune->vrxitem.itemLevel += rune->vrxitem.modifiers[i].value;
}
rune->vrxitem.numMods = CountRuneMods(&rune->vrxitem);
rune->s.effects |= EF_PENT;
}
else //ability rune
{
rune->vrxitem.itemtype = ITEM_ABILITY;
max_mods = 1 + (0.25 * targ_level); //This means lvl 20+ can get 6 mods
if (max_mods > MAX_VRXITEMMODS)
max_mods = MAX_VRXITEMMODS;
num_mods = GetRandom(0, max_mods);
for (i=0; i < num_mods; ++i)
{
//25% chance for rune mod not to show up
if (GetRandom(0, 4) == 0)
continue;
V_CreateAbilityModifier(rune, false, i);
}
rune->vrxitem.numMods = CountRuneMods(&rune->vrxitem);
rune->s.effects |= EF_QUAD;
}
}
//************************************************************************************************
void spawnClassRune(edict_t *rune, int targ_level)
{
int i;
int max_mods, num_mods;
max_mods = 1 + (0.2 * targ_level); //This means lvl 15+ can get 4 mods
if (max_mods > 4)
max_mods = 4;
num_mods = GetRandom(1, max_mods); // from 1 - don't be a dick
rune->vrxitem.itemtype = ITEM_CLASSRUNE;
rune->vrxitem.classNum = GetRandom(1, CLASS_MAX); //class number
if (rune->vrxitem.classNum == CLASS_WEAPONMASTER) // These ain't got class runes.
{
G_FreeEdict(rune);
return;
}
for (i = 0; i < num_mods; ++i)
{
V_CreateAbilityModifier(rune, true, i);
}
rune->vrxitem.numMods = CountRuneMods(&rune->vrxitem);
rune->s.effects |= EF_COLOR_SHELL;
rune->s.renderfx |= RF_SHELL_CYAN;
}
//************************************************************************************************
//************************************************************************************************
char *UniqueParseString(char **iterator)
{
char buf[30];
int i;
for (i = 0; i < strlen(*iterator); ++i)
{
if (*(*iterator + i) != ',')
buf[i] = *(*iterator + i);
else break;
}
buf[i] = 0;
*iterator += i+1;
return va("%s", buf);
}
//************************************************************************************************
int UniqueParseInteger(char **iterator)
{
char buf[30];
int i;
for (i = 0; i < strlen(*iterator); ++i)
{
if (*(*iterator + i) != ',')
buf[i] = *(*iterator + i);
else break;
}
buf[i] = 0;
*iterator += i+1;
return atoi(buf);
}
//************************************************************************************************
qboolean spawnUnique(edict_t *rune, int index)
{
int j, i;
char filename[256];
char buf[256];
FILE *fptr;
j = i = 0;
//determine path
#if defined(_WIN32) || defined(WIN32)
sprintf(filename, "%s\\%s", game_path->string, "settings\\Uniques\\uniques.csv");
#else
sprintf(filename, "%s/%s", game_path->string, "settings/Uniques/uniques.csv");
#endif
if ((fptr = fopen(filename, "r")) != NULL)
{
int linenumber, maxlines;
char *iterator;
long size;
int count = 0;
//Determine file size
fseek (fptr, 0, SEEK_END);
size=ftell (fptr);
rewind(fptr);
//Find a unique
maxlines = V_tFileCountLines(fptr, size);
if ((index == 0) || (index > maxlines))
{
if (maxlines > 1)
linenumber = GetRandom(1, maxlines-1);
else return false;
}
else linenumber = index;
V_tFileGotoLine(fptr, linenumber, size);
fgets(buf, 256, fptr);
//Load the rune stats
iterator = buf;
rune->vrxitem.itemtype = UniqueParseInteger(&iterator);
rune->vrxitem.untradeable = UniqueParseInteger(&iterator);
strcpy(rune->vrxitem.name, UniqueParseString(&iterator));
rune->vrxitem.numMods = UniqueParseInteger(&iterator);
rune->vrxitem.setCode = UniqueParseInteger(&iterator);
//Load the mods
for(i = 0; i < 6; ++i)
{
rune->vrxitem.modifiers[i].type = UniqueParseInteger(&iterator);
rune->vrxitem.modifiers[i].index = UniqueParseInteger(&iterator);
rune->vrxitem.modifiers[i].value = UniqueParseInteger(&iterator);
rune->vrxitem.modifiers[i].set = UniqueParseInteger(&iterator);
rune->vrxitem.itemLevel += rune->vrxitem.modifiers[i].value;
}
rune->s.effects |= EF_COLOR_SHELL;
if (rune->vrxitem.setCode != 0) rune->s.renderfx |= RF_SHELL_GREEN;
else rune->s.renderfx |= RF_SHELL_YELLOW;
fclose (fptr);
return true;
}
else
{
G_FreeEdict(rune);
return false;
}
}
//************************************************************************************************
//************************************************************************************************
void spawnCombo(edict_t *rune, int targ_level)
{
int i;
int max_mods, num_mods;
rune->vrxitem.itemtype = ITEM_COMBO;
max_mods = 1 + (0.2 * targ_level);
if (max_mods > 4)
max_mods = 4;
num_mods = GetRandom(0, max_mods);
for (i = 0; i < num_mods; ++i)
{
int type = GetRandom(1, 10);
//50% chance of ability mod
if (type > 5)
{
V_CreateAbilityModifier(rune, false, i);
}
else //50% chance of weapon mod
{
int modIndex = GetRandom(0, MAX_WEAPONMODS-1);
int wIndex = GetRandom(0, MAX_WEAPONS-1);
rune->vrxitem.modifiers[i].value = GetRandom(1, 3);
rune->vrxitem.modifiers[i].index = ((wIndex + 10) * 100) + modIndex; // ex: 1800 = rg damage
rune->vrxitem.modifiers[i].type = TYPE_WEAPON;
//Fix 1 time upgrades to 1 pt
if ((modIndex > 3) || ((modIndex > 2) && (wIndex != WEAPON_SWORD)))
{
if (rune->vrxitem.modifiers[i].value > 1)
rune->vrxitem.modifiers[i].value = 1;
}
rune->vrxitem.itemLevel += rune->vrxitem.modifiers[i].value;
}
}
rune->vrxitem.numMods = CountRuneMods(&rune->vrxitem);
rune->s.effects |= EF_COLOR_SHELL;
rune->s.renderfx |= RF_SHELL_RED | RF_SHELL_BLUE;
}
//************************************************************************************************
//************************************************************************************************
void PurchaseRandomRune(edict_t *ent, int runetype)
{
int cost;
edict_t *rune;
item_t *slot;
char buf[64];
cost = RUNE_COST_BASE + RUNE_COST_ADDON * ent->myskills.level;
if (ent->myskills.credits < cost)
{
safe_cprintf(ent, PRINT_HIGH, "You need %d credits to purchase a rune.\n", cost);
return;
}
slot = V_FindFreeItemSlot(ent);
if (!slot)
{
safe_cprintf(ent, PRINT_HIGH, "Not enough inventory space!\n");
return;
}
// rune pick-up delay
if (ent->client->rune_delay > level.time)
return;
rune = G_Spawn(); // create a rune
V_ItemClear(&rune->vrxitem); // initialize the rune
ent->myskills.credits -= cost;
if (runetype)
{
spawnNorm(rune, ent->myskills.level, runetype);
}
else if (random() > 0.5)
{
spawnNorm(rune, ent->myskills.level, ITEM_WEAPON);
}
else
{
spawnNorm(rune, ent->myskills.level, ITEM_ABILITY);
}
if (Pickup_Rune(rune, ent) == false)
{
G_FreeEdict(rune);
//gi.dprintf("WARNING: PurchaseRandomRune() was unable to spawn a rune\n");
return;
}
G_FreeEdict(rune);
//Find out what the player bought
strcpy(buf, GetRuneValString(slot));
switch(slot->itemtype)
{
case ITEM_WEAPON: strcat(buf, va(" weapon rune (%d mods)", slot->numMods)); break;
case ITEM_ABILITY: strcat(buf, va(" ability rune (%d mods)", slot->numMods)); break;
case ITEM_COMBO: strcat(buf, va(" combo rune (%d mods)", slot->numMods)); break;
}
//send the message to the player
safe_cprintf(ent, PRINT_HIGH, "You bought a %s.\n", buf);
safe_cprintf(ent, PRINT_HIGH, "You now have %d credits left. \n", ent->myskills.credits);
gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/gold.wav"), 1, ATTN_NORM, 0);
//Save the player
if (savemethod->value == 1)
SaveCharacter(ent);
else if (savemethod->value == 0)
{
char path[MAX_QPATH];
memset(path, 0, MAX_QPATH);
VRXGetPath(path, ent);
VSF_SaveRunes(ent, path);
}else if (savemethod->value == 3)
{
VSFU_SaveRunes(ent);
}
//write to the log
gi.dprintf("INFO: %s purchased a level %d rune (%s).\n",
ent->client->pers.netname, slot->itemLevel, slot->id);
WriteToLogfile(ent, va("Purchased a level %d rune (%s) for %d credits. Player has %d credits left.\n",
slot->itemLevel, slot->id, cost, ent->myskills.credits));
}
//************************************************************************************************
//************************************************************************************************
qboolean Pickup_Rune (edict_t *ent, edict_t *other)
{
item_t *slot;
if (!other->client)
return false;
//Show the user what kind of rune it is
if (level.time > other->msg_time)
{
V_PrintItemProperties(other, &ent->vrxitem);
other->msg_time = level.time+1;
}
if (other->client->rune_delay > level.time)
return false;
//4.2 if it's worthless, then just destroy it
if (ent->vrxitem.itemLevel < 1)
{
G_FreeEdict(ent);
return false;
}
//Can we pick it up?
if (!V_CanPickUpItem(other))
return false;
//Give them the rune
slot = V_FindFreeItemSlot(other);
V_ItemCopy(&ent->vrxitem, slot);
//Save the player file (prevents lost runes)
if (savemethod->value == 1)
SaveCharacter(other);
else if (savemethod->value == 0)
{
char path[MAX_QPATH];
memset(path, 0, MAX_QPATH);
VRXGetPath(path, other);
VSF_SaveRunes(other, path);
}
other->client->rune_delay = level.time + RUNE_PICKUP_DELAY;
//Done
return true;
}
//************************************************************************************************
//************************************************************************************************
void V_ItemCopy(item_t *source, item_t *dest)
{
memcpy(dest, source, sizeof(item_t));
}
//************************************************************************************************
void V_ItemClear(item_t *item)
{
memset(item, 0, sizeof(item_t));
}
//************************************************************************************************
item_t *V_FindFreeItemSlot (edict_t *ent)
{
int i;
//Fill items backwards from the bottom of the stash
for (i = MAX_VRXITEMS-1; i > 2; --i)
{
if (ent->myskills.items[i].itemtype)
continue;
return &ent->myskills.items[i];
}
return NULL;
}
//************************************************************************************************
item_t *V_FindFreeTradeSlot(edict_t *ent, int index)
{
int i;
int count = 0;
//Check items backwards from the bottom of the stash
for (i = MAX_VRXITEMS-1; i > 2; --i)
{
if (ent->myskills.items[i].itemtype)
continue;
++count;
if (count == index)
return &ent->myskills.items[i];
}
return NULL;
}
//************************************************************************************************
qboolean V_CanPickUpItem (edict_t *ent)
{
int i;
// only allow clients that are alive and haven't just
// respawned to pick up a rune
//if (!ent->client || !G_EntIsAlive(ent) || (ent->client->respawn_time > level.time))
// return false;
if (!ent || !ent->inuse || !ent->client || G_IsSpectator(ent)
|| (ent->client->respawn_time > level.time))
return false;
// do we have any space in our inventory?
// Skip hand, neck, and belt slots
for (i=3; i < MAX_VRXITEMS; ++i)
{
if (!ent->myskills.items[i].itemtype)
return true;
}
return false;
}
//************************************************************************************************
void V_PrintItemProperties(edict_t *player, item_t *item)
{
char buf[256];
int i;
//Did they find a unique?
if (strlen(item->name) > 0)
{
gi.centerprintf(player, "WOW! It's \"%s\"!!\n", item->name);
return;
}
strcpy(buf, GetRuneValString(item));
switch(item->itemtype)
{
case ITEM_WEAPON: strcat(buf, " weapon rune "); break;
case ITEM_ABILITY: strcat(buf, " ability rune "); break;
case ITEM_COMBO: strcat(buf, " combo rune "); break;
case ITEM_CLASSRUNE:strcpy(buf, va(" %s rune ", GetRuneValString(item))); break;
}
if(item->numMods == 1) strcat(buf, "(1 mod)");