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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "cbase.h"
#include "econ_item_interface.h"
#include "econ_item_tools.h" // needed for CEconTool_WrappedGift definition for IsMarketable()
#include "rtime.h"
#ifdef STAGING_ONLY
ConVar tf_paint_kit_force_wear( "tf_paint_kit_force_wear", "0", FCVAR_REPLICATED, "Set to force the wear level of paink kit weapons and ignore the GC dynamic attribute value." );
#endif
// --------------------------------------------------------------------------
bool IEconItemInterface::GetCustomPaintKitWear( float &flWear ) const
{
#ifdef STAGING_ONLY
// don't assert in staging if this ConVar is set
if ( tf_paint_kit_force_wear.GetInt() > 0 )
{
flWear = tf_paint_kit_force_wear.GetFloat();
return true;
}
#endif // STAGING_ONLY
static CSchemaAttributeDefHandle pAttrDef_PaintKitWear( "set_item_texture_wear" );
float flPaintKitWear = 0;
if ( pAttrDef_PaintKitWear && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( this, pAttrDef_PaintKitWear, &flPaintKitWear ) )
{
flWear = flPaintKitWear;
return true;
}
static CSchemaAttributeDefHandle pAttrDef_DefaultWear( "texture_wear_default" );
if ( pAttrDef_DefaultWear && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( this, pAttrDef_DefaultWear, &flPaintKitWear ) )
{
flWear = flPaintKitWear;
return true;
}
// If you have no wear, you also should not have a paint kit
AssertMsg( !GetCustomPainkKitDefinition(), "No Wear Found on Item [%llu - %s] that has a Paintkit!", GetID(), GetItemDefinition()->GetDefinitionName() );
return false;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
bool IEconItemInterface::IsTemporaryItem() const
{
// store preview items are also temporary
if ( GetOrigin() == kEconItemOrigin_PreviewItem )
return true;
RTime32 rtTime = GetExpirationDate();
if ( rtTime > 0 )
return true;
return false;
}
// --------------------------------------------------------------------------
RTime32 IEconItemInterface::GetExpirationDate() const
{
COMPILE_TIME_ASSERT( sizeof( float ) == sizeof( RTime32 ) );
// dynamic attributes, if present, will override any static expiration timer
static CSchemaAttributeDefHandle pAttrib_ExpirationDate( "expiration date" );
attrib_value_t unAttribExpirationTimeBits;
COMPILE_TIME_ASSERT( sizeof( unAttribExpirationTimeBits ) == sizeof( RTime32 ) );
if ( pAttrib_ExpirationDate && FindAttribute( pAttrib_ExpirationDate, &unAttribExpirationTimeBits ) )
return *(RTime32 *)&unAttribExpirationTimeBits;
// do we have a static timer set in the schema for all instances to expire?
return GetItemDefinition()
? GetItemDefinition()->GetExpirationDate()
: RTime32( 0 );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
RTime32 IEconItemInterface::GetTradableAfterDateTime() const
{
static CSchemaAttributeDefHandle pAttrib_TradableAfter( "tradable after date" );
Assert( pAttrib_TradableAfter );
if ( !pAttrib_TradableAfter )
return 0;
RTime32 rtTimestamp;
if ( !FindAttribute( pAttrib_TradableAfter, &rtTimestamp ) )
return 0;
return rtTimestamp;
}
// --------------------------------------------------------------------------
// Purpose: Return true if this item can never be traded
// --------------------------------------------------------------------------
bool IEconItemInterface::IsPermanentlyUntradable() const
{
if ( GetItemDefinition() == NULL )
return true;
// tagged to not be a part of the economy?
if ( ( kEconItemFlag_NonEconomy & GetFlags() ) != 0 )
return true;
// check attributes
static CSchemaAttributeDefHandle pAttrib_AlwaysTradable( "always tradable" );
static CSchemaAttributeDefHandle pAttrib_CannotTrade( "cannot trade" );
static CSchemaAttributeDefHandle pAttrib_NonEconomy( "non economy" );
Assert( pAttrib_AlwaysTradable != NULL );
Assert( pAttrib_CannotTrade != NULL );
if ( pAttrib_AlwaysTradable == NULL || pAttrib_CannotTrade == NULL || pAttrib_NonEconomy == NULL )
return true;
// Order matters, check for nonecon first. Always tradable overrides cannot trade.
if ( FindAttribute( pAttrib_NonEconomy ) )
return true;
if ( FindAttribute( pAttrib_AlwaysTradable ) ) // *sigh*
return false;
if ( FindAttribute( pAttrib_CannotTrade ) )
return true;
// items gained in this way are not tradable
switch ( GetOrigin() )
{
case kEconItemOrigin_Invalid:
case kEconItemOrigin_Achievement:
case kEconItemOrigin_Foreign:
case kEconItemOrigin_PreviewItem:
case kEconItemOrigin_SteamWorkshopContribution:
return true;
}
// temporary items (items that will expire for any reason) cannot be traded
if ( IsTemporaryItem() )
return true;
// certain quality levels are not tradable
if ( GetQuality() >= AE_COMMUNITY && GetQuality() <= AE_SELFMADE )
return true;
// explicitly marked cannot trade?
if ( ( kEconItemFlag_CannotTrade & GetFlags() ) != 0 )
return true;
return false;
}
// --------------------------------------------------------------------------
// Purpose: Return true if this item is a commodity on the Market (can place buy orders)
// --------------------------------------------------------------------------
bool IEconItemInterface::IsCommodity() const
{
if ( GetItemDefinition() == NULL )
return false;
static CSchemaAttributeDefHandle pAttrib_IsCommodity( "is commodity" );
if ( FindAttribute( pAttrib_IsCommodity ) )
return true;
return false;
}
// --------------------------------------------------------------------------
// Purpose: Return true if temporarily untradable
// --------------------------------------------------------------------------
bool IEconItemInterface::IsTemporarilyUntradable() const
{
// Temporary untradability does NOT take "always tradable" into account
if ( GetTradableAfterDateTime() >= CRTime::RTime32TimeCur() )
return true;
return false;
}
// --------------------------------------------------------------------------
// Purpose: Return true if this item is untradable
// --------------------------------------------------------------------------
bool IEconItemInterface::IsTradable() const
{
// Items that are expired are never listable, regardless of other rules.
//RTime32 timeExpirationDate = GetExpirationDate();
//if ( timeExpirationDate > 0 && timeExpirationDate < CRTime::RTime32TimeCur() )
// return false;
return GetUntradabilityFlags() == 0;
}
// --------------------------------------------------------------------------
// Purpose: Return untradability flags
// --------------------------------------------------------------------------
int IEconItemInterface::GetUntradabilityFlags() const
{
int nFlags = 0;
if ( IsTemporarilyUntradable() )
{
nFlags |= k_Untradability_Temporary;
}
if ( IsPermanentlyUntradable() )
{
nFlags |= k_Untradability_Permanent;
}
return nFlags;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
bool IEconItemInterface::IsUsableInCrafting() const
{
if ( GetItemDefinition() == NULL )
return false;
// tagged to not be a part of the economy?
if ( ( kEconItemFlag_NonEconomy & GetFlags() ) != 0 )
return false;
// always craftable?
static CSchemaAttributeDefHandle pAttrib_AlwaysUsableInCraft( "always tradable" );
Assert( pAttrib_AlwaysUsableInCraft );
if ( FindAttribute( pAttrib_AlwaysUsableInCraft ) )
return true;
// never craftable?
static CSchemaAttributeDefHandle pAttrib_NeverCraftable( "never craftable" );
Assert( pAttrib_NeverCraftable );
if ( FindAttribute( pAttrib_NeverCraftable ) )
return false;
// temporary items (items that will expire for any reason) cannot be turned into
// permanent items
if ( IsTemporaryItem() )
return false;
// explicitly marked not usable in crafting?
if ( ( kEconItemFlag_CannotBeUsedInCrafting & GetFlags() ) != 0 )
return false;
// items gained in this way are not craftable
switch ( GetOrigin() )
{
case kEconItemOrigin_Invalid:
case kEconItemOrigin_Foreign:
case kEconItemOrigin_StorePromotion:
case kEconItemOrigin_SteamWorkshopContribution:
return false;
// purchased items can be used in crafting if explicitly tagged, but not by default
case kEconItemOrigin_Purchased:
// deny items the GC didn't flag at purchase time
if ( (GetFlags() & kEconItemFlag_PurchasedAfterStoreCraftabilityChanges2012) == 0 )
return false;
// deny items that can never be used
if ( (GetItemDefinition()->GetCapabilities() & ITEM_CAP_CAN_BE_CRAFTED_IF_PURCHASED) == 0 )
return false;
break;
}
// certain quality levels are not craftable
if ( GetQuality() >= AE_COMMUNITY && GetQuality() <= AE_SELFMADE )
return false;
return true;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
bool IEconItemInterface::IsMarketable() const
{
const CEconItemDefinition *pItemDef = GetItemDefinition();
if ( pItemDef == NULL )
return false;
// Untradeable items can never be marketed, regardless of other rules.
// Temporarily untradable items can be marketed, only permanent untradable items cannot be marketed
if ( IsPermanentlyUntradable() )
return false;
// Items that are expired are never listable, regardless of other rules.
RTime32 timeExpirationDate = GetExpirationDate();
if ( timeExpirationDate > 0 && timeExpirationDate < CRTime::RTime32TimeCur() )
return false;
// Initially, only TF2 supports listing items in the Marketplace.
#if defined( TF_DLL ) || defined( TF_CLIENT_DLL ) || defined( TF_GC_DLL )
{
// User-created wrapped gifts are untradeable for the moment. This would provide a backdoor
// for users to sell anything they wanted, which is interesting but not what we want in
// the initial launch.
if ( pItemDef->GetTypedEconTool<CEconTool_WrappedGift>() )
return false;
// All other tools are listable. This includes keys, paints, backpack expanders, strange
// parts, Halloween spells, wedding rings, etc. It does not includes gifts (see above),
// noisemakers, or crates (see below).
if ( pItemDef->IsTool() )
return true;
// All crates are listable. Anything with the "decodable" flag is considered a crate.
if ( (pItemDef->GetCapabilities() & ITEM_CAP_DECODABLE) != 0 )
return true;
// Genuine-quality items come from time-limited purchase promos and are listable. Vintage
// items are from one-time transitions and are all finite quality. Haunted quality items are
// TF-Halloween-event specific. Some of the older haunted items didn't generate revenue, but
// the content is all old and there seems to be little harm in letting it be listed. The
// haunted items from 2013 all come from crates, which means they all generated revenue.
// Collectors items are created from a finite set of recipes.
// Paintkit Weapons are from cases or operations
if ( GetQuality() == AE_RARITY1 || GetQuality() == AE_VINTAGE || GetQuality() == AE_HAUNTED
|| GetQuality() == AE_COLLECTORS || GetQuality() == AE_PAINTKITWEAPON )
return true;
// All festive items are from time-limited holiday crates and are listable. This code seems
// safe. (...) (This code is in fact so safe that if we just do a substring match we'll also
// allow "A Rather Festive Tree".)
if ( !V_strncmp( pItemDef->GetDefinitionName(), "Festive", 7 ) )
return true;
// All botkiller items come from MvM rewards and are listable. This does a substring search
// to find all varieties (gold, silver, rust, etc.), etc.
if ( V_strstr( pItemDef->GetDefinitionName(), " Botkiller " ) )
return true;
// Mvm V2 Robit Parts
if ( V_strstr( pItemDef->GetDefinitionName(), "Robits " ) )
return true;
// MvM Killstreak Weapons
static CSchemaAttributeDefHandle pAttr_killstreak( "killstreak tier" );
if ( FindAttribute( pAttr_killstreak ) )
return true;
// Australium Items
static CSchemaAttributeDefHandle pAttrDef_IsAustralium( "is australium item" );
if ( FindAttribute( pAttrDef_IsAustralium ) )
return true;
// Glitch GateHat Replacement Item
static CSchemaItemDefHandle pItemDef_GlitchedCircuit( "Glitched Circuit Board" );
if ( pItemDef == pItemDef_GlitchedCircuit )
return true;
// Anything that says it wants to be marketable.
static CSchemaAttributeDefHandle pAttrDef_IsMarketable( "is marketable" );
if ( FindAttribute( pAttrDef_IsMarketable ) )
return true;
// Anything that is of limited quantity (ie limited promos)
static CSchemaAttributeDefHandle pAttrDef_IsLimited( "limited quantity item" );
if ( FindAttribute( pAttrDef_IsLimited ) )
return true;
// Allow the Giving items (not a wrapped_gift but a gift, ie Secret Saxton, Pile O Gifts, Pallet of Keys)
const CEconTool_Gift *pEconToolGift = pItemDef->GetTypedEconTool<CEconTool_Gift>();
if ( pEconToolGift )
return true;
// Unusual Cosmetics and Taunts
if ( GetQuality() == AE_UNUSUAL && ( GetItemDefinition()->GetLoadoutSlot( 0 ) == LOADOUT_POSITION_MISC || GetItemDefinition()->GetLoadoutSlot( 0 ) == LOADOUT_POSITION_TAUNT ) )
return true;
// Strange items. Dont just check for strange quality, actually check for a strange attribute.
// See if we've got any strange attributes.
for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
{
if ( FindAttribute( GetKillEaterAttr_Score( i ) ) )
{
return true;
}
}
}
#endif // defined( TF_DLL ) || defined( TF_CLIENT_DLL ) || defined( TF_GC_DLL )
// By default, items aren't listable.
return false;
}
// --------------------------------------------------------------------------
const char *IEconItemInterface::GetDefinitionString( const char *pszKeyName, const char *pszDefaultValue ) const
{
const GameItemDefinition_t *pDef = GetItemDefinition();
if ( pDef )
return pDef->GetDefinitionString( pszKeyName, pszDefaultValue );
return pszDefaultValue;
}
// --------------------------------------------------------------------------
KeyValues *IEconItemInterface::GetDefinitionKey( const char *pszKeyName ) const
{
const GameItemDefinition_t *pDef = GetItemDefinition();
if ( pDef )
return pDef->GetDefinitionKey( pszKeyName );
return NULL;
}
|