/
econ_item_schema.cpp
8972 lines (7586 loc) · 304 KB
/
econ_item_schema.cpp
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
//====== Copyright ?, Valve Corporation, All rights reserved. =======
//
// Purpose: EconItemSchema: Defines a schema for econ items
//
//=============================================================================
#include "cbase.h"
#include "econ_item_schema.h"
#include "tier1/fmtstr.h"
#include "tier2/tier2.h"
#include "filesystem.h"
#include "schemainitutils.h"
#include "cstrike15_gcconstants.h"
#include <google/protobuf/text_format.h>
#if defined(CLIENT_DLL) || defined(GAME_DLL)
#include "econ_item_system.h"
#include "econ_item.h"
#include "activitylist.h"
#if defined(TF_CLIENT_DLL) || defined(TF_DLL)
#include "tf_gcmessages.h"
#endif
#endif
#if defined(CSTRIKE_CLIENT_DLL) || defined(CSTRIKE_DLL)
#include "cstrike15_gcmessages.pb.h"
#endif
#include "gametypes.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace GCSDK;
#if defined(GAME_DLL)
void PrecacheParticleFileAndSystems( const char *pParticleSystemFile );
#endif
#if defined(CLIENT_DLL)
bool CWebResource::s_Initialized = false;
#endif
CEconItemSchema & GEconItemSchema()
{
#if defined( EXTERNALTESTS_DLL )
static CEconItemSchema g_econItemSchema;
return g_econItemSchema;
#else
return *ItemSystem()->GetItemSchema();
#endif
}
const char * g_arrQuestVars[ k_EQuestVar_Last ] = { "" };
/** Removed for partner depot **/
static void HelperValidateLocalizationStringToken( char const *pszToken )
{
#ifdef CLIENT_DLL
if ( pszToken && *pszToken == '#' )
AssertMsg1( g_pVGuiLocalize->Find( pszToken ), "Schema is referencing a non-existant token: %s", pszToken );
#endif
}
const char *g_szDropTypeStrings[] =
{
"", // Blank and none mean the same thing: stay attached to the body.
"none",
"drop", // The item drops off the body.
"break", // Not implemented, but an example of a type that could be added.
};
#if defined(CLIENT_DLL) || defined(GAME_DLL)
// Used to convert strings to ints for wearable animation types
const char *g_WearableAnimTypeStrings[NUM_WAP_TYPES] =
{
"on_spawn", // WAP_ON_SPAWN,
"start_building", // WAP_START_BUILDING,
"stop_building", // WAP_STOP_BUILDING,
};
#endif
const char *g_AttributeDescriptionFormats[] =
{
"value_is_percentage", // ATTDESCFORM_VALUE_IS_PERCENTAGE,
"value_is_inverted_percentage", // ATTDESCFORM_VALUE_IS_INVERTED_PERCENTAGE
"value_is_additive", // ATTDESCFORM_VALUE_IS_ADDITIVE
"value_is_additive_percentage", // ATTDESCFORM_VALUE_IS_ADDITIVE_PERCENTAGE
"value_is_or", // ATTDESCFORM_VALUE_IS_OR
"value_is_date", // ATTDESCFORM_VALUE_IS_DATE
"value_is_account_id", // ATTDESCFORM_VALUE_IS_ACCOUNT_ID
"value_is_particle_index", // ATTDESCFORM_VALUE_IS_PARTICLE_INDEX -> Could change to "string index"
"value_is_item_def", // ATTDESCFORM_VALUE_IS_ITEM_DEF
"value_is_color", // ATTDESCFORM_VALUE_IS_COLOR
"value_is_game_time", // ATTDESCFORM_VALUE_IS_GAME_TIME
"value_is_mins_as_hours", // ATTDESCFORM_VALUE_IS_MINS_AS_HOURS
"value_is_replace", // ATTDESCFORM_VALUE_IS_REPLACE
};
const char *g_EffectTypes[NUM_EFFECT_TYPES] =
{
"neutral", // ATTRIB_EFFECT_NEUTRAL = 0,
"positive", // ATTRIB_EFFECT_POSITIVE,
"negative", // ATTRIB_EFFECT_NEGATIVE,
};
const char *g_szParticleAttachTypes[] =
{
"absorigin", // PATTACH_ABSORIGIN = 0, // Create at absorigin, but don't follow
"absorigin_follow", // PATTACH_ABSORIGIN_FOLLOW, // Create at absorigin, and update to follow the entity
"customorigin", // PATTACH_CUSTOMORIGIN, // Create at a custom origin, but don't follow
"customorigin_follow", // PATTACH_CUSTOMORIGIN_FOLLOW, // Create at a custom origin, follow relative position to specified entity
"point", // PATTACH_POINT, // Create on attachment point, but don't follow
"point_follow", // PATTACH_POINT_FOLLOW, // Create on attachment point, and update to follow the entity
"eyes_follow", // PATTACH_EYES_FOLLOW, // Create on eyes of the attached entity, and update to follow the entity
"overhead_follow", // PATTACH_OVERHEAD_FOLLOW, // Create at the top of the entity's bbox
"worldorigin", // PATTACH_WORLDORIGIN, // Used for control points that don't attach to an entity
"rootbone_follow", // PATTACH_ROOTBONE_FOLLOW, // Create at the root bone of the entity, and update to follow
"point_follow_substepped", // PATTACH_POINT_FOLLOW_SUBSTEPPED,// Like point_follow with interpolation
"renderorigin_follow", // PATTACH_RENDERORIGIN_FOLLOW // Create at the renderorigin of the entity, and update to follow
};
const char *g_szParticleAttachToEnt[] =
{
"self", // ATTPART_TO_SELF,
"parent", // ATTPART_TO_PARENT,
};
//-----------------------------------------------------------------------------
// Purpose: Set the capabilities bitfield based on whether the entry is true/false.
//-----------------------------------------------------------------------------
const char *g_Capabilities[] =
{
"paintable", // ITEM_CAP_PAINTABLE
"nameable", // ITEM_CAP_NAMEABLE
"decodable", // ITEM_CAP_DECODABLE
"can_delete", // ITEM_CAP_CAN_DELETE
"can_customize_texture", // ITEM_CAP_CAN_CUSTOMIZE_TEXTURE
"usable", // ITEM_CAP_USABLE
"usable_gc", // ITEM_CAP_USABLE_GC
"can_gift_wrap", // ITEM_CAP_CAN_GIFT_WRAP
"usable_out_of_game", // ITEM_CAP_USABLE_OUT_OF_GAME
"can_collect", // ITEM_CAP_CAN_COLLECT
"can_craft_count", // ITEM_CAP_CAN_CRAFT_COUNT
"can_craft_mark", // ITEM_CAP_CAN_CRAFT_MARK
"paintable_team_colors", // ITEM_CAP_PAINTABLE_TEAM_COLORS
"can_be_restored", // ITEM_CAP_CAN_BE_RESTORED
"strange_parts", // ITEM_CAP_CAN_USE_STRANGE_PARTS
"paintable_unusual", // ITEM_CAP_PAINTABLE_UNUSUAL
"can_increment", // ITEM_CAP_CAN_INCREMENT
"uses_essence", // ITEM_CAP_USES_ESSENCE
"autograph", // ITEM_CAP_AUTOGRAPH
"recipe", // ITEM_CAP_RECIPE
"can_sticker", // ITEM_CAP_CAN_STICKER
"can_stattrack_swap", // ITEM_CAP_STATTRACK_SWAP
};
const char* g_AssetModifiers[] =
{
"activity",
"announcer",
"announcer_preview",
"hud_skin",
"ability_name",
"sound",
"speech",
"particle",
"particle_snapshot",
"particle_control_point",
"entity_model",
"entity_scale",
"icon_replacement",
"ability_icon_replacement",
"courier",
"courier_flying",
"hero_model_change"
};
#define RETURN_ATTRIBUTE_STRING( attrib_name, default_string ) \
static CSchemaAttributeDefHandle pAttribString( attrib_name ); \
const char *pchResultAttribString = default_string; \
FindAttribute_UnsafeBitwiseCast< CAttribute_String >( this, pAttribString, &pchResultAttribString ); \
return pchResultAttribString;
#define RETURN_ATTRIBUTE_STRING_F( func_name, attrib_name, default_string ) \
const char *func_name( void ) const { RETURN_ATTRIBUTE_STRING( attrib_name, default_string ) }
EAssetModifier GetAssetModifierType( const char* pszType )
{
for ( int i=0; i<AM_MAX; ++i )
{
if ( Q_strcmp( pszType, g_AssetModifiers[i] ) == 0 )
return (EAssetModifier) i;
}
return AM_Invalid;
}
CUniformRandomStream CEconItemSchema::m_RandomStream;
static void ParseCapability( item_capabilities_t &capsBitfield, KeyValues* pEntry )
{
COMPILE_TIME_ASSERT( ARRAYSIZE(g_Capabilities) == NUM_ITEM_CAPS );
int idx = StringFieldToInt( pEntry->GetName(), g_Capabilities, ARRAYSIZE(g_Capabilities) );
if ( idx < 0 )
{
return;
}
int bit = 1 << idx;
if ( pEntry->GetBool() )
{
(int&)capsBitfield |= bit;
}
else
{
(int&)capsBitfield &= ~bit;
}
}
//-----------------------------------------------------------------------------
// Purpose: interpret tint colors as integers for the values
//-----------------------------------------------------------------------------
static bool Helper_ExtractIntegerFromValueStringEntry( const char *szValue, int *pnValue )
{
if ( V_isdigit( *szValue ) )
{
*pnValue = V_atoi( szValue );
return true;
}
else if ( char const *szTint = StringAfterPrefix( szValue, "tint_") )
{
if ( !V_stricmp( szTint, "min" ) )
{
*pnValue = 1;
return true;
}
if ( !V_stricmp( szTint, "max" ) )
{
*pnValue = GEconItemSchema().GetGraffitiTintMaxValidDefID();
return true;
}
if ( const CEconGraffitiTintDefinition *pDef = GEconItemSchema().GetGraffitiTintDefinitionByName( szTint ) )
{
*pnValue = pDef->GetID();
return true;
}
return false;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: interprets a string such as "1-3,5-20,45,46,47" and adds the
// individual uint32s into the specified vector.
//-----------------------------------------------------------------------------
static bool Helper_ExtractIntegersFromValuesString( const char * pszValues, CCopyableUtlVector< uint32 > &vecValues )
{
bool bResult = true;
CUtlVector< char* > vecValueStrings;
V_SplitString( pszValues, ",", vecValueStrings );
if ( vecValueStrings.Count() < 1 )
bResult = false;
FOR_EACH_VEC( vecValueStrings, i )
{
if ( V_strstr( vecValueStrings[ i ], "-" ) )
{
CUtlVector< char* > vecRangeStrings;
V_SplitString( vecValueStrings[ i ], "-", vecRangeStrings );
if ( vecRangeStrings.Count() == 2 )
{
int iRangeMin = 0, iRangeMax = 0;
if ( !Helper_ExtractIntegerFromValueStringEntry( vecRangeStrings[ 0 ], &iRangeMin ) ||
!Helper_ExtractIntegerFromValueStringEntry( vecRangeStrings[ 1 ], &iRangeMax ) ||
( iRangeMin >= iRangeMax ) )
{
bResult = false;
break;
}
for ( int j = iRangeMin; j <= iRangeMax; j++ )
{
vecValues.AddToTail( j );
}
}
else
{
bResult = false;
break;
}
vecRangeStrings.PurgeAndDeleteElements();
}
else
{
int iValue = 0;
if ( !Helper_ExtractIntegerFromValueStringEntry( vecValueStrings[ i ], &iValue ) )
{
bResult = false;
break;
}
vecValues.AddToTail( iValue );
}
}
vecValueStrings.PurgeAndDeleteElements();
return bResult;
}
#if defined ( CSTRIKE15 )
const uint32 g_unNumWearBuckets = 3;
uint64 Helper_GetAlternateIconKeyForWeaponPaintWearItem( item_definition_index_t nDefIdx, uint32 nPaintId, uint32 nWear )
{
return ( nDefIdx << 16 ) + ( nPaintId << 2 ) + nWear;
}
uint64 Helper_GetAlternateIconKeyForTintedStickerItem( uint32 nStickerKitID, uint32 unTintID )
{
unTintID = CombinedTintIDGetHSVID( unTintID );
return ( uint64( 1 ) << 32 ) | ( ( nStickerKitID & 0xFFFFFF ) << 8 ) | ( unTintID & 0xFF );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CEconItemQualityDefinition::CEconItemQualityDefinition( void )
: m_nValue( INT_MAX )
, m_bCanSupportSet( false )
, m_unWeight( 0 )
, m_bExplicitMatchesOnly( false )
{
}
//-----------------------------------------------------------------------------
// Purpose: Copy constructor
//-----------------------------------------------------------------------------
CEconItemQualityDefinition::CEconItemQualityDefinition( const CEconItemQualityDefinition &that )
{
(*this) = that;
}
//-----------------------------------------------------------------------------
// Purpose: Operator=
//-----------------------------------------------------------------------------
CEconItemQualityDefinition &CEconItemQualityDefinition::operator=( const CEconItemQualityDefinition &rhs )
{
m_nValue = rhs.m_nValue;
m_strName = rhs.m_strName;
m_bCanSupportSet = rhs.m_bCanSupportSet;
m_unWeight = rhs.m_unWeight;
m_bExplicitMatchesOnly = rhs.m_bExplicitMatchesOnly;
return *this;
}
//-----------------------------------------------------------------------------
// Purpose: Initialize the quality definition
// Input: pKVQuality - The KeyValues representation of the quality
// schema - The overall item schema for this attribute
// pVecErrors - An optional vector that will contain error messages if
// the init fails.
// Output: True if initialization succeeded, false otherwise
//-----------------------------------------------------------------------------
bool CEconItemQualityDefinition::BInitFromKV( KeyValues *pKVQuality, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
m_nValue = pKVQuality->GetInt( "value", -1 );
m_strName = pKVQuality->GetName();
m_bCanSupportSet = pKVQuality->GetBool( "canSupportSet" );
m_strHexColor = pKVQuality->GetString( "hexColor" );
m_unWeight = pKVQuality->GetInt( "weight", 0 );
// Check for required fields
SCHEMA_INIT_CHECK(
NULL != pKVQuality->FindKey( "value" ),
CFmtStr( "Quality definition %s: Missing required field \"value\"", pKVQuality->GetName() ) );
#if defined(CLIENT_DLL) || defined(GAME_DLL)
return SCHEMA_INIT_SUCCESS();
#endif
// Check for data consistency
SCHEMA_INIT_CHECK(
0 != Q_stricmp( GetName(), "any" ),
CFmtStr( "Quality definition any: The quality name \"any\" is a reserved keyword and cannot be used." ) );
SCHEMA_INIT_CHECK(
m_nValue != k_unItemQuality_Any,
CFmtStr( "Quality definition %s: Invalid value (%d). It is reserved for Any", GetName(), k_unItemQuality_Any ) );
return SCHEMA_INIT_SUCCESS();
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CEconItemRarityDefinition::CEconItemRarityDefinition( void )
: m_nValue( INT_MAX )
{
}
//-----------------------------------------------------------------------------
// Purpose: Copy constructor
//-----------------------------------------------------------------------------
CEconItemRarityDefinition::CEconItemRarityDefinition( const CEconItemRarityDefinition &that )
{
(*this) = that;
}
//-----------------------------------------------------------------------------
// Purpose: Operator=
//-----------------------------------------------------------------------------
CEconItemRarityDefinition &CEconItemRarityDefinition::operator=( const CEconItemRarityDefinition &rhs )
{
m_nValue = rhs.m_nValue;
m_strName = rhs.m_strName;
m_strLocKey = rhs.m_strLocKey;
m_strWepLocKey = rhs.m_strWepLocKey;
m_strLootList = rhs.m_strLootList;
m_strRecycleLootList = rhs.m_strRecycleLootList;
m_strDropSound = rhs.m_strDropSound;
m_strNextRarity = rhs.m_strNextRarity;
m_iWhiteCount = rhs.m_iWhiteCount;
m_iBlackCount = rhs.m_iBlackCount;
m_flWeight = rhs.m_flWeight;
return *this;
}
//-----------------------------------------------------------------------------
// Purpose: Initialize the rarity definition
//-----------------------------------------------------------------------------
bool CEconItemRarityDefinition::BInitFromKV( KeyValues *pKVRarity, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
m_nValue = pKVRarity->GetInt( "value", -1 );
m_strName = pKVRarity->GetName();
m_strLocKey = pKVRarity->GetString( "loc_key" );
m_strWepLocKey = pKVRarity->GetString( "loc_key_weapon" );
m_iAttribColor = GetAttribColorIndexForName( pKVRarity->GetString( "color" ) );
m_strLootList = pKVRarity->GetString( "loot_list" ); // Not required.
m_strRecycleLootList = pKVRarity->GetString( "recycle_list" ); // Not required.
m_strDropSound = pKVRarity->GetString( "drop_sound" );
m_strNextRarity = pKVRarity->GetString( "next_rarity" ); // Not required.
m_flWeight = pKVRarity->GetFloat( "weight", 0 );
// Check for required fields
SCHEMA_INIT_CHECK(
NULL != pKVRarity->FindKey( "value" ),
CFmtStr( "Rarity definition %s: Missing required field \"value\"", pKVRarity->GetName() ) );
SCHEMA_INIT_CHECK(
NULL != pKVRarity->FindKey( "loc_key" ),
CFmtStr( "Rarity definition %s: Missing required field \"loc_key\"", pKVRarity->GetName() ) );
#if defined(CLIENT_DLL) || defined(GAME_DLL)
return SCHEMA_INIT_SUCCESS();
#endif
return SCHEMA_INIT_SUCCESS();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEconColorDefinition::BInitFromKV( KeyValues *pKVColor, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
m_strName = pKVColor->GetName();
m_strColorName = pKVColor->GetString( "color_name" );
m_strHexColor = pKVColor->GetString( "hex_color" );
SCHEMA_INIT_CHECK(
!m_strColorName.IsEmpty(),
CFmtStr( "Quality definition %s: missing \"color_name\"", GetName() ) );
SCHEMA_INIT_CHECK(
!m_strHexColor.IsEmpty(),
CFmtStr( "Quality definition %s: missing \"hex_color\"", GetName() ) );
return SCHEMA_INIT_SUCCESS();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEconGraffitiTintDefinition::BInitFromKV( KeyValues *pKVColor, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
m_nID = pKVColor->GetInt( "id" );
m_strColorName = pKVColor->GetName();
m_strHexColor = pKVColor->GetString( "hex_color" );
SCHEMA_INIT_CHECK(
!m_strColorName.IsEmpty(),
CFmtStr( "Graffiti tint definition #%d %s: missing name", GetID(), GetColorName() ) );
SCHEMA_INIT_CHECK(
!m_strHexColor.IsEmpty() && ( m_strHexColor.Get()[0] == '#' ),
CFmtStr( "Graffiti tint #%d %s: missing or invalid \"hex_color\"", GetID(), GetColorName() ) );
m_unHexColorRGB = ( !m_strHexColor.IsEmpty() ) ? V_atoi( CFmtStr( "0x%s", m_strHexColor.Get() + 1 ) ) : 0;
return !m_strColorName.IsEmpty() && !m_strHexColor.IsEmpty() && ( m_strHexColor.Get()[0] == '#' );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEconMusicDefinition::BInitFromKV( KeyValues *pKVMusicDef, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
nID = Q_atoi( pKVMusicDef->GetName() );
m_strName = pKVMusicDef->GetString( "name" );
m_strNameLocToken = pKVMusicDef->GetString( "loc_name" );
m_strLocDescription = pKVMusicDef->GetString( "loc_description" );
m_strPedestalDisplayModel = pKVMusicDef->GetString( "pedestal_display_model" );
m_strInventoryImage = pKVMusicDef->GetString( "image_inventory" );
SCHEMA_INIT_CHECK(
( nID > 0 ),
CFmtStr( "Music definition %s: name must be a positive integer", GetName() ) );
SCHEMA_INIT_CHECK(
!m_strName.IsEmpty(),
CFmtStr( "Music definition %s: missing \"name\"", GetName() ) );
return SCHEMA_INIT_SUCCESS();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CEconQuestDefinition::BInitFromKV( KeyValues *pKVQuestDef, CEconItemSchema &pschema, CUtlVector<CUtlString> *pVecErrors /* = NULL */ )
{
//TODO - do we care to parse quest definitions on GC at all or only on game server and client?
nID = Q_atoi( pKVQuestDef->GetName() );
SCHEMA_INIT_CHECK(
( nID > 0 ),
CFmtStr( "Quest definition %s: name must be a positive integer", GetName() ) );
m_strName = pKVQuestDef->GetString( "name" );
SCHEMA_INIT_CHECK(
!m_strName.IsEmpty(),
CFmtStr( "Quest definition %s: missing \"name\"", GetName() ) );
m_strGameMode = pKVQuestDef->GetString( "gamemode" );
m_strMapGroup = pKVQuestDef->GetString( "mapgroup" );
m_strMap = pKVQuestDef->GetString( "map" );
#ifndef GC_DLL
static bool bLoadBannedWords = ( !!CommandLine()->FindParm( "-usebanlist" ) ) || (
!!CommandLine()->FindParm( "-perfectworld" )
);
if ( bLoadBannedWords && !V_stricmp( m_strMap.Get(), "ar_monastery" ) )
m_strMap = "ar_shoots";
#endif
m_bIsAnEvent = pKVQuestDef->GetBool( "is_an_event", false );
// Campaign quests require client-exposed points remaining.
// load non-GC only points if it exists.
// Otherwise look for "gc_generation_settings/points"
// quest events are always 1 point.
if ( m_bIsAnEvent )
{
m_vecQuestPoints.AddToTail( 1 );
}
else
{
const char* pszPointsRemaining = pKVQuestDef->GetString( "points" );
m_vecQuestPoints.Purge();
if ( pszPointsRemaining && pszPointsRemaining[ 0 ] )
{
SCHEMA_INIT_CHECK(
Helper_ExtractIntegersFromValuesString( pszPointsRemaining, m_vecQuestPoints ),
CFmtStr( "Quest definition %s specifies a malformed values range: %s", GetName(), pszPointsRemaining ) );
}
else
{
// if points aren't specified then default to '1'
m_vecQuestPoints.AddToTail( 1 );
}
}
// campaigns use quest-defined rewards rather than attributes rolled later.
m_strRewardLootList = pKVQuestDef->GetString( "quest_reward" );
m_nDifficulty = pKVQuestDef->GetInt( "difficulty", 1 );
m_nOperationalPoints = pKVQuestDef->GetInt( "operational_points", 0 );
if ( !m_bIsAnEvent )
{
m_nXPReward = pKVQuestDef->GetInt( "xp_reward", ( m_nDifficulty + 1 ) * 100 ); // campaign quest: 1 = 200, 2 = 300, 3 = 400
}
else
{
m_nXPReward = pKVQuestDef->GetInt( "gc_generation_settings/xp_reward", 1 ); // default quest event xp reward to 1 per action
}
m_nTargetTeam = pKVQuestDef->GetInt( "target_team", 0 );
m_strExpr = pKVQuestDef->GetString( "expression" );
// BONUS
m_strBonusExpr = pKVQuestDef->GetString( "expr_bonus" );
// set bonus percent only if a bonus expression exists
if ( !m_strBonusExpr.IsEmpty() )
{
m_nXPBonusPercent = pKVQuestDef->GetInt( "xp_bonus_percent", 100 ); // default bonus is 100%
}
else
{
m_nXPBonusPercent = 0;
}
#ifdef CLIENT_DLL // strings
m_strNameLocToken = pKVQuestDef->GetString( "loc_name" );
if ( !m_strNameLocToken.IsEmpty() )
HelperValidateLocalizationStringToken( m_strNameLocToken );
m_strShortNameLocToken = pKVQuestDef->GetString( "loc_shortname" );
if ( !m_strShortNameLocToken.IsEmpty() )
HelperValidateLocalizationStringToken( m_strShortNameLocToken );
m_strDescriptionLocToken = pKVQuestDef->GetString( "loc_description" );
if ( !m_strDescriptionLocToken.IsEmpty() )
HelperValidateLocalizationStringToken( m_strDescriptionLocToken );
m_strHudDescriptionLocToken = pKVQuestDef->GetString( "loc_huddescription" );
if ( !m_strHudDescriptionLocToken.IsEmpty() )
HelperValidateLocalizationStringToken( m_strHudDescriptionLocToken );
// Localizers have request the ability to explicitly write each quest's description because the
// programatic string construction in place is not flexible enough to accommodate various grammars.
//
// Description will defer to this string, if it exists. It should not be used in CSGO_English.
if ( g_pVGuiLocalize->Find( CFmtStr( "Override_Quest_Description_%s", pKVQuestDef->GetName( ) ) ) )
m_strDescriptionLocToken = CFmtStr( "Override_Quest_Description_%s", pKVQuestDef->GetName( ) );
m_strLocBonus = pKVQuestDef->GetString( "loc_bonus" );
if ( !m_strLocBonus.IsEmpty() )
HelperValidateLocalizationStringToken( m_strLocBonus );
m_strIcon = pKVQuestDef->GetString( "quest_icon" );
// Quests used to use explicitly define "string_tokens" in their schema definitions.
// Now the string tokens kv is populated by interpreting the expression
// but we may still want to add tokens manually in the future.
m_kvStringTokens = pKVQuestDef->FindKey( "string_tokens" );
if ( !m_kvStringTokens )
m_kvStringTokens = new KeyValues( "string_tokens" );
KeyValues * pkvExpressionTokens = new KeyValues( "ExpressionTokens" );
KeyValues::AutoDelete autodelete_pKVExpressionTokens( pkvExpressionTokens );
TokenizeQuestExpression( m_strExpr, pkvExpressionTokens );
Assert( pkvExpressionTokens->GetFirstSubKey() != NULL );
PopulateQuestStringTokens( *this, *pkvExpressionTokens, *m_kvStringTokens );
if ( !m_strBonusExpr.IsEmpty() )
{
KeyValues * pKVBonusExpressionTokens = new KeyValues( "BonusExpressionTokens" );
KeyValues::AutoDelete autodelete_pKVBonusExpressionTokens( pKVBonusExpressionTokens );
TokenizeQuestExpression( m_strBonusExpr, pKVBonusExpressionTokens );
Assert( pKVBonusExpressionTokens->GetFirstSubKey() != NULL );
PopulateQuestStringTokens( *this, *pKVBonusExpressionTokens, *m_kvStringTokens, true );
}
#endif // ifndef GAME_DLL
// MAPGROUP
//
//
bool bMapGroupValid = false;
if ( m_strMapGroup.IsEmpty() ) { bMapGroupValid = true; } // "": empty mapgroups are technically valid
/** Removed for partner depot **/
AssertMsg2( bMapGroupValid, "QUEST %d references a non-existant mapgroup: %s.\n", nID, m_strMapGroup.Get() );
#ifndef GAME_DLL // strings
KeyValues *pGameModestxt = new KeyValues( "GameModes.txt" );
KeyValues::AutoDelete autodelete( pGameModestxt );
if ( !pGameModestxt->LoadFromFile( g_pFullFileSystem, "GameModes.txt" ) )
{
pGameModestxt = NULL;
}
// MAP
//
//
// get map string from gamemodes.txt and insert it into m_kvStringTokens
//
//
if ( !m_strMap.IsEmpty( ) && StringIsEmpty( m_kvStringTokens->GetString( "map" ) ) )
{
KeyValues *pMaps = pGameModestxt->FindKey( "maps" );
if ( pMaps )
{
KeyValues *pMapKV = pMaps->FindKey( m_strMap );
Assert( pMapKV );
if ( pMapKV )
{
m_kvStringTokens->SetString( "map", pMapKV->GetString( "nameID" ) );
m_kvStringTokens->SetString( "location", pMapKV->GetString( "nameID" ) );
}
}
}
// get mapgroup string from gamemodes.txt and insert it into m_kvStringTokens
//
//
if ( !m_strMapGroup.IsEmpty() && StringIsEmpty( m_kvStringTokens->GetString( "mapgroup" ) ) )
{
KeyValues *pMapGroups = pGameModestxt->FindKey( "mapgroups" );
if ( pMapGroups )
{
KeyValues *pMapGroup = pMapGroups->FindKey( m_strMapGroup );
Assert( pMapGroup );
if ( pMapGroup )
{
m_kvStringTokens->SetString( "mapgroup", pMapGroup->GetString( "nameID" ) );
}
// if we didn't specify a map then use the mapgroup as the location
if ( !m_kvStringTokens->FindKey("location") )
{
m_kvStringTokens->SetString( "location", pMapGroup->GetString( "nameID" ) );
}
}
}
//GAMEMODE
//
//
#ifdef DBGFLAG_ASSERT
const char * szType;
bool bGameModeValid = g_pGameTypes->GetGameTypeFromMode( m_strGameMode, szType );
AssertMsg2( bGameModeValid, "QUEST %d references a non-existant gamemode: %s.\n", nID, m_strGameMode );
#endif
if ( StringIsEmpty( m_kvStringTokens->GetString( "gamemode" ) ) )
{
// get gamemode string from gamemodes.txt and insert it into m_kvStringTokens
//
//
KeyValues *pGameTypes = pGameModestxt->FindKey( "gameTypes" );
FOR_EACH_SUBKEY( pGameTypes, kvGameType )
{
KeyValues *pGameModes = kvGameType->FindKey( "GameModes" );
if ( pGameModes )
{
KeyValues *pGameMode = pGameModes->FindKey( m_strGameMode );
if ( pGameMode )
{
m_kvStringTokens->SetString( "gamemode", pGameModes->FindKey( m_strGameMode )->GetString( "NameID" ) );
break;
}
}
}
}
// check all strings in m_kvStringTokens
FOR_EACH_VALUE( m_kvStringTokens, pKVStringToken )
{
const char* token = pKVStringToken->GetString();
HelperValidateLocalizationStringToken( token );
}
FOR_EACH_TRUE_SUBKEY( m_kvStringTokens, pKVSubKey )
{
FOR_EACH_VALUE( pKVSubKey, pKVStringToken )
{
const char* token = pKVStringToken->GetString( );
HelperValidateLocalizationStringToken( token );
}
}
#endif // not GAME_DLL
return SCHEMA_INIT_SUCCESS();
}
#ifdef CLIENT_DLL
///////////////////////////////////////////////////////////////////////////////////////////
//
// read the expression ( i.e. " %act_kill_human% && %cond_gun_borrowed% && %weapon_smg% )
// and insert appropriate string tokens into the string token keyvalues structure
//
////////////////////////////////////////////////////////////////////////////////////////////
void CEconQuestDefinition::PopulateQuestStringTokens( CEconQuestDefinition &questDef, KeyValues &kvExpressionTokens, KeyValues &kvStringTokens, bool bBonus )
{
// 1. Validate that every token ( %TOKEN% ) is accounted for.
// 2. Populate pkvStringTokens with tokens derived from expression keywords e.g. %weapon_ak47%
KeyValues * pkvExpressionTokens = &kvExpressionTokens;
int nItemCount = 0;
FOR_EACH_SUBKEY( pkvExpressionTokens, kvSubKey )
{
bool bFound = false;
if ( V_stristr( kvSubKey->GetName(), "act_" ) || V_stristr( kvSubKey->GetName(), "cond_" ) )
{
// validate that action or condition is recognized.
for ( int i = 0; i < k_EQuestVar_Last; i++ )
{
if ( FStrEq( g_arrQuestVars[ i ], kvSubKey->GetName() ) )
{
if ( g_pVGuiLocalize->Find( CFmtStr( "#quest_action_singular_%s", kvSubKey->GetName() ) ) )
{
if ( !kvStringTokens.FindKey( "action" ) )
{
kvStringTokens.SetString( "action", CFmtStr( "#quest_action_singular_%s", kvSubKey->GetName() ) );
}
if ( !kvStringTokens.FindKey( "actions" ) )
{
kvStringTokens.SetString( "actions", CFmtStr( "#quest_action_plural_%s", kvSubKey->GetName() ) );
}
}
/** Removed for partner depot **/
// note that we have at least one generic weapon if we use any item condition.
if ( V_stristr( kvSubKey->GetName( ), "cond_item" ) )
{
if ( nItemCount == 0 ) nItemCount = 1;
}
// debug kvStringTokens.SaveToFile( g_pFullFileSystem, "~expressiontokens.txt" );
// debug pkvExpressionTokens->SaveToFile( g_pFullFileSystem, "~expressiontokens.txt" );
bFound = true;
break;
}
}
}
else if ( V_stristr( kvSubKey->GetName(), "weapon_" ) )
{
// find the items subkey or create one if it doesnt exist
KeyValues* pkvItems = kvStringTokens.FindKey( "items" );
if ( !pkvItems )
{
pkvItems = new KeyValues( "items" );
kvStringTokens.AddSubKey( pkvItems );
}
CEconItemDefinition * pWeaponItemDef = GetItemSchema( )->GetItemDefinitionByName( kvSubKey->GetName( ) );
if ( pWeaponItemDef )
{
// LEGACY PRE-2016
if ( !kvStringTokens.FindKey( "weapon" ) )
{
kvStringTokens.SetString( "weapon", pWeaponItemDef->GetItemBaseName() );
}
// LEGACY PRE-2016
// insert the weapon into the 'items' true subkey
for ( int i = 1; i < 20; i++ )
{
const char * szItemKeyName = CFmtStr( "item%d", i );
if ( !pkvItems->FindKey( szItemKeyName ) )
{
pkvItems->SetString( szItemKeyName, pWeaponItemDef->GetItemBaseName( ) );
nItemCount++;
break;
}
}
bFound = true;
// set the quest icon to the weapon if an icon was not explicitly set.
if ( questDef.m_strIcon.IsEmpty( ) && !bBonus )
{
questDef.m_strIcon = kvSubKey->GetName() + WEAPON_CLASSNAME_PREFIX_LENGTH;
}
}
else
{
// look for a weapon category/type
for ( int i = 0; i < LOADOUT_POSITION_COUNT; i++ )
{
if ( V_stristr( kvSubKey->GetName(), CFmtStr( "weapon_%s", g_szLoadoutStrings[ i ] ) ) )
{
// LEGACY PRE-2016
if ( !kvStringTokens.FindKey( "weapon" ) )
{
kvStringTokens.SetString( "weapon", g_szLoadoutStringsForDisplay[ i ] );
}
// LEGACY PRE-2016
// insert the weapon into the 'items' true subkey
for ( int j = 1; j < 20; j++ )
{
const char * szItemKeyName = CFmtStr( "item%d", j );
if ( !pkvItems->FindKey( szItemKeyName ) )
{
const char * szLoadoutStringNoHashMark = g_szLoadoutStringsForDisplay[ i ] + 1;
pkvItems->SetString( szItemKeyName, CFmtStr( "#quest_%s", szLoadoutStringNoHashMark ) );
nItemCount++;
break;
}
}
bFound = true;
break;
}
}
}
}
else if ( V_stristr( kvSubKey->GetName(), "set_" ) )
{
for ( int i = 0; i < GetItemSchema()->GetItemSetCount(); i++ )
{
const CEconItemSetDefinition *pItemSetDef = GetItemSchema()->GetItemSetByIndex( i );
if ( pItemSetDef && FStrEq( kvSubKey->GetName(), pItemSetDef->GetName() ) )
{
if ( !kvStringTokens.FindKey( "set" ) )
{
kvStringTokens.SetString( "set", CFmtStr( "#CSGO_%s", pItemSetDef->GetName() ) );
}
bFound = true;
break;
}
}
}
else if ( V_stristr( kvSubKey->GetName(), "map_" ) )
{
/** Removed for partner depot **/
}
// debug save
// kvStringTokens.SaveToFile( g_pFullFileSystem, "~expressiontokens.txt" );
AssertMsg2( bFound, "QUEST %u refs a non-existant var: %s\n", questDef.GetID(), kvSubKey->GetName() );
}
// defaults
if ( !kvStringTokens.FindKey( "commandverb" ) )
{
kvStringTokens.SetString( "commandverb", "#quest_commandverb_default" );
}
if ( !kvStringTokens.FindKey( "target" ) )
{
kvStringTokens.SetString( "target", "#emptystring" );
}