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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
|
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "cbase.h"
#include "econ_item_description.h"
#include "econ_item_interface.h"
#include "econ_item_tools.h"
#include "econ_holidays.h"
#include "econ_store.h"
#include "tier1/ilocalize.h"
#include "localization_provider.h"
#include "rtime.h"
#include "econ_dynamic_recipe.h"
#ifdef GC
// the GC needs accountdetails to get persona names
#include "gcsdk/accountdetails.h"
#else // !GC
#ifndef EXTERNALTESTS_DLL
#include "econ_item_inventory.h"
#endif
#ifdef CLIENT_DLL
#include "gc_clientsystem.h"
#include "client_community_market.h" // for Market data in tooltips
#include "econ_ui.h" // for money-value-to-display-string formatting
#include "store/store_panel.h" // for money-value-to-display-string formatting
#endif // CLIENT_DLL
#endif // GC
#ifdef PROJECT_TF
#include "tf_duel_summary.h"
#include "econ_contribution.h"
#include "tf_player_info.h"
#include "tf_wardata.h"
#ifdef TF_CLIENT_DLL
#include "tf_gamerules.h"
#include "tf_mapinfo.h"
#endif
#endif
#ifdef VPROF_ENABLED
static const char *g_pszEconDescriptionVprofGroup = _T("Econ Description");
#endif
extern const char *GetWearLocalizationString( float flWear );
// --------------------------------------------------------------------------
// Local Helper
// --------------------------------------------------------------------------
const size_t k_VerboseStringBufferSize = 128;
static char *BuildVerboseStrings( char buf[k_VerboseStringBufferSize], bool bIsVerbose, const char *format, ... )
{
if ( !bIsVerbose )
return NULL;
va_list argptr;
va_start( argptr, format );
Q_vsnprintf( buf, k_VerboseStringBufferSize, format, argptr );
va_end(argptr);
return buf;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
static bool IsStorePreviewItem( const IEconItemInterface *pEconItem )
{
Assert( pEconItem );
#ifdef CLIENT_DLL
return pEconItem->GetFlags() & kEconItemFlagClient_StoreItem;
#else
return false;
#endif
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void IEconItemDescription::YieldingFillOutEconItemDescription( IEconItemDescription *out_pDescription, CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
VPROF_BUDGET( "IEconItemDescription::YieldingFillOutEconItemDescription()", g_pszEconDescriptionVprofGroup );
Assert( out_pDescription );
Assert( pLocalizationProvider );
Assert( pEconItem );
out_pDescription->YieldingCacheDescriptionData( pLocalizationProvider, pEconItem );
out_pDescription->GenerateDescriptionLines( pLocalizationProvider, pEconItem );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
const econ_item_description_line_t *IEconItemDescription::GetFirstLineWithMetaType( uint32 unMetaTypeSearchFlags ) const
{
for ( unsigned int i = 0; i < GetLineCount(); i++ )
{
const econ_item_description_line_t& pLine = GetLine(i);
if ( (pLine.unMetaType & unMetaTypeSearchFlags) == unMetaTypeSearchFlags )
return &pLine;
}
return NULL;
}
#ifdef BUILD_ITEM_NAME_AND_DESC
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
CLocalizedStringArg<CLocalizedRTime32>::CLocalizedStringArg( const CLocalizedRTime32& cTimeIn )
{
#if TF_ANTI_IDLEBOT_VERIFICATION
// We expect the client and the GC to display dates and times differently in certain situations (ie.,
// they may disagree on whether to display in GMT). Rather than trying to find the specific cases where
// they might agree and let them through, we just early out and feed back the empty string for all
// date/time formatting when doing client verification.
if ( cTimeIn.m_pHashContext )
return;
#endif
CRTime cTime( cTimeIn.m_unTime );
// The GC will always display time in GMT. "Local time" isn't a useful thing from a client's perspective
// when viewing an item in the Steam Community, etc.
#ifdef GC_DLL
cTime.SetToGMT( true );
#else
cTime.SetToGMT( cTimeIn.m_bForceGMTOnClient );
#endif
const locchar_t *loc_LocalizationFormat = cTimeIn.m_pLocalizationProvider->Find( cTime.BIsGMT() ? "Econ_DateFormat_GMT" : "Econ_DateFormat" );
time_t tTime = cTime.GetRTime32();
struct tm tmStruct;
struct tm *ptm = cTime.BIsGMT() ? Plat_gmtime( &tTime, &tmStruct ) : Plat_localtime( &tTime, &tmStruct );
time_t tFinalTime = mktime( ptm );
char rgchDateBuf[ 128 ];
BGetLocalFormattedDate( tFinalTime, rgchDateBuf, sizeof( rgchDateBuf ) );
KeyValues *pKeyValues = new KeyValues( "DateTokens" );
pKeyValues->SetString( "day", &rgchDateBuf[0] );
pKeyValues->SetInt( "hour", cTime.GetHour() );
pKeyValues->SetString( "min", CFmtStr( "%02u", cTime.GetMinute() ).Access() );
pKeyValues->SetString( "sec", CFmtStr( "%02u", cTime.GetSecond() ).Access() );
m_Str = CConstructLocalizedString( loc_LocalizationFormat, pKeyValues );
pKeyValues->deleteThis();
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::YieldingFillOutAccountPersonaName( const CLocalizationProvider *pLocalizationProvider, uint32 unAccountID )
{
Assert( pLocalizationProvider );
// Never cache invalid accounts.
if ( unAccountID == 0 )
return;
// Make sure we have a cache entry for this account ID. If we're hashing, we won't fill
// this with real data to avoid discrepancies between the GC view of a persona name and the
// client view, both of which are cached differently. If we're not hashing, we'll do our best
// to find the current name. Either way, by the time this function ends we expect to have a
// value stored for this account ID.
CEconItemDescription::steam_account_persona_name_t& AccountPersona = vecPersonaNames[ vecPersonaNames.AddToTail() ];
AccountPersona.unAccountID = unAccountID;
#if TF_ANTI_IDLEBOT_VERIFICATION
// Force persona names to match "verify" between the client and the GC for verification.
if ( m_pHashContext )
{
AccountPersona.loc_sPersonaName = LOCCHAR("verify");
}
else
#endif // TF_ANTI_IDLEBOT_VERIFICATION
{
const char *utf8_PersonaName = NULL;
#ifdef GC
CSteamID steamID( unAccountID, GCSDK::GGCHost()->GetUniverse(), k_EAccountTypeIndividual );
utf8_PersonaName = GGCGameBase()->YieldingGetPersonaName( steamID );
#else // if defined( CLIENT_DLL )
utf8_PersonaName = InventoryManager()->PersonaName_Get( unAccountID );
#endif
#if defined( CLIENT_DLL )
m_bUnknownPlayer = Q_strncmp( utf8_PersonaName, "[unknown]", ARRAYSIZE( "[unknown]" ) ) == 0;
#endif
// We should have filled this in with something by now, even if that something is "we couldn't
// find useful information".
Assert( utf8_PersonaName );
// Convert our UTF8 to whatever we're using for localized display, and done.
pLocalizationProvider->ConvertUTF8ToLocchar( utf8_PersonaName, &AccountPersona.loc_sPersonaName );
}
Assert( !AccountPersona.loc_sPersonaName.IsEmpty() );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
const locchar_t *CEconItemDescription::FindAccountPersonaName( uint32 unAccountID ) const
{
FOR_EACH_VEC( vecPersonaNames, i )
{
if ( vecPersonaNames[i].unAccountID == unAccountID )
return vecPersonaNames[i].loc_sPersonaName.Get();
}
// FIXME: add localization token
return LOCCHAR("Unknown User");
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::YieldingFillOutAccountTypeCache( uint32 unAccountID, int nClassID )
{
if( !unAccountID )
return;
#ifdef GC_DLL
CEconSharedObjectCache *pSOCache = GGCEcon()->YieldingFindOrLoadEconSOCache( CSteamID( unAccountID, GCSDK::GGCHost()->GetUniverse(), k_EAccountTypeIndividual ) );
#else // if defined( CLIENT_DLL )
EUniverse eUniverse = GetUniverse();
if ( eUniverse == k_EUniverseInvalid )
return;
GCSDK::CGCClientSharedObjectCache *pSOCache = GCClientSystem()->GetSOCache( CSteamID( unAccountID, eUniverse, k_EAccountTypeIndividual ) );
#endif
if ( !pSOCache )
return;
GCSDK::CSharedObjectTypeCache *pTypeCache = pSOCache->FindTypeCache( nClassID );
if ( !pTypeCache )
return;
CEconItemDescription::steam_account_type_cache_t& AccountTypeCache = vecTypeCaches[ vecTypeCaches.AddToTail() ];
AccountTypeCache.unAccountID = unAccountID;
AccountTypeCache.nClassID = nClassID;
AccountTypeCache.pTypeCache = pTypeCache;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
GCSDK::CSharedObjectTypeCache *CEconItemDescription::FindAccountTypeCache( uint32 unAccountID, int nClassID ) const
{
FOR_EACH_VEC( vecTypeCaches, i )
{
if ( vecTypeCaches[i].unAccountID == unAccountID &&
vecTypeCaches[i].nClassID == nClassID )
{
return vecTypeCaches[i].pTypeCache;
}
}
return NULL;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
template < typename T >
const T *CEconItemDescription::FindAccountTypeCacheSingleton( uint32 unAccountID, int nClassID ) const
{
GCSDK::CSharedObjectTypeCache *pSOTypeCache = FindAccountTypeCache( unAccountID, nClassID );
if ( !pSOTypeCache )
return NULL;
if ( pSOTypeCache->GetCount() != 1 )
return NULL;
return dynamic_cast<T *>( pSOTypeCache->GetObject( 0 ) );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::YieldingCacheDescriptionData( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
VPROF_BUDGET( "CEconItemDescription::YieldingCacheDescriptionData()", g_pszEconDescriptionVprofGroup );
vecPersonaNames.Purge();
vecTypeCaches.Purge();
// For each attribute that is set to display as an account ID, load the persona name for that account
// ID in advance so that we don't yield somewhere crazy down below.
// Walk our attribute list and accumulate IDs.
CSteamAccountIDAttributeCollector AccountIDCollector;
pEconItem->IterateAttributes( &AccountIDCollector );
const CUtlVector<uint32>& vecSteamAccountIDs = AccountIDCollector.GetAccountIDs();
// Look up the persona names for each account referenced by an attribute directly.
FOR_EACH_VEC( vecSteamAccountIDs, i )
{
YieldingFillOutAccountPersonaName( pLocalizationProvider, vecSteamAccountIDs[i] );
}
// Look up the persona names for each account referencing an attribute indirectly (ie., just stuffed
// into 32 bits).
for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
{
uint32 unRestrictionType;
if ( pEconItem->FindAttribute( GetKillEaterAttr_Restriction(i), &unRestrictionType ) &&
unRestrictionType == kStrangeEventRestriction_VictimSteamAccount )
{
uint32 unAccountID;
DbgVerify( pEconItem->FindAttribute( GetKillEaterAttr_RestrictionValue(i), &unAccountID ) );
YieldingFillOutAccountPersonaName( pLocalizationProvider, unAccountID );
}
}
#ifdef PROJECT_TF
uint32 unAccountID = pEconItem->GetAccountID();
// Duel summary.
{
// We'll need to access other information about our duel stats later, but we also need to precache
// the account name of whoever our last kill was beforehand.
YieldingFillOutAccountTypeCache( unAccountID, CTFDuelSummary::k_nTypeID );
// In TF, we also store information about our previous duel target, stored way way down inside some
// other structures.
const CTFDuelSummary *pDuelSummary = FindAccountTypeCacheSingleton<CTFDuelSummary>( unAccountID, CTFDuelSummary::k_nTypeID );
if ( pDuelSummary )
{
YieldingFillOutAccountPersonaName( pLocalizationProvider, pDuelSummary->Obj().last_duel_account_id() );
}
}
// Map contributions.
YieldingFillOutAccountTypeCache( unAccountID, CTFMapContribution::k_nTypeID );
// New users helped.
YieldingFillOutAccountTypeCache( unAccountID, CTFPlayerInfo::k_nTypeID );
// War data
YieldingFillOutAccountTypeCache( unAccountID, CWarData::k_nTypeID );
#ifdef CLIENT_DLL
// Duck LeaderBoards
{
static CSchemaAttributeDefHandle pAttrDef_DisplayDuckLeaderboard( "display duck leaderboard" );
if ( pEconItem->FindAttribute( pAttrDef_DisplayDuckLeaderboard ) )
{
CUtlVector< AccountID_t > accountIds;
Leaderboards_GetDuckLeaderboardSteamIDs( accountIds );
FOR_EACH_VEC( accountIds, i )
{
// Look up the persona names for each account referenced in the leaderboard
YieldingFillOutAccountPersonaName( pLocalizationProvider, accountIds[i] );
}
}
}
#endif // CLIENT_DLL
#if TF_ANTI_IDLEBOT_VERIFICATION
if ( m_pHashContext )
{
// Feed in the account IDs of each person we care about. We don't feed in the actual persona name
// string because this could theoretically differ between the GC and the client if one is out of sync.
FOR_EACH_VEC( vecPersonaNames, i )
{
char verboseStringBuf[ k_VerboseStringBufferSize ];
TFDescription_HashDataMunge( m_pHashContext, vecPersonaNames[i].unAccountID, m_bIsVerbose, BuildVerboseStrings( verboseStringBuf, m_bIsVerbose, "%d", vecPersonaNames[i].unAccountID ) );
}
// Are we in text mode or not? We'll use this to generate two different hashes to compare against.
unsigned int unRunningTextMode =
#ifdef GC_DLL
m_bTextModeEnabled
#else
*((bool *)g_pClientPurchaseInterface - 156)
#endif
? 0x73aaff8e
: 0x12800c0a;
char verboseStringBuf[ k_VerboseStringBufferSize ];
TFDescription_HashDataMunge( m_pHashContext, unRunningTextMode, m_bIsVerbose, BuildVerboseStrings( verboseStringBuf, m_bIsVerbose, "%d", unRunningTextMode ) );
}
#endif // TF_ANTI_IBLEBOT_VERIFICATION
#endif // PROJECT_TF
}
void CEconItemDescription::GenerateDescriptionLines( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
VPROF_BUDGET( "CEconItemDescription::GenerateDescriptionLines()", g_pszEconDescriptionVprofGroup );
Assert( pLocalizationProvider );
Assert( pEconItem );
m_vecDescLines.Purge();
Generate_ItemName( pLocalizationProvider, pEconItem );
Generate_ItemRarityDesc( pLocalizationProvider, pEconItem );
Generate_ItemLevelDesc( pLocalizationProvider, pEconItem );
//Generate_WearAmountDesc( pLocalizationProvider, pEconItem );
#if defined( STAGING_ONLY ) && defined( CLIENT_DLL )
Generate_DebugInformation( pLocalizationProvider, pEconItem );
#endif
// If we decide that for performance reasons some descriptions only want the name/description
// information and not all the details, this is the block to skip over.
{
Generate_CraftTag( pLocalizationProvider, pEconItem );
Generate_StyleDesc( pLocalizationProvider, pEconItem );
Generate_Painted( pLocalizationProvider, pEconItem );
Generate_HolidayRestriction( pLocalizationProvider, pEconItem );
#ifdef PROJECT_TF
Generate_SaxxyAwardDesc( pLocalizationProvider, pEconItem );
#endif // PROJECT_TF
Generate_VisibleAttributes( pLocalizationProvider, pEconItem );
Generate_QualityDesc( pLocalizationProvider, pEconItem );
Generate_ItemDesc( pLocalizationProvider, pEconItem );
Generate_Bundle( pLocalizationProvider, pEconItem );
Generate_GiftedBy( pLocalizationProvider, pEconItem );
#ifdef PROJECT_TF
Generate_DuelingMedal( pLocalizationProvider, pEconItem );
Generate_MapContributor( pLocalizationProvider, pEconItem );
Generate_FriendlyHat( pLocalizationProvider, pEconItem );
Generate_SquadSurplusClaimedBy( pLocalizationProvider, pEconItem );
Generate_MvmChallenges( pLocalizationProvider, pEconItem );
Generate_DynamicRecipe( pLocalizationProvider, pEconItem );
Generate_Leaderboard( pLocalizationProvider, pEconItem );
#endif // PROJECT_TF
Generate_XifierToolTargetItem( pLocalizationProvider, pEconItem );
Generate_LootListDesc( pLocalizationProvider, pEconItem );
Generate_EventDetail( pLocalizationProvider, pEconItem );
Generate_ItemSetDesc( pLocalizationProvider, pEconItem );
Generate_CollectionDesc( pLocalizationProvider, pEconItem );
Generate_ExpirationDesc( pLocalizationProvider, pEconItem );
Generate_DropPeriodDesc( pLocalizationProvider, pEconItem );
Generate_MarketInformation( pLocalizationProvider, pEconItem );
Generate_DirectX8Warning( pLocalizationProvider, pEconItem );
}
// Certain information (tradeability, etc.) used to only get displayed if we were the owning player, or
// if we were looking at an unowned item (ie., a store preview) and want to show what it will look like
// when it *is* owned. Unfortunately this led to problems where you wouldn't know if the item you were
// about to be traded (currently not owned by you) would be craftable, etc.
Generate_FlagsAttributes( pLocalizationProvider, pEconItem );
}
// --------------------------------------------------------------------------
// Purpose: Code to build up the item display name, including any relevant quality
// strings, custom renaming, craft numbers, and anything else we decide
// to throw at it.
// --------------------------------------------------------------------------
/*static*/ uint32 GetScoreTypeForKillEaterAttr( const IEconItemInterface *pEconItem, const CEconItemAttributeDefinition *pAttribDef )
{
// What sort of event are we tracking? If we don't have an attribute at all we're one of the
// old kill-eater weapons that didn't specify what it was tracking.
uint32 unKillEaterEventType = 0;
// This will overwrite our default 0 value if we have a value set but leave it if not.
{
float fKillEaterEventType;
if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttribDef, &fKillEaterEventType ) )
{
unKillEaterEventType = fKillEaterEventType;
}
}
return unKillEaterEventType;
}
// The item backend may add craft numbers well past what we want to display in the game. This
// function determines whether a given number should be visible rather than always showing
// whatever the GC shows.
bool ShouldDisplayCraftCounterValue( int iValue )
{
return iValue > 0 && iValue <= 100;
}
// This function will return the localized string (ie., "Face-Melting") for a specific item based
// on the score it has accumulated.
#if defined( CLIENT_DLL ) && defined( STAGING_ONLY )
ConVar staging_force_strange_score_selector_value( "staging_force_strange_score_selector_value", "-1" );
#endif // defined( CLIENT_DLL ) && defined( STAGING_ONLY )
class CStrangeRankLocalizationGenerator
{
public:
CStrangeRankLocalizationGenerator( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem, bool bHashContextOff );
bool IsValid() const { return m_bValid; }
const locchar_t *GetRankLocalized() const { Assert( m_bValid ); return m_loc_Rank; }
const locchar_t *GetRankSecondaryLocalized() const { Assert( m_bValid ); return m_loc_SecondaryRank; }
uint32 GetStrangeType() const { Assert( m_bValid ); return m_unType; }
uint32 GetStrangeScore() const { Assert( m_bValid ); return m_unScore; }
uint32 GetUsedStrangeSlot() const { Assert( m_bValid ); return m_unUsedStrangeSlot; }
private:
bool m_bValid;
const locchar_t *m_loc_Rank;
const locchar_t *m_loc_SecondaryRank;
uint32 m_unType;
uint32 m_unScore;
uint32 m_unUsedStrangeSlot;
};
CStrangeRankLocalizationGenerator::CStrangeRankLocalizationGenerator( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem, bool bHashContextOff )
: m_bValid( false )
, m_loc_Rank( NULL )
, m_loc_SecondaryRank( NULL )
, m_unType( kKillEaterEvent_PlayerKill )
, m_unScore( 0 )
, m_unUsedStrangeSlot( 0 )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_StrangeScoreSelector( "strange score selector" );
// Do we have a strange score selector attribute? If so, the value of this attribute will tell us which strange
// attribute we're actually going to use to generate a name. Leaving this value as 0 will fall back to the
// default behavior of looking at the base "kill eater" attribute.
if ( pEconItem->FindAttribute( pAttrDef_StrangeScoreSelector, &m_unUsedStrangeSlot ) )
{
// Make sure the value we pulled from the database is within range.
m_unUsedStrangeSlot = MIN( m_unUsedStrangeSlot, static_cast<uint32>( GetKillEaterAttrCount() ) );
}
#if defined( CLIENT_DLL ) && defined( STAGING_ONLY )
if ( staging_force_strange_score_selector_value.GetInt() > 0 )
{
m_unUsedStrangeSlot = staging_force_strange_score_selector_value.GetInt();
}
#endif // defined( CLIENT_DLL ) && defined( STAGING_ONLY )
// Use the strange prefix if the weapon has one.
if ( !pEconItem->FindAttribute( GetKillEaterAttr_Score( m_unUsedStrangeSlot ), &m_unScore ) )
return;
// What type of event are we tracking and how does it describe itself?
m_unType = GetScoreTypeForKillEaterAttr( pEconItem, GetKillEaterAttr_Type( m_unUsedStrangeSlot ) );
const char *pszLevelingDataName = GetItemSchema()->GetKillEaterScoreTypeLevelingDataName( m_unType );
if ( !pszLevelingDataName )
{
pszLevelingDataName = KILL_EATER_RANK_LEVEL_BLOCK_NAME;
}
uint32 uUsedScore = m_unScore;
#ifdef TF_ANTI_IDLEBOT_VERIFICATION
// TF2 Anti-Idle hack. It totally needs to be fixed
if ( !bHashContextOff )
{
uUsedScore = 0;
}
#endif //TF_ANTI_IDLEBOT_VERIFICATION
// For TF - Strange Scores reset on Trade, sharing that information is actually misleading so we'll always display base strange name
#ifdef TF_GC_DLL
uUsedScore = 0;
#endif // TF_GC_DLL
const CItemLevelingDefinition *pLevelDef = GetItemSchema()->GetItemLevelForScore( pszLevelingDataName, uUsedScore );
if ( !pLevelDef )
return;
// Primary rank established!
m_loc_Rank = pLocalizationProvider->Find( pLevelDef->GetNameLocalizationKey() );
m_bValid = true;
// Does this score slot have a restriction that adds additional text somewhere in the localization token?
uint32 unFilterType;
uint32 unFilterValue;
if ( pEconItem->FindAttribute( GetKillEaterAttr_Restriction( m_unUsedStrangeSlot ), &unFilterType ) &&
pEconItem->FindAttribute( GetKillEaterAttr_RestrictionValue( m_unUsedStrangeSlot ), &unFilterValue ) )
{
// Game-specific code doesn't belong here. "We're shipping soon" hack fun!
#ifdef PROJECT_TF
if ( unFilterType == kStrangeEventRestriction_Map )
{
const MapDef_t *pMap = GetItemSchema()->GetMasterMapDefByIndex( unFilterValue );
if ( pMap && pMap->pszStrangePrefixLocKey )
{
m_loc_SecondaryRank = pLocalizationProvider->Find( pMap->pszStrangePrefixLocKey );
}
}
else if (unFilterType == kStrangeEventRestriction_Competitive)
{
m_loc_SecondaryRank = pLocalizationProvider->Find( "TF_StrangeFilter_Prefix_Competitive" );
}
#endif // PROJECT_TF
}
}
// ---------------------------------------------------------------------------------------------------------------------------
void Econ_SetNameAsPaintkit( locchar_t( &out_pItemName )[MAX_ITEM_NAME_LENGTH], const CLocalizationProvider *pLocalizationProvider, CEconItemPaintKitDefinition *pPaintKit )
{
if ( !pPaintKit )
return;
// Generate Paint kitted name
// IE Purple Rain Sniper Rifle
locchar_t tempName[MAX_ITEM_NAME_LENGTH];
loc_scpy_safe( tempName, out_pItemName );
#ifndef GC
//bool bAppendWeapon = wcsstr( pPaintKitStr, out_pItemName ) == NULL;
g_pVGuiLocalize->ConstructString_safe( out_pItemName,
LOCCHAR( "%s1" ),
1,
pLocalizationProvider->Find( pPaintKit->GetLocalizeName() ) );
#else
// GC doesn't have g_pVGuiLocalize so we construct the painted gun string like this
locchar_t *pPaintKitStr = pLocalizationProvider->Find( pPaintKit->GetLocalizeName() );
loc_scpy_safe( out_pItemName, pPaintKitStr ? pPaintKitStr : LOCCHAR( "" ) );
#endif
}
// ---------------------------------------------------------------------------------------------------------------------------
void Econ_ConcatPaintKitName( locchar_t( &out_pItemName )[MAX_ITEM_NAME_LENGTH], const CLocalizationProvider *pLocalizationProvider, CEconItemPaintKitDefinition *pPaintKit )
{
if ( !pPaintKit )
return;
// Check to see if the paintkit localized name already has the weapon name, if so do not add (Weapon)
locchar_t *pPaintKitStr = pLocalizationProvider->FindSafe( pPaintKit->GetLocalizeName() );
locchar_t tempName[MAX_ITEM_NAME_LENGTH];
loc_scpy_safe( tempName, out_pItemName );
#ifndef GC
bool bAppendWeapon = wcsstr( pPaintKitStr, out_pItemName ) == NULL;
// Generate Paint kitted name
// IE Purple Rain Sniper Rifle
if ( bAppendWeapon )
{
g_pVGuiLocalize->ConstructString_safe( out_pItemName,
LOCCHAR("%s1 (%s2)"),
2,
pPaintKitStr,
tempName );
}
else
{
g_pVGuiLocalize->ConstructString_safe( out_pItemName,
LOCCHAR("%s1"),
1,
pPaintKitStr
);
}
#else
// GC doesn't have g_pVGuiLocalize so we construct the painted gun string like this
bool bAppendWeapon = V_strstr( pPaintKitStr, out_pItemName ) == NULL;
// Generate Paint kitted name
// IE Purple Rain Sniper Rifle
loc_scpy_safe( out_pItemName, pPaintKitStr ? pPaintKitStr : LOCCHAR( "" ) );
if ( bAppendWeapon )
{
loc_scat_safe( out_pItemName, LOCCHAR( " " ) );
loc_scat_safe( out_pItemName, tempName );
}
#endif
}
// ---------------------------------------------------------------------------------------------------------------------------
void Econ_ConcatPaintKitWear( locchar_t( &out_pItemName )[MAX_ITEM_NAME_LENGTH], const CLocalizationProvider *pLocalizationProvider, float flWear )
{
if ( flWear <= 0.0 )
return;
#ifndef GC
locchar_t tempName[MAX_ITEM_NAME_LENGTH];
loc_scpy_safe( tempName, out_pItemName );
g_pVGuiLocalize->ConstructString_safe( out_pItemName,
LOCCHAR( "%s1 (%s2)" ),
2,
tempName,
pLocalizationProvider->Find( GetWearLocalizationString( flWear ) )
);
#else
// GC doesn't have g_pVGuiLocalize so we construct the painted gun string like this
locchar_t *pWearStr = pLocalizationProvider->Find( GetWearLocalizationString( flWear ) );
loc_scat_safe( out_pItemName, LOCCHAR( " (" ) );
loc_scat_safe( out_pItemName, pWearStr ? pWearStr : LOCCHAR( "" ) );
loc_scat_safe( out_pItemName, LOCCHAR( ")" ) );
#endif
}
// ---------------------------------------------------------------------------------------------------------------------------
static bool GetLocalizedBaseItemName( locchar_t (&szItemName)[MAX_ITEM_NAME_LENGTH], const CLocalizationProvider *pLocalizationProvider, const CEconItemDefinition *pEconItemDefinition )
{
if ( pEconItemDefinition->GetItemBaseName() )
{
const locchar_t *pLocalizedItemName = pLocalizationProvider->Find( pEconItemDefinition->GetItemBaseName() );
if ( !pLocalizedItemName || !pLocalizedItemName[0] )
{
// Couldn't localize it, just use it raw
pLocalizationProvider->ConvertUTF8ToLocchar( pEconItemDefinition->GetItemBaseName(), szItemName, ARRAYSIZE( szItemName ) );
}
else
{
loc_scpy_safe( szItemName, pLocalizedItemName );
}
return true;
}
return false;
}
// Given the item in pEconItem and the localization provider passed in, stuff the correct *localized*
// string into out_pItemName.
static void GenerateLocalizedFullItemName
(
locchar_t (&out_pItemName)[MAX_ITEM_NAME_LENGTH],
const CLocalizationProvider *pLocalizationProvider,
const IEconItemInterface *pEconItem,
EGenerateLocalizedFullItemNameFlag_t eFlagsMask,
bool bHashContextOff
)
{
bool bUseProperName = bHashContextOff;
Assert( pLocalizationProvider );
Assert( pEconItem );
static const locchar_t *s_pUnknownItemName = LOCCHAR("Unknown Item");
const CEconItemDefinition *pEconItemDefinition = pEconItem->GetItemDefinition();
if ( !pEconItemDefinition )
{
out_pItemName[0] = (locchar_t)0;
return;
}
bool bIgnoreQualityAndWear = false;
bool bIgnoreNameWithPaintkit = false;
bool bHasCustomName = false;
if ( eFlagsMask == k_EGenerateLocalizedFullItemName_Default )
{
bIgnoreQualityAndWear = pEconItem->GetCustomPainkKitDefinition() ? true : false;
}
if ( eFlagsMask == k_EGenerateLocalizedFullItemName_WithPaintkitNoItem )
{
bIgnoreNameWithPaintkit = pEconItem->GetCustomPainkKitDefinition() ? true : false;
bIgnoreQualityAndWear = pEconItem->GetCustomPainkKitDefinition() ? true : false;
}
// Figure out which localization pattern we're using. By default we assume we're using the common "[Quality] [Item Name]"
// format, but if we're a unique item with an article we'll change this later on.
const char *pszLocalizationPattern = "ItemNameFormat";
// Start with the base name.
locchar_t szItemName[ MAX_ITEM_NAME_LENGTH ];
static CSchemaAttributeDefHandle pAttrDef_ItemNameTextOverride( "item name text override" );
CAttribute_String attrItemNameTextOverride;
// Check if we ahve a item name override
if ( pEconItem->FindAttribute( pAttrDef_ItemNameTextOverride, &attrItemNameTextOverride ) )
{
const locchar_t *pNameOverrideString = pLocalizationProvider->Find( attrItemNameTextOverride.value().c_str() );
if ( pNameOverrideString )
{
loc_scpy_safe( szItemName, pNameOverrideString );
bHasCustomName = true;
}
}
else if( !GetLocalizedBaseItemName( szItemName, pLocalizationProvider, pEconItemDefinition ) )
{
loc_scpy_safe( szItemName, s_pUnknownItemName );
}
// Check for killstreak attribute
enum { kKillStreakLength = 64, };
locchar_t szKillStreak[ kKillStreakLength ] = LOCCHAR("");
static CSchemaAttributeDefHandle pAttrDef_KillStreak( "killstreak tier" );
uint32 nKillStreakValue;
if ( pEconItem->FindAttribute( pAttrDef_KillStreak, &nKillStreakValue ) && !bIgnoreQualityAndWear )
{
nKillStreakValue = (float&)(nKillStreakValue);
// if you have the eyeballs you are automatically higher tier
static CSchemaAttributeDefHandle pAttrDef_KillStreakEyes( "killstreak effect" );
static CSchemaAttributeDefHandle pAttrDef_KillStreakSheen( "killstreak idleeffect" );
if ( pEconItem->FindAttribute( pAttrDef_KillStreakEyes ) )
{
nKillStreakValue = 3; // professional
}
else if ( pEconItem->FindAttribute( pAttrDef_KillStreakSheen ) )
{
nKillStreakValue = 2; // specialized
}
const locchar_t *pKillStreakLocalizedString = NULL;
// All tier-1 killstreaks have idle effect 1
if ( nKillStreakValue == 1 )
{
pKillStreakLocalizedString = pLocalizationProvider->Find( "ItemNameKillStreakv0" );
}
else if ( nKillStreakValue == 2 )
{
pKillStreakLocalizedString = pLocalizationProvider->Find( "ItemNameKillStreakv1" );
}
else // Tier-2's are things above 1
{
pKillStreakLocalizedString = pLocalizationProvider->Find( "ItemNameKillStreakv2" );
}
if ( pKillStreakLocalizedString )
{
loc_scpy_safe( szKillStreak, pKillStreakLocalizedString );
// If we're appending some sort of killstreak identifier, dont use the proper name
bUseProperName = false;
}
}
// Check to see if we have a quality text override attribute. We can get this when a temporary item
// comes in from a crafting recipe that needs to get its name generated, and wants to specify that it
// takes in any quality
static CSchemaAttributeDefHandle pAttrDef_QualityTextOverride( "quality text override" );
CAttribute_String attrQualityTextOverride;
pEconItem->FindAttribute( pAttrDef_QualityTextOverride, &attrQualityTextOverride );
// Generate our quality string.
enum { kQualityLength = 128, };
locchar_t szQuality[ kQualityLength ] = LOCCHAR("");
// Unique names may have a prefix or not, and so use a different format. (This is less to deal
// with the space after "The" and more to deal with foreign languages that want to display unique
// and non-unique items differently.
const uint8 unQuality = pEconItem->GetQuality();
if ( unQuality == AE_SELFMADE || ( !bIgnoreQualityAndWear ) )
{
// It's possible to get in here with a quality of -1 if we're dealing with an item view that has no
// associated item. In that case we're probably doing something like browsing the armory, and in any
// event don't have an item and so don't have a quality and so we just don't show a quality string.
// If we have a quality text override, use that.
const char *pszQualityLocalizationString = attrQualityTextOverride.has_value()
? attrQualityTextOverride.value().c_str()
: EconQuality_GetLocalizationString( (EEconItemQuality)unQuality );
if ( unQuality > 0 && pszQualityLocalizationString && unQuality != AE_PAINTKITWEAPON )
{
// Unique items use proper names, but not if we have a quality text override
if ( unQuality == AE_UNIQUE && !attrQualityTextOverride.has_value() )
{
const locchar_t *pszArticleContent = NULL;
if ( bUseProperName && pEconItemDefinition->HasProperName() )
{
pszArticleContent = pLocalizationProvider->Find( "TF_Unique_Prepend_Proper" );
}
// If the language isn't supposed to have articles or we just haven't provided one yet, fall
// back to the empty string.
if ( !pszArticleContent )
{
pszArticleContent = LOCCHAR("");
}
loc_scpy_safe( szQuality, pszArticleContent );
}
// Any quality besides unique ignores "proper name" articles.
else
{
const locchar_t *pQualityLocalizedString = pLocalizationProvider->Find( pszQualityLocalizationString );
if ( pQualityLocalizedString )
{
loc_scpy_safe( szQuality, pQualityLocalizedString );
loc_scat_safe( szQuality, LOCCHAR(" ") );
}
}
}
{
static CSchemaAttributeDefHandle pAttrDef_HideStrangePrefix( "hide_strange_prefix" );
if ( !pAttrDef_HideStrangePrefix || !pEconItem->FindAttribute( pAttrDef_HideStrangePrefix ) )
{
//
CStrangeRankLocalizationGenerator RankGenerator( pLocalizationProvider, pEconItem, bHashContextOff );
if ( RankGenerator.IsValid() )
{
// If the quality of this item is special (not just strange) persist and append that value
// Otherwise the ranker will replace the 'strange' quality tag with a strange rank
if ( unQuality == AE_STRANGE )
{
loc_scpy_safe( szQuality,
CConstructLocalizedString( LOCCHAR("%s1%s2 "),
RankGenerator.GetRankLocalized(),
RankGenerator.GetRankSecondaryLocalized() ? RankGenerator.GetRankSecondaryLocalized() : LOCCHAR("") ) );
}
else // Strange Unusual Something
{
loc_scpy_safe( szQuality,
CConstructLocalizedString( LOCCHAR("%s1%s2 %s3"),
RankGenerator.GetRankLocalized(),
RankGenerator.GetRankSecondaryLocalized() ? RankGenerator.GetRankSecondaryLocalized() : LOCCHAR(""),
szQuality) );
}
}
}
}
}
static CSchemaAttributeDefHandle pAttrDef_IsAustralium( "is australium item" );
enum { kAustraliumLength = 64, };
locchar_t szAustraliumSkin[ kAustraliumLength ] = LOCCHAR("");
if ( pAttrDef_IsAustralium && pEconItem->FindAttribute( pAttrDef_IsAustralium ) )
{
const locchar_t *pAustraliumLocalizedString = pLocalizationProvider->Find( "ItemNameAustralium" );
if ( pAustraliumLocalizedString )
{
loc_scpy_safe( szAustraliumSkin, pAustraliumLocalizedString );
}
}
static CSchemaAttributeDefHandle pAttrDef_IsFestivized( "is_festivized" );
enum { kFestiveLength = 64, };
locchar_t szIsFestivized[kFestiveLength] = LOCCHAR( "" );
if ( pAttrDef_IsFestivized && pEconItem->FindAttribute( pAttrDef_IsFestivized ) )
{
// TODO : update ItemNameFestive in tf_english to Festivized later to differentiate Festive vs Festivized
const locchar_t *pFestivizedLocalizedString = pLocalizationProvider->Find( "ItemNameFestive" );
if ( pFestivizedLocalizedString )
{
loc_scpy_safe( szIsFestivized, pFestivizedLocalizedString );
}
}
const char* pszQualityFormat = ( !attrQualityTextOverride.has_value() && ( unQuality == AE_NORMAL || unQuality == AE_UNIQUE || unQuality == AE_PAINTKITWEAPON || bIgnoreQualityAndWear ) && unQuality != AE_SELFMADE )
? "ItemNameNormalOrUniqueQualityFormat"
: "ItemNameQualityFormat";
// TODO : Make Generic
// Journal Leveling
uint32 unDuckBadgeLevel;
static CSchemaAttributeDefHandle pAttrDef_DuckBadgeLevel( "duck rating" );
enum { kDuckBadgeLength = 64, };
locchar_t szDuckBadge[kDuckBadgeLength] = LOCCHAR("");
{ //if ( pItem && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pItem, pAttr_DuckLevelBadge, &iDuckBadgeLevel ) )
if ( pAttrDef_DuckBadgeLevel && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttrDef_DuckBadgeLevel, &unDuckBadgeLevel ) && unDuckBadgeLevel != 0 )
{
const CItemLevelingDefinition *pLevelDef = GetItemSchema()->GetItemLevelForScore( "Journal_DuckBadge", unDuckBadgeLevel );
if ( pLevelDef )
{
loc_scpy_safe( szDuckBadge, pLocalizationProvider->Find( pLevelDef->GetNameLocalizationKey() ) );
loc_scat_safe( szDuckBadge, LOCCHAR(" ") );
}
}
}
// Strange Unusual Festive Killstreak Australium ducks
loc_scpy_safe( szQuality, CConstructLocalizedString( pLocalizationProvider->Find( pszQualityFormat ), szQuality, szIsFestivized, szKillStreak, szAustraliumSkin, szDuckBadge ) );
enum { kLocalizedCrateSeriesLength = 128, };
locchar_t szLocalizedCrateSeries[ kLocalizedCrateSeriesLength ] = LOCCHAR("");
#ifdef PROJECT_TF
static CSchemaAttributeDefHandle pAttrDef_SupplyCrateSeries( "set supply crate series" );
// do not display series number for crates that have a collection reference
if ( pAttrDef_SupplyCrateSeries && pEconItemDefinition->GetItemClass() && !Q_stricmp( pEconItemDefinition->GetItemClass(), "supply_crate" ) && !pEconItemDefinition->GetCollectionReference() )
{
// It's a crate, find a series #
uint32 unSupplyCrateSeries;
float fSupplyCrateSeries;
if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttrDef_SupplyCrateSeries, &fSupplyCrateSeries ) && fSupplyCrateSeries != 0.0f )
{
unSupplyCrateSeries = fSupplyCrateSeries;
loc_scpy_safe( szLocalizedCrateSeries,
CConstructLocalizedString( pLocalizationProvider->Find( "ItemNameCraftSeries" ),
unSupplyCrateSeries ) );
}
}
// This is not "crate series number"; this is "release series number", ie., "a series 3 chemistry kit".
static CSchemaAttributeDefHandle pAttrDef_SeriesNumber( "series number" );
if ( pAttrDef_SeriesNumber )
{
float flSeriesNumber = 0.0f;
if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttrDef_SeriesNumber, &flSeriesNumber ) && flSeriesNumber != 0.0f )
{
uint32 unSeriesNumber = flSeriesNumber;
loc_scpy_safe( szLocalizedCrateSeries,
CConstructLocalizedString( pLocalizationProvider->Find( "ItemNameCraftSeries" ),
unSeriesNumber ) );
}
}
#endif
// Were we one of the first couple that were crafted? If so, output our craft number as well.
locchar_t *pCraftNumberLocFormat = pLocalizationProvider->Find( "ItemNameCraftNumberFormat" );
enum { kLocalizedCraftIndexLength = 128, };
locchar_t szLocalizedCraftIndex[ kLocalizedCraftIndexLength ] = LOCCHAR("");
if ( pCraftNumberLocFormat )
{
static CSchemaAttributeDefHandle pAttrDef_UniqueCraftIndex( "unique craft index" );
uint32 unCraftIndex;
if ( pEconItem->FindAttribute( pAttrDef_UniqueCraftIndex, &unCraftIndex ) &&
ShouldDisplayCraftCounterValue( unCraftIndex ) )
{
locchar_t szCraftNumber[ kLocalizedCraftIndexLength ];
loc_sprintf_safe( szCraftNumber, LOCCHAR( "%i" ), unCraftIndex );
ILocalize::ConstructString_safe( szLocalizedCraftIndex,
pCraftNumberLocFormat,
1,
szCraftNumber );
}
}
// Generate tool application string
enum { kToolApplicationNameLength = 128, };
locchar_t szToolTargetNameName[ kToolApplicationNameLength ] = LOCCHAR("");
locchar_t szDynamicRecipeOutputName[ kToolApplicationNameLength ] = LOCCHAR("");
static CSchemaAttributeDefHandle pAttribDef_ToolTarget( "tool target item" );
if( pAttribDef_ToolTarget && pEconItem->GetItemDefinition()->GetItemClass() && !Q_stricmp( pEconItem->GetItemDefinition()->GetItemClass(), "tool" ) )
{
// It's a tool, see if it has a tool target item attribute
float flItemDef;
if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttribDef_ToolTarget, &flItemDef ) )
{
const item_definition_index_t unItemDef = flItemDef;
locchar_t szTargetItemName[ MAX_ITEM_NAME_LENGTH ] = LOCCHAR("Unknown Item");
// Get base name of target item
const CEconItemDefinition *pEconTargetDef = GetItemSchema()->GetItemDefinition( unItemDef );
if ( pEconTargetDef )
{
GetLocalizedBaseItemName( szTargetItemName, pLocalizationProvider, pEconTargetDef );
}
loc_scpy_safe( szToolTargetNameName,
CConstructLocalizedString( pLocalizationProvider->Find( "ItemNameToolTargetNameFormat" ),
szTargetItemName ) );
}
else
{
CRecipeComponentMatchingIterator componentIterator( pEconItem, NULL );
pEconItem->IterateAttributes( &componentIterator );
// It only makes sense to mention the output if there's only 1 output
if( componentIterator.GetMatchingComponentOutputs().Count() == 1 )
{
CAttribute_DynamicRecipeComponent attribValue;
pEconItem->FindAttribute( componentIterator.GetMatchingComponentOutputs().Head(), &attribValue );
CEconItem tempItem;
if ( !DecodeItemFromEncodedAttributeString( attribValue, &tempItem ) )
{
AssertMsg2( 0, "%s: Unable to decode dynamic recipe output attribute on item %llu.", __FUNCTION__, pEconItem->GetID() );
}
else
{
locchar_t loc_ItemName[MAX_ITEM_NAME_LENGTH];
GenerateLocalizedFullItemName( loc_ItemName, pLocalizationProvider, &tempItem, k_EGenerateLocalizedFullItemName_Default, false );
loc_scpy_safe( szDynamicRecipeOutputName,
CConstructLocalizedString( pLocalizationProvider->Find( "ItemNameDynamicRecipeTargetNameFormat" ),
loc_ItemName ) );
}
}
}
}
// PaintKit and Wear
if ( !bHasCustomName )
{
CEconItemPaintKitDefinition *pPaintKit = pEconItem->GetCustomPainkKitDefinition();
if ( pPaintKit )
{
if ( bIgnoreNameWithPaintkit )
{
Econ_SetNameAsPaintkit( szItemName, pLocalizationProvider, pPaintKit );
}
else
{
Econ_ConcatPaintKitName( szItemName, pLocalizationProvider, pPaintKit );
if ( !bIgnoreQualityAndWear )
{
float flWear = 0;
if ( pEconItem->GetCustomPaintKitWear( flWear ) )
{
Econ_ConcatPaintKitWear( szItemName, pLocalizationProvider, flWear );
}
}
}
}
}
locchar_t *pNameLocalizationFormat = pLocalizationProvider->Find( pszLocalizationPattern );
if ( pNameLocalizationFormat )
{
ILocalize::ConstructString_safe( out_pItemName,
pNameLocalizationFormat,
6,
szQuality,
szItemName,
szLocalizedCraftIndex,
szLocalizedCrateSeries,
szToolTargetNameName,
szDynamicRecipeOutputName);
}
else
{
loc_scpy_safe( out_pItemName, s_pUnknownItemName );
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_ItemName( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// If this item has a custom name, use it instead of doing our crazy name compositing based on quality,
// type, etc.
const char *utf8_CustomName = pEconItem->GetCustomName();
if ( utf8_CustomName && utf8_CustomName[0] )
{
locchar_t loc_CustomName[ MAX_ITEM_NAME_LENGTH ];
pLocalizationProvider->ConvertUTF8ToLocchar( utf8_CustomName, loc_CustomName, sizeof( loc_CustomName ) );
// Store it in the item name, wrapped in quotes to prevent item name spoofing
// We use two single quotes, because the double quote isn't very visible in the TF2 font
locchar_t loc_CustomNameWithQuotes[ MAX_ITEM_NAME_LENGTH ];
loc_scpy_safe( loc_CustomNameWithQuotes, LOCCHAR("''") );
loc_scat_safe( loc_CustomNameWithQuotes, loc_CustomName );
loc_scat_safe( loc_CustomNameWithQuotes, LOCCHAR("''") );
AddDescLine( loc_CustomNameWithQuotes, /* this will be ignored: */ ATTRIB_COL_LEVEL, kDescLineFlag_Name );
}
else
{
locchar_t loc_ItemName[MAX_ITEM_NAME_LENGTH];
GenerateLocalizedFullItemName( loc_ItemName, pLocalizationProvider, pEconItem, k_EGenerateLocalizedFullItemName_WithPaintkitNoItem, m_pHashContext == NULL );
AddDescLine( loc_ItemName, /* this will be ignored: */ ATTRIB_COL_LEVEL, kDescLineFlag_Name );
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
const locchar_t *GetLocalizedStringForKillEaterTypeAttr( const CLocalizationProvider *pLocalizationProvider, uint32 unKillEaterEventType )
{
Assert( pLocalizationProvider );
// Generate localized string.
const char *pszLocString = GetItemSchema()->GetKillEaterScoreTypeLocString( unKillEaterEventType );
return pszLocString != NULL
? pLocalizationProvider->Find( pszLocString )
: LOCCHAR("");
}
class CStrangeRestrictionAttrWrapper
{
public:
CStrangeRestrictionAttrWrapper( const CLocalizationProvider *pLocalizationProvider, const locchar_t *loc_In )
: m_str( loc_In ? pLocalizationProvider->Find( "ItemTypeDescStrangeFilterSubStr" ) : LOCCHAR(""), loc_In ? loc_In : LOCCHAR("") )
{
//
}
const locchar_t *operator *() const
{
return static_cast<const locchar_t *>( m_str );
}
private:
CConstructLocalizedString m_str;
};
const locchar_t *CEconItemDescription::GetLocalizedStringForStrangeRestrictionAttr( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem, int iAttrIndex ) const
{
uint32 unRestrictionType;
uint32 unRestrictionValue;
if ( !pEconItem->FindAttribute( GetKillEaterAttr_Restriction( iAttrIndex ), &unRestrictionType ) ||
!pEconItem->FindAttribute( GetKillEaterAttr_RestrictionValue( iAttrIndex ), &unRestrictionValue ) ||
unRestrictionType == kStrangeEventRestriction_None )
{
return NULL;
}
switch ( unRestrictionType )
{
#ifdef PROJECT_TF
case kStrangeEventRestriction_Map:
{
const MapDef_t *pMap = GetItemSchema()->GetMasterMapDefByIndex( unRestrictionValue );
if ( pMap )
return pLocalizationProvider->Find( pMap->pszMapNameLocKey );
}
case kStrangeEventRestriction_Competitive:
{
return pLocalizationProvider->Find( "ItemTypeDescStrangeFilterCompetitive" );
}
#endif // PROJECT_TF
case kStrangeEventRestriction_VictimSteamAccount:
return FindAccountPersonaName( unRestrictionValue );
}
return NULL;
}
bool CEconItemDescription::BGenerate_ItemLevelDesc_StrangeNameAndStats( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem, const locchar_t *locTypename )
{
CStrangeRankLocalizationGenerator RankGenerator( pLocalizationProvider, pEconItem, m_pHashContext == NULL );
if ( !RankGenerator.IsValid() )
return false;
// For Collection Items
if ( pEconItem->GetCustomPainkKitDefinition() )
{
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "Attrib_stattrakmodule" ), RankGenerator.GetRankLocalized() ),
ATTRIB_COL_STRANGE,
kDescLineFlag_Misc
);
// Are we tracking alternate stats as well?
for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
{
const CEconItemAttributeDefinition *pKillEaterAltAttrDef = GetKillEaterAttr_Score( i ),
*pKillEaterAltScoreTypeAttrDef = GetKillEaterAttr_Type( i );
if ( !pKillEaterAltAttrDef || !pKillEaterAltScoreTypeAttrDef )
continue;
uint32 unKillEaterAltScore;
if ( !pEconItem->FindAttribute( pKillEaterAltAttrDef, &unKillEaterAltScore ) )
continue;
// Older items can optionally not specify a type attribute at all and have an implicit "I'm tracking
// kills" zeroth attribute. We require a score type for any slot besides that.
if ( i != 0 && !pEconItem->FindAttribute( pKillEaterAltScoreTypeAttrDef ) )
continue;
const uint32 unKillEaterAltType = GetScoreTypeForKillEaterAttr( pEconItem, pKillEaterAltScoreTypeAttrDef );
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "ItemTypeDescKillEaterAltv2" ),
unKillEaterAltScore,
GetLocalizedStringForKillEaterTypeAttr( pLocalizationProvider, unKillEaterAltType ),
*CStrangeRestrictionAttrWrapper( pLocalizationProvider, GetLocalizedStringForStrangeRestrictionAttr( pLocalizationProvider, pEconItem, i ) ) ),
ATTRIB_COL_LEVEL,
kDescLineFlag_Misc ); // strange item scores past the first are not considered part of the type
}
return true;
} // End Collection Items
// Normal old way
// Look for Limited Item Attr
bool bLimitedQuantity = false;
static CSchemaAttributeDefHandle pAttrDef_LimitedQuantityItem( "limited quantity item" );
bLimitedQuantity = pEconItem->FindAttribute( pAttrDef_LimitedQuantityItem );
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "ItemTypeDescKillEater" ),
RankGenerator.GetRankLocalized(),
locTypename ? locTypename : LOCCHAR(""),
RankGenerator.GetStrangeScore(),
GetLocalizedStringForKillEaterTypeAttr( pLocalizationProvider, RankGenerator.GetStrangeType() ),
*CStrangeRestrictionAttrWrapper( pLocalizationProvider, GetLocalizedStringForStrangeRestrictionAttr( pLocalizationProvider, pEconItem, RankGenerator.GetUsedStrangeSlot() ) ),
RankGenerator.GetRankSecondaryLocalized() ? RankGenerator.GetRankSecondaryLocalized() : LOCCHAR(""),
bLimitedQuantity ? pLocalizationProvider->Find( "LimitedQualityDesc" ) : LOCCHAR("")
),
bLimitedQuantity ? ATTRIB_COL_LIMITED_QUANTITY : ATTRIB_COL_LEVEL,
kDescLineFlag_Type );
// Are we tracking alternate stats as well?
for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
{
const CEconItemAttributeDefinition *pKillEaterAltAttrDef = GetKillEaterAttr_Score(i),
*pKillEaterAltScoreTypeAttrDef = GetKillEaterAttr_Type(i);
if ( !pKillEaterAltAttrDef || !pKillEaterAltScoreTypeAttrDef )
continue;
uint32 unKillEaterAltScore;
if ( !pEconItem->FindAttribute( pKillEaterAltAttrDef, &unKillEaterAltScore ) )
continue;
// Older items can optionally not specify a type attribute at all and have an implicit "I'm tracking
// kills" zeroth attribute. We require a score type for any slot besides that.
if ( i != 0 && !pEconItem->FindAttribute( pKillEaterAltScoreTypeAttrDef ) )
continue;
const uint32 unKillEaterAltType = GetScoreTypeForKillEaterAttr( pEconItem, pKillEaterAltScoreTypeAttrDef );
// Skip if this is our primary stat and we already output it above.
if ( unKillEaterAltType == RankGenerator.GetStrangeType() )
continue;
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "ItemTypeDescKillEaterAlt" ),
unKillEaterAltScore,
GetLocalizedStringForKillEaterTypeAttr( pLocalizationProvider, unKillEaterAltType ),
*CStrangeRestrictionAttrWrapper( pLocalizationProvider, GetLocalizedStringForStrangeRestrictionAttr( pLocalizationProvider, pEconItem, i ) ) ),
ATTRIB_COL_LEVEL,
kDescLineFlag_Misc ); // strange item scores past the first are not considered part of the type
}
return true;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
uint32 GetItemDescriptionDisplayLevel( const IEconItemInterface *pEconItem )
{
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_WideItemLevel( "wide item level" );
uint32 unWideLevelValue;
if ( pEconItem->FindAttribute( pAttrDef_WideItemLevel, &unWideLevelValue ) )
return unWideLevelValue;
return pEconItem->GetItemLevel();
}
void CEconItemDescription::Generate_ItemLevelDesc_Default( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem, const locchar_t *locTypename )
{
// By default, items will only show the level if there is an item type to go along with it.
// Combined, these will build a string like "Level 10 Shotgun". We allow a custom attribute
// to force the level to be displayed by itself even if there is no item class ("Level 10").
static CSchemaAttributeDefHandle pAttrDef_ForceLevelDisplay( "force_level_display" );
item_definition_index_t usDefIndex = pEconItem->GetItemDefIndex();
#ifdef CLIENT_DLL
const bool bIsStoreItem = IsStorePreviewItem( pEconItem );
const bool bIsPreviewItem = pEconItem->GetFlags() & kEconItemFlagClient_Preview;
// If the item doesn't have a valid itemID, we'll just use the locTypename for the item level description.
// We don't want to display "Level 0 Hat" in places like the Mann Co. Store and Armory. We'll just display "Hat".
if ( bIsStoreItem || bIsPreviewItem || pEconItem->GetItemDefinition()->GetRarity() != k_unItemRarity_Any )
{
if ( locTypename && *locTypename )
{
AddDescLine( locTypename, ATTRIB_COL_LEVEL, kDescLineFlag_Type, NULL, usDefIndex );
}
return;
}
#endif
float fForceLevelDisplayValue;
bool bForceLevelDisplay = FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttrDef_ForceLevelDisplay, &fForceLevelDisplayValue )
&& fForceLevelDisplayValue > 0.0f;
if ( ( locTypename && *locTypename ) || bForceLevelDisplay )
{
if ( locTypename )
{
// How are we going to format our level number and base type string?
const locchar_t *pszFormatString = NULL;
#ifdef PROJECT_TF
static CSchemaAttributeDefHandle pAttrDef_OverrideItemLevelDescString( CTFItemSchema::k_rchOverrideItemLevelDescStringAttribName );
static const char *s_pszCustomItemLevelDescLocalizationTokens[] =
{
"ItemTypeDescCustomLevelString_MvMTour",
};
// ...are we going to use a custom format string specified in an attribute?
uint32 unOverrideItemLevelDescString = 0;
if ( pEconItem->FindAttribute( pAttrDef_OverrideItemLevelDescString, &unOverrideItemLevelDescString )
&& unOverrideItemLevelDescString != 0
&& unOverrideItemLevelDescString <= ARRAYSIZE( s_pszCustomItemLevelDescLocalizationTokens ) )
{
const char *pszLevelLocalizationToken = s_pszCustomItemLevelDescLocalizationTokens[ unOverrideItemLevelDescString - 1 ];
Assert( pszLevelLocalizationToken );
pszFormatString = pLocalizationProvider->Find( pszLevelLocalizationToken );
}
#endif // PROJECT_TF
// Either we didn't have a custom override attribute, or we did and it had an invalid value, or it had a valid
// value but the localization system failed to find something for that key. In any event, we fall back to our default
// format string here.
if ( pszFormatString == NULL )
{
bool bLimitedQuantity = false;
static CSchemaAttributeDefHandle pAttrDef_LimitedQuantityItem( "limited quantity item" );
bLimitedQuantity = pEconItem->FindAttribute( pAttrDef_LimitedQuantityItem );
#if defined( TF_CLIENT_DLL )
if ( pEconItem->GetItemDefinition()->GetItemClass() && V_strcmp( pEconItem->GetItemDefinition()->GetItemClass(), "map_token" ) == 0 )
{
// For map stamps on the client we can show how many hours they've played each map
// And how many times they've donated to it instead of the generic "level"
for ( int i = 0; i < GetItemSchema()->GetMapCount(); i++ )
{
const MapDef_t* pMap = GetItemSchema()->GetMasterMapDefByIndex( i );
if ( pMap->mapStampDef != pEconItem->GetItemDefinition() )
continue;
int nItemLevel = MapInfo_GetDonationAmount( steamapicontext->SteamUser()->GetSteamID().GetAccountID(), pMap->pszMapName );
MapStats_t &mapStats = GetMapStats( pMap->GetStatsIdentifier() );
int nNumHours = ( mapStats.accumulated.m_iStat[TFMAPSTAT_PLAYTIME] ) / ( 60 /*sec*/ * 60 /*min*/ );
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "ItemTypeDescCustomLevelString_MapStamp" ), (uint32)nItemLevel, (uint32)nNumHours ), ATTRIB_COL_LEVEL, kDescLineFlag_Type );
return;
}
}
else
#endif
{
if ( bLimitedQuantity )
{
// Limited Item Description
pszFormatString = pLocalizationProvider->Find( "ItemTypeDescLimited" );
AddDescLine( CConstructLocalizedString(
pszFormatString,
GetItemDescriptionDisplayLevel( pEconItem ),
locTypename,
pLocalizationProvider->Find( "LimitedQualityDesc" ) ),
ATTRIB_COL_LIMITED_QUANTITY,
kDescLineFlag_Type,
NULL,
usDefIndex
);
return;
}
pszFormatString = pLocalizationProvider->Find( "ItemTypeDesc" );
}
}
// If we still don't have a format string here, it means our default also failed, but CConstructLocalizedString will
// handle that safely.
AddDescLine( CConstructLocalizedString( pszFormatString, GetItemDescriptionDisplayLevel( pEconItem ), locTypename ), ATTRIB_COL_LEVEL, kDescLineFlag_Type, NULL, usDefIndex );
}
else
{
Assert( bForceLevelDisplay );
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "ItemTypeDescNoLevel" ), GetItemDescriptionDisplayLevel( pEconItem ) ), ATTRIB_COL_LEVEL, kDescLineFlag_Type, NULL, usDefIndex );
}
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_ItemLevelDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const locchar_t *locTypename = pLocalizationProvider->Find( pItemDef->GetItemTypeName() );
// Kill-eating weapons replace the standard weapon name/level line with a label
// describing the current class of the item instead of the level. This overrides
// even "force_level_display".
if ( BGenerate_ItemLevelDesc_StrangeNameAndStats( pLocalizationProvider, pEconItem, locTypename ) )
return;
// Not strange, but if you are paint kitted or have a collection reference dont create this
if ( pEconItem->GetCustomPainkKitDefinition() || pItemDef->GetCollectionReference() )
return;
// If we didn't generate a fancy strange name, we fall back to our default behavior.
Generate_ItemLevelDesc_Default( pLocalizationProvider, pEconItem, locTypename );
}
#if defined( STAGING_ONLY ) && defined( CLIENT_DLL )
ConVar econ_include_debug_item_description( "econ_include_debug_item_description","0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE, "Controls display of the additional debug fields in CEconItemDescription (definition index, etc.)." );
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_DebugInformation( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
if ( !econ_include_debug_item_description.GetBool() )
return;
#if TF_ANTI_IDLEBOT_VERIFICATION
// Adding these extra description lines would mess with our GC/client sync.
if ( m_pHashContext )
return;
#endif // TF_ANTI_IDLEBOT_VERIFICATION
AddDescLine( CConstructLocalizedString( LOCCHAR("([ Item ID: %s1 ])"), pEconItem->GetID() ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
AddDescLine( CConstructLocalizedString( LOCCHAR("([ Item Definition Index: %s1 ])"), (uint32)pEconItem->GetItemDefIndex() ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
AddDescLine( CConstructLocalizedString( LOCCHAR("([ In Use?: %s1 ])"), pEconItem->GetInUse() ? LOCCHAR("true") : LOCCHAR("false") ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
AddEmptyDescLine();
class CDebugAttributeDisplayer : public IEconItemAttributeIterator
{
public:
CDebugAttributeDisplayer( CEconItemDescription *pOut_Desc ) : m_pDesc( pOut_Desc ) { Assert( m_pDesc ); }
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, attrib_value_t value ) OVERRIDE
{
// Ugh.
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR("([ Attribute [%s1]: '%s2' ( %s3 | %s4 ) ])"),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef,
*(uint32 *)&value,
*(float *)&value ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, float value ) OVERRIDE
{
// Ugh.
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR("([ Attribute [%s1]: '%s2' ( %f ) ])"),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef,
value ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const uint64& value ) OVERRIDE
{
// Ugh.
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR("([ Attribute [%s1]: '%s2' ( %llu ) ])"),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef,
value ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_String& value ) OVERRIDE
{
// Ugh.
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
wchar_t wszAttrContents[ 1024 ];
ILocalize::ConvertANSIToUnicode( value.value().c_str(), &wszAttrContents[0], sizeof( wszAttrContents ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR("([ Attribute [%s1]: '%s2' ( \"%s3\" ) ])"),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef,
wszAttrContents ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_DynamicRecipeComponent& value ) OVERRIDE
{
const char* pszItemName = GetItemSchema()->GetItemDefinition( value.def_index() )->GetItemBaseName();
wchar_t wszItemQuality[ 256 ];
ILocalize::ConvertANSIToUnicode( EconQuality_GetQualityString(EEconItemQuality(value.item_quality())), &wszItemQuality[0], sizeof( wszItemQuality ) );
wchar_t wszAttrString[ 256 ];
ILocalize::ConvertANSIToUnicode( value.attributes_string().c_str(), &wszAttrString[0], sizeof( wszAttrString ) );
wchar_t wszCount[ 64 ];
ILocalize::ConvertANSIToUnicode( CFmtStr( "%d/%d", value.num_fulfilled(), value.num_required() ), &wszCount[0], sizeof( wszCount ) );
locchar_t wszLocalizedItemName[ 128 ];
const locchar_t *pLocalizedItemName = GLocalizationProvider()->Find( pszItemName );
if ( pLocalizedItemName )
{
V_wcscpy_safe( wszLocalizedItemName, pLocalizedItemName );
}
else
{
// name wasn't found by Find(), so just convert the pszItemName
ILocalize::ConvertANSIToUnicode( pszItemName, &wszLocalizedItemName[0], sizeof( wszLocalizedItemName ) );
}
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR( "\nItem: \"%s1\"\nQuality: %s2\nAttribs:%s3\nCount: %s4" ),
wszLocalizedItemName,
wszItemQuality,
wszAttrString,
wszCount ),
ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_ItemSlotCriteria& value ) OVERRIDE
{
// Ugh.
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
wchar_t wszAttrTags[ 256 ];
ILocalize::ConvertANSIToUnicode( value.tags().c_str(), &wszAttrTags[0], sizeof( wszAttrTags ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR("([ Attribute [%s1]: '%s2'])\nTags: \"%s3\""),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef,
wszAttrTags ),
ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_WorldItemPlacement& value ) OVERRIDE
{
wchar_t wszAttrDef[ 256 ];
ILocalize::ConvertANSIToUnicode( pAttrDef->GetDefinitionName(), &wszAttrDef[0], sizeof( wszAttrDef ) );
m_pDesc->AddDescLine( CConstructLocalizedString( LOCCHAR( "([ Attribute [%s1]: '%s2'])\n" ),
(uint32)pAttrDef->GetDefinitionIndex(),
wszAttrDef ),
ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
return true;
}
private:
CEconItemDescription *m_pDesc;
};
CDebugAttributeDisplayer DebugAttributeDisplayer( this );
pEconItem->IterateAttributes( &DebugAttributeDisplayer );
}
#endif // defined( STAGING_ONLY ) && defined( CLIENT_DLL )
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_CraftTag( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttribDef_MakersMarkId( "makers mark id" );
attrib_value_t value;
if ( !pEconItem->FindAttribute( pAttribDef_MakersMarkId, &value ) )
return;
AddAttributeDescription( pLocalizationProvider, pAttribDef_MakersMarkId, value );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_StyleDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const CEconStyleInfo *pStyle = pItemDef->GetStyleInfo( pEconItem->GetStyle() );
if ( !pStyle )
return;
const locchar_t *loc_StyleName = pLocalizationProvider->Find( pStyle->GetName() );
if ( !loc_StyleName )
return;
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Econ_Style_Desc" ), loc_StyleName ), ATTRIB_COL_LEVEL, kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_HolidayRestriction( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const char *pszHolidayRestriction = pItemDef->GetHolidayRestriction();
if ( !pszHolidayRestriction )
return;
// Report any special restrictions. We'll output in a different color depending on whether or not
// the restriction currently prevents the item from showing up.
LocalizedAddDescLine( pLocalizationProvider,
CFmtStr( "Econ_holiday_restriction_%s", pszHolidayRestriction ).Access(),
EconHolidays_IsHolidayActive( EconHolidays_GetHolidayForString( pszHolidayRestriction ), CRTime::RTime32TimeCur() ) ? ATTRIB_COL_LEVEL : ATTRIB_COL_NEGATIVE,
kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_QualityDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// Does this item quality have additional description information that goes along with
// besides the usual name/coloration changes?
const char *pszQualityDescLocalizationKey = NULL;
switch( pEconItem->GetQuality() )
{
case AE_SELFMADE:
pszQualityDescLocalizationKey = "Attrib_Selfmade_Description";
break;
case AE_COMMUNITY:
pszQualityDescLocalizationKey = "Attrib_Community_Description";
break;
}
// We don't need to do anything special.
if ( !pszQualityDescLocalizationKey )
return;
// If this item has a particle system attached but doesn't have the attribute that we usually use
// to attach particles, we hack it and dump out an extra line to show the particle system description
// as well.
static CSchemaAttributeDefHandle pAttrDef_ParticleEffect( "attach particle effect" );
static attachedparticlesystem_t *pSparkleSystem = GetItemSchema()->FindAttributeControlledParticleSystem( "community_sparkle" );
// If the schema understands these properties...
if ( pAttrDef_ParticleEffect && pSparkleSystem )
{
// ...and we don't have a real particle effect attribute attribute...
if ( !pEconItem->FindAttribute( pAttrDef_ParticleEffect ) )
{
// check for Unusual Cap def index (1173)
// We manually assign unusual effect to content author. No community sparkle
if ( pEconItem->GetItemDefIndex() != 1173 )
{
// ...then manually add the description as if we did.
float flSystemID = pSparkleSystem->nSystemID;
AddAttributeDescription( pLocalizationProvider, pAttrDef_ParticleEffect, *(uint32*)&flSystemID );
}
}
}
LocalizedAddDescLine( pLocalizationProvider, pszQualityDescLocalizationKey, ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_ItemRarityDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
const CEconItemRarityDefinition* pItemRarity = GetItemSchema()->GetRarityDefinition( pEconItem->GetItemDefinition()->GetRarity() );
if ( !pItemRarity )
return;
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const char *pszTooltip = "TFUI_InvTooltip_Rarity";
attrib_colors_t colorRarity = pItemRarity->GetAttribColor();
const locchar_t *loc_RarityText = pLocalizationProvider->Find( pItemRarity->GetLocKey() );
const locchar_t *locTypename = pLocalizationProvider->Find( pItemDef->GetItemTypeName() );
const locchar_t *loc_WearText = LOCCHAR("");
float flWear = 0;
if ( pEconItem->GetCustomPaintKitWear( flWear ) )
{
loc_WearText = pLocalizationProvider->Find( GetWearLocalizationString( flWear ) );
}
else
{
pszTooltip = "TFUI_InvTooltip_RarityNoWear";
}
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( pszTooltip ), loc_RarityText, locTypename, loc_WearText ), colorRarity, kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_WearAmountDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
if ( pEconItem->GetCustomPainkKitDefinition() == 0 )
return;
Assert( pLocalizationProvider );
Assert( pEconItem );
float flWear = 0;
if ( pEconItem->GetCustomPaintKitWear( flWear ) )
{
locchar_t loc_WearText[MAX_ATTRIBUTE_DESCRIPTION_LENGTH];
loc_scpy_safe( loc_WearText, pLocalizationProvider->Find( "#TFUI_InvTooltip_Wear" ) );
loc_scat_safe( loc_WearText, LOCCHAR( " " ) );
loc_scat_safe( loc_WearText, pLocalizationProvider->Find( GetWearLocalizationString( flWear ) ) );
AddDescLine( loc_WearText, ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_ItemDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// Show the custom description if it has one.
const char *utf8_CustomDesc = pEconItem->GetCustomDesc();
if ( utf8_CustomDesc && utf8_CustomDesc[0] )
{
locchar_t loc_CustomDesc[ MAX_ITEM_DESC_LENGTH ];
pLocalizationProvider->ConvertUTF8ToLocchar( utf8_CustomDesc, loc_CustomDesc, sizeof( loc_CustomDesc ) );
locchar_t loc_CustomDescWithQuotes[ MAX_ITEM_DESC_LENGTH ];
loc_scpy_safe( loc_CustomDescWithQuotes, LOCCHAR("''") );
loc_scat_safe( loc_CustomDescWithQuotes, loc_CustomDesc );
loc_scat_safe( loc_CustomDescWithQuotes, LOCCHAR("''") );
AddDescLine( loc_CustomDescWithQuotes, ATTRIB_COL_NEUTRAL, kDescLineFlag_Desc );
return;
}
// No custom description -- see if the item has a default description as part of the definition.
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
// Add any additional item description
if ( pItemDef->GetItemDesc() )
{
LocalizedAddDescLine( pLocalizationProvider, pItemDef->GetItemDesc(), ATTRIB_COL_NEUTRAL, kDescLineFlag_Desc );
}
// If we're a store preview item, show the available styles in the tooltip so potential buyers
// have more information.
if ( IsStorePreviewItem( pEconItem ) )
{
if ( pItemDef && pItemDef->GetNumStyles() > 0 )
{
AddEmptyDescLine();
LocalizedAddDescLine( pLocalizationProvider, "#Store_AvailableStyles_Header", ATTRIB_COL_LEVEL, kDescLineFlag_Misc );
for ( int i = 0; i < pItemDef->GetNumStyles(); i++ )
{
LocalizedAddDescLine( pLocalizationProvider, pItemDef->GetStyleInfo( i )->GetName(), ATTRIB_COL_LEVEL, kDescLineFlag_Misc );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
// If we have at least this many items in our bundle then display multiple entries
// per line. Otherwise display one item per line for clarity.
enum { kDescription_CompositeBundleEntriesCount = 15 };
void CEconItemDescription::Generate_Bundle( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const bundleinfo_t *pBundleInfo = pItemDef->GetBundleInfo();
if ( !pBundleInfo )
return;
enum EBundleEntryDisplayStyle
{
kBundleDisplay_SingleEntry, // one entry per line
kBundleDisplay_PairEntry, // "Some Item, Some Other Item," (with ending comma)
kBundleDisplay_PairEntryFinal, // "Some Item, Some Other Item" (with no ending comma)
};
#ifdef GC_DLL
AddEmptyDescLine();
#endif // GC_DLL
CUtlVector< item_definition_index_t > vecPackBundlesAdded;
FOR_EACH_VEC( pBundleInfo->vecItemDefs, i )
{
// Sanity check.
const CEconItemDefinition *pBundleItemDef = pBundleInfo->vecItemDefs[i];
if ( !pBundleItemDef )
continue;
// If the current item is part of a pack bundle, add the pack bundle to the description, rather than the individual item
#ifdef DOTA
if ( pBundleItemDef->IsPackItem() )
{
const CUtlVector< CEconItemDefinition * > &vecPackBundleItemDefs = pBundleItemDef->GetOwningPackBundles();
item_definition_index_t usPackBundleItemDefIndex = vecPackBundleItemDefs[i]->GetDefinitionIndex();
if ( vecPackBundlesAdded.HasElement( usPackBundleItemDefIndex ) )
continue;
// Remember the def index so we don't add the reference to the pack bundle more than once
vecPackBundlesAdded.AddToTail( usPackBundleItemDefIndex );
// Now, point pBundleItemDef at the pack bundle itself and carry on
pBundleItemDef = pPackBundleItemDef;
}
#endif
// Figure out which display style to use for this item. By default we put one item one each line...
EBundleEntryDisplayStyle eDisplayStyle = kBundleDisplay_SingleEntry;
// ...but if we have a whole bunch of items in a single bundle, we lump them together two per line to
// save space. Only do this on the client. On the GC, use single lines so that link meta data can be passed
// along per-line to the store bundle pages.
#if defined( CLIENT_DLL ) && !defined( TF_CLIENT_DLL )
if ( pBundleInfo->vecItemDefs.Count() >= kDescription_CompositeBundleEntriesCount )
{
const int iRemainingItems = pBundleInfo->vecItemDefs.Count() - i;
// We distinguish between "there are at least three entries left", which means we'll end the line
// with a comma, etc.
if ( iRemainingItems > 2 )
{
eDisplayStyle = kBundleDisplay_PairEntry;
}
// ...or if these are our very last two items, we list our last two items and that's it.
else if ( iRemainingItems == 2 )
{
eDisplayStyle = kBundleDisplay_PairEntryFinal;
}
}
#endif
if ( eDisplayStyle == kBundleDisplay_SingleEntry )
{
// pBundleItemDef will point at the pack bundle if pBundleItemDef is a pack item. In DotA, pack bundles *only* include pack items, whereas in TF, there are bundles which include some items where are individually for sale and others that are not. For example, the Scout Starter Bundle, etc.
#ifdef DOTA
LocalizedAddDescLine( pLocalizationProvider, pBundleItemDef->GetItemBaseName(), ATTRIB_COL_BUNDLE_ITEM, kDescLineFlag_Misc, NULL, pBundleItemDef->GetDefinitionIndex() );
#else
LocalizedAddDescLine( pLocalizationProvider, pBundleItemDef->GetItemBaseName(), pBundleItemDef->IsPackItem() ? ATTRIB_COL_NEUTRAL : ATTRIB_COL_BUNDLE_ITEM, kDescLineFlag_Misc, NULL, pBundleItemDef->IsPackItem() ? INVALID_ITEM_DEF_INDEX : pBundleItemDef->GetDefinitionIndex(), !pBundleItemDef->IsPackItem() );
#endif
}
else
{
Assert( eDisplayStyle == kBundleDisplay_PairEntry || eDisplayStyle == kBundleDisplay_PairEntryFinal );
const CEconItemDefinition *pOtherBundleItem = pBundleInfo->vecItemDefs[i + 1];
const char *pOtherBundleItemBaseName = pOtherBundleItem ? pOtherBundleItem->GetItemBaseName() : "";
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( eDisplayStyle == kBundleDisplay_PairEntryFinal ? "Econ_Bundle_Double" : "Econ_Bundle_DoubleContinued" ),
pLocalizationProvider->Find( pBundleItemDef->GetItemBaseName() ),
pLocalizationProvider->Find( pOtherBundleItemBaseName ) ),
ATTRIB_COL_BUNDLE_ITEM,
kDescLineFlag_Misc,
NULL,
pBundleItemDef->GetDefinitionIndex() );
// We consumed a second element as well.
i++;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_GiftedBy( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_GiftedBy( "gifter account id" );
static CSchemaAttributeDefHandle pAttrDef_EventDate( "event date" );
attrib_value_t val_GifterId;
if ( pAttrDef_GiftedBy && pEconItem->FindAttribute( pAttrDef_GiftedBy, &val_GifterId ) )
{
// Who gifted us this present?
AddAttributeDescription( pLocalizationProvider, pAttrDef_GiftedBy, val_GifterId );
// Do we also have (optional) information about when it happened?
attrib_value_t val_EventData;
if ( pAttrDef_EventDate && pEconItem->FindAttribute( pAttrDef_EventDate, &val_EventData ) )
{
AddAttributeDescription( pLocalizationProvider, pAttrDef_EventDate, val_EventData );
}
}
}
#ifdef PROJECT_TF
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
static bool IsDuelingMedal( const GameItemDefinition_t *pItemDef )
{
static CSchemaItemDefHandle pAttrDef_DuelingMedals[] =
{
CSchemaItemDefHandle( "Duel Medal Bronze" ),
CSchemaItemDefHandle( "Duel Medal Silver" ),
CSchemaItemDefHandle( "Duel Medal Gold" ),
CSchemaItemDefHandle( "Duel Medal Plat" ),
};
Assert( pItemDef );
for ( int i = 0; i < ARRAYSIZE( pAttrDef_DuelingMedals ); i++ )
if ( pItemDef == pAttrDef_DuelingMedals[i] )
return true;
return false;
}
void CEconItemDescription::Generate_DuelingMedal( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_EventDate( "event date" );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
if ( !IsDuelingMedal( pItemDef ) )
return;
const CTFDuelSummary *pDuelSummary = FindAccountTypeCacheSingleton<CTFDuelSummary>( pEconItem->GetAccountID(), CTFDuelSummary::k_nTypeID );
if ( !pDuelSummary )
return;
// Add the date received first.
attrib_value_t value;
if ( !pEconItem->FindAttribute( pAttrDef_EventDate, &value ) )
return;
// We feed our format-string parameters in via KeyValues.
KeyValues *pKeyValues = new KeyValues( "DuelStrings" );
CLocalizedRTime32 time = { pDuelSummary->Obj().last_duel_timestamp(), false, pLocalizationProvider TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( m_pHashContext ) };
TypedKeyValuesStringHelper<locchar_t>::Write( pKeyValues, "last_date", CLocalizedStringArg<CLocalizedRTime32>( time ).GetLocArg() );
TypedKeyValuesStringHelper<locchar_t>::Write( pKeyValues, "wins", CLocalizedStringArg<uint32>( pDuelSummary->Obj().duel_wins() ).GetLocArg() );
TypedKeyValuesStringHelper<locchar_t>::Write( pKeyValues, "last_target", FindAccountPersonaName( pDuelSummary->Obj().last_duel_account_id() ) );
// What happened in our last duel? This will be used as a format string to wrap the above data.
const char *pszTextFormat;
switch ( pDuelSummary->Obj().last_duel_status() )
{
case kDuelStatus_Loss:
pszTextFormat = "#TF_Duel_Desc_Lost";
break;
case kDuelStatus_Tie:
pszTextFormat = "#TF_Duel_Desc_Tied";
break;
case kDuelStatus_Win:
default:
pszTextFormat = "#TF_Duel_Desc_Won";
break;
}
// Output our whole description.
AddEmptyDescLine();
AddAttributeDescription( pLocalizationProvider, pAttrDef_EventDate, value );
AddEmptyDescLine();
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( pszTextFormat ), pKeyValues ), ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
pKeyValues->deleteThis();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_MapContributor( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaItemDefHandle pItemDef_WorldTraveler( "World Traveler" );
if ( !pItemDef_WorldTraveler || pEconItem->GetItemDefinition() != pItemDef_WorldTraveler )
return;
GCSDK::CSharedObjectTypeCache *pTypeCache = FindAccountTypeCache( pEconItem->GetAccountID(), CTFMapContribution::k_nTypeID );
if ( !pTypeCache )
return;
static const char *kDonationLevels[] =
{
"#TF_MapDonationLevel_Bronze",
"#TF_MapDonationLevel_Silver",
"#TF_MapDonationLevel_Gold",
"#TF_MapDonationLevel_Platinum",
"#TF_MapDonationLevel_Diamond",
"#TF_MapDonationLevel_Australium1",
"#TF_MapDonationLevel_Australium2",
"#TF_MapDonationLevel_Australium3",
"#TF_MapDonationLevel_Unobtainium"
};
const int kNumDonationLevels = ARRAYSIZE( kDonationLevels );
const int kNumDonationsPerLevel = 25;
CUtlVector<const CTFMapContribution *> vecContributionsPerLevel[ kNumDonationLevels ];
for ( uint32 i = 0; i < pTypeCache->GetCount(); ++i )
{
CTFMapContribution *pMapContribution = (CTFMapContribution*)( pTypeCache->GetObject( i ) );
const CEconItemDefinition *pMapItemDef = GetItemSchema()->GetItemDefinition( pMapContribution->Obj().def_index() );
if ( pMapItemDef )
{
int iLevel = MIN( pMapContribution->Obj().contribution_level() / kNumDonationsPerLevel, kNumDonationLevels - 1 );
vecContributionsPerLevel[iLevel].AddToTail( pMapContribution );
}
}
for ( int i = 0; i < kNumDonationLevels; ++i )
{
const CUtlVector<const CTFMapContribution *>& vecContributions = vecContributionsPerLevel[i];
if ( vecContributions.Count() > 0 )
{
// Add header like "Silver:" to show the level of contribution for each of the maps following.
LocalizedAddDescLine( pLocalizationProvider, kDonationLevels[i], ATTRIB_COL_ITEMSET_NAME, kDescLineFlag_Misc );
// Add a label showing the map names and number of contributions for each map.
locchar_t tempDescription[MAX_ITEM_DESCRIPTION_LENGTH] = { 0 };
FOR_EACH_VEC( vecContributions, j )
{
const CTFMapContribution *pMapContribution = vecContributions[j];
const CEconItemDefinition *pMapItemDef = GetItemSchema()->GetItemDefinition( pMapContribution->Obj().def_index() );
Assert( pMapItemDef );
const char *pszMapNameLocalizationToken = pMapItemDef->GetDefinitionString( "map_name", NULL );
if ( pszMapNameLocalizationToken )
{
loc_sncat( tempDescription,
CConstructLocalizedString( pLocalizationProvider->Find( "#Attrib_MapDonation" ),
pLocalizationProvider->Find( pszMapNameLocalizationToken ),
(uint32)pMapContribution->Obj().contribution_level() ),
MAX_ITEM_DESCRIPTION_LENGTH );
if ( j < ( vecContributions.Count() - 1 ) )
{
loc_sncat( tempDescription, LOCCHAR( ", " ), MAX_ITEM_DESCRIPTION_LENGTH );
}
}
}
if ( tempDescription[0] )
{
AddDescLine( tempDescription, ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_FriendlyHat( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaItemDefHandle pItemDef_FriendlyHat( "Friendly Item" );
if ( !pItemDef_FriendlyHat || pEconItem->GetItemDefinition() != pItemDef_FriendlyHat )
return;
const CTFPlayerInfo *pPlayerInfo = FindAccountTypeCacheSingleton<CTFPlayerInfo>( pEconItem->GetAccountID(), CTFPlayerInfo::k_nTypeID );
if ( !pPlayerInfo )
return;
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Attrib_NewUsersHelped" ), (uint32)pPlayerInfo->Obj().num_new_users_helped() ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_SaxxyAwardDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// Don't display anything for items besides the Saxxy itself.
static CSchemaItemDefHandle pItemDef_Saxxy( "Saxxy" );
static CSchemaItemDefHandle pItemDef_MemoryMaker( "The Memory Maker" );
if ( ( !pItemDef_Saxxy || pEconItem->GetItemDefinition() != pItemDef_Saxxy ) &&
( !pItemDef_MemoryMaker || pEconItem->GetItemDefinition() != pItemDef_MemoryMaker ) )
{
return;
}
// Output our award category if present, or abort if absent.
static CSchemaAttributeDefHandle pAttrDef_SaxxyAwardCategory( "saxxy award category" );
static CSchemaAttributeDefHandle pAttrDef_EventDate( "event date" );
uint32 unAwardCategory,
unEventDate;
if ( !pEconItem->FindAttribute( pAttrDef_SaxxyAwardCategory, &unAwardCategory ) ||
!pEconItem->FindAttribute( pAttrDef_EventDate, &unEventDate ) )
{
return;
}
CRTime cTime( unEventDate );
cTime.SetToGMT( false );
const char *pszFormatString = "#Attrib_SaxxyAward";
if ( pEconItem->GetItemDefinition() == pItemDef_MemoryMaker )
{
pszFormatString = "#Attrib_MemoryMakerAward";
}
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( pszFormatString ),
pLocalizationProvider->Find( CFmtStr( "Replay_Contest_Category%d", unAwardCategory ).Access() ),
(uint32)cTime.GetYear() ),
ATTRIB_COL_POSITIVE,
kDescLineFlag_Misc );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_MvmChallenges( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
// Look for our "challenges completed" attribute. If we have this, we assume we're a badge
// of some kind. If we don't, we don't display MvM information. This would be a little weird
// for level 0 badges that have no completed challenges, but those are something that currently
// exist.
static CSchemaAttributeDefHandle pAttrDef_ChallengesCompleted( CTFItemSchema::k_rchMvMChallengeCompletedMaskAttribName );
uint32 unMask = 0;
if ( !pEconItem->FindAttribute( pAttrDef_ChallengesCompleted, &unMask ) )
return;
// Look through our list of MvM tours to figure out which badge this came from. The badge itself
// doesn't know and we need this information to figure out which completion bits map to which
// missions.
const MvMTour_t *pTour = NULL;
FOR_EACH_VEC( GetItemSchema()->GetMvmTours(), i )
{
const MvMTour_t& tour = GetItemSchema()->GetMvmTours()[i];
if ( tour.m_pBadgeItemDef == pEconItem->GetItemDefinition() )
{
pTour = &tour;
break;
}
}
// Couldn't find a tour matching this badge? (This can happen if a client has a busted schema or if
// we remove a tour for some reason.)
if ( !pTour )
return;
const CUtlVector<MvMMission_t>& vecAllMissions = GetItemSchema()->GetMvmMissions();
CUtlVector<int> vecCompletedMissions;
FOR_EACH_VEC( pTour->m_vecMissions, i )
{
// Make sure our mission index is valid based on our current schema. If we're a client playing a
// game during a GC roll, we could wind up looking at someone else's badge where they have a
// mission that we don't understand.
const int iMissionIndex = pTour->m_vecMissions[i].m_iMissionIndex;
if ( !vecAllMissions.IsValidIndex( iMissionIndex ) )
continue;
const int iBadgeSlot = pTour->m_vecMissions[i].m_iBadgeSlot;
if ( iBadgeSlot >= 0 && ((unMask & (1U << iBadgeSlot)) != 0) )
{
vecCompletedMissions.AddToTail( iMissionIndex );
}
}
// Add a summary line for the number they have completed
AddDescLine(
CConstructLocalizedString(
pLocalizationProvider->Find( "#Attrib_MvMChallengesCompletedSummary" ),
uint32( vecCompletedMissions.Count() )
),
ATTRIB_COL_POSITIVE,
kDescLineFlag_Misc
);
// Detail lines for each completed challenge
FOR_EACH_VEC( vecCompletedMissions, i )
{
const MvMMission_t& mission = vecAllMissions[ vecCompletedMissions[i] ];
const MvMMap_t& map = GetItemSchema()->GetMvmMaps()[ mission.m_iDisplayMapIndex ];
const locchar_t *pszLocFmt = pLocalizationProvider->Find( "#Attrib_MvMChallengeCompletedDetail" );
const locchar_t *pszLocMap = pLocalizationProvider->Find( map.m_sDisplayName.Get() );
const locchar_t *pszLocChal = pLocalizationProvider->Find( mission.m_sDisplayName.Get() );
if ( pszLocFmt && pszLocMap && pszLocChal )
{
CConstructLocalizedString locLine(
pszLocFmt,
pszLocMap,
pszLocChal
);
AddDescLine(
locLine,
ATTRIB_COL_POSITIVE,
kDescLineFlag_Misc
);
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_SquadSurplusClaimedBy( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_SquadSurplusClaimer( "squad surplus claimer id" );
static CSchemaAttributeDefHandle pAttrDef_EventDate( "event date" );
attrib_value_t val_GifterId;
if ( pAttrDef_SquadSurplusClaimer&& pEconItem->FindAttribute( pAttrDef_SquadSurplusClaimer, &val_GifterId ) )
{
// Who gifted us this present?
AddAttributeDescription( pLocalizationProvider, pAttrDef_SquadSurplusClaimer, val_GifterId );
// Do we also have (optional) information about when it happened?
attrib_value_t val_EventData;
if ( pAttrDef_EventDate && pEconItem->FindAttribute( pAttrDef_EventDate, &val_EventData ) )
{
AddAttributeDescription( pLocalizationProvider, pAttrDef_EventDate, val_EventData );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_DynamicRecipe( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
// Gather our attributes we care about
CRecipeComponentMatchingIterator componentIterator( pEconItem, NULL );
pEconItem->IterateAttributes( &componentIterator );
// Nothing to say, bail!
if( !componentIterator.GetMatchingComponentInputs().Count() &&
!componentIterator.GetMatchingComponentOutputs().Count() )
{
return;
}
// Add the no partial complete tag if the attribute exists
static CSchemaAttributeDefHandle pAttrib_NoPartialComplete( "recipe no partial complete" );
if ( pEconItem->FindAttribute( pAttrib_NoPartialComplete ) )
{
LocalizedAddDescLine( pLocalizationProvider, "TF_ItemDynamic_Recipe_No_Partial_Completion", ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
AddEmptyDescLine();
if ( componentIterator.GetMatchingComponentInputs().Count() )
{
// Print out item input header
LocalizedAddDescLine( pLocalizationProvider, "TF_ItemDynamic_Recipe_Inputs", ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
// Print out inputs
FOR_EACH_VEC( componentIterator.GetMatchingComponentInputs(), i )
{
CAttribute_DynamicRecipeComponent attribValue;
pEconItem->FindAttribute( componentIterator.GetMatchingComponentInputs()[i], &attribValue );
const GameItemDefinition_t *pItemDef = dynamic_cast<GameItemDefinition_t *>( GetItemSchema()->GetItemDefinition( attribValue.def_index() ) );
if ( !pItemDef )
continue;
int nCount = attribValue.num_required() - attribValue.num_fulfilled();
// This is a completed component. We don't want to show it (for now)
if( nCount == 0 )
continue;
CEconItem tempItem;
if ( !DecodeItemFromEncodedAttributeString( attribValue, &tempItem ) )
{
AssertMsg2( 0, "%s: Unable to decode dynamic recipe input attribute on item %llu.", __FUNCTION__, pEconItem->GetID() );
continue;
}
locchar_t lineItem[256];
locchar_t loc_ItemName[MAX_ITEM_NAME_LENGTH];
GenerateLocalizedFullItemName( loc_ItemName, pLocalizationProvider, &tempItem, k_EGenerateLocalizedFullItemName_Default, m_pHashContext == NULL );
loc_sprintf_safe( lineItem,
LOCCHAR("%s x %d"),
loc_ItemName,
nCount
);
AddDescLine( lineItem, ATTRIB_COL_ITEMSET_MISSING, kDescLineFlag_Misc );
}
AddEmptyDescLine();
}
// Print out outputs
LocalizedAddDescLine( pLocalizationProvider, "TF_ItemDynamic_Recipe_Outputs", ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
FOR_EACH_VEC( componentIterator.GetMatchingComponentOutputs(), i )
{
CAttribute_DynamicRecipeComponent attribValue;
pEconItem->FindAttribute( componentIterator.GetMatchingComponentOutputs()[i], &attribValue );
CEconItem tempItem;
if ( !DecodeItemFromEncodedAttributeString( attribValue, &tempItem ) )
{
AssertMsg2( 0, "%s: Unable to decode dynamic recipe output attribute on item %llu.", __FUNCTION__, pEconItem->GetID() );
continue;
}
locchar_t loc_ItemName[MAX_ITEM_NAME_LENGTH];
GenerateLocalizedFullItemName( loc_ItemName, pLocalizationProvider, &tempItem, k_EGenerateLocalizedFullItemName_Default, m_pHashContext == NULL );
AddDescLine( loc_ItemName, /* this will be ignored: */ ATTRIB_COL_ITEMSET_MISSING, kDescLineFlag_Misc );
// Iterate through the attributes on this temp item and have it store the attributes that should affect
// this component's name. Once we have that, have it fill out a temporary CEconItemDescription.
CRecipeNameAttributeDisplayer recipeAttributeIterator;
tempItem.IterateAttributes( &recipeAttributeIterator );
recipeAttributeIterator.SortAttributes();
CEconItemDescription tempDescription;
recipeAttributeIterator.Finalize( &tempItem, &tempDescription, pLocalizationProvider );
// Check if that temp CEconItemDescription has any attributes we want. If so, steal them.
if ( tempDescription.m_vecDescLines.Count() > 0 )
{
locchar_t loc_Attribs[MAX_ITEM_NAME_LENGTH] = LOCCHAR("");
// Put the attributes on the next line in parenthesis
loc_scat_safe( loc_Attribs, LOCCHAR("(") );
// Put in each attribute
FOR_EACH_VEC( tempDescription.m_vecDescLines, j )
{
// Comma separated
if ( j > 0 )
{
loc_scat_safe( loc_Attribs, LOCCHAR(", ") );
}
loc_sprintf_safe( loc_Attribs,
LOCCHAR("%s%s"),
loc_Attribs,
tempDescription.m_vecDescLines[j].sText.Get() );
}
loc_scat_safe( loc_Attribs, LOCCHAR(")") );
// Print out in the same color as the item name above
AddDescLine( loc_Attribs, /* this will be ignored: */ ATTRIB_COL_ITEMSET_MISSING, kDescLineFlag_Misc );
}
}
}
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_Leaderboard( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
#ifdef GC_DLL
return;
#endif
#ifdef TF_CLIENT_DLL
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_DisplayDuckLeaderboard( "display duck leaderboard" );
if ( pEconItem->FindAttribute( pAttrDef_DisplayDuckLeaderboard ) )
{
// Friend Board
//locchar_t lineItem[256];
//
//AddDescLine( pLocalizationProvider->Find( "#TF_DuckLeaderboard_Friends" ), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
//
//CUtlVector< LeaderboardEntry_t > scores;
//Leaderboards_GetDuckLeaderboard( scores, g_szDuckLeaderboardNames[0] );
//// Show max of top 10
//for ( int i = 0; i < scores.Count() && i < 10; i++ )
//{
// const locchar_t *pName = FindAccountPersonaName( scores[i].m_steamIDUser.GetAccountID() );
// uint32 iRank = scores[i].m_nGlobalRank;
// uint32 iScore = scores[i].m_nScore;
//
// AddDescLine(
// CConstructLocalizedString(
// pLocalizationProvider->Find( "#TF_DuckLeaderboard_Entry" ),
// iRank, pName, iScore
// ),
// ATTRIB_COL_POSITIVE,
// kDescLineFlag_Misc
// );
//}
}
#endif // TF_CLIENT_DLL
}
#endif // PROJECT_TF
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const CEconItemDefinition *GetPaintItemDefinitionForPaintedItem( const IEconItemInterface *pEconItem )
{
static CSchemaAttributeDefHandle pAttribDef_Paint( "set item tint RGB" );
attrib_value_t unPaintRGBAttrBits;
if ( !pAttribDef_Paint || !pEconItem->FindAttribute( pAttribDef_Paint, &unPaintRGBAttrBits ) )
return NULL;
const CEconItemSchema::ToolsItemDefinitionMap_t &toolDefs = GetItemSchema()->GetToolsItemDefinitionMap();
FOR_EACH_MAP_FAST( toolDefs, i )
{
const CEconItemDefinition *pItemDef = toolDefs[i];
// ignore everything that is not a paint can tool
const IEconTool *pEconTool = pItemDef->GetEconTool();
if ( pEconTool && !V_strcmp( pEconTool->GetTypeName(), "paint_can" ) )
{
attrib_value_t unPaintRGBAttrCompareBits;
if ( FindAttribute( pItemDef, pAttribDef_Paint, &unPaintRGBAttrCompareBits ) && unPaintRGBAttrCompareBits == unPaintRGBAttrBits )
return pItemDef;
}
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Specify target (strangifiers, etc that can only be applied to specific items)
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_XifierToolTargetItem( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// Make sure it's a tool of the appropriate type
const CEconTool_Xifier *pTool = pEconItem->GetItemDefinition()->GetTypedEconTool<CEconTool_Xifier>();
if ( pTool == NULL )
return;
// Make sure there is a specific target item
static CSchemaAttributeDefHandle pAttribDef_ToolTargetItem( "tool target item" );
float flItemDef;
if( pAttribDef_ToolTargetItem && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttribDef_ToolTargetItem, &flItemDef ) )
{
locchar_t szTargetItemName[ MAX_ITEM_NAME_LENGTH ] = LOCCHAR("Unknown Item");
// It's a tool, see if it has a tool target item attribute
const item_definition_index_t unItemDef = flItemDef;
const CEconItemDefinition *pEconTargetDef = GetItemSchema()->GetItemDefinition( unItemDef );
// Start with the base name.
if ( pEconTargetDef )
{
GetLocalizedBaseItemName( szTargetItemName, pLocalizationProvider, pEconTargetDef );
}
const char *pszDesc = pTool->GetItemDescToolTargetLocToken();
AssertMsg( pszDesc && *pszDesc, "%s: missing 'item_desc_tool_target' key", pTool->GetTypeName() );
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( pszDesc ),
szTargetItemName ),
ATTRIB_COL_NEUTRAL,
kDescLineFlag_Desc );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_Painted( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttrDef_PaintEffect( "Paint Effect" );
float fPaintEffectType;
if ( pAttrDef_PaintEffect && FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pEconItem, pAttrDef_PaintEffect, &fPaintEffectType ) )
{
if ( fPaintEffectType == 1 )
{
LocalizedAddDescLine( pLocalizationProvider, "Econ_Paint_Effect_Oscillating", ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
else if ( fPaintEffectType == 2 )
{
LocalizedAddDescLine( pLocalizationProvider, "Econ_Paint_Effect_Position", ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
else if ( fPaintEffectType == 3 )
{
LocalizedAddDescLine( pLocalizationProvider, "Econ_Paint_Effect_LowHealthWarning", ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
}
// Find the name of the paint we have applied in the least efficient way imaginable!
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
static CSchemaAttributeDefHandle pAttrDef_ShowPaint( "show paint description" );
if ( pItemDef && ( !pItemDef->IsTool() || FindAttribute( pEconItem, pAttrDef_ShowPaint ) ) )
{
const CEconItemDefinition *pTempDef = GetPaintItemDefinitionForPaintedItem( pEconItem );
if ( pTempDef )
{
const locchar_t *locLocalizedPaintName = pLocalizationProvider->Find( pTempDef->GetItemBaseName() );
if ( locLocalizedPaintName )
{
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "Econ_Paint_Name" ),
locLocalizedPaintName ),
ATTRIB_COL_LEVEL,
kDescLineFlag_Misc );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CEconItemDescription::Generate_Uses( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
// don't display a quantity if we have the unlimited quantity attribute
static CSchemaAttributeDefHandle unlimitedQuantityAttribute( "unlimited quantity" );
if ( pEconItem->FindAttribute( unlimitedQuantityAttribute ) )
return;
// Collection tools don't display this.
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const IEconTool *pEconTool = pItemDef->GetEconTool();
if ( !pEconTool->ShouldDisplayQuantity( pEconItem ) )
return;
int iQuantity = pEconItem->GetQuantity();
bool bIsTool = pItemDef->GetItemClass() && !Q_strcmp( pItemDef->GetItemClass(), "tool" );
bool bIsConsumable = ( pItemDef->GetCapabilities() & ITEM_CAP_USABLE_GC ) != 0 && iQuantity != 0;
if ( bIsTool || bIsConsumable )
{
locchar_t wszQuantity[10];
loc_sprintf_safe( wszQuantity, LOCCHAR( "%d" ), iQuantity );
// Add an empty line before the usage display.
AddEmptyDescLine();
// Display our usage count.
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Attrib_LimitedUse" ), &wszQuantity[0] ), ATTRIB_COL_LIMITED_USE, kDescLineFlag_Misc );
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_LootListDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
// Don't add this description if the item is a special crate type.
const IEconTool *pEconTool = pItemDef->GetEconTool();
const bool bIsRestrictedCrate = pEconTool && pEconTool->GetUsageRestriction()
? !V_stricmp( pEconTool->GetUsageRestriction(), "winter" ) || !V_stricmp( pEconTool->GetUsageRestriction(), "summer" )
: false;
if ( bIsRestrictedCrate )
return;
// Do we have a generation code we want to make public? We do this regardless of whether we're describing our
// loot list contents in detail.
{
static CSchemaAttributeDefHandle pAttrDef_CrateGenerationCode( "crate generation code" );
CAttribute_String sCrateGenerationCode;
const locchar_t *pszCrateGenerationCodeLoc = pLocalizationProvider->Find( "Attrib_CrateGenerationCode" );
if ( pEconItem->FindAttribute( pAttrDef_CrateGenerationCode, &sCrateGenerationCode ) && sCrateGenerationCode.value().length() > 0 )
{
CUtlConstStringBase<locchar_t> loc_sAttrValue;
pLocalizationProvider->ConvertUTF8ToLocchar( sCrateGenerationCode.value().c_str(), &loc_sAttrValue );
AddDescLine( CConstructLocalizedString( pszCrateGenerationCodeLoc, loc_sAttrValue.Get() ),
ATTRIB_COL_POSITIVE,
kDescLineFlag_Misc );
}
}
// Grab the actual contents of our loot list.
CCrateLootListWrapper LootListWrapper( pEconItem );
const IEconLootList *pLootList = LootListWrapper.GetEconLootList();
if ( pLootList == nullptr )
return;
// If our base loot list is set not to list contents, skip the header/footer as well and don't display anything.
if ( !pLootList->BPublicListContents() )
return;
AddEmptyDescLine();
if ( !pLootList->GetLootListCollectionReference() )
{
LocalizedAddDescLine( pLocalizationProvider, pLootList->GetLootListHeaderLocalizationKey(), ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
else
{
int iCollectionIndex = GetItemSchema()->GetItemCollections().Find( pLootList->GetLootListCollectionReference() );
if ( GetItemSchema()->GetItemCollections().IsValidIndex( iCollectionIndex ) )
{
LocalizedAddDescLine( pLocalizationProvider, (GetItemSchema()->GetItemCollections()[iCollectionIndex])->m_pszLocalizedDesc, ATTRIB_COL_NEUTRAL, kDescLineFlag_Misc );
}
}
class CDescriptionLootListIterator : public IEconLootList::IEconLootListIterator
{
public:
CDescriptionLootListIterator( CEconItemDescription *pThis, const CLocalizationProvider *pLocalizationProvider, bool bUseProperName )
: m_pThis( pThis )
, m_pLocalizationProvider( pLocalizationProvider )
, m_bUseProperName( bUseProperName )
{
}
virtual void OnIterate( item_definition_index_t unItemDefIndex ) OVERRIDE
{
const CEconItemDefinition *pItemDef = GetItemSchema()->GetItemDefinition( unItemDefIndex );
if ( pItemDef )
{
// Check if this item is already owned
bool bOwned = false;
bool bUnusual = false;
#ifdef CLIENT_DLL
CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
if ( pLocalInv )
{
for ( int i = 0; i < pLocalInv->GetItemCount(); ++i )
{
CEconItemView *pItem = pLocalInv->GetItem( i );
if ( pItem->GetItemDefinition() == pItemDef )
{
bOwned = true;
// Check Quality
if ( pItem->GetQuality() == AE_UNUSUAL )
{
bUnusual = true;
break;
}
}
}
}
#endif
const locchar_t * pCheckmark = bOwned ? m_pLocalizationProvider->Find( "TF_Checkmark" ) : m_pLocalizationProvider->Find( "TF_LackOfCheckmark" );
if ( bOwned && bUnusual )
{
pCheckmark = m_pLocalizationProvider->Find( "TF_Checkmark_Unusual" );
}
attrib_colors_t colorRarity = ATTRIB_COL_RARITY_DEFAULT;
const CEconItemRarityDefinition* pItemRarity = GetItemSchema()->GetRarityDefinition( pItemDef->GetRarity() );
if ( pItemRarity )
{
colorRarity = pItemRarity->GetAttribColor();
}
m_pThis->AddDescLine(
CConstructLocalizedString( LOCCHAR( "%s1%s2" ), pCheckmark,
CEconItemLocalizedFullNameGenerator(
m_pLocalizationProvider,
pItemDef,
m_bUseProperName
).GetFullName() ),
colorRarity,
kDescLineFlag_Misc,
NULL,
pItemDef->GetDefinitionIndex()
);
}
}
private:
CEconItemDescription *m_pThis; // look at me I'm a lambda!
const CLocalizationProvider *m_pLocalizationProvider;
bool m_bUseProperName;
};
CDescriptionLootListIterator it( this, pLocalizationProvider, m_pHashContext == NULL );
pLootList->EnumerateUserFacingPotentialDrops( &it );
if ( pLootList->GetLootListFooterLocalizationKey() )
{
LocalizedAddDescLine( pLocalizationProvider, pLootList->GetLootListFooterLocalizationKey(), ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
else
{
const char *pszRareLootListFooterLocalizationKey = pItemDef->GetDefinitionString( "loot_list_rare_item_footer", "#Econ_Revolving_Loot_List_Rare_Item" );
LocalizedAddDescLine( pLocalizationProvider, pszRareLootListFooterLocalizationKey, ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
}
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_EventDetail( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
// Check to see if we should append any extra description information
const char *pszEventLocalizationKey = pItemDef->GetDefinitionString( "event_desc_footer", NULL );
if ( pszEventLocalizationKey )
{
AddEmptyDescLine();
LocalizedAddDescLine( pLocalizationProvider, pszEventLocalizationKey, ATTRIB_COL_POSITIVE, kDescLineFlag_Misc );
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
#ifdef CLIENT_DLL
static bool IsItemEquipped( uint32 unAccountID, const CEconItemDefinition *pSearchItemDef, const GameItemDefinition_t **ppFoundSetItemDef )
{
Assert( pSearchItemDef );
Assert( ppFoundSetItemDef );
CPlayerInventory *pInv = InventoryManager()->GetInventoryForAccount( unAccountID );
if ( !pInv )
return false;
for ( int i = 0; i < pInv->GetItemCount(); i++ )
{
const CEconItemView *pInvItem = pInv->GetItem( i );
if ( !pInvItem )
continue;
// This code is client-only so we expect to always get back an item definition pointer.
const GameItemDefinition_t *pInvItemDef = pInvItem->GetItemDefinition();
Assert( pInvItemDef );
if ( pInvItemDef->GetSetItemRemap() != pSearchItemDef->GetDefinitionIndex() )
continue;
if ( !pInvItem->IsEquipped() )
continue;
*ppFoundSetItemDef = pInvItemDef;
return true;
}
return false;
}
#endif // CLIENT_DLL
void CEconItemDescription::Generate_ItemSetDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const GameItemDefinition_t *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const CEconItemSetDefinition *pItemSetDef = pItemDef->GetItemSetDefinition();
if ( !pItemSetDef )
return;
bool bAllItemsEquipped = true; // filled in below when iterating over items
// Some item sets are tagged to only appear on items at all if the entire set is visible. Rather than
// walk the whole set multiple times checking for item equipped state, we build up a set of description lines
// that we *will* display if we display anything at all. Later, we either submit all those lines for real or
// return before adding any of them.
{
CUtlVector<econ_item_description_line_t> vecPotentialDescLines;
AddEmptyDescLine( &vecPotentialDescLines );
LocalizedAddDescLine( pLocalizationProvider, pItemSetDef->m_pszLocalizedName, ATTRIB_COL_ITEMSET_NAME, kDescLineFlag_Set | kDescLineFlag_SetName, &vecPotentialDescLines, pItemSetDef->m_iBundleItemDef );
// Kyle says: Jon wants different formatting on the GC for sets.
#if defined( GC_DLL )
#if TF_ANTI_IDLEBOT_VERIFICATION
if ( !m_pHashContext )
#endif // TF_ANTI_IDLEBOT_VERIFICATION
{
AddEmptyDescLine( &vecPotentialDescLines );
}
#endif // defined( GC_DLL ) &&
// Iterate over the items in the set. We'll output a line in different colors to show
// the current state of this item. For normal item sets, the color is based on whether
// the owner has the item in question equipped (except on the GC, where we always say
// "it's not equipped" to avoid confusion). For collections, the color is based on whether
// the item has been collected.
FOR_EACH_VEC( pItemSetDef->m_iItemDefs, i )
{
const GameItemDefinition_t *pOtherSetItem = dynamic_cast<const GameItemDefinition_t *>( GetItemSchema()->GetItemDefinition( pItemSetDef->m_iItemDefs[i] ) );
if ( !pOtherSetItem )
continue;
item_definition_index_t usLinkItemDefIndex = pOtherSetItem->GetDefinitionIndex();
#ifdef DOTA
// If the current item is part of a pack bundle, add the pack bundle to the description, rather than the individual item
if ( pOtherSetItem->IsPackItem() )
{
// Link to the pack bundle, not the individual pack item
usLinkItemDefIndex = pOtherSetItem->GetOwningPackBundle()->GetDefinitionIndex();
}
#endif
// Only used on non-GC in case we have an item misrepresenting itself intentionally for set
// grouping purposes. NULL elsewhere.
const GameItemDefinition_t *pFoundSetItemDef = NULL;
const bool bItemPresent =
#ifdef GC_DLL
false; // the GC always treats set items as unequipped for clarity in trading
#else
#if TF_ANTI_IDLEBOT_VERIFICATION
m_pHashContext
? false // when generating descriptions for GC verification we treat item sets as unequipped to match the GC
#endif
: IsItemEquipped( pEconItem->GetAccountID(), pOtherSetItem, &pFoundSetItemDef ); // non-GC display will find out whether the player in question has this item actively equipped
#endif
AddDescLine( CEconItemLocalizedFullNameGenerator(
pLocalizationProvider,
pFoundSetItemDef ? pFoundSetItemDef : pOtherSetItem,
m_pHashContext == NULL
).GetFullName(), bItemPresent ? ATTRIB_COL_ITEMSET_EQUIPPED : ATTRIB_COL_ITEMSET_MISSING, kDescLineFlag_Set, &vecPotentialDescLines, usLinkItemDefIndex );
bAllItemsEquipped &= bItemPresent;
}
// If the item set is set to be only displayed when the full set is equipped, give up here and
// toss out our potential lines. Otherwise submit them for real.
if ( pItemSetDef->m_bIsHiddenSet && !bAllItemsEquipped )
return;
FOR_EACH_VEC( vecPotentialDescLines, i )
{
AddDescLine( vecPotentialDescLines[i].sText.Get(), vecPotentialDescLines[i].eColor, vecPotentialDescLines[i].unMetaType, NULL, vecPotentialDescLines[i].unDefIndex );
}
}
// Show the set only attributes if we have the entire set and we have bonus attributes to display.
bool bHasVisible = false;
FOR_EACH_VEC( pItemSetDef->m_iAttributes, i )
{
const CEconItemSetDefinition::itemset_attrib_t& attrib = pItemSetDef->m_iAttributes[i];
const CEconItemAttributeDefinition *pAttrDef = GetItemSchema()->GetAttributeDefinition( attrib.m_iAttribDefIndex );
if ( !pAttrDef->IsHidden() )
{
bHasVisible = true;
break;
}
}
if ( !bHasVisible )
return;
AddEmptyDescLine();
LocalizedAddDescLine( pLocalizationProvider, "#Econ_Set_Bonus", ATTRIB_COL_ITEMSET_NAME, kDescLineFlag_Set );
FOR_EACH_VEC( pItemSetDef->m_iAttributes, i )
{
const CEconItemSetDefinition::itemset_attrib_t& attrib = pItemSetDef->m_iAttributes[i];
const CEconItemAttributeDefinition *pAttrDef = GetItemSchema()->GetAttributeDefinition( attrib.m_iAttribDefIndex );
if ( pAttrDef )
{
// Add the attribute description. Override the color to be grayed out if we don't have the
// full set equipped.
AddAttributeDescription( pLocalizationProvider,
pAttrDef,
*(attrib_value_t *)&attrib.m_flValue,
bAllItemsEquipped ? /* "do not override": */ NUM_ATTRIB_COLORS : ATTRIB_COL_ITEMSET_MISSING );
}
}
}
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_CollectionDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
const CEconItemCollectionDefinition *pCollection = pItemDef->GetItemCollectionDefinition();
if ( !pCollection )
return;
// Collection Header ..
const locchar_t *loc_name = pLocalizationProvider->Find( pCollection->m_pszLocalizedName );
// Add a bit of spacing, this is only for the market
// Add empty line
AddDescLine( LOCCHAR( " " ), ATTRIB_COL_NEUTRAL, kDescLineFlag_CollectionName | kDescLineFlag_Empty );
AddDescLine( LOCCHAR( " " ), ATTRIB_COL_NEUTRAL, kDescLineFlag_CollectionName | kDescLineFlag_Empty );
AddDescLine(
CConstructLocalizedString( LOCCHAR( "%s1" ), loc_name ),
ATTRIB_COL_NEUTRAL,
kDescLineFlag_CollectionName
);
FOR_EACH_VEC( pCollection->m_iItemDefs, index )
{
int eFlag = kDescLineFlag_Collection;
const CEconItemDefinition *pTempItemDef = GetItemSchema()->GetItemDefinition( pCollection->m_iItemDefs[index] );
if ( pTempItemDef )
{
// Check if this item is already owned
bool bOwned = false;
bool bUnusual = false;
if ( pTempItemDef == pItemDef )
{
bOwned = true;
eFlag |= kDescLineFlag_CollectionCurrentItem;
if ( pEconItem->GetQuality() == AE_UNUSUAL )
{
bUnusual = true;
}
}
#ifdef CLIENT_DLL
else
{
CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
if ( pLocalInv )
{
const CEconItemCollectionDefinition *pRefCollection = GetItemSchema()->GetCollectionByName( pTempItemDef->GetCollectionReference() );
// if item has a collection reference, we are looking for all those items and this item
if ( pRefCollection )
{
bOwned = true;
FOR_EACH_VEC( pRefCollection->m_iItemDefs, iRefCollectionItem )
{
const CEconItemView *pRefItem = pLocalInv->FindFirstItembyItemDef( pRefCollection->m_iItemDefs[ iRefCollectionItem ] );
if ( !pRefItem )
{
bOwned = false;
break;
}
}
}
else
{
// Normal Backpack scan
for ( int i = 0; i < pLocalInv->GetItemCount(); ++i )
{
CEconItemView *pItem = pLocalInv->GetItem( i );
if ( pItem->GetItemDefinition() == pTempItemDef )
{
bOwned = true;
// Check Quality
if ( pItem->GetQuality() == AE_UNUSUAL )
{
bUnusual = true;
break;
}
}
}
}
}
}
#endif
const locchar_t * pCheckmark = bOwned ? pLocalizationProvider->Find( "TF_Checkmark" ) : pLocalizationProvider->Find( "TF_LackOfCheckmark" );
if ( bOwned && bUnusual )
{
pCheckmark = pLocalizationProvider->Find( "TF_Checkmark_Unusual" );
}
attrib_colors_t colorRarity = ATTRIB_COL_RARITY_DEFAULT;
const CEconItemRarityDefinition* pItemRarity = GetItemSchema()->GetRarityDefinition( pTempItemDef->GetRarity() );
if ( pItemRarity )
{
colorRarity = pItemRarity->GetAttribColor();
}
AddDescLine(
CConstructLocalizedString( LOCCHAR("%s1%s2"), pCheckmark,
CEconItemLocalizedFullNameGenerator(
pLocalizationProvider,
pTempItemDef,
m_pHashContext == NULL
).GetFullName() ),
colorRarity,
eFlag,
NULL,
pTempItemDef->GetDefinitionIndex()
);
}
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_ExpirationDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
if ( !pItemDef )
return;
// Look for schema-specified static expiration date.
RTime32 timeSchemaExpiration = pItemDef->GetExpirationDate();
// Look also for a dynamic attribute -- this could come from item tryouts.
static CSchemaAttributeDefHandle pAttrDef_ExpirationDate( "expiration date" );
RTime32 timeAttrExpiration = 0;
pEconItem->FindAttribute( pAttrDef_ExpirationDate, &timeAttrExpiration ); // if we don't have the attribute we'll use our starting value of 0
// Which will have us expire first?
RTime32 timeExpiration = MAX( timeSchemaExpiration, timeAttrExpiration );
// If we still don't have an expiration date we don't display anything.
if ( !timeExpiration )
return;
AddEmptyDescLine();
#ifdef TF_CLIENT_DLL
// is this a loaner item?
if ( GetAssociatedQuestItemID( pEconItem ) != INVALID_ITEM_ID )
{
AddDescLine( pLocalizationProvider->Find( "#Attrib_LoanerItemExpirationDate" ),
ATTRIB_COL_NEGATIVE,
kDescLineFlag_Misc );
}
else
#endif // TF_CLIENT_DLL
{
CLocalizedRTime32 time = { timeExpiration, false, pLocalizationProvider TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( m_pHashContext ) };
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Attrib_ExpirationDate" ),
time ),
ATTRIB_COL_NEGATIVE,
kDescLineFlag_Misc );
}
}
void CEconItemDescription::Generate_DropPeriodDesc( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
static CSchemaAttributeDefHandle pAttr_EndDropDate( "end drop date" );
// See if we have the drop date period end attribute
CAttribute_String value;
if ( !FindAttribute( pEconItem, pAttr_EndDropDate, &value ) )
return;
AddEmptyDescLine();
// Convert the string value to an RTime32
RTime32 endDate = CRTime::RTime32FromString( value.value().c_str() );
// Is the time before or after now? Use different strings for each
const char* pszDropString = endDate > CRTime::RTime32TimeCur()
? "#Attrib_DropPeriodComing"
: "#Attrib_DropPeriodPast";
CLocalizedRTime32 time = { endDate, false, pLocalizationProvider TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( m_pHashContext ) };
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( pszDropString ),
time ),
ATTRIB_COL_LEVEL,
kDescLineFlag_Misc );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
#ifdef TF_CLIENT_DLL
extern ConVar cl_showbackpackrarities;
extern ConVar cl_show_market_data_on_items;
#endif
void CEconItemDescription::Generate_MarketInformation( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
// Deprecated;
// We now have right click go to market
return;
//
// Assert( pLocalizationProvider );
// Assert( pEconItem );
//
// // Early-out to avoid doing more expensive name lookups for items that can't possibly have
// // entries.
// if ( !pEconItem->IsMarketable() )
// return;
//
// // For now, Market information is only shown on clients, and even then only sometimes.
//#ifdef CLIENT_DLL
//#if TF_ANTI_IDLEBOT_VERIFICATION
// // Don't generate this client-only information when we're trying to match GC output.
// if ( m_pHashContext )
// return;
//#endif // TF_ANTI_IDLEBOT_VERIFICATION
//
//#ifdef TF_CLIENT_DLL
// if ( cl_show_market_data_on_items.GetInt() == 0 )
// return;
//
// if ( cl_show_market_data_on_items.GetInt() == 1 && cl_showbackpackrarities.GetInt() != 2 )
// return;
//#endif // TF_CLIENT_DLL
//
// steam_market_gc_identifier_t ident;
// ident.m_unDefIndex = pEconItem->GetItemDefIndex();
// ident.m_unQuality = pEconItem->GetQuality();
//
// const client_market_data_t *pClientMarketData = GetClientMarketData( ident );
// if ( !pClientMarketData )
// return;
//
// locchar_t loc_Price[ kLocalizedPriceSizeInChararacters ];
// MakeMoneyString( loc_Price, ARRAYSIZE( loc_Price ), pClientMarketData->m_unLowestPrice, EconUI()->GetStorePanel()->GetCurrency() );
//
// AddEmptyDescLine();
// AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Econ_MarketTooltipFormat" ),
// pClientMarketData->m_unQuantityAvailable,
// loc_Price ),
// ATTRIB_COL_POSITIVE,
// kDescLineFlag_Misc );
//#endif // CLIENT_DLL
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
struct localized_localplayer_line_t
{
localized_localplayer_line_t( const char *pLocalizationKey, attrib_colors_t eAttribColor, const char *pLocalizationSubKey = NULL )
: m_pLocalizationKey( pLocalizationKey )
, m_pLocalizationSubKey( pLocalizationSubKey )
, m_eAttribColor( eAttribColor )
{
//
}
const char *m_pLocalizationKey;
const char *m_pLocalizationSubKey;
attrib_colors_t m_eAttribColor;
};
void CEconItemDescription::Generate_FlagsAttributes( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
const CEconItemDefinition *pItemDef = pEconItem->GetItemDefinition();
if ( pItemDef && pItemDef->GetEconTool() && pItemDef->GetEconTool()->ShouldDisplayQuantity( pEconItem ) )
{
AddEmptyDescLine();
AddDescLine( CConstructLocalizedString( pLocalizationProvider->Find( "#Attrib_LimitedUse" ), (uint32)pEconItem->GetQuantity() ),
ATTRIB_COL_LIMITED_USE,
kDescLineFlag_LimitedUse );
}
CUtlVector<localized_localplayer_line_t> vecLines;
// Is this item in use? (ie., being used as part of a cross-game trade)
if ( pEconItem->GetInUse() )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_InUse", ATTRIB_COL_NEUTRAL ) );
}
static CSchemaAttributeDefHandle pAttrDef_TradableAfter( "tradable after date" );
static CSchemaAttributeDefHandle pAttrDef_ToolEscrowUntil( "tool escrow until date" );
static CSchemaAttributeDefHandle pAttrDef_AlwaysTradableAndUsableInCrafting( "always tradable" );
uint32 unTradeTime = 0,
unEscrowTime = 0;
const bool bHasTradableAfterDate = pEconItem->FindAttribute( pAttrDef_TradableAfter, &unTradeTime );
const bool bHasToolEscrowUntilDate = pEconItem->FindAttribute( pAttrDef_ToolEscrowUntil, &unEscrowTime );
const bool bHasExpiringTimer = bHasTradableAfterDate || bHasToolEscrowUntilDate;
#ifdef CLIENT_DLL
const bool bIsStoreItem = IsStorePreviewItem( pEconItem );
const bool bIsPreviewItem = pEconItem->GetFlags() & kEconItemFlagClient_Preview;
if ( bIsStoreItem || bIsPreviewItem )
{
#if TF_ANTI_IDLEBOT_VERIFICATION
if ( !m_pHashContext )
#endif // TF_ANTI_IDLEBOT_VERIFICATION
{
// Does this item come with other packages on Steam?
const econ_store_entry_t *pStoreEntry = GetEconPriceSheet() ? GetEconPriceSheet()->GetEntry( pItemDef->GetDefinitionIndex() ) : NULL;
if ( pStoreEntry && pStoreEntry->GetGiftSteamPackageID() != 0 )
{
const char *pszSteamPackageLocalizationToken = GetItemSchema()->GetSteamPackageLocalizationToken( pStoreEntry->GetGiftSteamPackageID() );
if ( pszSteamPackageLocalizationToken )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_Store_IncludesSteamGiftPackage", ATTRIB_COL_POSITIVE, pszSteamPackageLocalizationToken ) );
vecLines.AddToTail( localized_localplayer_line_t( NULL, ATTRIB_COL_POSITIVE ) );
}
}
// While the above apply to store *and* preview items, the below only apply to store items.
if ( bIsStoreItem )
{
// Don't display this line for map stamps because they can't be traded.
if ( pItemDef && pItemDef->GetItemClass() && !FStrEq( pItemDef->GetItemClass(), "map_token" ) )
{
static CSchemaAttributeDefHandle pAttrib_CannotTrade( "cannot trade" );
Assert( pAttrib_CannotTrade );
// Some items cannot ever be traded, so don't indicate to the users that they'll be tradeable after a few days.
if ( !FindAttribute( pItemDef, pAttrib_CannotTrade ) )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_Store_TradableAfterDate", ATTRIB_COL_NEGATIVE ) );
}
if ( pItemDef->GetEconTool() && pItemDef->GetEconTool()->RequiresToolEscrowPeriod() )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_Store_ToolEscrowUntilDate", ATTRIB_COL_NEGATIVE ) );
}
}
if ( !pItemDef || (pItemDef->GetCapabilities() & ITEM_CAP_CAN_BE_CRAFTED_IF_PURCHASED) == 0 )
{
if ( pItemDef->IsBundle() )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotCraftWeapons", ATTRIB_COL_NEGATIVE ) );
}
else
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotCraft", ATTRIB_COL_NEGATIVE ) );
}
}
}
}
}
else
#endif // CLIENT_DLL
if ( bHasExpiringTimer )
{
if ( unTradeTime > CRTime::RTime32TimeCur() )
{
AddAttributeDescription( pLocalizationProvider, pAttrDef_TradableAfter, unTradeTime );
}
if ( unEscrowTime > CRTime::RTime32TimeCur() )
{
AddAttributeDescription( pLocalizationProvider, pAttrDef_ToolEscrowUntil, unEscrowTime );
}
if ( !pEconItem->IsUsableInCrafting() )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotCraft", ATTRIB_COL_NEUTRAL ) );
}
}
else if ( pEconItem->FindAttribute( pAttrDef_AlwaysTradableAndUsableInCrafting ) && pEconItem->IsTradable() )
{
// do nothing if we are always tradable or usable in crafting
//
// some items are marked as "always_tradable" in their itemDef but the specific item may have the
// "non_economy" flag, so we need to also check that this specific item is tradable before doing nothing
}
else
{
const int32 iQuality = pEconItem->GetQuality();
const eEconItemOrigin eOrigin = pEconItem->GetOrigin();
if ( iQuality >= AE_COMMUNITY && iQuality <= AE_SELFMADE )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_SpecialItem", ATTRIB_COL_NEUTRAL ) );
}
else if ( eOrigin == kEconItemOrigin_Achievement )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_AchievementItem", ATTRIB_COL_NEUTRAL ) );
}
else if ( eOrigin == kEconItemOrigin_CollectionReward )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CollectionReward", ATTRIB_COL_NEUTRAL ) );
}
else if ( eOrigin == kEconItemOrigin_PreviewItem )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_PreviewItem", ATTRIB_COL_NEUTRAL ) );
}
else if ( eOrigin == kEconItemOrigin_QuestLoanerItem )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_LoanerItem", ATTRIB_COL_NEUTRAL ) );
}
else if ( eOrigin == kEconItemOrigin_Invalid )
{
// do nothing, but skip the below "cannot trade/cannot craft" block below"
}
else if ( (pEconItem->GetFlags() & kEconItemFlag_NonEconomy) != 0 )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_NonEconomyItem", ATTRIB_COL_NEUTRAL ) );
}
else
{
const bool bIsTradable = pEconItem->IsTradable(),
bIsCraftable = pEconItem->IsUsableInCrafting();
if ( !bIsTradable && !bIsCraftable )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotTradeOrCraft", ATTRIB_COL_NEUTRAL ) );
}
else
{
if ( !bIsTradable )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotTrade", ATTRIB_COL_NEUTRAL ) );
}
if ( !bIsCraftable )
{
vecLines.AddToTail( localized_localplayer_line_t( "#Attrib_CannotCraft", ATTRIB_COL_NEUTRAL ) );
}
}
}
}
if ( vecLines.Count() > 0 )
{
const locchar_t *loc_AttribFormat_AdditionalNode = pLocalizationProvider->Find( "#AttribFormat_AdditionalNote" );
if ( loc_AttribFormat_AdditionalNode )
{
AddEmptyDescLine();
FOR_EACH_VEC( vecLines, i )
{
const char *pszLocalizationKey = vecLines[i].m_pLocalizationKey;
const char *pszLocalizationSubKey = vecLines[i].m_pLocalizationSubKey;
if ( pszLocalizationKey )
{
AddDescLine( pszLocalizationSubKey ?
CConstructLocalizedString( pLocalizationProvider->Find( pszLocalizationKey ), pLocalizationProvider->Find( pszLocalizationSubKey ) ): // has subtoken, doesn't use additional note format
CConstructLocalizedString( loc_AttribFormat_AdditionalNode, pLocalizationProvider->Find( pszLocalizationKey ) ), // no subtoken, uses base additional note format
vecLines[i].m_eAttribColor,
kDescLineFlag_Misc );
}
else
{
AddEmptyDescLine();
}
}
}
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
bool CEconItemDescription::CVisibleAttributeDisplayer::OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, attrib_value_t value )
{
if ( !pAttrDef->IsHidden() )
{
attrib_iterator_value_t attrVal = { pAttrDef, value };
m_vecAttributes.AddToTail( attrVal );
}
return true;
}
void CEconItemDescription::CVisibleAttributeDisplayer::SortAttributes()
{
// We need to make sure we process attributes in the same order when iterating on the GC and the client
// when looking for agreement. We take advantage of this to also sort our attributes into a coherent
// order for display -- first come neutral attributes, then positive, then negative. In the event of a
// tie, we sort by attribute index, which is arbitrary but consistent across the client/GC.
struct AttributeValueSorter
{
static int sSort( const attrib_iterator_value_t *pA, const attrib_iterator_value_t *pB )
{
const int iEffectTypeDelta = pA->m_pAttrDef->GetEffectType() - pB->m_pAttrDef->GetEffectType();
if ( iEffectTypeDelta != 0 )
return iEffectTypeDelta;
return pA->m_pAttrDef->GetDefinitionIndex() - pB->m_pAttrDef->GetDefinitionIndex();
}
};
m_vecAttributes.Sort( &AttributeValueSorter::sSort );
}
void CEconItemDescription::CVisibleAttributeDisplayer::Finalize( const IEconItemInterface *pEconItem, CEconItemDescription *pEconItemDescription, const CLocalizationProvider *pLocalizationProvider )
{
// HACK so we dont show series number on select crates since they are self describing (Event Crates, Collection Crates)
static CSchemaAttributeDefHandle pAttrDef_SupplyCrateSeries( "set supply crate series" );
static CSchemaAttributeDefHandle pAttrDef_HideSeries( "hide crate series number" );
FOR_EACH_VEC( m_vecAttributes, i )
{
if ( pEconItem && m_vecAttributes[i].m_pAttrDef == pAttrDef_SupplyCrateSeries && pEconItem->FindAttribute( pAttrDef_HideSeries ) )
continue;
pEconItemDescription->AddAttributeDescription( pLocalizationProvider, m_vecAttributes[i].m_pAttrDef, m_vecAttributes[i].m_value );
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_VisibleAttributes( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
Assert( pLocalizationProvider );
Assert( pEconItem );
CVisibleAttributeDisplayer AttributeDisplayer;
pEconItem->IterateAttributes( &AttributeDisplayer );
AttributeDisplayer.SortAttributes();
AttributeDisplayer.Finalize( pEconItem, this, pLocalizationProvider );
}
// --------------------------------------------------------------------------
void CEconItemDescription::Generate_DirectX8Warning( const CLocalizationProvider *pLocalizationProvider, const IEconItemInterface *pEconItem )
{
#ifdef CLIENT_DLL
static ConVarRef mat_dxlevel( "mat_dxlevel" );
const CEconItemDefinition *pEconItemDefinition = pEconItem->GetItemDefinition();
// If less than 90, we�re in DX8 mode.
// Display warning if you are looking at a painthit item or case
if ( mat_dxlevel.GetInt() < 90 && pEconItemDefinition && ( pEconItemDefinition->GetItemCollectionDefinition() || pEconItemDefinition->GetCollectionReference() ) )
{
AddEmptyDescLine();
AddDescLine( pLocalizationProvider->Find( "#Attrib_DirectX8Warning" ),
ATTRIB_COL_NEGATIVE,
kDescLineFlag_Misc );
}
#endif
}
bool CEconItemDescription::CRecipeNameAttributeDisplayer::OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, attrib_value_t value )
{
if ( pAttrDef->CanAffectRecipeComponentName() )
{
return CVisibleAttributeDisplayer::OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
static attrib_colors_t GetAttributeDefaultColor( const CEconItemAttributeDefinition *pAttribDef )
{
// positive attribute?
switch ( pAttribDef->GetEffectType() )
{
case ATTRIB_EFFECT_NEUTRAL: return ATTRIB_COL_NEUTRAL;
case ATTRIB_EFFECT_POSITIVE: return ATTRIB_COL_POSITIVE;
case ATTRIB_EFFECT_NEGATIVE: return ATTRIB_COL_NEGATIVE;
case ATTRIB_EFFECT_STRANGE: return ATTRIB_COL_STRANGE;
case ATTRIB_EFFECT_UNUSUAL: return ATTRIB_COL_UNUSUAL;
}
// hell if we know
return ATTRIB_COL_NEUTRAL;
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconAttributeDescription::InternalConstruct
(
const CLocalizationProvider *pLocalizationProvider,
const CEconItemAttributeDefinition *pAttribDef,
attrib_value_t value,
TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( MD5Context_t *pHashContext ) TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA
IAccountPersonaLocalizer *pOptionalAccountPersonaLocalizer
)
{
Assert( pAttribDef != NULL );
const float& value_as_float = (float&)value;
const uint32& value_as_uint32 = (uint32&)value;
// Calculate our color first -- if we don't know what to do, we'll wind up as neutral.
m_eDefaultColor = GetAttributeDefaultColor( pAttribDef );
// Early out abort if we don't have a localization string for this attribute.
locchar_t *loc_String = pAttribDef->GetDescriptionString() && pLocalizationProvider
? pLocalizationProvider->Find( pAttribDef->GetDescriptionString() )
: NULL;
if ( !loc_String )
return;
char szAttrShortDescToken[MAX_PATH];
V_sprintf_safe( szAttrShortDescToken, "%s%s", pAttribDef->GetDescriptionString(), "_shortdesc" );
locchar_t *loc_ShortString = pLocalizationProvider
? pLocalizationProvider->Find( szAttrShortDescToken )
: NULL;
// How do we format an attribute value of this type?
switch ( pAttribDef->GetDescriptionFormat() )
{
case ATTDESCFORM_VALUE_IS_ADDITIVE_PERCENTAGE:
m_loc_sValue = CLocalizedStringArg<float>( value_as_float * 100.0f ).GetLocArg();
break;
case ATTDESCFORM_VALUE_IS_ACCOUNT_ID:
#ifdef CLIENT_DLL
// If this assert fires, it means that the client fed in an attribute that should be localized
// as a Steam persona name but didn't feed it any way to get that information. The GC won't
// assert, but also won't generate anything for the attribute text.
//
// It's still totally fine to pass in NULL for the persona localizer as long as you don't
// expect to have any attributes that have account IDs.
Assert( pOptionalAccountPersonaLocalizer );
#endif
if ( pOptionalAccountPersonaLocalizer )
{
m_loc_sValue = pOptionalAccountPersonaLocalizer->FindAccountPersonaName( value_as_uint32 );
}
break;
case ATTDESCFORM_VALUE_IS_ADDITIVE:
m_loc_sValue = pAttribDef->IsStoredAsFloat()
? CLocalizedStringArg<float>( value_as_float ).GetLocArg()
: CLocalizedStringArg<uint32>( value_as_uint32 ).GetLocArg();
break;
case ATTDESCFORM_VALUE_IS_INVERTED_PERCENTAGE:
if ( value_as_float < 1.0 )
{
m_loc_sValue = CLocalizedStringArg<float>( (1.0 - value_as_float) * 100.0f ).GetLocArg();
break;
}
// We intentionally fall through when value_as_float >= 1.0f to treat it the same as "value as
// percentage".
case ATTDESCFORM_VALUE_IS_PERCENTAGE:
m_loc_sValue = CLocalizedStringArg<float>( (value_as_float * 100.0f) - 100.0f ).GetLocArg();
break;
case ATTDESCFORM_VALUE_IS_DATE:
{
bool bUseGMT = false;
#ifdef PROJECT_TF
static CSchemaAttributeDefHandle pAttribDef_SetEmployeeNumber( "custom employee number" );
// only use GMT for custom employee number -- not doing this generated a bunch of support
// tickets because items were granted based on GC time but would display local time, causing
// people on the border to think they deserved a better badge, etc.
bUseGMT = (pAttribDef == pAttribDef_SetEmployeeNumber);
#endif // PROJECT_TF
CLocalizedRTime32 time = { value_as_uint32, bUseGMT, pLocalizationProvider TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( pHashContext ) };
m_loc_sValue = CLocalizedStringArg<CLocalizedRTime32>( time ).GetLocArg();
break;
}
case ATTDESCFORM_VALUE_IS_PARTICLE_INDEX:
{
// This is a horrible, horrible line of code. It exists because old particle references are
// ints stored as floats as float bit patterns and new particle references are ints stored
// as ints all the way through.
CUtlConstString utf8_ParticleKeyName( CFmtStr( "#Attrib_Particle%i", pAttribDef->IsStoredAsInteger() ? value_as_uint32 : (int)value_as_float ).Access() ); // this value is stored as a float but interpreted as an int (1.0 -> 1)
if ( utf8_ParticleKeyName.IsEmpty() )
return;
m_loc_sValue = pLocalizationProvider->Find( utf8_ParticleKeyName.Get() );
break;
}
case ATTDESCFORM_VALUE_IS_KILLSTREAKEFFECT_INDEX:
{
CUtlConstString utf8_KeyName( CFmtStr( "#Attrib_KillStreakEffect%i", (int)value_as_float ).Access() ); // this value is stored as a float but interpreted as an int (1.0 -> 1)
if ( utf8_KeyName.IsEmpty() )
return;
m_loc_sValue = pLocalizationProvider->Find( utf8_KeyName.Get() );
break;
}
case ATTDESCFORM_VALUE_IS_KILLSTREAK_IDLEEFFECT_INDEX:
{
CUtlConstString utf8_KeyName( CFmtStr( "#Attrib_KillStreakIdleEffect%i", (int)value_as_float ).Access() ); // this value is stored as a float but interpreted as an int (1.0 -> 1)
if ( utf8_KeyName.IsEmpty() )
return;
m_loc_sValue = pLocalizationProvider->Find( utf8_KeyName.Get() );
break;
}
// Don't output any value for bitmasks, but let the attribute text display.
case ATTDESCFORM_VALUE_IS_OR:
break;
default:
#ifdef CLIENT_DLL
// Only assert on the client -- the GC will just silently fail rather than crash if we ever run into
// this case, but if we are adding a new display type this will help us catch a reason why it isn't
// showing up.
Assert( !"Unhandled attribute value display type in CEconAttributeDescription." );
// Anywhere besides the client, we intentionally fall through to return immediately.
#endif
case ATTDESCFORM_VALUE_IS_ITEM_DEF: // referencing definitions is handled per-attribute
return;
case ATTDESCFORM_VALUE_IS_FROM_LOOKUP_TABLE:
{
const char *pszLocalizationToken = GetItemSchema()->FindStringTableEntry( pAttribDef->GetDefinitionName(), (int)value_as_float );
if ( !pszLocalizationToken )
return;
const locchar_t *loc_Entry = pLocalizationProvider->Find( pszLocalizationToken );
if ( !loc_Entry )
return;
m_loc_sValue = loc_Entry;
break;
}
}
// Some attributes have a short description for the upgrade
if ( loc_ShortString )
{
m_loc_sShortValue = CConstructLocalizedString( loc_ShortString, m_loc_sValue.Get() );
}
// Combine the value string we just generated with the localized display for that value. (ie., the value
// might be "10" and the display would be "health is increased by 10%".)
m_loc_sValue = CConstructLocalizedString( loc_String, m_loc_sValue.Get() );
// Is this an attribute that needs a custom wrapper around the default attribute text? (ie.,
// if our string was "Damage +10%" we want that to be "(only on Hightower: Damage +10%)")
if ( pAttribDef->GetUserGenerationType() )
{
const locchar_t *locUGTLocalizationKey = pLocalizationProvider->Find( CFmtStr( "#Econ_Attrib_UserGeneratedWrapper_%i", pAttribDef->GetUserGenerationType() ).Get() );
if ( locUGTLocalizationKey )
{
m_loc_sValue = CConstructLocalizedString( locUGTLocalizationKey, m_loc_sValue.Get() );
}
}
// If there's no short description, just copy the normal one
if ( !loc_ShortString )
{
m_loc_sShortValue = m_loc_sValue;
}
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::AddAttributeDescription( const CLocalizationProvider *pLocalizationProvider, const CEconItemAttributeDefinition *pAttribDef, attrib_value_t value, attrib_colors_t eOverrideDisplayColor /* = NUM_ATTRIB_COLORS */ )
{
Assert( pLocalizationProvider );
Assert( pAttribDef );
CEconAttributeDescription AttrDesc( pLocalizationProvider,
pAttribDef,
value,
TF_ANTI_IDLEBOT_VERIFICATION_ONLY_ARG( m_pHashContext ) TF_ANTI_IDLEBOT_VERIFICATION_ONLY_COMMA
this );
if ( AttrDesc.GetDescription().IsEmpty() )
return;
// Is this an attribute that needs a custom wrapper around the default attribute text? (ie.,
// if our string was "Damage +10%" we want that to be "(only on Hightower: Damage +10%)")
attrib_colors_t eDefaultAttribColor = GetAttributeDefaultColor( pAttribDef );
#ifdef TF_CLIENT_DLL
enum
{
kUserGeneratedAttributeType_None = 0,
kUserGeneratedAttributeType_MVMEngineering = 1,
kUserGeneratedAttributeType_HalloweenSpell = 2
};
// On TF, these user-generated attributes can be from upgrade cards which only apply in MvM.
// We then colorize them based on whether they'll be active, with the caveat that out-of-game
// views always say yes (GC, loadout when not on a server, etc.).
if ( pAttribDef->GetUserGenerationType() == kUserGeneratedAttributeType_MVMEngineering && TFGameRules() && !TFGameRules()->IsMannVsMachineMode() )
{
eDefaultAttribColor = ATTRIB_COL_ITEMSET_MISSING;
}
// They can also be from Halloween spells. These are intended to expire after Halloween in any
// event, but for display purposes they'll appear in grey unless the holiday is active.
else if ( pAttribDef->GetUserGenerationType() == kUserGeneratedAttributeType_HalloweenSpell && !EconHolidays_IsHolidayActive( kHoliday_Halloween, CRTime::RTime32TimeCur() ) )
{
eDefaultAttribColor = ATTRIB_COL_ITEMSET_MISSING;
}
#endif // TF_CLIENT_DLL
AddDescLine( AttrDesc.GetDescription().Get(),
eOverrideDisplayColor != NUM_ATTRIB_COLORS ? // are we overriding the output color?
eOverrideDisplayColor : // we are
eDefaultAttribColor, // fall back to normal attribute color
kDescLineFlag_Attribute );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::AddDescLine( const locchar_t *pString, attrib_colors_t eColor, uint32 unMetaType, CUtlVector<econ_item_description_line_t> *out_pOptionalDescLineDest /* = NULL */, item_definition_index_t unDefIndex /* = INVALID_ITEM_DEF_INDEX */, bool bIsItemForSale /*= true*/ )
{
CUtlVector<econ_item_description_line_t>& vecTargetDescLines = out_pOptionalDescLineDest ? *out_pOptionalDescLineDest : m_vecDescLines;
econ_item_description_line_t& line = vecTargetDescLines[ vecTargetDescLines.AddToTail() ];
line.eColor = eColor;
line.unMetaType = unMetaType;
line.sText = pString;
line.unDefIndex = unDefIndex;
line.bIsItemForSale = bIsItemForSale;
#if TF_ANTI_IDLEBOT_VERIFICATION
if ( m_pHashContext )
{
const int iLineCount = vecTargetDescLines.Count() + 1;
char verboseStringBuf[ k_VerboseStringBufferSize ];
TFDescription_HashDataMunge( m_pHashContext, iLineCount, m_bIsVerbose, BuildVerboseStrings( verboseStringBuf, m_bIsVerbose, "%d", iLineCount ) ); // which line did we just add?
TFDescription_HashDataMunge( m_pHashContext, line.eColor, m_bIsVerbose, BuildVerboseStrings( verboseStringBuf, m_bIsVerbose,"%d", line.eColor ) );
TFDescription_HashDataMunge( m_pHashContext, line.unMetaType, m_bIsVerbose, BuildVerboseStrings( verboseStringBuf, m_bIsVerbose, "%d", line.unMetaType ) );
#ifdef GC_DLL
COMPILE_TIME_ASSERT( sizeof( locchar_t ) == sizeof( char ) );
TFDescription_HashDataMungeContents( m_pHashContext, pString, StringFuncs<locchar_t>::Length( pString ) * sizeof( locchar_t ), m_bIsVerbose, pString );
#else
COMPILE_TIME_ASSERT( sizeof( locchar_t ) == sizeof( wchar_t ) );
CUtlConstString ansiString;
GLocalizationProvider()->ConvertLoccharToANSI( pString, &ansiString );
TFDescription_HashDataMungeContents( m_pHashContext, ansiString.Get(), StringFuncs<char>::Length( ansiString.Get() ) * sizeof( char ), m_bIsVerbose, ansiString.Get() );
#endif
}
#endif // TF_ANTI_IDLEBOT_VERIFICATION
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::AddEmptyDescLine( CUtlVector<econ_item_description_line_t> *out_pOptionalDescLineDest )
{
AddDescLine( LOCCHAR(" "), ATTRIB_COL_NEUTRAL, kDescLineFlag_Empty, out_pOptionalDescLineDest );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
void CEconItemDescription::LocalizedAddDescLine( const CLocalizationProvider *pLocalizationProvider, const char *pLocalizationToken, attrib_colors_t eColor, uint32 unMetaType, CUtlVector<econ_item_description_line_t> *out_pOptionalDescLineDest /* = NULL */, item_definition_index_t unDefIndex /* = INVALID_ITEM_DEF_INDEX */, bool bIsItemForSale /* = true */ )
{
Assert( pLocalizationToken );
const locchar_t *pTextToAdd = pLocalizationProvider->Find( pLocalizationToken );
if ( pTextToAdd )
{
AddDescLine( pTextToAdd, eColor, unMetaType, out_pOptionalDescLineDest, unDefIndex, bIsItemForSale );
}
else if ( pLocalizationToken && (pLocalizationToken[0] != '#') )
{
// If we couldn't localize correctly, we might be a string literal like "My temp item desc.". In
// this case, we use that string as-is.
CUtlConstStringBase<locchar_t> loc_sText;
pLocalizationProvider->ConvertUTF8ToLocchar( pLocalizationToken, &loc_sText );
AddDescLine( loc_sText.Get(), eColor, unMetaType, out_pOptionalDescLineDest, unDefIndex, bIsItemForSale );
}
else
{
// We couldn't localize this token, but also don't think it was a string meant to be user-facing so
// just silently fail.
}
#if TF_ANTI_IDLEBOT_VERIFICATION
if ( m_pHashContext )
{
TFDescription_HashDataMungeContents( m_pHashContext, pLocalizationToken, V_strlen( pLocalizationToken ), m_bIsVerbose, pLocalizationToken );
}
#endif // TF_ANTI_IDLEBOT_VERIFICATION
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
class CGameItemDefinition_EconItemInterfaceWrapper : public CMaterialOverrideContainer< IEconItemInterface >
{
public:
CGameItemDefinition_EconItemInterfaceWrapper( const CEconItemDefinition *pEconItemDefinition, entityquality_t eQuality )
: m_pEconItemDefinition( pEconItemDefinition )
, m_eQuality( eQuality )
{
Assert( m_pEconItemDefinition );
}
virtual const GameItemDefinition_t *GetItemDefinition() const { return assert_cast<const GameItemDefinition_t *>( m_pEconItemDefinition ); }
virtual itemid_t GetID() const { return INVALID_ITEM_ID; }
virtual uint32 GetAccountID() const { return 0; }
virtual int32 GetQuality() const { return m_eQuality; }
virtual style_index_t GetStyle() const { return INVALID_STYLE_INDEX; }
virtual uint8 GetFlags() const { return 0; }
virtual eEconItemOrigin GetOrigin() const { return kEconItemOrigin_Invalid; }
virtual int GetQuantity() const { return 1; }
virtual uint32 GetItemLevel() const { return 0; }
virtual bool GetInUse() const { return false; }
virtual const char *GetCustomName() const { return NULL; }
virtual const char *GetCustomDesc() const { return NULL; }
virtual CEconItemPaintKitDefinition *GetCustomPainkKitDefinition( void ) const { return GetItemDefinition()->GetCustomPainkKitDefinition(); }
// IEconItemInterface attribute iteration interface. This is not meant to be used for
// attribute lookup! This is meant for anything that requires iterating over the full
// attribute list.
virtual void IterateAttributes( class IEconItemAttributeIterator *pIterator ) const OVERRIDE
{
Assert( pIterator );
m_pEconItemDefinition->IterateAttributes( pIterator );
}
private:
const CEconItemDefinition *m_pEconItemDefinition;
entityquality_t m_eQuality;
};
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
CEconItemLocalizedFullNameGenerator::CEconItemLocalizedFullNameGenerator( const CLocalizationProvider *pLocalizationProvider, const CEconItemDefinition *pItemDef, bool bUseProperName, entityquality_t eQuality )
{
Assert( pItemDef );
CGameItemDefinition_EconItemInterfaceWrapper EconItemDefinitionWrapper( pItemDef, eQuality );
GenerateLocalizedFullItemName( m_loc_LocalizedItemName, pLocalizationProvider, &EconItemDefinitionWrapper, k_EGenerateLocalizedFullItemName_Default, bUseProperName );
}
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
class CMarketNameGenerator_EconItemInterfaceWrapper : public IEconItemInterface
{
public:
CMarketNameGenerator_EconItemInterfaceWrapper( CEconItem *pItem )
: m_pItem( pItem )
{
Assert( m_pItem );
}
virtual const GameItemDefinition_t *GetItemDefinition() const { return m_pItem->GetItemDefinition(); }
virtual itemid_t GetID() const { return m_pItem->GetID(); }
virtual uint32 GetAccountID() const { return 0; }
virtual int32 GetQuality() const { return m_pItem->GetQuality(); }
virtual style_index_t GetStyle() const { return INVALID_STYLE_INDEX; }
virtual uint8 GetFlags() const { return 0; }
virtual eEconItemOrigin GetOrigin() const { return kEconItemOrigin_Invalid; }
virtual int GetQuantity() const { return 1; }
virtual uint32 GetItemLevel() const { return 0; }
virtual bool GetInUse() const { return false; }
virtual const char *GetCustomName() const { return NULL; }
virtual const char *GetCustomDesc() const { return NULL; }
virtual CEconItemPaintKitDefinition *GetCustomPainkKitDefinition( void ) const { return m_pItem->GetCustomPainkKitDefinition(); }
virtual bool GetCustomPaintKitWear( float &flWear ) const { return m_pItem->GetCustomPaintKitWear( flWear ); }
virtual IMaterial *GetMaterialOverride( int iTeam ) OVERRIDE { return m_pItem->GetMaterialOverride( iTeam ); }
// IEconItemInterface attribute iteration interface. This is not meant to be used for
// attribute lookup! This is meant for anything that requires iterating over the full
// attribute list.
virtual void IterateAttributes( class IEconItemAttributeIterator *pIterator ) const OVERRIDE
{
Assert( pIterator );
// Wrap their iterator in our iterator that will selectively let specific attributes
// get iterated on by the wrapped iterator.
CMarketNameGenerator_SelectiveAttributeIterator iteratorWrapper( pIterator );
m_pItem->IterateAttributes( &iteratorWrapper );
}
private:
CEconItem *m_pItem;
// Iterator class that wraps another iterator and selectively allows specific attributes to be
// iterated by the passed in iterator
class CMarketNameGenerator_SelectiveAttributeIterator : public IEconItemAttributeIterator
{
public:
CMarketNameGenerator_SelectiveAttributeIterator( IEconItemAttributeIterator* pIterator )
: m_pIterator( pIterator )
{}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, attrib_value_t value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, float value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const uint64& value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_String& value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_DynamicRecipeComponent& value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_ItemSlotCriteria& value ) OVERRIDE
{
if( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef, const CAttribute_WorldItemPlacement& value ) OVERRIDE
{
if ( pAttrDef->CanAffectMarketName() )
{
m_pIterator->OnIterateAttributeValue( pAttrDef, value );
}
return true;
}
private:
IEconItemAttributeIterator *m_pIterator;
};
};
// --------------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------------
CEconItemLocalizedMarketNameGenerator::CEconItemLocalizedMarketNameGenerator( const CLocalizationProvider *pLocalizationProvider, CEconItem *pItem, bool bUseProperName )
{
Assert( pItem );
CMarketNameGenerator_EconItemInterfaceWrapper EconItemWrapper( pItem );
GenerateLocalizedFullItemName( m_loc_LocalizedItemName, pLocalizationProvider, &EconItemWrapper, k_EGenerateLocalizedFullItemName_WithPaintWear, bUseProperName );
}
#endif // BUILD_ITEM_NAME_AND_DESC
|