Guest User

Untitled

a guest
Aug 19th, 2023
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 163.71 KB | None | 0 0
  1. /***********************************************************************/
  2. /** © 2015 CD PROJEKT S.A. All rights reserved.
  3. /** THE WITCHER® is a trademark of CD PROJEKT S. A.
  4. /** The Witcher game is based on the prose of Andrzej Sapkowski.
  5. /***********************************************************************/
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. class IInventoryScriptedListener
  13. {
  14. event OnInventoryScriptedEvent( eventType : EInventoryEventType, itemId : SItemUniqueId, quantity : int, fromAssociatedInventory : bool ) {}
  15. }
  16.  
  17. import struct SItemNameProperty
  18. {
  19. import editable var itemName : name;
  20. };
  21.  
  22. import struct SR4LootNameProperty
  23. {
  24. import editable var lootName : name;
  25. };
  26.  
  27. struct SItemExt
  28. {
  29. editable var itemName : SItemNameProperty;
  30. editable var quantity : int;
  31. default quantity = 1;
  32. };
  33.  
  34. struct SCardSourceData
  35. {
  36. var cardName : name;
  37. var source : string;
  38. var originArea : string;
  39. var originQuest : string;
  40. var details : string;
  41. var coords : string;
  42. };
  43.  
  44.  
  45. import struct SItemChangedData
  46. {
  47. import const var itemName : name;
  48. import const var quantity : int;
  49. import const var informGui : bool;
  50. import const var ids : array< SItemUniqueId >;
  51. };
  52.  
  53. import class CInventoryComponent extends CComponent
  54. {
  55. editable var priceMult : float;
  56. editable var priceRepairMult : float;
  57. editable var priceRepair : float;
  58. editable var fundsType : EInventoryFundsType;
  59.  
  60. private var recentlyAddedItems : array<SItemUniqueId>;
  61. private var fundsMax : int;
  62. private var daysToIncreaseFunds : int;
  63.  
  64. default priceMult = 1.0;
  65. default priceRepairMult = 1.0;
  66. default priceRepair = 10.0;
  67. default fundsType = EInventoryFunds_Avg;
  68. default daysToIncreaseFunds = 5;
  69.  
  70.  
  71.  
  72.  
  73. public function GetFundsType() : EInventoryFundsType
  74. {
  75. return fundsType;
  76. }
  77.  
  78. public function GetDaysToIncreaseFunds() : int
  79. {
  80. return daysToIncreaseFunds;
  81. }
  82.  
  83. public function GetFundsMax() : float
  84. {
  85. if ( EInventoryFunds_Broke == fundsType )
  86. {
  87. return 0;
  88. }
  89. else if ( EInventoryFunds_Avg == fundsType )
  90. {
  91. return 5000;
  92. }
  93. else if ( EInventoryFunds_Poor == fundsType )
  94. {
  95. return 2500;
  96. }
  97. else if ( EInventoryFunds_Rich == fundsType )
  98. {
  99. return 7500;
  100. }
  101. else if ( EInventoryFunds_RichQuickStart == fundsType )
  102. {
  103. return 15000;
  104. }
  105. return -1;
  106. }
  107.  
  108. public function SetupFunds()
  109. {
  110. if ( EInventoryFunds_Broke == fundsType )
  111. {
  112. AddMoney( 0 );
  113. }
  114. else if ( EInventoryFunds_Poor == fundsType )
  115. {
  116. AddMoney( (int)( 200 * GetFundsModifier() ) );
  117. }
  118. else if ( EInventoryFunds_Avg == fundsType )
  119. {
  120. AddMoney( (int)( 500 * GetFundsModifier() ) );
  121. }
  122. else if ( EInventoryFunds_Rich == fundsType )
  123. {
  124. AddMoney( (int)( 1000 * GetFundsModifier() ) );
  125. }
  126. else if ( EInventoryFunds_RichQuickStart == fundsType )
  127. {
  128. AddMoney( (int)( 5000 * GetFundsModifier() ) );
  129. }
  130. }
  131.  
  132. public function IncreaseFunds()
  133. {
  134. if ( GetMoney() < GetFundsMax() )
  135. {
  136. if ( EInventoryFunds_Avg == fundsType )
  137. {
  138. AddMoney( (int)( 150 * GetFundsModifier()) );
  139. }
  140. else if ( EInventoryFunds_Poor == fundsType )
  141. {
  142. AddMoney( (int)( 100 * GetFundsModifier() ) );
  143. }
  144. else if ( EInventoryFunds_Rich == fundsType )
  145. {
  146. AddMoney( (int)( 1000 * GetFundsModifier() ) );
  147. }
  148. else if ( EInventoryFunds_RichQuickStart == fundsType )
  149. {
  150. AddMoney( 1000 + (int)( 2500 * GetFundsModifier() ) );
  151. }
  152. }
  153. }
  154.  
  155. public function GetMoney() : int
  156. {
  157. return GetItemQuantityByName( 'Crowns' );
  158. }
  159.  
  160. public function SetMoney( amount : int )
  161. {
  162. var currentMoney : int;
  163.  
  164. if ( amount >= 0 )
  165. {
  166. currentMoney = GetMoney();
  167. RemoveMoney( currentMoney );
  168.  
  169. AddAnItem( 'Crowns', amount );
  170. }
  171. }
  172.  
  173. public function AddMoney( amount : int )
  174. {
  175. if ( amount > 0 )
  176. {
  177. AddAnItem( 'Crowns', amount );
  178.  
  179. if ( thePlayer == GetEntity() )
  180. {
  181. theTelemetry.LogWithValue( TE_HERO_CASH_CHANGED, amount );
  182. }
  183. }
  184. }
  185.  
  186. public function RemoveMoney( amount : int )
  187. {
  188. if ( amount > 0 )
  189. {
  190. RemoveItemByName( 'Crowns', amount );
  191.  
  192. if ( thePlayer == GetEntity() )
  193. {
  194. theTelemetry.LogWithValue( TE_HERO_CASH_CHANGED, -amount );
  195. }
  196. }
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203. import final function GetItemAbilityAttributeValue( itemId : SItemUniqueId, attributeName : name, abilityName : name) : SAbilityAttributeValue;
  204.  
  205. import final function GetItemFromSlot( slotName : name ) : SItemUniqueId;
  206.  
  207.  
  208. import final function IsIdValid( itemId : SItemUniqueId ) : bool;
  209.  
  210.  
  211. import final function GetItemCount( optional useAssociatedInventory : bool ) : int;
  212.  
  213.  
  214. import final function GetItemsNames() : array< name >;
  215.  
  216.  
  217. import final function GetAllItems( out items : array< SItemUniqueId > );
  218.  
  219.  
  220. import public function GetItemId( itemName : name ) : SItemUniqueId;
  221.  
  222.  
  223. import public function GetItemsIds( itemName : name ) : array< SItemUniqueId >;
  224.  
  225.  
  226. import final function GetItemsByTag( tag : name ) : array< SItemUniqueId >;
  227.  
  228.  
  229. import final function GetItemsByCategory( category : name ) : array< SItemUniqueId >;
  230.  
  231.  
  232. import final function GetSchematicIngredients(itemName : SItemUniqueId, out quantity : array<int>, out names : array<name>);
  233.  
  234.  
  235. import final function GetSchematicRequiredCraftsmanType(craftName : SItemUniqueId) : name;
  236.  
  237.  
  238. import final function GetSchematicRequiredCraftsmanLevel(craftName : SItemUniqueId) : name;
  239.  
  240.  
  241. import final function GetNumOfStackedItems( itemUniqueId: SItemUniqueId ) : int;
  242.  
  243. import final function InitInvFromTemplate( resource : CEntityTemplate );
  244.  
  245.  
  246.  
  247.  
  248. import final function SplitItem( itemID : SItemUniqueId, quantity : int ) : SItemUniqueId;
  249.  
  250.  
  251.  
  252. import final function SetItemStackable( itemID : SItemUniqueId, flag : bool );
  253.  
  254.  
  255. import final function GetCategoryDefaultItem( category : name ) : name;
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. import final function GetItemLocalizedNameByName( itemName : CName ) : string;
  263.  
  264.  
  265. import final function GetItemLocalizedDescriptionByName( itemName : CName ) : string;
  266.  
  267.  
  268. import final function GetItemLocalizedNameByUniqueID( itemUniqueId : SItemUniqueId ) : string;
  269.  
  270.  
  271. import final function GetItemLocalizedDescriptionByUniqueID( itemUniqueId : SItemUniqueId ) : string;
  272.  
  273.  
  274. import final function GetItemIconPathByUniqueID( itemUniqueId : SItemUniqueId ) : string;
  275.  
  276.  
  277. import final function GetItemIconPathByName( itemName : CName ) : string;
  278.  
  279. import final function AddSlot( itemUniqueId : SItemUniqueId ) : bool;
  280.  
  281. import final function GetSlotItemsLimit( itemUniqueId : SItemUniqueId ) : int;
  282.  
  283. import private final function BalanceItemsWithPlayerLevel( playerLevel : int );
  284.  
  285. public function ForceSpawnItemOnStart( itemId : SItemUniqueId ) : bool
  286. {
  287. return ItemHasTag(itemId, 'MutagenIngredient');
  288. }
  289.  
  290.  
  291. public final function GetItemArmorTotal(item : SItemUniqueId) : SAbilityAttributeValue
  292. {
  293. var armor, armorBonus : SAbilityAttributeValue;
  294. var durMult : float;
  295.  
  296. armor = GetItemAttributeValue(item, theGame.params.ARMOR_VALUE_NAME);
  297. armorBonus = GetRepairObjectBonusValueForArmor(item);
  298. durMult = theGame.params.GetDurabilityMultiplier( GetItemDurabilityRatio(item), false);
  299.  
  300. return armor * durMult + armorBonus;
  301. }
  302.  
  303. public final function GetItemLevel(item : SItemUniqueId) : int
  304. {
  305. var itemCategory : name;
  306. var itemAttributes : array<SAbilityAttributeValue>;
  307. var itemName : name;
  308. var isWitcherGear : bool;
  309. var isRelicGear : bool;
  310. var level, baseLevel : int;
  311.  
  312. itemCategory = GetItemCategory(item);
  313. itemName = GetItemName(item);
  314.  
  315. isWitcherGear = false;
  316. isRelicGear = false;
  317. if ( RoundMath(CalculateAttributeValue( GetItemAttributeValue(item, 'quality' ) )) == 5 ) isWitcherGear = true;
  318. if ( RoundMath(CalculateAttributeValue( GetItemAttributeValue(item, 'quality' ) )) == 4 ) isRelicGear = true;
  319.  
  320. switch(itemCategory)
  321. {
  322. case 'armor' :
  323. case 'boots' :
  324. case 'gloves' :
  325. case 'pants' :
  326. itemAttributes.PushBack( GetItemAttributeValue(item, 'armor') );
  327. break;
  328.  
  329. case 'silversword' :
  330. itemAttributes.PushBack( GetItemAttributeValue(item, 'SilverDamage') );
  331. itemAttributes.PushBack( GetItemAttributeValue(item, 'BludgeoningDamage') );
  332. itemAttributes.PushBack( GetItemAttributeValue(item, 'RendingDamage') );
  333. itemAttributes.PushBack( GetItemAttributeValue(item, 'ElementalDamage') );
  334. itemAttributes.PushBack( GetItemAttributeValue(item, 'FireDamage') );
  335. itemAttributes.PushBack( GetItemAttributeValue(item, 'PiercingDamage') );
  336. break;
  337.  
  338. case 'steelsword' :
  339. itemAttributes.PushBack( GetItemAttributeValue(item, 'SlashingDamage') );
  340. itemAttributes.PushBack( GetItemAttributeValue(item, 'BludgeoningDamage') );
  341. itemAttributes.PushBack( GetItemAttributeValue(item, 'RendingDamage') );
  342. itemAttributes.PushBack( GetItemAttributeValue(item, 'ElementalDamage') );
  343. itemAttributes.PushBack( GetItemAttributeValue(item, 'FireDamage') );
  344. itemAttributes.PushBack( GetItemAttributeValue(item, 'SilverDamage') );
  345. itemAttributes.PushBack( GetItemAttributeValue(item, 'PiercingDamage') );
  346. break;
  347.  
  348. case 'crossbow' :
  349. itemAttributes.PushBack( GetItemAttributeValue(item, 'attack_power') );
  350. break;
  351.  
  352. default :
  353. break;
  354. }
  355.  
  356. level = theGame.params.GetItemLevel(itemCategory, itemAttributes, itemName, baseLevel);
  357.  
  358. if ( FactsQuerySum("NewGamePlus") > 0 )
  359. {
  360. if ( baseLevel > GetWitcherPlayer().GetMaxLevel() )
  361. {
  362. level = baseLevel;
  363. }
  364. }
  365.  
  366. if ( isWitcherGear ) level = level - 2;
  367. if ( isRelicGear ) level = level - 1;
  368. if ( level < 1 ) level = 1;
  369. if ( ItemHasTag(item, 'OlgierdSabre') ) level = level - 3;
  370. if ( (isRelicGear || isWitcherGear) && ItemHasTag(item, 'EP1') ) level = level - 1;
  371.  
  372. if ( FactsQuerySum("NewGamePlus") > 0 )
  373. {
  374. if ( level > GetWitcherPlayer().GetMaxLevel() )
  375. {
  376. level = GetWitcherPlayer().GetMaxLevel();
  377. }
  378. }
  379.  
  380. return level;
  381. }
  382.  
  383. public function GetItemLevelColorById( itemId : SItemUniqueId ) : string
  384. {
  385. var color : string;
  386.  
  387. if (GetItemLevel(itemId) <= thePlayer.GetLevel())
  388. {
  389. color = "<font color = '#A09588'>";
  390. }
  391. else
  392. {
  393. color = "<font color = '#9F1919'>";
  394. }
  395.  
  396. return color;
  397. }
  398.  
  399. public function GetItemLevelColor( lvl_item : int ) : string
  400. {
  401. var color : string;
  402.  
  403. if ( lvl_item > thePlayer.GetLevel() )
  404. {
  405. color = "<font color = '#9F1919'>";
  406. } else
  407. {
  408. color = "<font color = '#A09588'>";
  409. }
  410.  
  411. return color;
  412. }
  413.  
  414. public final function AutoBalanaceItemsWithPlayerLevel()
  415. {
  416. var playerLevel : int;
  417.  
  418. playerLevel = thePlayer.GetLevel();
  419.  
  420. if( playerLevel < 0 )
  421. {
  422. playerLevel = 0;
  423. }
  424.  
  425. BalanceItemsWithPlayerLevel( playerLevel );
  426. }
  427.  
  428. public function GetItemsByName(itemName : name) : array<SItemUniqueId>
  429. {
  430. var ret : array<SItemUniqueId>;
  431. var i : int;
  432.  
  433. if(!IsNameValid(itemName))
  434. return ret;
  435.  
  436. GetAllItems(ret);
  437.  
  438. for(i=ret.Size()-1; i>=0; i-=1)
  439. {
  440. if(GetItemName(ret[i]) != itemName)
  441. {
  442. ret.EraseFast( i );
  443. }
  444. }
  445.  
  446. return ret;
  447. }
  448.  
  449. public final function GetSingletonItems() : array<SItemUniqueId>
  450. {
  451. return GetItemsByTag(theGame.params.TAG_ITEM_SINGLETON);
  452. }
  453.  
  454.  
  455. import final function GetItemQuantityByName( itemName : name, optional useAssociatedInventory : bool , optional ignoreTags : array< name > ) : int;
  456.  
  457.  
  458. import final function GetItemQuantityByCategory( itemCategory : name, optional useAssociatedInventory : bool , optional ignoreTags : array< name > ) : int;
  459.  
  460.  
  461. import final function GetItemQuantityByTag( itemTag : name, optional useAssociatedInventory : bool , optional ignoreTags : array< name > ) : int;
  462.  
  463.  
  464. import final function GetAllItemsQuantity( optional useAssociatedInventory : bool , optional ignoreTags : array< name > ) : int;
  465.  
  466.  
  467. public function IsEmpty(optional bSkipNoDropNoShow : bool) : bool
  468. {
  469. var i : int;
  470. var itemIds : array<SItemUniqueId>;
  471.  
  472. if(bSkipNoDropNoShow)
  473. {
  474. GetAllItems( itemIds );
  475. for( i = itemIds.Size() - 1; i >= 0; i -= 1 )
  476. {
  477. if( !ItemHasTag( itemIds[ i ],theGame.params.TAG_DONT_SHOW ) && !ItemHasTag( itemIds[ i ], 'NoDrop' ) )
  478. {
  479. return false;
  480. }
  481. else if ( ItemHasTag( itemIds[ i ], 'Lootable') )
  482. {
  483. return false;
  484. }
  485. }
  486.  
  487. return true;
  488. }
  489.  
  490. return GetItemCount() <= 0;
  491. }
  492.  
  493.  
  494. public function GetAllHeldAndMountedItemsCategories( out heldItems : array<name>, optional out mountedItems : array<name> )
  495. {
  496. var allItems : array<SItemUniqueId>;
  497. var i : int;
  498.  
  499. GetAllItems(allItems);
  500. for(i=allItems.Size()-1; i >= 0; i-=1)
  501. {
  502. if ( IsItemHeld(allItems[i]) )
  503. heldItems.PushBack(GetItemCategory(allItems[i]));
  504. else if ( IsItemMounted(allItems[i]) )
  505. mountedItems.PushBack(GetItemCategory(allItems[i]));
  506. }
  507. }
  508.  
  509. public function GetAllHeldItemsNames( out heldItems : array<name> )
  510. {
  511. var allItems : array<SItemUniqueId>;
  512. var i : int;
  513.  
  514. GetAllItems(allItems);
  515. for(i=allItems.Size()-1; i >= 0; i-=1)
  516. {
  517. if ( IsItemHeld(allItems[i]) )
  518. heldItems.PushBack(GetItemName(allItems[i]));
  519. }
  520. }
  521.  
  522. public function HasMountedItemByTag(tag : name) : bool
  523. {
  524. var i : int;
  525. var allItems : array<SItemUniqueId>;
  526.  
  527. if(!IsNameValid(tag))
  528. return false;
  529.  
  530. allItems = GetItemsByTag(tag);
  531. for(i=0; i<allItems.Size(); i+=1)
  532. if(IsItemMounted(allItems[i]))
  533. return true;
  534.  
  535. return false;
  536. }
  537.  
  538. public function HasHeldOrMountedItemByTag(tag : name) : bool
  539. {
  540. var i : int;
  541. var allItems : array<SItemUniqueId>;
  542.  
  543. if(!IsNameValid(tag))
  544. return false;
  545.  
  546. allItems = GetItemsByTag(tag);
  547. for(i=0; i<allItems.Size(); i+=1)
  548. if( IsItemMounted(allItems[i]) || IsItemHeld(allItems[i]) )
  549. return true;
  550.  
  551. return false;
  552. }
  553.  
  554.  
  555. import final function GetItem( itemId : SItemUniqueId ) : SInventoryItem;
  556.  
  557.  
  558. import final function GetItemName( itemId : SItemUniqueId ) : name;
  559.  
  560.  
  561. import final function GetItemCategory( itemId : SItemUniqueId ) : name;
  562.  
  563.  
  564. import final function GetItemClass( itemId : SItemUniqueId ) : EInventoryItemClass;
  565.  
  566.  
  567. import final function GetItemTags( itemId : SItemUniqueId, out tags : array<name> ) : bool;
  568.  
  569.  
  570. import final function GetCraftedItemName( itemId : SItemUniqueId ) : name;
  571.  
  572.  
  573. import final function TotalItemStats( invItem : SInventoryItem ) : float;
  574.  
  575. import final function GetItemPrice( itemId : SItemUniqueId ) : int;
  576.  
  577.  
  578. import final function GetItemPriceModified( itemId : SItemUniqueId, optional playerSellingItem : Bool ) : int;
  579.  
  580.  
  581. import final function GetInventoryItemPriceModified( invItem : SInventoryItem, optional playerSellingItem : Bool ) : int;
  582.  
  583.  
  584. import final function GetItemPriceRepair( invItem : SInventoryItem, out costRepairPoint : int, out costRepairTotal : int );
  585.  
  586.  
  587. import final function GetItemPriceRemoveUpgrade( invItem : SInventoryItem ) : int;
  588.  
  589.  
  590. import final function GetItemPriceDisassemble( invItem : SInventoryItem ) : int;
  591.  
  592.  
  593. import final function GetItemPriceAddSlot( invItem : SInventoryItem ) : int;
  594.  
  595.  
  596. import final function GetItemPriceCrafting( invItem : SInventoryItem ) : int;
  597.  
  598.  
  599. import final function GetItemPriceEnchantItem( invItem : SInventoryItem ) : int;
  600.  
  601.  
  602. import final function GetItemPriceRemoveEnchantment( invItem : SInventoryItem ) : int;
  603.  
  604. import final function GetFundsModifier() : float;
  605.  
  606.  
  607. import final function GetItemQuantity( itemId : SItemUniqueId ) : int;
  608.  
  609.  
  610. import final function ItemHasTag( itemId : SItemUniqueId, tag : name ) : bool;
  611.  
  612.  
  613. import final function AddItemTag( itemId : SItemUniqueId, tag : name ) : bool;
  614.  
  615.  
  616. import final function RemoveItemTag( itemId : SItemUniqueId, tag : name ) : bool;
  617.  
  618.  
  619. public final function ManageItemsTag( items : array<SItemUniqueId>, tag : name, add : bool )
  620. {
  621. var i : int;
  622.  
  623. if( add )
  624. {
  625. for( i = 0 ; i < items.Size() ; i += 1 )
  626. {
  627. AddItemTag( items[ i ], tag );
  628. }
  629. }
  630. else
  631. {
  632. for( i = 0 ; i < items.Size() ; i += 1 )
  633. {
  634. RemoveItemTag( items[ i ], tag );
  635. }
  636. }
  637. }
  638.  
  639.  
  640. import final function GetItemByItemEntity( itemEntity : CItemEntity ) : SItemUniqueId;
  641.  
  642.  
  643. public function ItemHasAbility(item : SItemUniqueId, abilityName : name) : bool
  644. {
  645. var abilities : array<name>;
  646.  
  647. GetItemAbilities(item, abilities);
  648. return abilities.Contains(abilityName);
  649. }
  650.  
  651. import final function GetItemAttributeValue( itemId : SItemUniqueId, attributeName : name, optional abilityTags : array< name >, optional withoutTags : bool ) : SAbilityAttributeValue;
  652.  
  653.  
  654. import final function GetItemBaseAttributes( itemId : SItemUniqueId, out attributes : array<name> );
  655.  
  656.  
  657. import final function GetItemAttributes( itemId : SItemUniqueId, out attributes : array<name> );
  658.  
  659.  
  660. import final function GetItemAbilities( itemId : SItemUniqueId, out abilities : array<name> );
  661.  
  662.  
  663. import final function GetItemContainedAbilities( itemId : SItemUniqueId, out abilities : array<name> );
  664.  
  665.  
  666. public function GetItemAbilitiesWithAttribute(id : SItemUniqueId, attributeName : name, attributeVal : float) : array<name>
  667. {
  668. var i : int;
  669. var abs, ret : array<name>;
  670. var dm : CDefinitionsManagerAccessor;
  671. var val : float;
  672. var min, max : SAbilityAttributeValue;
  673.  
  674. GetItemAbilities(id, abs);
  675. dm = theGame.GetDefinitionsManager();
  676.  
  677. for(i=0; i<abs.Size(); i+=1)
  678. {
  679. dm.GetAbilityAttributeValue(abs[i], attributeName, min, max);
  680. val = CalculateAttributeValue(GetAttributeRandomizedValue(min, max));
  681.  
  682. if(val == attributeVal)
  683. ret.PushBack(abs[i]);
  684. }
  685.  
  686. return ret;
  687. }
  688. public function GetItemAbilitiesWithTag( itemId : SItemUniqueId, tag : name, out abilities : array<name> )
  689. {
  690. var i : int;
  691. var dm : CDefinitionsManagerAccessor;
  692. var allAbilities : array<name>;
  693.  
  694. dm = theGame.GetDefinitionsManager();
  695. GetItemAbilities(itemId, allAbilities);
  696.  
  697. for(i=0; i<allAbilities.Size(); i+=1)
  698. {
  699. if(dm.AbilityHasTag(allAbilities[i], tag))
  700. {
  701. abilities.PushBack(allAbilities[i]);
  702. }
  703. }
  704. }
  705.  
  706.  
  707.  
  708.  
  709. import private final function GiveItem( otherInventory : CInventoryComponent, itemId : SItemUniqueId, optional quantity : int ) : array<SItemUniqueId>;
  710.  
  711. public final function GiveMoneyTo(otherInventory : CInventoryComponent, optional quantity : int, optional informGUI : bool )
  712. {
  713. var moneyId : array<SItemUniqueId>;
  714.  
  715. moneyId = GetItemsByName('Crowns');
  716. GiveItemTo(otherInventory, moneyId[0], quantity, false, true, informGUI);
  717. }
  718.  
  719. public final function GiveItemTo( otherInventory : CInventoryComponent, itemId : SItemUniqueId, optional quantity : int, optional refreshNewFlag : bool, optional forceTransferNoDrops : bool, optional informGUI : bool ) : SItemUniqueId
  720. {
  721. var arr : array<SItemUniqueId>;
  722. var itemName : name;
  723. var i : int;
  724. var uiData : SInventoryItemUIData;
  725. var isQuestItem : bool;
  726.  
  727.  
  728. if(quantity == 0)
  729. quantity = 1;
  730.  
  731. quantity = Clamp(quantity, 0, GetItemQuantity(itemId));
  732. if(quantity == 0)
  733. return GetInvalidUniqueId();
  734.  
  735. itemName = GetItemName(itemId);
  736.  
  737. if(!forceTransferNoDrops && ( ItemHasTag(itemId, 'NoDrop') && !ItemHasTag(itemId, 'Lootable') ))
  738. {
  739. LogItems("Cannot transfer item <<" + itemName + ">> as it has the NoDrop tag set!!!");
  740. return GetInvalidUniqueId();
  741. }
  742.  
  743.  
  744. if(IsItemSingletonItem(itemId))
  745. {
  746.  
  747. if(otherInventory == thePlayer.inv && otherInventory.GetItemQuantityByName(itemName) > 0)
  748. {
  749. LogAssert(false, "CInventoryComponent.GiveItemTo: cannot add singleton item as player already has this item!");
  750. return GetInvalidUniqueId();
  751. }
  752.  
  753. else
  754. {
  755. arr = GiveItem(otherInventory, itemId, quantity);
  756. }
  757. }
  758. else
  759. {
  760.  
  761. arr = GiveItem(otherInventory, itemId, quantity);
  762. }
  763.  
  764.  
  765. if(otherInventory == thePlayer.inv)
  766. {
  767. isQuestItem = this.IsItemQuest( itemId );
  768. theTelemetry.LogWithLabelAndValue(TE_INV_ITEM_PICKED, itemName, quantity);
  769.  
  770. if ( !theGame.AreSavesLocked() && ( isQuestItem || this.GetItemQuality( itemId ) >= 4 ) )
  771. {
  772. theGame.RequestAutoSave( "item gained", false );
  773. }
  774. }
  775.  
  776. if (refreshNewFlag)
  777. {
  778. for (i = 0; i < arr.Size(); i += 1)
  779. {
  780. uiData = otherInventory.GetInventoryItemUIData( arr[i] );
  781. uiData.isNew = true;
  782. otherInventory.SetInventoryItemUIData( arr[i], uiData );
  783. }
  784. }
  785.  
  786. return arr[0];
  787. }
  788.  
  789. public final function GiveAllItemsTo(otherInventory : CInventoryComponent, optional forceTransferNoDrops : bool, optional informGUI : bool)
  790. {
  791. var items : array<SItemUniqueId>;
  792.  
  793. GetAllItems(items);
  794. GiveItemsTo(otherInventory, items, forceTransferNoDrops, informGUI);
  795. }
  796.  
  797. public final function GiveItemsTo(otherInventory : CInventoryComponent, items : array<SItemUniqueId>, optional forceTransferNoDrops : bool, optional informGUI : bool) : array<SItemUniqueId>
  798. {
  799. var i : int;
  800. var ret : array<SItemUniqueId>;
  801.  
  802. for( i = 0; i < items.Size(); i += 1 )
  803. {
  804. ret.PushBack(GiveItemTo(otherInventory, items[i], GetItemQuantity(items[i]), true, forceTransferNoDrops, informGUI));
  805. }
  806.  
  807. return ret;
  808. }
  809.  
  810.  
  811. import final function HasItem( item : name ) : bool;
  812.  
  813.  
  814.  
  815. final function HasItemById(id : SItemUniqueId) : bool
  816. {
  817. var arr : array<SItemUniqueId>;
  818.  
  819. GetAllItems(arr);
  820. return arr.Contains(id);
  821. }
  822.  
  823. public function HasItemByTag(tag : name) : bool
  824. {
  825. var quantity : int;
  826.  
  827. quantity = GetItemQuantityByTag( tag );
  828. return quantity > 0;
  829. }
  830.  
  831. public function HasItemByCategory(category : name) : bool
  832. {
  833. var quantity : int;
  834.  
  835. quantity = GetItemQuantityByCategory( category );
  836. return quantity > 0;
  837. }
  838.  
  839.  
  840. public function HasInfiniteBolts() : bool
  841. {
  842. var ids : array<SItemUniqueId>;
  843. var i : int;
  844.  
  845. ids = GetItemsByTag(theGame.params.TAG_INFINITE_AMMO);
  846. for(i=0; i<ids.Size(); i+=1)
  847. {
  848. if(IsItemBolt(ids[i]))
  849. {
  850. return true;
  851. }
  852. }
  853.  
  854. return false;
  855. }
  856.  
  857.  
  858. public function HasGroundBolts() : bool
  859. {
  860. var ids : array<SItemUniqueId>;
  861. var i : int;
  862.  
  863. ids = GetItemsByTag(theGame.params.TAG_GROUND_AMMO);
  864. for(i=0; i<ids.Size(); i+=1)
  865. {
  866. if(IsItemBolt(ids[i]))
  867. {
  868. return true;
  869. }
  870. }
  871.  
  872. return false;
  873. }
  874.  
  875.  
  876. public function HasUnderwaterBolts() : bool
  877. {
  878. var ids : array<SItemUniqueId>;
  879. var i : int;
  880.  
  881. ids = GetItemsByTag(theGame.params.TAG_UNDERWATER_AMMO);
  882. for(i=0; i<ids.Size(); i+=1)
  883. {
  884. if(IsItemBolt(ids[i]))
  885. {
  886. return true;
  887. }
  888. }
  889.  
  890. return false;
  891. }
  892.  
  893.  
  894.  
  895. import private final function AddMultiItem( item : name, optional quantity : int, optional informGui : bool , optional markAsNew : bool , optional lootable : bool ) : array<SItemUniqueId>;
  896. import private final function AddSingleItem( item : name, optional informGui : bool , optional markAsNew : bool , optional lootable : bool ) : SItemUniqueId;
  897.  
  898.  
  899. public final function AddAnItem(item : name, optional quantity : int, optional dontInformGui : bool, optional dontMarkAsNew : bool, optional showAsRewardInUIHax : bool) : array<SItemUniqueId>
  900. {
  901. var arr : array<SItemUniqueId>;
  902. var i : int;
  903. var isReadableItem : bool;
  904.  
  905.  
  906. if( theGame.GetDefinitionsManager().IsItemSingletonItem(item) && GetEntity() == thePlayer)
  907. {
  908. if(GetItemQuantityByName(item) > 0)
  909. {
  910. arr = GetItemsIds(item);
  911. }
  912. else
  913. {
  914. arr.PushBack(AddSingleItem(item, !dontInformGui, !dontMarkAsNew));
  915. }
  916.  
  917. quantity = 1;
  918. }
  919. else
  920. {
  921. if(quantity < 2 )
  922. {
  923. arr.PushBack(AddSingleItem(item, !dontInformGui, !dontMarkAsNew));
  924. }
  925. else
  926. {
  927. arr = AddMultiItem(item, quantity, !dontInformGui, !dontMarkAsNew);
  928. }
  929. }
  930.  
  931.  
  932. if(this == thePlayer.GetInventory())
  933. {
  934. if(ItemHasTag(arr[0],'ReadableItem'))
  935. UpdateInitialReadState(arr[0]);
  936.  
  937.  
  938. if(showAsRewardInUIHax || ItemHasTag(arr[0],'GwintCard'))
  939. thePlayer.DisplayItemRewardNotification(GetItemName(arr[0]), quantity );
  940. }
  941.  
  942. return arr;
  943. }
  944.  
  945.  
  946. import final function RemoveItem( itemId : SItemUniqueId, optional quantity : int ) : bool;
  947.  
  948.  
  949. private final function InternalRemoveItems(ids : array<SItemUniqueId>, quantity : int)
  950. {
  951. var i, currQuantityToTake : int;
  952.  
  953.  
  954. for(i=0; i<ids.Size(); i+=1 )
  955. {
  956.  
  957. currQuantityToTake = Min(quantity, GetItemQuantity(ids[i]) );
  958.  
  959.  
  960. if( GetEntity() == thePlayer )
  961. {
  962. GetWitcherPlayer().RemoveGwentCard( GetItemName(ids[i]) , currQuantityToTake);
  963. }
  964.  
  965.  
  966. RemoveItem(ids[i], currQuantityToTake);
  967.  
  968.  
  969. quantity -= currQuantityToTake;
  970.  
  971.  
  972. if ( quantity == 0 )
  973. {
  974. return;
  975. }
  976.  
  977.  
  978. LogAssert(quantity>0, "CInventoryComponent.InternalRemoveItems(" + GetItemName(ids[i]) + "): somehow took too many items! Should be " + (-quantity) + " less... Investigate!");
  979. }
  980. }
  981.  
  982.  
  983.  
  984. public function RemoveItemByName(itemName : name, optional quantity : int) : bool
  985. {
  986. var totalItemCount : int;
  987. var ids : array<SItemUniqueId>;
  988.  
  989.  
  990. totalItemCount = GetItemQuantityByName(itemName);
  991. if(totalItemCount < quantity || quantity == 0)
  992. {
  993. return false;
  994. }
  995.  
  996. if(quantity == 0)
  997. {
  998. quantity = 1;
  999. }
  1000. else if(quantity < 0)
  1001. {
  1002. quantity = totalItemCount;
  1003. }
  1004.  
  1005. ids = GetItemsIds(itemName);
  1006.  
  1007. if(GetEntity() == thePlayer && thePlayer.GetSelectedItemId() == ids[0] )
  1008. {
  1009. thePlayer.ClearSelectedItemId();
  1010. }
  1011.  
  1012. InternalRemoveItems(ids, quantity);
  1013.  
  1014. return true;
  1015. }
  1016.  
  1017.  
  1018.  
  1019. public function RemoveItemByCategory(itemCategory : name, optional quantity : int) : bool
  1020. {
  1021. var totalItemCount : int;
  1022. var ids : array<SItemUniqueId>;
  1023. var selectedItemId : SItemUniqueId;
  1024. var i : int;
  1025.  
  1026.  
  1027. totalItemCount = GetItemQuantityByCategory(itemCategory);
  1028. if(totalItemCount < quantity)
  1029. {
  1030. return false;
  1031. }
  1032.  
  1033. if(quantity == 0)
  1034. {
  1035. quantity = 1;
  1036. }
  1037. else if(quantity < 0)
  1038. {
  1039. quantity = totalItemCount;
  1040. }
  1041.  
  1042. ids = GetItemsByCategory(itemCategory);
  1043.  
  1044. if(GetEntity() == thePlayer)
  1045. {
  1046. selectedItemId = thePlayer.GetSelectedItemId();
  1047. for(i=0; i<ids.Size(); i+=1)
  1048. {
  1049. if(selectedItemId == ids[i] )
  1050. {
  1051. thePlayer.ClearSelectedItemId();
  1052. break;
  1053. }
  1054. }
  1055. }
  1056.  
  1057. InternalRemoveItems(ids, quantity);
  1058.  
  1059. return true;
  1060. }
  1061.  
  1062.  
  1063.  
  1064. public function RemoveItemByTag(itemTag : name, optional quantity : int) : bool
  1065. {
  1066. var totalItemCount : int;
  1067. var ids : array<SItemUniqueId>;
  1068. var i : int;
  1069. var selectedItemId : SItemUniqueId;
  1070.  
  1071.  
  1072. totalItemCount = GetItemQuantityByTag(itemTag);
  1073. if(totalItemCount < quantity)
  1074. {
  1075. return false;
  1076. }
  1077.  
  1078. if(quantity == 0)
  1079. {
  1080. quantity = 1;
  1081. }
  1082. else if(quantity < 0)
  1083. {
  1084. quantity = totalItemCount;
  1085. }
  1086.  
  1087. ids = GetItemsByTag(itemTag);
  1088.  
  1089. if(GetEntity() == thePlayer)
  1090. {
  1091. selectedItemId = thePlayer.GetSelectedItemId();
  1092. for(i=0; i<ids.Size(); i+=1)
  1093. {
  1094. if(selectedItemId == ids[i] )
  1095. {
  1096. thePlayer.ClearSelectedItemId();
  1097. break;
  1098. }
  1099. }
  1100. }
  1101.  
  1102. InternalRemoveItems(ids, quantity);
  1103.  
  1104. return true;
  1105. }
  1106.  
  1107.  
  1108. import final function RemoveAllItems();
  1109.  
  1110.  
  1111. import final function GetItemEntityUnsafe( itemId : SItemUniqueId ) : CItemEntity;
  1112.  
  1113.  
  1114. import final function GetDeploymentItemEntity( itemId : SItemUniqueId, optional position : Vector, optional rotation : EulerAngles, optional allocateIdTag : bool ) : CEntity;
  1115.  
  1116.  
  1117. import final function MountItem( itemId : SItemUniqueId, optional toHand : bool, optional force : bool ) : bool;
  1118.  
  1119.  
  1120. import final function UnmountItem( itemId : SItemUniqueId, optional destroyEntity : bool ) : bool;
  1121.  
  1122.  
  1123.  
  1124. import final function IsItemMounted( itemId : SItemUniqueId ) : bool;
  1125.  
  1126.  
  1127.  
  1128. import final function IsItemHeld( itemId : SItemUniqueId ) : bool;
  1129.  
  1130.  
  1131. import final function DropItem( itemId : SItemUniqueId, optional removeFromInv : bool );
  1132.  
  1133.  
  1134. import final function GetItemHoldSlot( itemId : SItemUniqueId ) : name;
  1135.  
  1136.  
  1137. import final function PlayItemEffect( itemId : SItemUniqueId, effectName : name );
  1138. import final function StopItemEffect( itemId : SItemUniqueId, effectName : name );
  1139.  
  1140.  
  1141. import final function ThrowAwayItem( itemId : SItemUniqueId, optional quantity : int ) : bool;
  1142.  
  1143.  
  1144. import final function ThrowAwayAllItems() : CEntity;
  1145.  
  1146.  
  1147. import final function ThrowAwayItemsFiltered( excludedTags : array< name > ) : CEntity;
  1148.  
  1149.  
  1150. import final function ThrowAwayLootableItems( optional skipNoDropNoShow : bool ) : CEntity;
  1151.  
  1152.  
  1153. import final function GetItemRecyclingParts( itemId : SItemUniqueId ) : array<SItemParts>;
  1154.  
  1155. import final function GetItemWeight( id : SItemUniqueId ) : float;
  1156.  
  1157.  
  1158. public final function HasQuestItem() : bool
  1159. {
  1160. var allItems : array< SItemUniqueId >;
  1161. var i : int;
  1162.  
  1163. allItems = GetItemsByTag('Quest');
  1164. for ( i=0; i<allItems.Size(); i+=1 )
  1165. {
  1166. if(!ItemHasTag(allItems[i], theGame.params.TAG_DONT_SHOW))
  1167. {
  1168. return true;
  1169. }
  1170. }
  1171.  
  1172. return false;
  1173. }
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180. import final function HasItemDurability( itemId : SItemUniqueId ) : bool;
  1181. import final function GetItemDurability( itemId : SItemUniqueId ) : float;
  1182. import private final function SetItemDurability( itemId : SItemUniqueId, durability : float );
  1183. import final function GetItemInitialDurability( itemId : SItemUniqueId ) : float;
  1184. import final function GetItemMaxDurability( itemId : SItemUniqueId ) : float;
  1185. import final function GetItemGridSize( itemId : SItemUniqueId ) : int;
  1186.  
  1187.  
  1188. import final function NotifyItemLooted( item : SItemUniqueId );
  1189. import final function ResetContainerData();
  1190.  
  1191. public function SetItemDurabilityScript( itemId : SItemUniqueId, durability : float )
  1192. {
  1193. var oldDur : float;
  1194.  
  1195. oldDur = GetItemDurability(itemId);
  1196.  
  1197. if(oldDur == durability)
  1198. return;
  1199.  
  1200. if(durability < oldDur)
  1201. {
  1202. if ( ItemHasAbility( itemId, 'MA_Indestructible' ) )
  1203. {
  1204. return;
  1205. }
  1206.  
  1207. if(GetEntity() == thePlayer && ShouldProcessTutorial('TutorialDurability'))
  1208. {
  1209. if ( durability <= theGame.params.ITEM_DAMAGED_DURABILITY && oldDur > theGame.params.ITEM_DAMAGED_DURABILITY )
  1210. {
  1211. FactsAdd( "tut_item_damaged", 1 );
  1212. }
  1213. }
  1214. }
  1215.  
  1216. SetItemDurability( itemId, durability );
  1217. }
  1218.  
  1219.  
  1220. public function ReduceItemDurability(itemId : SItemUniqueId, optional forced : bool) : bool
  1221. {
  1222. var dur, value, durabilityDiff, itemToughness, indestructible : float;
  1223. var chance : int;
  1224. if(!IsIdValid(itemId) || !HasItemDurability(itemId) || ItemHasAbility(itemId, 'MA_Indestructible'))
  1225. {
  1226. return false;
  1227. }
  1228.  
  1229.  
  1230. if(IsItemWeapon(itemId))
  1231. {
  1232. chance = theGame.params.DURABILITY_WEAPON_LOSE_CHANCE;
  1233. value = theGame.params.GetWeaponDurabilityLoseValue();
  1234. }
  1235. else if(IsItemAnyArmor(itemId))
  1236. {
  1237. chance = theGame.params.DURABILITY_ARMOR_LOSE_CHANCE;
  1238. value = theGame.params.DURABILITY_ARMOR_LOSE_VALUE;
  1239. }
  1240.  
  1241. dur = GetItemDurability(itemId);
  1242.  
  1243. if ( dur == 0 )
  1244. {
  1245. return false;
  1246. }
  1247.  
  1248.  
  1249. if ( forced || RandRange( 100 ) < chance )
  1250. {
  1251. itemToughness = CalculateAttributeValue( GetItemAttributeValue( itemId, 'toughness' ) );
  1252. indestructible = CalculateAttributeValue( GetItemAttributeValue( itemId, 'indestructible' ) );
  1253.  
  1254. value = value * ( 1 - indestructible );
  1255.  
  1256. if ( itemToughness > 0.0f && itemToughness <= 1.0f )
  1257. {
  1258. durabilityDiff = ( dur - value ) * itemToughness;
  1259.  
  1260. SetItemDurabilityScript( itemId, MaxF(durabilityDiff, 0 ) );
  1261. }
  1262. else
  1263. {
  1264. SetItemDurabilityScript( itemId, MaxF( dur - value, 0 ) );
  1265. }
  1266. }
  1267.  
  1268. return true;
  1269. }
  1270.  
  1271. public function GetItemDurabilityRatio(itemId : SItemUniqueId) : float
  1272. {
  1273. if ( !IsIdValid( itemId ) || !HasItemDurability( itemId ) )
  1274. return -1;
  1275.  
  1276. return GetItemDurability(itemId) / GetItemMaxDurability(itemId);
  1277. }
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284. public function GetItemResistStatWithDurabilityModifiers(itemId : SItemUniqueId, stat : ECharacterDefenseStats, out points : SAbilityAttributeValue, out percents : SAbilityAttributeValue)
  1285. {
  1286. var mult : float;
  1287. var null : SAbilityAttributeValue;
  1288.  
  1289. points = null;
  1290. percents = null;
  1291. if(!IsItemAnyArmor(itemId))
  1292. return;
  1293.  
  1294. mult = theGame.params.GetDurabilityMultiplier(GetItemDurabilityRatio(itemId), false);
  1295.  
  1296. points = GetItemAttributeValue(itemId, ResistStatEnumToName(stat, true));
  1297. percents = GetItemAttributeValue(itemId, ResistStatEnumToName(stat, false));
  1298.  
  1299. points = points * mult;
  1300. percents = percents * mult;
  1301. }
  1302.  
  1303.  
  1304. public function GetItemResistanceTypes(id : SItemUniqueId) : array<ECharacterDefenseStats>
  1305. {
  1306. var ret : array<ECharacterDefenseStats>;
  1307. var i : int;
  1308. var stat : ECharacterDefenseStats;
  1309. var atts : array<name>;
  1310. var tmpBool : bool;
  1311.  
  1312. if(!IsIdValid(id))
  1313. return ret;
  1314.  
  1315. GetItemAttributes(id, atts);
  1316. for(i=0; i<atts.Size(); i+=1)
  1317. {
  1318. stat = ResistStatNameToEnum(atts[i], tmpBool);
  1319. if(stat != CDS_None && !ret.Contains(stat))
  1320. ret.PushBack(stat);
  1321. }
  1322.  
  1323. return ret;
  1324. }
  1325.  
  1326. import final function GetItemModifierFloat( itemId : SItemUniqueId, modName : name, optional defValue : float ) : float;
  1327. import final function SetItemModifierFloat( itemId : SItemUniqueId, modName : name, val : float);
  1328. import final function GetItemModifierInt ( itemId : SItemUniqueId, modName : name, optional defValue : int ) : int;
  1329. import final function SetItemModifierInt ( itemId : SItemUniqueId, modName : name, val : int );
  1330.  
  1331.  
  1332. import final function ActivateQuestBonus();
  1333.  
  1334.  
  1335. import final function GetItemSetName( itemId : SItemUniqueId ) : name;
  1336.  
  1337.  
  1338. import final function AddItemCraftedAbility( itemId : SItemUniqueId, abilityName : name, optional allowDuplicate : bool );
  1339.  
  1340.  
  1341. import final function RemoveItemCraftedAbility( itemId : SItemUniqueId, abilityName : name );
  1342.  
  1343.  
  1344. import final function AddItemBaseAbility(item : SItemUniqueId, abilityName : name);
  1345.  
  1346.  
  1347. import final function RemoveItemBaseAbility(item : SItemUniqueId, abilityName : name);
  1348.  
  1349.  
  1350. import final function DespawnItem( itemId : SItemUniqueId );
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357. import final function GetInventoryItemUIData( item : SItemUniqueId ) : SInventoryItemUIData;
  1358.  
  1359.  
  1360. import final function SetInventoryItemUIData( item : SItemUniqueId, data : SInventoryItemUIData );
  1361.  
  1362. import final function SortInventoryUIData();
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369. import final function PrintInfo();
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376. import final function EnableLoot( enable : bool );
  1377.  
  1378.  
  1379. import final function UpdateLoot();
  1380.  
  1381.  
  1382. import final function AddItemsFromLootDefinition( lootDefinitionName : name );
  1383.  
  1384.  
  1385. import final function IsLootRenewable() : bool;
  1386.  
  1387.  
  1388. import final function IsReadyToRenew() : bool;
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395. function Created()
  1396. {
  1397. LoadBooksDefinitions();
  1398. }
  1399.  
  1400. function ClearGwintCards()
  1401. {
  1402. var attr : SAbilityAttributeValue;
  1403. var allItems : array<SItemUniqueId>;
  1404. var card : array<SItemUniqueId>;
  1405. var iHave, shopHave, cardLimit, delta : int;
  1406. var curItem : SItemUniqueId;
  1407. var i : int;
  1408.  
  1409. allItems = GetItemsByCategory('gwint');
  1410. for(i=allItems.Size()-1; i >= 0; i-=1)
  1411. {
  1412. curItem = allItems[i];
  1413.  
  1414. attr = GetItemAttributeValue( curItem, 'max_count');
  1415. card = thePlayer.GetInventory().GetItemsByName( GetItemName( curItem ) );
  1416. iHave = thePlayer.GetInventory().GetItemQuantity( card[0] );
  1417. cardLimit = RoundF(attr.valueBase);
  1418. shopHave = GetItemQuantity( curItem );
  1419.  
  1420. if (iHave > 0 && shopHave > 0)
  1421. {
  1422. delta = shopHave - (cardLimit - iHave);
  1423.  
  1424. if ( delta > 0 )
  1425. {
  1426. RemoveItem( curItem, delta );
  1427. }
  1428. }
  1429. }
  1430. }
  1431.  
  1432. function ClearTHmaps()
  1433. {
  1434. var attr : SAbilityAttributeValue;
  1435. var allItems : array<SItemUniqueId>;
  1436. var map : array<SItemUniqueId>;
  1437. var i : int;
  1438. var thCompleted : bool;
  1439. var iHave, shopHave : int;
  1440.  
  1441. allItems = GetItemsByTag('ThMap');
  1442. for(i=allItems.Size()-1; i >= 0; i-=1)
  1443. {
  1444. attr = GetItemAttributeValue( allItems[i], 'max_count');
  1445. map = thePlayer.GetInventory().GetItemsByName( GetItemName( allItems[i] ) );
  1446. thCompleted = FactsDoesExist(GetItemName(allItems[i]));
  1447. iHave = thePlayer.GetInventory().GetItemQuantity( map[0] );
  1448. shopHave = RoundF(attr.valueBase);
  1449.  
  1450. if ( iHave >= shopHave || thCompleted )
  1451. {
  1452. RemoveItem( allItems[i], GetItemQuantity( allItems[i] ) );
  1453. }
  1454. }
  1455. }
  1456.  
  1457.  
  1458. public final function ClearKnownRecipes()
  1459. {
  1460. var witcher : W3PlayerWitcher;
  1461. var recipes, craftRecipes : array<name>;
  1462. var i : int;
  1463. var itemName : name;
  1464. var allItems : array<SItemUniqueId>;
  1465.  
  1466. witcher = GetWitcherPlayer();
  1467. if(!witcher)
  1468. return;
  1469.  
  1470.  
  1471. recipes = witcher.GetAlchemyRecipes();
  1472. craftRecipes = witcher.GetCraftingSchematicsNames();
  1473. ArrayOfNamesAppend(recipes, craftRecipes);
  1474.  
  1475.  
  1476. GetAllItems(allItems);
  1477.  
  1478.  
  1479. for(i=allItems.Size()-1; i>=0; i-=1)
  1480. {
  1481. itemName = GetItemName(allItems[i]);
  1482. if(recipes.Contains(itemName))
  1483. RemoveItem(allItems[i], GetItemQuantity(allItems[i]));
  1484. }
  1485. }
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491. function LoadBooksDefinitions() : void
  1492. {
  1493. var readableArray : array<SItemUniqueId>;
  1494. var i : int;
  1495.  
  1496. readableArray = GetItemsByTag('ReadableItem');
  1497.  
  1498. for( i = 0; i < readableArray.Size(); i += 1 )
  1499. {
  1500. if( IsBookRead(readableArray[i]))
  1501. {
  1502. continue;
  1503. }
  1504. UpdateInitialReadState(readableArray[i]);
  1505. }
  1506. }
  1507.  
  1508. function UpdateInitialReadState( item : SItemUniqueId )
  1509. {
  1510. var abilitiesArray : array<name>;
  1511. var i : int;
  1512. GetItemAbilities(item,abilitiesArray);
  1513.  
  1514. for( i = 0; i < abilitiesArray.Size(); i += 1 )
  1515. {
  1516. if( abilitiesArray[i] == 'WasRead' )
  1517. {
  1518. ReadBook(item);
  1519. break;
  1520. }
  1521. }
  1522. }
  1523.  
  1524. function IsBookRead( item : SItemUniqueId ) : bool
  1525. {
  1526. var bookName : name;
  1527. var bResult : bool;
  1528.  
  1529. bookName = GetItemName( item );
  1530.  
  1531. bResult = IsBookReadByName( bookName );
  1532. return bResult;
  1533. }
  1534.  
  1535. function IsBookReadByName( bookName : name ) : bool
  1536. {
  1537. var bookFactName : string;
  1538.  
  1539. bookFactName = GetBookReadFactName( bookName );
  1540. if( FactsDoesExist(bookFactName) )
  1541. {
  1542. return FactsQuerySum( bookFactName );
  1543. }
  1544.  
  1545. return false;
  1546. }
  1547.  
  1548. function ReadBook( item : SItemUniqueId, optional noNotification : bool )
  1549. {
  1550.  
  1551. var bookName : name;
  1552. var abilitiesArray : array<name>;
  1553. var i : int;
  1554. var commonMapManager : CCommonMapManager = theGame.GetCommonMapManager();
  1555.  
  1556. bookName = GetItemName( item );
  1557.  
  1558. if ( !IsBookRead ( item ) && ItemHasTag ( item, 'FastTravel' ))
  1559. {
  1560. GetItemAbilities(item, abilitiesArray);
  1561.  
  1562. for ( i = 0; i < abilitiesArray.Size(); i+=1 )
  1563. {
  1564. commonMapManager.SetEntityMapPinDiscoveredScript(true, abilitiesArray[i], true );
  1565. }
  1566. }
  1567. ReadBookByNameId( bookName, item, false, noNotification );
  1568.  
  1569.  
  1570.  
  1571.  
  1572. if(ItemHasTag(item, 'PerkBook'))
  1573. {
  1574.  
  1575. }
  1576. }
  1577.  
  1578. public function GetBookText(item : SItemUniqueId) : string
  1579. {
  1580. if ( GetItemName( item ) != 'Gwent Almanac' )
  1581. {
  1582. return ReplaceTagsToIcons(GetLocStringByKeyExt(GetItemLocalizedNameByUniqueID(item)+"_text"));
  1583. }
  1584. else
  1585. {
  1586. return GetGwentAlmanacContents();
  1587. }
  1588. }
  1589.  
  1590. public function GetBookTextByName( bookName : name ) : string
  1591. {
  1592. if( bookName != 'Gwent Almanac' )
  1593. {
  1594. return ReplaceTagsToIcons( GetLocStringByKeyExt( GetItemLocalizedNameByName( bookName ) + "_text" ) );
  1595. }
  1596. else
  1597. {
  1598. return GetGwentAlmanacContents();
  1599. }
  1600. }
  1601.  
  1602. function ReadSchematicsAndRecipes( item : SItemUniqueId )
  1603. {
  1604. var itemCategory : name;
  1605. var itemName : name;
  1606. var player : W3PlayerWitcher;
  1607.  
  1608. ReadBook( item );
  1609.  
  1610. player = GetWitcherPlayer();
  1611. if ( !player )
  1612. {
  1613. return;
  1614. }
  1615.  
  1616. itemName = GetItemName( item );
  1617. itemCategory = GetItemCategory( item );
  1618. if ( itemCategory == 'alchemy_recipe' )
  1619. {
  1620. if ( player.CanLearnAlchemyRecipe( itemName ) )
  1621. {
  1622. player.AddAlchemyRecipe( itemName );
  1623. player.GetInventory().AddItemTag(item, 'NoShow');
  1624.  
  1625. }
  1626. }
  1627. else if ( itemCategory == 'crafting_schematic' )
  1628. {
  1629. player.AddCraftingSchematic( itemName );
  1630. player.GetInventory().AddItemTag(item, 'NoShow');
  1631.  
  1632. }
  1633. }
  1634.  
  1635. function ReadBookByName( bookName : name , unread : bool, optional noNotification : bool )
  1636. {
  1637. var defMgr : CDefinitionsManagerAccessor;
  1638. var bookFactName : string;
  1639.  
  1640. if( IsBookReadByName( bookName ) != unread )
  1641. {
  1642. return;
  1643. }
  1644.  
  1645. bookFactName = "BookReadState_"+bookName;
  1646. bookFactName = StrReplace(bookFactName," ","_");
  1647.  
  1648. if( unread )
  1649. {
  1650. FactsSubstract( bookFactName, 1 );
  1651. }
  1652. else
  1653. {
  1654. FactsAdd( bookFactName, 1 );
  1655.  
  1656.  
  1657. defMgr = theGame.GetDefinitionsManager();
  1658. if(!IsAlchemyRecipe(bookName) && !IsCraftingSchematic(bookName) && !defMgr.ItemHasTag( bookName, 'Painting' ) )
  1659. {
  1660. theGame.GetGamerProfile().IncStat(ES_ReadBooks);
  1661.  
  1662. if( !noNotification )
  1663. {
  1664. theGame.GetGuiManager().ShowNotification( GetLocStringByKeyExt( "notification_book_moved" ), 0, false );
  1665. }
  1666. }
  1667.  
  1668.  
  1669. if ( AddBestiaryFromBook(bookName) )
  1670. return;
  1671.  
  1672.  
  1673.  
  1674. }
  1675. }
  1676.  
  1677. function ReadBookByNameId( bookName : name, itemId:SItemUniqueId, unread : bool, optional noNotification : bool )
  1678. {
  1679. var bookFactName : string;
  1680.  
  1681. if( IsBookReadByName( bookName ) != unread )
  1682. {
  1683. return;
  1684. }
  1685.  
  1686. bookFactName = "BookReadState_"+bookName;
  1687. bookFactName = StrReplace(bookFactName," ","_");
  1688.  
  1689. if( unread )
  1690. {
  1691. FactsSubstract( bookFactName, 1 );
  1692. }
  1693. else
  1694. {
  1695. FactsAdd( bookFactName, 1 );
  1696.  
  1697.  
  1698. if( !IsAlchemyRecipe( bookName ) && !IsCraftingSchematic( bookName ) )
  1699. {
  1700. theGame.GetGamerProfile().IncStat(ES_ReadBooks);
  1701.  
  1702. if( !noNotification )
  1703. {
  1704.  
  1705. GetWitcherPlayer().AddReadBook( bookName );
  1706. }
  1707. }
  1708.  
  1709.  
  1710. if ( AddBestiaryFromBook(bookName) )
  1711. return;
  1712. else
  1713. ReadSchematicsAndRecipes( itemId );
  1714. }
  1715. }
  1716.  
  1717.  
  1718. private function AddBestiaryFromBook( bookName : name ) : bool
  1719. {
  1720. var i, j, r, len : int;
  1721. var manager : CWitcherJournalManager;
  1722. var resource : array<CJournalResource>;
  1723. var entryBase : CJournalBase;
  1724. var childGroups : array<CJournalBase>;
  1725. var childEntries : array<CJournalBase>;
  1726. var descriptionGroup : CJournalCreatureDescriptionGroup;
  1727. var descriptionEntry : CJournalCreatureDescriptionEntry;
  1728.  
  1729. manager = theGame.GetJournalManager();
  1730.  
  1731. switch ( bookName )
  1732. {
  1733. case 'Beasts vol 1':
  1734. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWolf" ) );
  1735. resource.PushBack( (CJournalResource)LoadResource( "BestiaryDog" ) );
  1736. break;
  1737. case 'Beasts vol 2':
  1738. resource.PushBack( (CJournalResource)LoadResource( "BestiaryBear" ) );
  1739. break;
  1740. case 'Cursed Monsters vol 1':
  1741. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWerewolf" ) );
  1742. resource.PushBack( (CJournalResource)LoadResource( "BestiaryLycanthrope" ) );
  1743. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 24');
  1744. break;
  1745. case 'Cursed Monsters vol 2':
  1746. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWerebear" ) );
  1747. resource.PushBack( (CJournalResource)LoadResource( "BestiaryMiscreant" ) );
  1748. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 11');
  1749. break;
  1750. case 'Draconides vol 1':
  1751. resource.PushBack( (CJournalResource)LoadResource( "BestiaryCockatrice" ) );
  1752. resource.PushBack( (CJournalResource)LoadResource( "BestiaryBasilisk" ) );
  1753. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 3');
  1754. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 23');
  1755. break;
  1756. case 'Draconides vol 2':
  1757. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWyvern" ) );
  1758. resource.PushBack( (CJournalResource)LoadResource( "BestiaryForktail" ) );
  1759. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 10');
  1760. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 17');
  1761. break;
  1762. case 'Hybrid Monsters vol 1':
  1763. resource.PushBack( (CJournalResource)LoadResource( "BestiaryHarpy" ) );
  1764. resource.PushBack( (CJournalResource)LoadResource( "BestiaryErynia" ) );
  1765. resource.PushBack( (CJournalResource)LoadResource( "BestiarySiren" ) );
  1766. resource.PushBack( (CJournalResource)LoadResource( "BestiarySuccubus" ) );
  1767. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 14');
  1768. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 21');
  1769. break;
  1770. case 'Hybrid Monsters vol 2':
  1771. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGriffin" ) );
  1772. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 4');
  1773. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 27');
  1774. break;
  1775. case 'Insectoids vol 1':
  1776. resource.PushBack( (CJournalResource)LoadResource( "BestiaryEndriagaWorker" ) );
  1777. resource.PushBack( (CJournalResource)LoadResource( "BestiaryEndriagaTruten" ) );
  1778. resource.PushBack( (CJournalResource)LoadResource( "BestiaryEndriaga" ) );
  1779. break;
  1780. case 'Insectoids vol 2':
  1781. resource.PushBack( (CJournalResource)LoadResource( "BestiaryCrabSpider" ) );
  1782. resource.PushBack( (CJournalResource)LoadResource( "BestiaryArmoredArachas" ) );
  1783. resource.PushBack( (CJournalResource)LoadResource( "BestiaryPoisonousArachas" ) );
  1784. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 2');
  1785. break;
  1786. case 'Magical Monsters vol 1':
  1787. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGolem" ) );
  1788. break;
  1789. case 'Magical Monsters vol 2':
  1790. resource.PushBack( (CJournalResource)LoadResource( "BestiaryElemental" ) );
  1791. resource.PushBack( (CJournalResource)LoadResource( "BestiaryIceGolem" ) );
  1792. resource.PushBack( (CJournalResource)LoadResource( "BestiaryFireElemental" ) );
  1793. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWhMinion" ) );
  1794. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 20');
  1795. break;
  1796. case 'Necrophage vol 1':
  1797. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGhoul" ) );
  1798. resource.PushBack( (CJournalResource)LoadResource( "BestiaryAlghoul" ) );
  1799. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGreaterRotFiend" ) );
  1800. resource.PushBack( (CJournalResource)LoadResource( "BestiaryDrowner" ) );
  1801. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 15');
  1802. break;
  1803. case 'Necrophage vol 2':
  1804. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGraveHag" ) );
  1805. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWaterHag" ) );
  1806. resource.PushBack( (CJournalResource)LoadResource( "BestiaryFogling" ) );
  1807. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 5');
  1808. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 9');
  1809. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 18');
  1810. break;
  1811. case 'Relict Monsters vol 1':
  1812. resource.PushBack( (CJournalResource)LoadResource( "BestiaryBies" ) );
  1813. resource.PushBack( (CJournalResource)LoadResource( "BestiaryCzart" ) );
  1814. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 8');
  1815. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 16');
  1816. break;
  1817. case 'Relict Monsters vol 2':
  1818. resource.PushBack( (CJournalResource)LoadResource( "BestiaryLeshy" ) );
  1819. resource.PushBack( (CJournalResource)LoadResource( "BestiarySilvan" ) );
  1820. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 22');
  1821. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 26');
  1822. break;
  1823. case 'Specters vol 1':
  1824. resource.PushBack( (CJournalResource)LoadResource( "BestiaryMoonwright" ) );
  1825. resource.PushBack( (CJournalResource)LoadResource( "BestiaryNoonwright" ) );
  1826. resource.PushBack( (CJournalResource)LoadResource( "BestiaryPesta" ) );
  1827. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 6');
  1828. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 13');
  1829. break;
  1830. case 'Specters vol 2':
  1831. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWraith" ) );
  1832. resource.PushBack( (CJournalResource)LoadResource( "BestiaryHim" ) );
  1833. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 19');
  1834. break;
  1835. case 'Ogres vol 1':
  1836. resource.PushBack( (CJournalResource)LoadResource( "BestiaryNekker" ) );
  1837. resource.PushBack( (CJournalResource)LoadResource( "BestiaryIceTroll" ) );
  1838. resource.PushBack( (CJournalResource)LoadResource( "BestiaryCaveTroll" ) );
  1839. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 12');
  1840. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 25');
  1841. break;
  1842. case 'Ogres vol 2':
  1843. resource.PushBack( (CJournalResource)LoadResource( "BestiaryCyclop" ) );
  1844. resource.PushBack( (CJournalResource)LoadResource( "BestiaryIceGiant" ) );
  1845. break;
  1846. case 'Vampires vol 1':
  1847. resource.PushBack( (CJournalResource)LoadResource( "BestiaryEkkima" ) );
  1848. resource.PushBack( (CJournalResource)LoadResource( "BestiaryHigherVampire" ) );
  1849. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 7');
  1850. break;
  1851. case 'Vampires vol 2':
  1852. resource.PushBack( (CJournalResource)LoadResource( "BestiaryKatakan" ) );
  1853. GetWitcherPlayer().AddAlchemyRecipe('Recipe for Mutagen 1');
  1854. break;
  1855.  
  1856. case 'bestiary_sharley_book':
  1857. resource.PushBack( (CJournalResource)LoadResource( "BestiarySharley" ) );
  1858. break;
  1859. case 'bestiary_barghest_book':
  1860. resource.PushBack( (CJournalResource)LoadResource( "BestiaryBarghest" ) );
  1861. break;
  1862. case 'bestiary_garkain_book':
  1863. resource.PushBack( (CJournalResource)LoadResource( "BestiaryGarkain" ) );
  1864. break;
  1865. case 'bestiary_alp_book':
  1866. resource.PushBack( (CJournalResource)LoadResource( "BestiaryAlp" ) );
  1867. break;
  1868. case 'bestiary_bruxa_book':
  1869. resource.PushBack( (CJournalResource)LoadResource( "BestiaryBruxa" ) );
  1870. break;
  1871. case 'bestiary_spriggan_book':
  1872. resource.PushBack( (CJournalResource)LoadResource( "BestiarySpriggan" ) );
  1873. break;
  1874. case 'bestiary_fleder_book':
  1875. resource.PushBack( (CJournalResource)LoadResource( "BestiaryFleder" ) );
  1876. break;
  1877. case 'bestiary_wight_book':
  1878. resource.PushBack( (CJournalResource)LoadResource( "BestiaryWicht" ) );
  1879. break;
  1880. case 'bestiary_dracolizard_book':
  1881. resource.PushBack( (CJournalResource)LoadResource( "BestiaryDracolizard" ) );
  1882. break;
  1883. case 'bestiary_panther_book':
  1884. resource.PushBack( (CJournalResource)LoadResource( "BestiaryPanther" ) );
  1885. break;
  1886. case 'bestiary_kikimore_book':
  1887. resource.PushBack( (CJournalResource)LoadResource( "BestiaryKikimoraWarrior" ) );
  1888. resource.PushBack( (CJournalResource)LoadResource( "BestiaryKikimoraWorker" ) );
  1889. break;
  1890. case 'bestiary_scolopendromorph_book':
  1891. case 'mq7023_fluff_book_scolopendromorphs':
  1892. resource.PushBack( (CJournalResource)LoadResource( "BestiaryScolopendromorph" ) );
  1893. break;
  1894. case 'bestiary_archespore_book':
  1895. resource.PushBack( (CJournalResource)LoadResource( "BestiaryArchespore" ) );
  1896. break;
  1897. case 'bestiary_protofleder_book':
  1898. resource.PushBack( (CJournalResource)LoadResource( "BestiaryProtofleder" ) );
  1899. break;
  1900. default:
  1901. return false;
  1902. }
  1903.  
  1904.  
  1905.  
  1906.  
  1907. len = resource.Size();
  1908. if( len > 0)
  1909. {
  1910.  
  1911. theGame.GetGuiManager().ShowNotification( GetLocStringByKeyExt( "panel_hud_journal_entry_bestiary_new" ), 0, true );
  1912. theSound.SoundEvent("gui_ingame_new_journal");
  1913. }
  1914.  
  1915. for (r=0; r < len; r += 1 )
  1916. {
  1917. if ( !resource[ r ] )
  1918. {
  1919.  
  1920. continue;
  1921. }
  1922. entryBase = resource[r].GetEntry();
  1923. if ( entryBase )
  1924. {
  1925. manager.ActivateEntry( entryBase, JS_Active );
  1926. manager.SetEntryHasAdvancedInfo( entryBase, true );
  1927.  
  1928.  
  1929. manager.GetAllChildren( entryBase, childGroups );
  1930. for ( i = 0; i < childGroups.Size(); i += 1 )
  1931. {
  1932. descriptionGroup = ( CJournalCreatureDescriptionGroup )childGroups[ i ];
  1933. if ( descriptionGroup )
  1934. {
  1935. manager.GetAllChildren( descriptionGroup, childEntries );
  1936. for ( j = 0; j < childEntries.Size(); j += 1 )
  1937. {
  1938. descriptionEntry = ( CJournalCreatureDescriptionEntry )childEntries[ j ];
  1939. if ( descriptionEntry )
  1940. {
  1941. manager.ActivateEntry( descriptionEntry, JS_Active );
  1942. }
  1943. }
  1944. break;
  1945. }
  1946. }
  1947. }
  1948. }
  1949.  
  1950. if ( resource.Size() > 0 )
  1951. return true;
  1952. else
  1953. return false;
  1954. }
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963. function GetWeaponDTNames( id : SItemUniqueId, out dmgNames : array< name > ) : int
  1964. {
  1965. var attrs : array< name >;
  1966. var i, size : int;
  1967.  
  1968. dmgNames.Clear();
  1969.  
  1970. if( IsIdValid(id) )
  1971. {
  1972. GetItemAttributes( id, attrs );
  1973. size = attrs.Size();
  1974.  
  1975. for( i = 0; i < size; i += 1 )
  1976. if( IsDamageTypeNameValid(attrs[i]) )
  1977. dmgNames.PushBack( attrs[i] );
  1978.  
  1979. if(dmgNames.Size() == 0)
  1980. LogAssert(false, "CInventoryComponent.GetWeaponDTNames: weapon <<" + GetItemName(id) + ">> has no damage types defined!");
  1981. }
  1982. return dmgNames.Size();
  1983. }
  1984.  
  1985. public function GetWeapons() : array<SItemUniqueId>
  1986. {
  1987. var ids, ids2 : array<SItemUniqueId>;
  1988.  
  1989. ids = GetItemsByCategory('monster_weapon');
  1990. ids2 = GetItemsByTag('Weapon');
  1991. ArrayOfIdsAppend(ids, ids2);
  1992.  
  1993. return ids;
  1994. }
  1995.  
  1996. public function GetHeldWeapons() : array<SItemUniqueId>
  1997. {
  1998. var i : int;
  1999. var w : array<SItemUniqueId>;
  2000.  
  2001. w = GetWeapons();
  2002.  
  2003. for(i=w.Size()-1; i>=0; i-=1)
  2004. {
  2005. if(!IsItemHeld(w[i]))
  2006. {
  2007. w.EraseFast( i );
  2008. }
  2009. }
  2010.  
  2011. return w;
  2012. }
  2013.  
  2014. public function GetCurrentlyHeldSword() : SItemUniqueId
  2015. {
  2016. var i : int;
  2017. var w : array<SItemUniqueId>;
  2018.  
  2019. w = GetHeldWeapons();
  2020.  
  2021. for( i = 0 ; i < w.Size() ; i+=1 )
  2022. {
  2023. if( IsItemSteelSwordUsableByPlayer( w[i] ) || IsItemSilverSwordUsableByPlayer( w[i] ) )
  2024. {
  2025. return w[i];
  2026. }
  2027. }
  2028.  
  2029. return GetInvalidUniqueId();
  2030. }
  2031.  
  2032. public function GetCurrentlyHeldSwordEntity( out ent : CItemEntity ) : bool
  2033. {
  2034. var id : SItemUniqueId;
  2035.  
  2036. id = GetCurrentlyHeldSword();
  2037.  
  2038. if( IsIdValid( id ) )
  2039. {
  2040. ent = GetItemEntityUnsafe( id );
  2041.  
  2042. if( ent )
  2043. {
  2044. return true;
  2045. }
  2046. else
  2047. {
  2048. return false;
  2049. }
  2050. }
  2051. return false;
  2052. }
  2053.  
  2054. public function GetHeldWeaponsWithCategory( category : name, out items : array<SItemUniqueId> )
  2055. {
  2056. var i : int;
  2057.  
  2058. items = GetItemsByCategory( category );
  2059.  
  2060. for ( i = items.Size()-1; i >= 0; i -= 1)
  2061. {
  2062. if ( !IsItemHeld( items[i] ) )
  2063. {
  2064. items.EraseFast( i );
  2065. }
  2066. }
  2067. }
  2068.  
  2069. public function GetPotionItemBuffData(id : SItemUniqueId, out type : EEffectType, out customAbilityName : name) : bool
  2070. {
  2071. var size, i : int;
  2072. var arr : array<name>;
  2073.  
  2074. if(IsIdValid(id))
  2075. {
  2076. GetItemContainedAbilities( id, arr );
  2077. size = arr.Size();
  2078.  
  2079. for( i = 0; i < size; i += 1 )
  2080. {
  2081. if( IsEffectNameValid(arr[i]) )
  2082. {
  2083. EffectNameToType(arr[i], type, customAbilityName);
  2084. return true;
  2085. }
  2086. }
  2087. }
  2088.  
  2089. return false;
  2090. }
  2091.  
  2092.  
  2093. public function RecycleItem( id : SItemUniqueId, level : ECraftsmanLevel ) : array<SItemUniqueId>
  2094. {
  2095. var itemsAdded : array<SItemUniqueId>;
  2096. var currentAdded : array<SItemUniqueId>;
  2097.  
  2098. var parts : array<SItemParts>;
  2099. var i : int;
  2100.  
  2101. parts = GetItemRecyclingParts( id );
  2102.  
  2103. for ( i = 0; i < parts.Size(); i += 1 )
  2104. {
  2105. if ( ECL_Grand_Master == level || ECL_Arch_Master == level )
  2106. {
  2107. currentAdded = AddAnItem( parts[i].itemName, parts[i].quantity );
  2108. }
  2109. else if ( ECL_Master == level && parts[i].quantity > 1 )
  2110. {
  2111. currentAdded = AddAnItem( parts[i].itemName, RandRange( parts[i].quantity, 1 ) );
  2112. }
  2113. else
  2114. {
  2115. currentAdded = AddAnItem( parts[i].itemName, 1 );
  2116. }
  2117. itemsAdded.PushBack(currentAdded[0]);
  2118. }
  2119.  
  2120. RemoveItem(id);
  2121.  
  2122. return itemsAdded;
  2123. }
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130. public function GetItemBuffs( id : SItemUniqueId, out buffs : array<SEffectInfo>) : int
  2131. {
  2132. var attrs, abs, absFast : array< name >;
  2133. var i, k : int;
  2134. var type : EEffectType;
  2135. var abilityName : name;
  2136. var buff : SEffectInfo;
  2137. var dm : CDefinitionsManagerAccessor;
  2138.  
  2139. buffs.Clear();
  2140.  
  2141. if( !IsIdValid(id) )
  2142. return 0;
  2143.  
  2144.  
  2145. GetItemContainedAbilities(id, absFast);
  2146. if(absFast.Size() == 0)
  2147. return 0;
  2148.  
  2149. GetItemAbilities(id, abs);
  2150. dm = theGame.GetDefinitionsManager();
  2151. for(k=0; k<abs.Size(); k+=1)
  2152. {
  2153. dm.GetContainedAbilities(abs[k], attrs);
  2154. buff.applyChance = CalculateAttributeValue(GetItemAbilityAttributeValue(id, 'buff_apply_chance', abs[k])) * ArrayOfNamesCount(abs, abs[k]);
  2155.  
  2156. for( i = 0; i < attrs.Size(); i += 1 )
  2157. {
  2158. if( IsEffectNameValid(attrs[i]) )
  2159. {
  2160. EffectNameToType(attrs[i], type, abilityName);
  2161.  
  2162. buff.effectType = type;
  2163. buff.effectAbilityName = abilityName;
  2164.  
  2165. buffs.PushBack(buff);
  2166.  
  2167.  
  2168. if(absFast.Size() == 1)
  2169. return buffs.Size();
  2170. else
  2171. absFast.EraseFast(0);
  2172. }
  2173. }
  2174. }
  2175.  
  2176. return buffs.Size();
  2177. }
  2178.  
  2179.  
  2180. public function DropItemInBag( item : SItemUniqueId, quantity : int )
  2181. {
  2182. var entities : array<CGameplayEntity>;
  2183. var i : int;
  2184. var owner : CActor;
  2185. var bag : W3ActorRemains;
  2186. var template : CEntityTemplate;
  2187. var bagtags : array <name>;
  2188. var bagPosition : Vector;
  2189. var tracedPosition, tracedNormal : Vector;
  2190.  
  2191. if(ItemHasTag(item, 'NoDrop'))
  2192. return;
  2193.  
  2194. owner = (CActor)GetEntity();
  2195. FindGameplayEntitiesInRange(entities, owner, 0.5, 100);
  2196.  
  2197. for(i=0; i<entities.Size(); i+=1)
  2198. {
  2199. bag = (W3ActorRemains)entities[i];
  2200.  
  2201. if(bag)
  2202. break;
  2203. }
  2204.  
  2205.  
  2206. if(!bag)
  2207. {
  2208. template = (CEntityTemplate)LoadResource("lootbag");
  2209. bagtags.PushBack('lootbag');
  2210.  
  2211.  
  2212. bagPosition = owner.GetWorldPosition();
  2213. if ( theGame.GetWorld().StaticTrace( bagPosition, bagPosition + Vector( 0.0f, 0.0f, -10.0f, 0.0f ), tracedPosition, tracedNormal ) )
  2214. {
  2215. bagPosition = tracedPosition;
  2216. }
  2217. bag = (W3ActorRemains)theGame.CreateEntity(template, bagPosition, owner.GetWorldRotation(), true, false, false, PM_Persist,bagtags);
  2218. }
  2219.  
  2220.  
  2221. GiveItemTo(bag.GetInventory(), item, quantity, false);
  2222.  
  2223.  
  2224. if(bag.GetInventory().IsEmpty())
  2225. {
  2226. delete bag;
  2227. return;
  2228. }
  2229.  
  2230. bag.LootDropped();
  2231. theTelemetry.LogWithLabelAndValue(TE_INV_ITEM_DROPPED, GetItemName(item), quantity);
  2232.  
  2233.  
  2234. if( thePlayer.IsSwimming() )
  2235. {
  2236. bag.PlayPropertyAnimation( 'float', 0 );
  2237. }
  2238. }
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245. public final function AddRepairObjectItemBonuses(buffArmor : bool, buffSwords : bool, ammoArmor : int, ammoWeapon : int) : bool
  2246. {
  2247. var upgradedSomething, isArmor : bool;
  2248. var i, ammo, currAmmo : int;
  2249. var items, items2 : array<SItemUniqueId>;
  2250.  
  2251.  
  2252. if(buffArmor)
  2253. {
  2254. items = GetItemsByTag(theGame.params.TAG_ARMOR);
  2255. }
  2256. if(buffSwords)
  2257. {
  2258. items2 = GetItemsByTag(theGame.params.TAG_PLAYER_STEELSWORD);
  2259. ArrayOfIdsAppend(items, items2);
  2260. items2.Clear();
  2261. items2 = GetItemsByTag(theGame.params.TAG_PLAYER_SILVERSWORD);
  2262. ArrayOfIdsAppend(items, items2);
  2263. }
  2264.  
  2265. upgradedSomething = false;
  2266.  
  2267. for(i=0; i<items.Size(); i+=1)
  2268. {
  2269.  
  2270. if(IsItemAnyArmor(items[i]))
  2271. {
  2272. isArmor = true;
  2273. ammo = ammoArmor;
  2274. }
  2275. else
  2276. {
  2277. isArmor = false;
  2278. ammo = ammoWeapon;
  2279. }
  2280.  
  2281.  
  2282. currAmmo = GetItemModifierInt(items[i], 'repairObjectBonusAmmo', 0);
  2283.  
  2284.  
  2285. if(ammo > currAmmo)
  2286. {
  2287. SetItemModifierInt(items[i], 'repairObjectBonusAmmo', ammo);
  2288. upgradedSomething = true;
  2289.  
  2290.  
  2291. if(currAmmo == 0)
  2292. {
  2293. if(isArmor)
  2294. AddItemCraftedAbility(items[i], theGame.params.REPAIR_OBJECT_BONUS_ARMOR_ABILITY, false);
  2295. else
  2296. AddItemCraftedAbility(items[i], theGame.params.REPAIR_OBJECT_BONUS_WEAPON_ABILITY, false);
  2297. }
  2298. }
  2299. }
  2300.  
  2301. return upgradedSomething;
  2302. }
  2303.  
  2304. public final function ReduceItemRepairObjectBonusCharge(item : SItemUniqueId)
  2305. {
  2306. var currAmmo : int;
  2307.  
  2308. currAmmo = GetItemModifierInt(item, 'repairObjectBonusAmmo', 0);
  2309.  
  2310. if(currAmmo > 0)
  2311. {
  2312. SetItemModifierInt(item, 'repairObjectBonusAmmo', currAmmo - 1);
  2313.  
  2314. if(currAmmo == 1)
  2315. {
  2316. if(IsItemAnyArmor(item))
  2317. RemoveItemCraftedAbility(item, theGame.params.REPAIR_OBJECT_BONUS_ARMOR_ABILITY);
  2318. else
  2319. RemoveItemCraftedAbility(item, theGame.params.REPAIR_OBJECT_BONUS_WEAPON_ABILITY);
  2320. }
  2321. }
  2322. }
  2323.  
  2324.  
  2325. public final function GetRepairObjectBonusValueForArmor(armor : SItemUniqueId) : SAbilityAttributeValue
  2326. {
  2327. var retVal, bonusValue, baseArmor : SAbilityAttributeValue;
  2328.  
  2329. if(GetItemModifierInt(armor, 'repairObjectBonusAmmo', 0) > 0)
  2330. {
  2331. bonusValue = GetItemAttributeValue(armor, theGame.params.REPAIR_OBJECT_BONUS);
  2332. baseArmor = GetItemAttributeValue(armor, theGame.params.ARMOR_VALUE_NAME);
  2333.  
  2334. baseArmor.valueMultiplicative += 1;
  2335. retVal.valueAdditive = bonusValue.valueAdditive + CalculateAttributeValue(baseArmor) * bonusValue.valueMultiplicative;
  2336. }
  2337.  
  2338. return retVal;
  2339. }
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346. public function CanItemHaveOil(id : SItemUniqueId) : bool
  2347. {
  2348. return IsItemSteelSwordUsableByPlayer(id) || IsItemSilverSwordUsableByPlayer(id);
  2349. }
  2350.  
  2351. public final function RemoveAllOilsFromItem( id : SItemUniqueId )
  2352. {
  2353. var i : int;
  2354. var oils : array< W3Effect_Oil >;
  2355. var actor : CActor;
  2356.  
  2357. actor = ( CActor ) GetEntity();
  2358. oils = GetOilsAppliedOnItem( id );
  2359. for( i = oils.Size() - 1; i >= 0; i -= 1 )
  2360. {
  2361. actor.RemoveEffect( oils[ i ] );
  2362. }
  2363. }
  2364.  
  2365. public final function GetActiveOilsAppliedOnItemCount( id : SItemUniqueId ) : int
  2366. {
  2367. var oils : array< W3Effect_Oil >;
  2368. var i, count : int;
  2369.  
  2370. count = 0;
  2371. oils = GetOilsAppliedOnItem( id );
  2372. for( i=0; i<oils.Size(); i+=1 )
  2373. {
  2374. if( oils[ i ].GetAmmoCurrentCount() > 0 )
  2375. {
  2376. count += 1;
  2377. }
  2378. }
  2379. return count;
  2380. }
  2381.  
  2382. public final function RemoveOldestOilFromItem( id : SItemUniqueId )
  2383. {
  2384. var buffToRemove : W3Effect_Oil;
  2385. var actor : CActor;
  2386.  
  2387. actor = ( CActor ) GetEntity();
  2388. if(! actor )
  2389. return;
  2390.  
  2391. buffToRemove = GetOldestOilAppliedOnItem(id, false);
  2392.  
  2393. if(buffToRemove)
  2394. {
  2395. actor.RemoveEffect( buffToRemove );
  2396. }
  2397. }
  2398.  
  2399. public final function GetOilsAppliedOnItem( id : SItemUniqueId ) : array< W3Effect_Oil >
  2400. {
  2401. var i : int;
  2402. var oils : array< CBaseGameplayEffect >;
  2403. var buff : W3Effect_Oil;
  2404. var ret : array < W3Effect_Oil >;
  2405. var actor : CActor;
  2406.  
  2407. actor = ( CActor ) GetEntity();
  2408. if(! actor )
  2409. return ret;
  2410.  
  2411. oils = actor.GetBuffs( EET_Oil );
  2412. for( i = oils.Size() - 1; i >= 0; i -= 1 )
  2413. {
  2414. buff = ( W3Effect_Oil ) oils[ i ];
  2415. if(buff && buff.GetSwordItemId() == id )
  2416. {
  2417. ret.PushBack( buff );
  2418. }
  2419. }
  2420.  
  2421. return ret;
  2422. }
  2423.  
  2424. public final function GetNewestOilAppliedOnItem( id : SItemUniqueId, onlyShowable : bool ) : W3Effect_Oil
  2425. {
  2426. return GetOilAppliedOnItemInternal( id, onlyShowable, true );
  2427. }
  2428.  
  2429. public final function GetOldestOilAppliedOnItem( id : SItemUniqueId, onlyShowable : bool ) : W3Effect_Oil
  2430. {
  2431. return GetOilAppliedOnItemInternal( id, onlyShowable, false );
  2432. }
  2433.  
  2434. private final function GetOilAppliedOnItemInternal( id : SItemUniqueId, onlyShowable : bool, newest : bool ) : W3Effect_Oil
  2435. {
  2436. var oils : array< W3Effect_Oil >;
  2437. var i, lastIndex : int;
  2438.  
  2439. oils = GetOilsAppliedOnItem( id );
  2440. lastIndex = -1;
  2441.  
  2442. for( i=0; i<oils.Size(); i+=1 )
  2443. {
  2444. if( onlyShowable && !oils[i].GetShowOnHUD() )
  2445. {
  2446. continue;
  2447. }
  2448.  
  2449. if( lastIndex == -1 )
  2450. {
  2451. lastIndex = i;
  2452. }
  2453. else if( newest && oils[i].GetQueueTimer() < oils[lastIndex].GetQueueTimer() )
  2454. {
  2455. lastIndex = i;
  2456. }
  2457. else if( !newest && oils[i].GetQueueTimer() > oils[lastIndex].GetQueueTimer() )
  2458. {
  2459. lastIndex = i;
  2460. }
  2461. }
  2462.  
  2463. if( lastIndex == -1 )
  2464. {
  2465. return NULL;
  2466. }
  2467.  
  2468. return oils[lastIndex];
  2469. }
  2470.  
  2471. public final function ItemHasAnyActiveOilApplied( id : SItemUniqueId ) : bool
  2472. {
  2473. return GetActiveOilsAppliedOnItemCount( id );
  2474. }
  2475.  
  2476. public final function ItemHasActiveOilApplied( id : SItemUniqueId, monsterCategory : EMonsterCategory ) : bool
  2477. {
  2478. var i : int;
  2479. var oils : array< W3Effect_Oil >;
  2480.  
  2481. oils = GetOilsAppliedOnItem( id );
  2482. for( i=0; i<oils.Size(); i+=1 )
  2483. {
  2484. if( oils[ i ].GetMonsterCategory() == monsterCategory && oils[ i ].GetAmmoCurrentCount() > 0 )
  2485. {
  2486. return true;
  2487. }
  2488. }
  2489.  
  2490. return false;
  2491. }
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497. public final function GetParamsForRunewordTooltip(runewordName : name, out i : array<int>, out f : array<float>, out s : array<string>)
  2498. {
  2499. var min, max : SAbilityAttributeValue;
  2500. var val : float;
  2501. var attackRangeBase, attackRangeExt : CAIAttackRange;
  2502.  
  2503. i.Clear();
  2504. f.Clear();
  2505. s.Clear();
  2506.  
  2507. switch(runewordName)
  2508. {
  2509. case 'Glyphword 5':
  2510. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 5 _Stats', 'glyphword5_chance', min, max);
  2511. i.PushBack( RoundMath( CalculateAttributeValue(min) * 100) );
  2512. break;
  2513. case 'Glyphword 6' :
  2514. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 6 _Stats', 'glyphword6_stamina_drain_perc', min, max);
  2515. i.PushBack( RoundMath( CalculateAttributeValue(min) * 100) );
  2516. break;
  2517. case 'Glyphword 12' :
  2518. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 12 _Stats', 'glyphword12_range', min, max);
  2519. val = CalculateAttributeValue(min);
  2520. s.PushBack( NoTrailZeros(val) );
  2521.  
  2522. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 12 _Stats', 'glyphword12_chance', min, max);
  2523. i.PushBack( RoundMath( min.valueAdditive * 100) );
  2524. break;
  2525. case 'Glyphword 17' :
  2526. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 17 _Stats', 'quen_apply_chance', min, max);
  2527. val = CalculateAttributeValue(min);
  2528. i.PushBack( RoundMath(val * 100) );
  2529. break;
  2530. case 'Glyphword 14' :
  2531. case 'Glyphword 18' :
  2532. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 18 _Stats', 'increas_duration', min, max);
  2533. val = CalculateAttributeValue(min);
  2534. s.PushBack( NoTrailZeros(val) );
  2535. break;
  2536.  
  2537. case 'Runeword 2' :
  2538. attackRangeBase = theGame.GetAttackRangeForEntity(GetWitcherPlayer(), 'specialattacklight');
  2539. attackRangeExt = theGame.GetAttackRangeForEntity(GetWitcherPlayer(), 'runeword2_light');
  2540. s.PushBack( NoTrailZeros(attackRangeExt.rangeMax - attackRangeBase.rangeMax) );
  2541.  
  2542. attackRangeBase = theGame.GetAttackRangeForEntity(GetWitcherPlayer(), 'slash_long');
  2543. attackRangeExt = theGame.GetAttackRangeForEntity(GetWitcherPlayer(), 'runeword2_heavy');
  2544. s.PushBack( NoTrailZeros(attackRangeExt.rangeMax - attackRangeBase.rangeMax) );
  2545.  
  2546. break;
  2547. case 'Runeword 4' :
  2548. theGame.GetDefinitionsManager().GetAbilityAttributeValue('Runeword 4 _Stats', 'max_bonus', min, max);
  2549. i.PushBack( RoundMath(max.valueMultiplicative * 100) );
  2550. break;
  2551. case 'Runeword 6' :
  2552. theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'Runeword 6 _Stats', 'runeword6_duration_bonus', min, max );
  2553. i.PushBack( RoundMath(min.valueMultiplicative * 100) );
  2554. break;
  2555. case 'Runeword 7' :
  2556. theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'Runeword 7 _Stats', 'stamina', min, max );
  2557. i.PushBack( RoundMath(min.valueMultiplicative * 100) );
  2558. break;
  2559. case 'Runeword 10' :
  2560. theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'Runeword 10 _Stats', 'stamina', min, max );
  2561. i.PushBack( RoundMath(min.valueMultiplicative * 100) );
  2562. break;
  2563. case 'Runeword 11' :
  2564. theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'Runeword 11 _Stats', 'duration', min, max );
  2565. s.PushBack( NoTrailZeros(min.valueAdditive) );
  2566. break;
  2567. case 'Runeword 12' :
  2568. theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'Runeword 12 _Stats', 'focus', min, max );
  2569. f.PushBack(min.valueAdditive);
  2570. f.PushBack(max.valueAdditive);
  2571. break;
  2572. default:
  2573. break;
  2574. }
  2575. }
  2576.  
  2577. public final function GetPotionAttributesForTooltip(potionId : SItemUniqueId, out tips : array<SAttributeTooltip>):void
  2578. {
  2579. var i, j, settingsSize : int;
  2580. var buffType : EEffectType;
  2581. var abilityName : name;
  2582. var abs, attrs : array<name>;
  2583. var val : SAbilityAttributeValue;
  2584. var newAttr : SAttributeTooltip;
  2585. var attributeString : string;
  2586.  
  2587.  
  2588. if(!( IsItemPotion(potionId) || IsItemFood(potionId) ) )
  2589. return;
  2590.  
  2591.  
  2592. GetItemContainedAbilities(potionId, abs);
  2593. for(i=0; i<abs.Size(); i+=1)
  2594. {
  2595. EffectNameToType(abs[i], buffType, abilityName);
  2596.  
  2597.  
  2598. if(buffType == EET_Undefined)
  2599. continue;
  2600.  
  2601.  
  2602. theGame.GetDefinitionsManager().GetAbilityAttributes(abs[i], attrs);
  2603. break;
  2604. }
  2605.  
  2606.  
  2607. attrs.Remove('duration');
  2608. attrs.Remove('level');
  2609.  
  2610. if(buffType == EET_Cat)
  2611. {
  2612.  
  2613. attrs.Remove('highlightObjectsRange');
  2614. }
  2615. else if(buffType == EET_GoldenOriole)
  2616. {
  2617.  
  2618. attrs.Remove('poison_resistance_perc');
  2619. }
  2620. else if(buffType == EET_MariborForest)
  2621. {
  2622.  
  2623. attrs.Remove('focus_on_drink');
  2624. }
  2625. else if(buffType == EET_KillerWhale)
  2626. {
  2627.  
  2628. attrs.Remove('swimmingStamina');
  2629. attrs.Remove('vision_strength');
  2630. }
  2631. else if(buffType == EET_Thunderbolt)
  2632. {
  2633.  
  2634. attrs.Remove('critical_hit_chance');
  2635. }
  2636. else if(buffType == EET_WhiteRaffardDecoction)
  2637. {
  2638. val = GetItemAttributeValue(potionId, 'level');
  2639. if(val.valueAdditive == 3)
  2640. attrs.Insert(0, 'duration');
  2641. }
  2642. else if(buffType == EET_Mutagen20)
  2643. {
  2644. attrs.Remove('burning_DoT_damage_resistance_perc');
  2645. attrs.Remove('poison_DoT_damage_resistance_perc');
  2646. attrs.Remove('bleeding_DoT_damage_resistance_perc');
  2647. }
  2648. else if(buffType == EET_Mutagen27)
  2649. {
  2650. attrs.Remove('mutagen27_max_stack');
  2651. }
  2652. else if(buffType == EET_Mutagen18)
  2653. {
  2654. attrs.Remove('mutagen18_max_stack');
  2655. }
  2656. else if(buffType == EET_Mutagen19)
  2657. {
  2658. attrs.Remove('max_hp_perc_trigger');
  2659. }
  2660. else if(buffType == EET_Mutagen21)
  2661. {
  2662. attrs.Remove('healingRatio');
  2663. }
  2664. else if(buffType == EET_Mutagen22)
  2665. {
  2666. attrs.Remove('mutagen22_max_stack');
  2667. }
  2668. else if(buffType == EET_Mutagen02)
  2669. {
  2670. attrs.Remove('resistGainRate');
  2671. }
  2672. else if(buffType == EET_Mutagen04)
  2673. {
  2674. attrs.Remove('staminaCostPerc');
  2675. attrs.Remove('healthReductionPerc');
  2676. }
  2677. else if(buffType == EET_Mutagen08)
  2678. {
  2679. attrs.Remove('resistGainRate');
  2680. }
  2681. else if(buffType == EET_Mutagen10)
  2682. {
  2683. attrs.Remove('mutagen10_max_stack');
  2684. }
  2685. else if(buffType == EET_Mutagen14)
  2686. {
  2687. attrs.Remove('mutagen14_max_stack');
  2688. }
  2689.  
  2690.  
  2691. for(j=0; j<attrs.Size(); j+=1)
  2692. {
  2693. val = GetItemAbilityAttributeValue(potionId, attrs[j], abs[i]);
  2694.  
  2695. newAttr.originName = attrs[j];
  2696. newAttr.attributeName = GetAttributeNameLocStr(attrs[j], false);
  2697.  
  2698. if(buffType == EET_MariborForest && attrs[j] == 'focus_gain')
  2699. {
  2700. newAttr.value = val.valueAdditive;
  2701. newAttr.percentageValue = false;
  2702. }
  2703. else if(val.valueMultiplicative != 0)
  2704. {
  2705. if(buffType == EET_Mutagen26)
  2706. {
  2707.  
  2708. newAttr.value = val.valueAdditive;
  2709. newAttr.percentageValue = false;
  2710. tips.PushBack(newAttr);
  2711.  
  2712. newAttr.value = val.valueMultiplicative;
  2713. newAttr.percentageValue = true;
  2714.  
  2715. attrs.Erase(1);
  2716. }
  2717. else if(buffType == EET_Mutagen07)
  2718. {
  2719.  
  2720. attrs.Erase(1);
  2721. newAttr.value = val.valueBase;
  2722. newAttr.percentageValue = true;
  2723. }
  2724. else
  2725. {
  2726. newAttr.value = val.valueMultiplicative;
  2727. newAttr.percentageValue = true;
  2728. }
  2729. }
  2730. else if(val.valueAdditive != 0)
  2731. {
  2732. if(buffType == EET_Thunderbolt)
  2733. {
  2734. newAttr.value = val.valueAdditive * 100;
  2735. newAttr.percentageValue = true;
  2736. }
  2737. else if(buffType == EET_Blizzard)
  2738. {
  2739. newAttr.value = 1 - val.valueAdditive;
  2740. newAttr.percentageValue = true;
  2741. }
  2742. else if(buffType == EET_Mutagen01 || buffType == EET_Mutagen15 || buffType == EET_Mutagen28 || buffType == EET_Mutagen27)
  2743. {
  2744. newAttr.value = val.valueAdditive;
  2745. newAttr.percentageValue = true;
  2746. }
  2747. else
  2748. {
  2749. newAttr.value = val.valueAdditive;
  2750. newAttr.percentageValue = false;
  2751. }
  2752. }
  2753. else if(buffType == EET_GoldenOriole)
  2754. {
  2755. newAttr.value = val.valueBase;
  2756. newAttr.percentageValue = true;
  2757. }
  2758. else
  2759. {
  2760. newAttr.value = val.valueBase;
  2761. newAttr.percentageValue = false;
  2762. }
  2763.  
  2764. tips.PushBack(newAttr);
  2765. }
  2766. }
  2767.  
  2768.  
  2769. public function GetItemRelativeTooltipType(id :SItemUniqueId, invOther : CInventoryComponent, idOther : SItemUniqueId) : ECompareType
  2770. {
  2771.  
  2772. if( (GetItemCategory(id) == invOther.GetItemCategory(idOther)) ||
  2773. ItemHasTag(id, 'PlayerSteelWeapon') && invOther.ItemHasTag(idOther, 'PlayerSteelWeapon') ||
  2774. ItemHasTag(id, 'PlayerSilverWeapon') && invOther.ItemHasTag(idOther, 'PlayerSilverWeapon') ||
  2775. ItemHasTag(id, 'PlayerSecondaryWeapon') && invOther.ItemHasTag(idOther, 'PlayerSecondaryWeapon')
  2776. )
  2777. {
  2778. return ECT_Compare;
  2779. }
  2780. return ECT_Incomparable;
  2781. }
  2782.  
  2783.  
  2784. private function FormatFloatForTooltip(fValue : float) : string
  2785. {
  2786. var valueInt, valueDec : int;
  2787. var strValue : string;
  2788.  
  2789. if(fValue < 0)
  2790. {
  2791. valueInt = CeilF(fValue);
  2792. valueDec = RoundMath((fValue - valueInt)*(-100));
  2793. }
  2794. else
  2795. {
  2796. valueInt = FloorF(fValue);
  2797. valueDec = RoundMath((fValue - valueInt)*(100));
  2798. }
  2799. strValue = valueInt+".";
  2800. if(valueDec < 10)
  2801. strValue += "0"+valueDec;
  2802. else
  2803. strValue += ""+valueDec;
  2804.  
  2805. return strValue;
  2806. }
  2807.  
  2808. public function SetPriceMultiplier( mult : float )
  2809. {
  2810. priceMult = mult;
  2811. }
  2812.  
  2813.  
  2814. public function GetMerchantPriceModifier( shopNPC : CNewNPC, item : SItemUniqueId ) : float
  2815. {
  2816. var areaPriceMult : float;
  2817. var itemPriceMult : float;
  2818. var importPriceMult : float;
  2819. var finalPriceMult : float;
  2820. var tag : name;
  2821. var zoneName : EZoneName;
  2822.  
  2823. zoneName = theGame.GetCurrentZone();
  2824.  
  2825. switch ( zoneName )
  2826. {
  2827. case ZN_NML_CrowPerch : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('crow_perch_price_mult'));
  2828. case ZN_NML_SpitfireBluff : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('spitfire_bluff_price_mult'));
  2829. case ZN_NML_TheMire : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('the_mire_price_mult'));
  2830. case ZN_NML_Mudplough : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('mudplough_price_mult'));
  2831. case ZN_NML_Grayrocks : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('grayrocks_price_mult'));
  2832. case ZN_NML_TheDescent : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('the_descent_price_mult'));
  2833. case ZN_NML_CrookbackBog : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('crookback_bog_price_mult'));
  2834. case ZN_NML_BaldMountain : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('bald_mountain_price_mult'));
  2835. case ZN_NML_Novigrad : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('novigrad_price_mult'));
  2836. case ZN_NML_Homestead : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('homestead_price_mult'));
  2837. case ZN_NML_Gustfields : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('gustfields_price_mult'));
  2838. case ZN_NML_Oxenfurt : areaPriceMult = CalculateAttributeValue(thePlayer.GetAttributeValue('oxenfurt_price_mult'));
  2839. case ZN_Undefined : areaPriceMult = 1;
  2840. }
  2841.  
  2842. if (ItemHasTag(item,'weapon')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('weapon_price_mult')); }
  2843. else if (ItemHasTag(item,'armor')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('armor_price_mult')); }
  2844. else if (ItemHasTag(item,'crafting')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('crafting_price_mult')); }
  2845. else if (ItemHasTag(item,'alchemy')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('alchemy_price_mult')); }
  2846. else if (ItemHasTag(item,'alcohol')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('alcohol_price_mult')); }
  2847. else if (ItemHasTag(item,'food')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('food_price_mult')); }
  2848. else if (ItemHasTag(item,'fish')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('fish_price_mult')); }
  2849. else if (ItemHasTag(item,'books')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('books_price_mult')); }
  2850. else if (ItemHasTag(item,'valuables')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('valuables_price_mult')); }
  2851. else if (ItemHasTag(item,'junk')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('junk_price_mult')); }
  2852. else if (ItemHasTag(item,'orens')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('orens_price_mult')); }
  2853. else if (ItemHasTag(item,'florens')) { itemPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('florens_price_mult')); }
  2854. else { itemPriceMult = 1; }
  2855.  
  2856. if (ItemHasTag(item,'novigrad')) { importPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('novigrad_price_mult')); }
  2857. else if (ItemHasTag(item,'nilfgard')) { importPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('nilfgard_price_mult')); }
  2858. else if (ItemHasTag(item,'nomansland')) { importPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('nomansland_price_mult')); }
  2859. else if (ItemHasTag(item,'skellige')) { importPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('skellige_price_mult')); }
  2860. else if (ItemHasTag(item,'nonhuman')) { importPriceMult = CalculateAttributeValue(shopNPC.GetAttributeValue('nonhuman_price_mult')); }
  2861. else { importPriceMult = 1; }
  2862.  
  2863. finalPriceMult = areaPriceMult*itemPriceMult*importPriceMult*priceMult;
  2864. return finalPriceMult;
  2865. }
  2866.  
  2867. public function SetRepairPriceMultiplier( mult : float )
  2868. {
  2869. priceRepairMult = mult;
  2870. }
  2871.  
  2872.  
  2873. public function GetRepairPriceModifier( repairNPC : CNewNPC ) : float
  2874. {
  2875. return priceRepairMult;
  2876. }
  2877.  
  2878. public function GetRepairPrice( item : SItemUniqueId ) : float
  2879. {
  2880. var currDiff : float;
  2881. currDiff = GetItemMaxDurability(item) - GetItemDurability(item);
  2882.  
  2883. return priceRepair * currDiff;
  2884. }
  2885.  
  2886.  
  2887. public function GetTooltipData(itemId : SItemUniqueId, out localizedName : string, out localizedDescription : string, out price : int, out localizedCategory : string,
  2888. out itemStats : array<SAttributeTooltip>, out localizedFluff : string)
  2889. {
  2890. if( !IsIdValid(itemId) )
  2891. {
  2892. return;
  2893. }
  2894. localizedName = GetItemLocalizedNameByUniqueID(itemId);
  2895. localizedDescription = GetItemLocalizedDescriptionByUniqueID(itemId);
  2896. localizedFluff = "IMPLEMENT ME - fluff text";
  2897. price = GetItemPriceModified( itemId, false );
  2898. localizedCategory = GetItemCategoryLocalisedString(GetItemCategory(itemId));
  2899. GetItemStats(itemId, itemStats);
  2900. }
  2901.  
  2902.  
  2903. public function GetItemBaseStats(itemId : SItemUniqueId, out itemStats : array<SAttributeTooltip>)
  2904. {
  2905. var attributes : array<name>;
  2906.  
  2907. var dm : CDefinitionsManagerAccessor;
  2908. var oilAbilities, oilAttributes : array<name>;
  2909. var weights : array<float>;
  2910. var i, j : int;
  2911. var tmpI, tmpJ : int;
  2912.  
  2913. var idx : int;
  2914. var oilStatsCount : int;
  2915. var oilName : name;
  2916. var oilStats : array<SAttributeTooltip>;
  2917. var oilStatFirst : SAttributeTooltip;
  2918. var oils : array< W3Effect_Oil >;
  2919.  
  2920. GetItemBaseAttributes(itemId, attributes);
  2921.  
  2922.  
  2923. oils = GetOilsAppliedOnItem( itemId );
  2924. dm = theGame.GetDefinitionsManager();
  2925. for( i=0; i<oils.Size(); i+=1 )
  2926. {
  2927. oilName = oils[ i ].GetOilItemName();
  2928.  
  2929. oilAbilities.Clear();
  2930. weights.Clear();
  2931. dm.GetItemAbilitiesWithWeights(oilName, GetEntity() == thePlayer, oilAbilities, weights, tmpI, tmpJ);
  2932.  
  2933. oilAttributes.Clear();
  2934. oilAttributes = dm.GetAbilitiesAttributes(oilAbilities);
  2935.  
  2936. oilStatsCount = oilAttributes.Size();
  2937. for (idx = 0; idx < oilStatsCount; idx+=1)
  2938. {
  2939. attributes.Remove(oilAttributes[idx]);
  2940. }
  2941. }
  2942.  
  2943. GetItemTooltipAttributes(itemId, attributes, itemStats);
  2944. }
  2945.  
  2946.  
  2947. public function GetItemStats(itemId : SItemUniqueId, out itemStats : array<SAttributeTooltip>)
  2948. {
  2949. var attributes : array<name>;
  2950.  
  2951. GetItemAttributes(itemId, attributes);
  2952. GetItemTooltipAttributes(itemId, attributes, itemStats);
  2953. }
  2954.  
  2955. private function GetItemTooltipAttributes(itemId : SItemUniqueId, attributes : array<name>, out itemStats : array<SAttributeTooltip>):void
  2956. {
  2957. var itemCategory:name;
  2958. var i, j, settingsSize : int;
  2959. var attributeString : string;
  2960. var attributeColor : string;
  2961. var attributeName : name;
  2962. var isPercentageValue : string;
  2963. var primaryStatLabel : string;
  2964. var statLabel : string;
  2965.  
  2966. var stat : SAttributeTooltip;
  2967. var attributeVal : SAbilityAttributeValue;
  2968.  
  2969. settingsSize = theGame.tooltipSettings.GetNumRows();
  2970. itemStats.Clear();
  2971. itemCategory = GetItemCategory(itemId);
  2972. for(i=0; i<settingsSize; i+=1)
  2973. {
  2974.  
  2975. attributeString = theGame.tooltipSettings.GetValueAt(0,i);
  2976. if(StrLen(attributeString) <= 0)
  2977. continue;
  2978.  
  2979. attributeName = '';
  2980.  
  2981.  
  2982. for(j=0; j<attributes.Size(); j+=1)
  2983. {
  2984. if(NameToString(attributes[j]) == attributeString)
  2985. {
  2986. attributeName = attributes[j];
  2987. break;
  2988. }
  2989. }
  2990. if(!IsNameValid(attributeName))
  2991. continue;
  2992.  
  2993.  
  2994. if(itemCategory == 'silversword' && attributeName == 'SlashingDamage') continue;
  2995. if(itemCategory == 'steelsword' && attributeName == 'SilverDamage') continue;
  2996.  
  2997.  
  2998. attributeColor = theGame.tooltipSettings.GetValueAt(1,i);
  2999.  
  3000. isPercentageValue = theGame.tooltipSettings.GetValueAt(2,i);
  3001.  
  3002.  
  3003. attributeVal = GetItemAttributeValue(itemId, attributeName);
  3004. stat.attributeColor = attributeColor;
  3005. stat.percentageValue = isPercentageValue;
  3006. stat.primaryStat = IsPrimaryStatById(itemId, attributeName, primaryStatLabel);
  3007. stat.value = 0;
  3008. stat.originName = attributeName;
  3009. if(attributeVal.valueBase != 0)
  3010. {
  3011. statLabel = GetAttributeNameLocStr(attributeName, false);
  3012. stat.value = attributeVal.valueBase;
  3013. }
  3014. if(attributeVal.valueMultiplicative != 0)
  3015. {
  3016.  
  3017.  
  3018. statLabel = GetAttributeNameLocStr(attributeName, false);
  3019. stat.value = attributeVal.valueMultiplicative;
  3020. stat.percentageValue = true;
  3021. }
  3022. if(attributeVal.valueAdditive != 0)
  3023. {
  3024. statLabel = GetAttributeNameLocStr(attributeName, false);
  3025. stat.value = attributeVal.valueAdditive;
  3026. }
  3027. if (stat.value != 0)
  3028. {
  3029. stat.attributeName = statLabel;
  3030.  
  3031. itemStats.PushBack(stat);
  3032. }
  3033. }
  3034. }
  3035.  
  3036.  
  3037. public function GetItemStatsFromName(itemName : name, out itemStats : array<SAttributeTooltip>)
  3038. {
  3039. var itemCategory : name;
  3040. var i, j, settingsSize : int;
  3041. var attributeString : string;
  3042. var attributeColor : string;
  3043. var attributeName : name;
  3044. var isPercentageValue : string;
  3045. var attributes, itemAbilities, tmpArray : array<name>;
  3046. var weights : array<float>;
  3047. var stat : SAttributeTooltip;
  3048. var attributeVal, min, max : SAbilityAttributeValue;
  3049. var dm : CDefinitionsManagerAccessor;
  3050. var primaryStatLabel : string;
  3051. var statLabel : string;
  3052.  
  3053. settingsSize = theGame.tooltipSettings.GetNumRows();
  3054. dm = theGame.GetDefinitionsManager();
  3055. dm.GetItemAbilitiesWithWeights(itemName, GetEntity() == thePlayer, itemAbilities, weights, i, j);
  3056. attributes = dm.GetAbilitiesAttributes(itemAbilities);
  3057.  
  3058. itemStats.Clear();
  3059. itemCategory = dm.GetItemCategory(itemName);
  3060. for(i=0; i<settingsSize; i+=1)
  3061. {
  3062.  
  3063. attributeString = theGame.tooltipSettings.GetValueAt(0,i);
  3064. if(StrLen(attributeString) <= 0)
  3065. continue;
  3066.  
  3067. attributeName = '';
  3068.  
  3069.  
  3070. for(j=0; j<attributes.Size(); j+=1)
  3071. {
  3072. if(NameToString(attributes[j]) == attributeString)
  3073. {
  3074. attributeName = attributes[j];
  3075. break;
  3076. }
  3077. }
  3078. if(!IsNameValid(attributeName))
  3079. continue;
  3080.  
  3081.  
  3082. if(itemCategory == 'silversword' && attributeName == 'SlashingDamage') continue;
  3083. if(itemCategory == 'steelsword' && attributeName == 'SilverDamage') continue;
  3084.  
  3085.  
  3086. attributeColor = theGame.tooltipSettings.GetValueAt(1,i);
  3087.  
  3088. isPercentageValue = theGame.tooltipSettings.GetValueAt(2,i);
  3089.  
  3090.  
  3091. dm.GetAbilitiesAttributeValue(itemAbilities, attributeName, min, max);
  3092. attributeVal = GetAttributeRandomizedValue(min, max);
  3093.  
  3094. stat.attributeColor = attributeColor;
  3095. stat.percentageValue = isPercentageValue;
  3096.  
  3097. stat.primaryStat = IsPrimaryStat(itemCategory, attributeName, primaryStatLabel);
  3098.  
  3099. stat.value = 0;
  3100. stat.originName = attributeName;
  3101.  
  3102. if(attributeVal.valueBase != 0)
  3103. {
  3104. stat.value = attributeVal.valueBase;
  3105. }
  3106. if(attributeVal.valueMultiplicative != 0)
  3107. {
  3108. stat.value = attributeVal.valueMultiplicative;
  3109. stat.percentageValue = true;
  3110. }
  3111. if(attributeVal.valueAdditive != 0)
  3112. {
  3113. statLabel = GetAttributeNameLocStr(attributeName, false);
  3114. stat.value = attributeVal.valueBase + attributeVal.valueAdditive;
  3115. }
  3116.  
  3117. if (attributeName == 'toxicity_offset')
  3118. {
  3119. statLabel = GetAttributeNameLocStr('toxicity', false);
  3120. stat.percentageValue = false;
  3121. }
  3122. else
  3123. {
  3124. statLabel = GetAttributeNameLocStr(attributeName, false);
  3125. }
  3126.  
  3127. if (stat.value != 0)
  3128. {
  3129. stat.attributeName = statLabel;
  3130.  
  3131. itemStats.PushBack(stat);
  3132. }
  3133.  
  3134.  
  3135. }
  3136. }
  3137.  
  3138. public function IsThereItemOnSlot(slot : EEquipmentSlots) : bool
  3139. {
  3140. var player : W3PlayerWitcher;
  3141.  
  3142. player = ((W3PlayerWitcher)GetEntity());
  3143. if(player)
  3144. {
  3145. return player.IsAnyItemEquippedOnSlot(slot);
  3146. }
  3147. else
  3148. {
  3149. return false;
  3150. }
  3151. }
  3152.  
  3153. public function GetItemEquippedOnSlot(slot : EEquipmentSlots, out item : SItemUniqueId) : bool
  3154. {
  3155. var player : W3PlayerWitcher;
  3156.  
  3157. player = ((W3PlayerWitcher)GetEntity());
  3158. if(player)
  3159. {
  3160. return player.GetItemEquippedOnSlot(slot, item);
  3161. }
  3162. else
  3163. {
  3164. return false;
  3165. }
  3166. }
  3167.  
  3168. public function IsItemExcluded ( itemID : SItemUniqueId, excludedItems : array < SItemNameProperty > ) : bool
  3169. {
  3170. var i : int;
  3171. var currItemName : name;
  3172.  
  3173. currItemName = GetItemName( itemID );
  3174.  
  3175. for ( i = 0; i < excludedItems.Size(); i+=1 )
  3176. {
  3177. if ( currItemName == excludedItems[i].itemName )
  3178. {
  3179. return true;
  3180. }
  3181. }
  3182. return false;
  3183. }
  3184.  
  3185.  
  3186. public function GetItemPrimaryStat(itemId : SItemUniqueId, out attributeLabel : string, out attributeVal : float ) : void
  3187. {
  3188. var attributeName : name;
  3189. var attributeValue:SAbilityAttributeValue;
  3190.  
  3191. GetItemPrimaryStatImplById(itemId, attributeLabel, attributeVal, attributeName);
  3192.  
  3193. attributeValue = GetItemAttributeValue(itemId, attributeName);
  3194.  
  3195. if(attributeValue.valueBase != 0)
  3196. {
  3197. attributeVal = attributeValue.valueBase;
  3198. }
  3199. if(attributeValue.valueMultiplicative != 0)
  3200. {
  3201. attributeVal = attributeValue.valueMultiplicative;
  3202. }
  3203. if(attributeValue.valueAdditive != 0)
  3204. {
  3205. attributeVal = attributeValue.valueAdditive;
  3206. }
  3207. }
  3208.  
  3209. public function GetItemStatByName(itemName : name, statName : name, out resultValue : float) : void
  3210. {
  3211. var dm : CDefinitionsManagerAccessor;
  3212. var attributes, itemAbilities : array<name>;
  3213. var min, max, attributeValue : SAbilityAttributeValue;
  3214. var tmpInt : int;
  3215. var tmpArray : array<float>;
  3216.  
  3217. dm = theGame.GetDefinitionsManager();
  3218. dm.GetItemAbilitiesWithWeights(itemName, GetEntity() == thePlayer, itemAbilities, tmpArray, tmpInt, tmpInt);
  3219. attributes = dm.GetAbilitiesAttributes(itemAbilities);
  3220.  
  3221. dm.GetAbilitiesAttributeValue(itemAbilities, statName, min, max);
  3222. attributeValue = GetAttributeRandomizedValue(min, max);
  3223.  
  3224. if(attributeValue.valueBase != 0)
  3225. {
  3226. resultValue = attributeValue.valueBase;
  3227. }
  3228. if(attributeValue.valueMultiplicative != 0)
  3229. {
  3230. resultValue = attributeValue.valueMultiplicative;
  3231. }
  3232. if(attributeValue.valueAdditive != 0)
  3233. {
  3234. resultValue = attributeValue.valueAdditive;
  3235. }
  3236. }
  3237.  
  3238. public function GetItemPrimaryStatFromName(itemName : name, out attributeLabel : string, out attributeVal : float, out primAttrName : name) : void
  3239. {
  3240. var dm : CDefinitionsManagerAccessor;
  3241. var attributeName : name;
  3242. var attributes, itemAbilities : array<name>;
  3243. var attributeValue, min, max : SAbilityAttributeValue;
  3244.  
  3245. var tmpInt : int;
  3246. var tmpArray : array<float>;
  3247.  
  3248. dm = theGame.GetDefinitionsManager();
  3249.  
  3250. GetItemPrimaryStatImpl(dm.GetItemCategory(itemName), attributeLabel, attributeVal, attributeName);
  3251. dm.GetItemAbilitiesWithWeights(itemName, GetEntity() == thePlayer, itemAbilities, tmpArray, tmpInt, tmpInt);
  3252. attributes = dm.GetAbilitiesAttributes(itemAbilities);
  3253. for (tmpInt = 0; tmpInt < attributes.Size(); tmpInt += 1)
  3254. if (attributes[tmpInt] == attributeName)
  3255. {
  3256. dm.GetAbilitiesAttributeValue(itemAbilities, attributeName, min, max);
  3257. attributeValue = GetAttributeRandomizedValue(min, max);
  3258. primAttrName = attributeName;
  3259. break;
  3260. }
  3261.  
  3262. if(attributeValue.valueBase != 0)
  3263. {
  3264. attributeVal = attributeValue.valueBase;
  3265. }
  3266. if(attributeValue.valueMultiplicative != 0)
  3267. {
  3268. attributeVal = attributeValue.valueMultiplicative;
  3269. }
  3270. if(attributeValue.valueAdditive != 0)
  3271. {
  3272. attributeVal = attributeValue.valueAdditive;
  3273. }
  3274.  
  3275. }
  3276.  
  3277. public function IsPrimaryStatById(itemId : SItemUniqueId, attributeName : name, out attributeLabel : string) : bool
  3278. {
  3279. var attrValue : float;
  3280. var attrName : name;
  3281.  
  3282. GetItemPrimaryStatImplById(itemId, attributeLabel, attrValue, attrName);
  3283. return attrName == attributeName;
  3284. }
  3285.  
  3286. private function GetItemPrimaryStatImplById(itemId : SItemUniqueId, out attributeLabel : string, out attributeVal : float, out attributeName : name ) : void
  3287. {
  3288. var itemOnSlot : SItemUniqueId;
  3289. var categoryName : name;
  3290. var abList : array<name>;
  3291.  
  3292. attributeName = '';
  3293. attributeLabel = "";
  3294. categoryName = GetItemCategory(itemId);
  3295.  
  3296.  
  3297. if (categoryName == 'bolt' || categoryName == 'petard')
  3298. {
  3299. GetItemAttributes(itemId, abList);
  3300. if (abList.Contains('FireDamage'))
  3301. {
  3302. attributeName = 'FireDamage';
  3303. }
  3304. else if (abList.Contains('PiercingDamage'))
  3305. {
  3306. attributeName = 'PiercingDamage';
  3307. }
  3308. else if (abList.Contains('PiercingDamage'))
  3309. {
  3310. attributeName = 'PiercingDamage';
  3311. }
  3312. else if (abList.Contains('PoisonDamage'))
  3313. {
  3314. attributeName = 'PoisonDamage';
  3315. }
  3316. else if (abList.Contains('BludgeoningDamage'))
  3317. {
  3318. attributeName = 'BludgeoningDamage';
  3319. }
  3320. else
  3321. {
  3322. attributeName = 'PhysicalDamage';
  3323. }
  3324. attributeLabel = GetAttributeNameLocStr(attributeName, false);
  3325. }
  3326. else if (categoryName == 'secondary')
  3327. {
  3328. GetItemAttributes(itemId, abList);
  3329. if (abList.Contains('BludgeoningDamage'))
  3330. {
  3331. attributeName = 'BludgeoningDamage';
  3332. }
  3333. else
  3334. {
  3335. attributeName = 'PhysicalDamage';
  3336. }
  3337. attributeLabel = GetAttributeNameLocStr(attributeName, false);
  3338. }
  3339. else if (categoryName == 'steelsword')
  3340. {
  3341. GetItemAttributes(itemId, abList);
  3342. if (abList.Contains('SlashingDamage'))
  3343. {
  3344. attributeName = 'SlashingDamage';
  3345. attributeLabel = GetLocStringByKeyExt("panel_inventory_tooltip_damage");
  3346. }
  3347. else if (abList.Contains('BludgeoningDamage'))
  3348. {
  3349. attributeName = 'BludgeoningDamage';
  3350. }
  3351. else if (abList.Contains('PiercingDamage'))
  3352. {
  3353. attributeName = 'PiercingDamage';
  3354. }
  3355. else
  3356. {
  3357. attributeName = 'PhysicalDamage';
  3358. }
  3359. if (attributeLabel == "")
  3360. {
  3361. attributeLabel = GetAttributeNameLocStr(attributeName, false);
  3362. }
  3363. }
  3364. else
  3365. {
  3366. GetItemPrimaryStatImpl(categoryName, attributeLabel, attributeVal, attributeName);
  3367. }
  3368. }
  3369.  
  3370. public function IsPrimaryStat(categoryName : name, attributeName : name, out attributeLabel : string) : bool
  3371. {
  3372. var attrValue : float;
  3373. var attrName : name;
  3374.  
  3375. GetItemPrimaryStatImpl(categoryName, attributeLabel, attrValue, attrName);
  3376. return attrName == attributeName;
  3377. }
  3378.  
  3379. private function GetItemPrimaryStatImpl(categoryName : name, out attributeLabel : string, out attributeVal : float, out attributeName : name ) : void
  3380. {
  3381. attributeName = '';
  3382. attributeLabel = "";
  3383. switch (categoryName)
  3384. {
  3385. case 'steelsword':
  3386. attributeName = 'SlashingDamage';
  3387. attributeLabel = GetLocStringByKeyExt("panel_inventory_tooltip_damage");
  3388. break;
  3389. case 'silversword':
  3390. attributeName = 'SilverDamage';
  3391. attributeLabel = GetLocStringByKeyExt("panel_inventory_tooltip_damage");
  3392. break;
  3393. case 'armor':
  3394. case 'gloves':
  3395. case 'gloves':
  3396. case 'boots':
  3397. case 'pants':
  3398. attributeName = 'armor';
  3399. break;
  3400. case 'potion':
  3401. case 'oil':
  3402.  
  3403. break;
  3404. case 'bolt':
  3405. case 'petard':
  3406. attributeName = 'PhysicalDamage';
  3407. break;
  3408. case 'crossbow':
  3409. default:
  3410. attributeLabel = "";
  3411. attributeVal = 0;
  3412. return;
  3413. break;
  3414. }
  3415.  
  3416. if (attributeLabel == "")
  3417. {
  3418. attributeLabel = GetAttributeNameLocStr(attributeName, false);
  3419. }
  3420. }
  3421.  
  3422. public function CanBeCompared(itemId : SItemUniqueId) : bool
  3423. {
  3424. var wplayer : W3PlayerWitcher;
  3425. var itemSlot : EEquipmentSlots;
  3426. var equipedItem : SItemUniqueId;
  3427. var horseManager : W3HorseManager;
  3428.  
  3429. var isArmorOrWeapon : bool;
  3430.  
  3431. if (IsItemHorseItem(itemId))
  3432. {
  3433. horseManager = GetWitcherPlayer().GetHorseManager();
  3434.  
  3435. if (!horseManager)
  3436. {
  3437. return false;
  3438. }
  3439.  
  3440. if (horseManager.IsItemEquipped(itemId))
  3441. {
  3442. return false;
  3443. }
  3444.  
  3445. itemSlot = GetHorseSlotForItem(itemId);
  3446. equipedItem = horseManager.GetItemInSlot(itemSlot);
  3447. if (!horseManager.GetInventoryComponent().IsIdValid(equipedItem))
  3448. {
  3449. return false;
  3450. }
  3451. }
  3452. else
  3453. {
  3454. isArmorOrWeapon = IsItemAnyArmor(itemId) || IsItemWeapon(itemId);
  3455. if (!isArmorOrWeapon)
  3456. {
  3457. return false;
  3458. }
  3459.  
  3460. wplayer = GetWitcherPlayer();
  3461. if (wplayer.IsItemEquipped(itemId))
  3462. {
  3463. return false;
  3464. }
  3465.  
  3466. itemSlot = GetSlotForItemId(itemId);
  3467. wplayer.GetItemEquippedOnSlot(itemSlot, equipedItem);
  3468. if (!wplayer.inv.IsIdValid(equipedItem))
  3469. {
  3470. return false;
  3471. }
  3472. }
  3473.  
  3474. return true;
  3475. }
  3476.  
  3477. public function GetHorseSlotForItem(id : SItemUniqueId) : EEquipmentSlots
  3478. {
  3479. var tags : array<name>;
  3480.  
  3481. GetItemTags(id, tags);
  3482.  
  3483. if(tags.Contains('Saddle')) return EES_HorseSaddle;
  3484. else if(tags.Contains('HorseBag')) return EES_HorseBag;
  3485. else if(tags.Contains('Trophy')) return EES_HorseTrophy;
  3486. else if(tags.Contains('Blinders')) return EES_HorseBlinders;
  3487. else return EES_InvalidSlot;
  3488. }
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494. public final function SingletonItemRefillAmmo( id : SItemUniqueId, optional alchemyTableUsed : bool )
  3495. {
  3496. var l_bed : W3WitcherBed;
  3497. var refilledByBed : bool;
  3498.  
  3499. refilledByBed = false;
  3500.  
  3501.  
  3502. if( FactsQuerySum( "PlayerInsideOuterWitcherHouse" ) >= 1 && FactsQuerySum( "AlchemyTableExists" ) >= 1 && !IsItemMutagenPotion( id ) )
  3503. {
  3504. l_bed = (W3WitcherBed)theGame.GetEntityByTag( 'witcherBed' );
  3505.  
  3506. if( l_bed.GetWasUsed() || alchemyTableUsed )
  3507. {
  3508. SetItemModifierInt( id, 'ammo_current', SingletonItemGetMaxAmmo(id) + theGame.params.QUANTITY_INCREASED_BY_ALCHEMY_TABLE ) ;
  3509. refilledByBed = true;
  3510. if( !l_bed.GetWereItemsRefilled() )
  3511. {
  3512. l_bed.SetWereItemsRefilled( true );
  3513. }
  3514. }
  3515. }
  3516.  
  3517.  
  3518. if( !refilledByBed && SingletonItemGetAmmo( id ) < SingletonItemGetMaxAmmo( id ) )
  3519. {
  3520. SetItemModifierInt(id, 'ammo_current', SingletonItemGetMaxAmmo(id));
  3521. }
  3522.  
  3523. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnAmmoChanged );
  3524. }
  3525.  
  3526. public function SingletonItemSetAmmo(id : SItemUniqueId, quantity : int)
  3527. {
  3528. var amount : int;
  3529.  
  3530. if(ItemHasTag(id, theGame.params.TAG_INFINITE_AMMO))
  3531. {
  3532. amount = -1;
  3533. }
  3534. else
  3535. {
  3536. amount = Clamp(quantity, 0, SingletonItemGetMaxAmmo(id));
  3537. }
  3538.  
  3539. SetItemModifierInt(id, 'ammo_current', amount);
  3540. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnAmmoChanged );
  3541. }
  3542.  
  3543. public function SingletonItemAddAmmo(id : SItemUniqueId, quantity : int)
  3544. {
  3545. var ammo : int;
  3546.  
  3547. if(quantity <= 0)
  3548. return;
  3549.  
  3550. ammo = GetItemModifierInt(id, 'ammo_current');
  3551.  
  3552. if(ammo == -1)
  3553. return;
  3554.  
  3555. ammo = Clamp(ammo + quantity, 0, SingletonItemGetMaxAmmo(id));
  3556. SetItemModifierInt(id, 'ammo_current', ammo);
  3557. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnAmmoChanged );
  3558. }
  3559.  
  3560. public function SingletonItemsRefillAmmo( optional alchemyTableUsed : bool ) : bool
  3561. {
  3562. var i : int;
  3563. var singletonItems : array<SItemUniqueId>;
  3564. var alco : SItemUniqueId;
  3565. var arrStr : array<string>;
  3566. var witcher : W3PlayerWitcher;
  3567. var itemLabel : string;
  3568.  
  3569. witcher = GetWitcherPlayer();
  3570. if(GetEntity() == witcher && HasNotFilledSingletonItem( alchemyTableUsed ) )
  3571. {
  3572. alco = witcher.GetAlcoholForAlchemicalItemsRefill();
  3573.  
  3574. if(!IsIdValid(alco))
  3575. {
  3576.  
  3577. theGame.GetGuiManager().ShowNotification(GetLocStringByKeyExt("message_common_alchemy_items_cannot_refill"));
  3578. theSound.SoundEvent("gui_global_denied");
  3579.  
  3580. return false;
  3581. }
  3582. else
  3583. {
  3584.  
  3585. arrStr.PushBack(GetItemName(alco));
  3586. itemLabel = GetLocStringByKeyExt(GetItemLocalizedNameByUniqueID(alco));
  3587. theGame.GetGuiManager().ShowNotification( itemLabel + " - " + GetLocStringByKeyExtWithParams("message_common_alchemy_items_refilled", , , arrStr));
  3588. theSound.SoundEvent("gui_alchemy_brew");
  3589.  
  3590. if(!ItemHasTag(alco, theGame.params.TAG_INFINITE_USE))
  3591. RemoveItem(alco);
  3592. }
  3593. }
  3594.  
  3595. singletonItems = GetSingletonItems();
  3596. for(i=0; i<singletonItems.Size(); i+=1)
  3597. {
  3598. SingletonItemRefillAmmo( singletonItems[i], alchemyTableUsed );
  3599. }
  3600.  
  3601. return true;
  3602. }
  3603.  
  3604. public function SingletonItemsRefillAmmoNoAlco(optional dontUpdateUI : bool)
  3605. {
  3606. var i : int;
  3607. var singletonItems : array<SItemUniqueId>;
  3608. var alco : SItemUniqueId;
  3609. var arrStr : array<string>;
  3610. var witcher : W3PlayerWitcher;
  3611. var itemLabel : string;
  3612.  
  3613. witcher = GetWitcherPlayer();
  3614. if(!dontUpdateUI && GetEntity() == witcher && HasNotFilledSingletonItem())
  3615. {
  3616.  
  3617. arrStr.PushBack(GetItemName(alco));
  3618. itemLabel = GetLocStringByKeyExt(GetItemLocalizedNameByUniqueID(alco));
  3619. theGame.GetGuiManager().ShowNotification( itemLabel + " - " + GetLocStringByKeyExtWithParams("message_common_alchemy_items_refilled", , , arrStr));
  3620. theSound.SoundEvent("gui_alchemy_brew");
  3621. }
  3622.  
  3623. singletonItems = GetSingletonItems();
  3624. for(i=0; i<singletonItems.Size(); i+=1)
  3625. {
  3626. SingletonItemRefillAmmo(singletonItems[i]);
  3627. }
  3628. }
  3629.  
  3630.  
  3631. private final function HasNotFilledSingletonItem( optional alchemyTableUsed : bool ) : bool
  3632. {
  3633. var i : int;
  3634. var singletonItems : array<SItemUniqueId>;
  3635. var hasLab : bool;
  3636. var l_bed : W3WitcherBed;
  3637.  
  3638.  
  3639. hasLab = false;
  3640. if( FactsQuerySum( "PlayerInsideOuterWitcherHouse" ) >= 1 && FactsQuerySum( "AlchemyTableExists" ) >= 1 )
  3641. {
  3642. l_bed = (W3WitcherBed)theGame.GetEntityByTag( 'witcherBed' );
  3643. if( l_bed.GetWasUsed() || alchemyTableUsed )
  3644. {
  3645. hasLab = true;
  3646. }
  3647. }
  3648.  
  3649. singletonItems = GetSingletonItems();
  3650. for(i=0; i<singletonItems.Size(); i+=1)
  3651. {
  3652. if( hasLab && !IsItemMutagenPotion( singletonItems[i] ) )
  3653. {
  3654. if(SingletonItemGetAmmo(singletonItems[i]) <= SingletonItemGetMaxAmmo(singletonItems[i]))
  3655. {
  3656. return true;
  3657. }
  3658. }
  3659. else if(SingletonItemGetAmmo(singletonItems[i]) < SingletonItemGetMaxAmmo(singletonItems[i]))
  3660. {
  3661. return true;
  3662. }
  3663. }
  3664.  
  3665. return false;
  3666. }
  3667.  
  3668. public function SingletonItemRemoveAmmo(itemID : SItemUniqueId, optional quantity : int)
  3669. {
  3670. var ammo : int;
  3671.  
  3672. if(!IsItemSingletonItem(itemID) || ItemHasTag(itemID, theGame.params.TAG_INFINITE_AMMO))
  3673. return;
  3674.  
  3675. if(quantity <= 0)
  3676. quantity = 1;
  3677.  
  3678. ammo = GetItemModifierInt(itemID, 'ammo_current');
  3679. ammo = Max(0, ammo - quantity);
  3680. SetItemModifierInt(itemID, 'ammo_current', ammo);
  3681.  
  3682.  
  3683. if(ammo == 0 && ShouldProcessTutorial('TutorialAlchemyRefill') && FactsQuerySum("q001_nightmare_ended") > 0)
  3684. {
  3685. FactsAdd('tut_alch_refill', 1);
  3686. }
  3687. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnAmmoChanged );
  3688. }
  3689.  
  3690. public function SingletonItemGetAmmo(itemID : SItemUniqueId) : int
  3691. {
  3692. if(!IsItemSingletonItem(itemID))
  3693. return 0;
  3694.  
  3695. return GetItemModifierInt(itemID, 'ammo_current');
  3696. }
  3697.  
  3698. public function SingletonItemGetMaxAmmo(itemID : SItemUniqueId) : int
  3699. {
  3700. var ammo, i : int;
  3701. var perk20Bonus, min, max : SAbilityAttributeValue;
  3702. var atts : array<name>;
  3703. var canUseSkill : bool;
  3704.  
  3705. ammo = RoundMath(CalculateAttributeValue(GetItemAttributeValue(itemID, 'ammo')));
  3706.  
  3707. if( !ItemHasTag( itemID, 'NoAdditionalAmmo' ) )
  3708. {
  3709. if(GetEntity() == GetWitcherPlayer() && ammo > 0)
  3710. {
  3711. if(IsItemBomb(itemID) && thePlayer.CanUseSkill(S_Alchemy_s08) )
  3712. {
  3713. ammo += thePlayer.GetSkillLevel(S_Alchemy_s08);
  3714. }
  3715.  
  3716. if(thePlayer.HasBuff(EET_Mutagen03) && (IsItemBomb(itemID) || (!IsItemMutagenPotion(itemID) && IsItemPotion(itemID))) )
  3717. {
  3718. ammo += 1;
  3719. }
  3720.  
  3721. if( GetWitcherPlayer().IsSetBonusActive( EISB_RedWolf_2 ) && !IsItemMutagenPotion(itemID) )
  3722. {
  3723. theGame.GetDefinitionsManager().GetAbilityAttributeValue( GetSetBonusAbility( EISB_RedWolf_2 ), 'amount', min, max);
  3724. ammo += (int)min.valueAdditive;
  3725. }
  3726.  
  3727.  
  3728. if( IsItemBomb( itemID ) && thePlayer.CanUseSkill( S_Perk_20 ) && GetItemName( itemID ) != 'Snow Ball' )
  3729. {
  3730. GetItemAttributes( itemID, atts );
  3731. canUseSkill = thePlayer.CanUseSkill( S_Alchemy_s10 );
  3732. perk20Bonus = GetWitcherPlayer().GetSkillAttributeValue( S_Perk_20, 'stack_multiplier', false, false );
  3733.  
  3734. for( i=0 ; i<atts.Size() ; i+=1 )
  3735. {
  3736. if( canUseSkill || IsDamageTypeNameValid( atts[i] ) )
  3737. {
  3738. ammo = RoundMath( ammo * perk20Bonus.valueMultiplicative );
  3739. break;
  3740. }
  3741. }
  3742. }
  3743. }
  3744. }
  3745.  
  3746. return ammo;
  3747. }
  3748.  
  3749. public function ManageSingletonItemsBonus()
  3750. {
  3751. var l_items : array<SItemUniqueId>;
  3752. var l_i : int;
  3753. var l_haveBombOrPot : bool;
  3754.  
  3755. l_items = GetSingletonItems();
  3756.  
  3757. for( l_i = 0 ; l_i < l_items.Size() ; l_i += 1 )
  3758. {
  3759. if( IsItemPotion( l_items[ l_i ] ) || IsItemBomb( l_items[ l_i ] ) )
  3760. {
  3761. l_haveBombOrPot = true;
  3762. if( SingletonItemGetMaxAmmo( l_items[ l_i ] ) >= SingletonItemGetAmmo( l_items[ l_i ] ) )
  3763. {
  3764. if( SingletonItemsRefillAmmo( true ) )
  3765. {
  3766. theGame.GetGuiManager().ShowNotification( GetLocStringByKeyExt( "message_common_alchemy_table_buff_applied" ),, true );
  3767. }
  3768.  
  3769. return;
  3770. }
  3771. }
  3772. }
  3773.  
  3774. if( !l_haveBombOrPot )
  3775. {
  3776. theGame.GetGuiManager().ShowNotification( GetLocStringByKeyExt( "message_common_alchemy_table_buff_no_items" ),, true );
  3777. return;
  3778. }
  3779.  
  3780. theGame.GetGuiManager().ShowNotification( GetLocStringByKeyExt( "message_common_alchemy_table_buff_already_on" ),, true );
  3781. }
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787. public final function IsItemSteelSwordUsableByPlayer(item : SItemUniqueId) : bool
  3788. {
  3789. return ItemHasTag(item, theGame.params.TAG_PLAYER_STEELSWORD) && !ItemHasTag(item, 'SecondaryWeapon');
  3790. }
  3791.  
  3792. public final function IsItemSilverSwordUsableByPlayer(item : SItemUniqueId) : bool
  3793. {
  3794. return ItemHasTag(item, theGame.params.TAG_PLAYER_SILVERSWORD) && !ItemHasTag(item, 'SecondaryWeapon');
  3795. }
  3796.  
  3797. public final function IsItemFists(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'fist';}
  3798. public final function IsItemWeapon(item : SItemUniqueId) : bool {return ItemHasTag(item, 'Weapon') || ItemHasTag(item, 'WeaponTab');}
  3799. public final function IsItemCrossbow(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'crossbow';}
  3800. public final function IsItemChestArmor(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'armor';}
  3801. public final function IsItemBody(item : SItemUniqueId) : bool {return ItemHasTag(item, 'Body');}
  3802. public final function IsRecipeOrSchematic( item : SItemUniqueId ) : bool {return GetItemCategory(item) == 'alchemy_recipe' || GetItemCategory(item) == 'crafting_schematic'; }
  3803. public final function IsItemBoots(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'boots';}
  3804. public final function IsItemGloves(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'gloves';}
  3805. public final function IsItemPants(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'trousers' || GetItemCategory(item) == 'pants';}
  3806. public final function IsItemTrophy(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'trophy';}
  3807. public final function IsItemMask(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'mask';}
  3808. public final function IsItemBomb(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'petard';}
  3809. public final function IsItemBolt(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'bolt';}
  3810. public final function IsItemUpgrade(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'upgrade';}
  3811. public final function IsItemTool(item : SItemUniqueId) : bool {return GetItemCategory(item) == 'tool';}
  3812. public final function IsItemPotion(item : SItemUniqueId) : bool {return ItemHasTag(item, 'Potion');}
  3813. public final function IsItemOil(item : SItemUniqueId) : bool {return ItemHasTag(item, 'SilverOil') || ItemHasTag(item, 'SteelOil');}
  3814. public final function IsItemAnyArmor(item : SItemUniqueId) : bool {return ItemHasTag(item, theGame.params.TAG_ARMOR);}
  3815. public final function IsItemUpgradeable(item : SItemUniqueId) : bool {return ItemHasTag(item, theGame.params.TAG_ITEM_UPGRADEABLE);}
  3816. public final function IsItemIngredient(item : SItemUniqueId) : bool {return ItemHasTag(item, 'AlchemyIngredient') || ItemHasTag(item, 'CraftingIngredient');}
  3817. public final function IsItemDismantleKit(item : SItemUniqueId) : bool {return ItemHasTag(item, 'DismantleKit');}
  3818. public final function IsItemHorseBag(item : SItemUniqueId) : bool {return ItemHasTag(item, 'HorseBag');}
  3819. public final function IsItemReadable(item : SItemUniqueId) : bool {return ItemHasTag(item, 'ReadableItem');}
  3820. public final function IsItemAlchemyItem(item : SItemUniqueId) : bool {return IsItemOil(item) || IsItemPotion(item) || IsItemBomb(item); }
  3821. public final function IsItemSingletonItem(item : SItemUniqueId) : bool {return ItemHasTag(item, theGame.params.TAG_ITEM_SINGLETON);}
  3822. public final function IsItemQuest(item : SItemUniqueId) : bool {return ItemHasTag(item, 'Quest');}
  3823. public final function IsItemFood(item : SItemUniqueId) : bool {return ItemHasTag(item, 'Edibles') || ItemHasTag(item, 'Drinks');}
  3824. public final function IsItemSecondaryWeapon(item : SItemUniqueId) : bool {return ItemHasTag(item, 'SecondaryWeapon');}
  3825. public final function IsItemHorseItem(item: SItemUniqueId) : bool {return ItemHasTag(item, 'Saddle') || ItemHasTag(item, 'HorseBag') || ItemHasTag(item, 'Trophy') || ItemHasTag(item, 'Blinders'); }
  3826. public final function IsItemSaddle(item: SItemUniqueId) : bool {return ItemHasTag(item, 'Saddle');}
  3827. public final function IsItemBlinders(item: SItemUniqueId) : bool {return ItemHasTag(item, 'Blinders');}
  3828. public final function IsItemDye( item : SItemUniqueId ) : bool { return ItemHasTag( item, 'mod_dye' ); }
  3829. public final function IsItemUsable( item : SItemUniqueId ) : bool { return GetItemCategory( item ) == 'usable'; }
  3830. public final function IsItemJunk( item : SItemUniqueId ) : bool { return ItemHasTag( item,'junk' ) || GetItemCategory( item ) == 'junk' ; }
  3831. public final function IsItemAlchemyIngredient(item : SItemUniqueId) : bool { return ItemHasTag( item, 'AlchemyIngredient' ); }
  3832. public final function IsItemCraftingIngredient(item : SItemUniqueId) : bool { return ItemHasTag( item, 'CraftingIngredient' ); }
  3833. public final function IsItemArmorReapairKit(item : SItemUniqueId) : bool { return ItemHasTag( item, 'ArmorReapairKit' ); }
  3834. public final function IsItemWeaponReapairKit(item : SItemUniqueId) : bool { return ItemHasTag( item, 'WeaponReapairKit' ); }
  3835. public final function IsQuickSlotItem( item : SItemUniqueId ) : bool { return ItemHasTag( item, 'QuickSlot' ); }
  3836.  
  3837. public final function IsItemNew( item : SItemUniqueId ) : bool
  3838. {
  3839. var uiData : SInventoryItemUIData;
  3840.  
  3841. uiData = GetInventoryItemUIData( item );
  3842. return uiData.isNew;
  3843. }
  3844.  
  3845. public final function IsItemMutagenPotion(item : SItemUniqueId) : bool
  3846. {
  3847. return IsItemPotion(item) && ItemHasTag(item, 'Mutagen');
  3848. }
  3849.  
  3850. public final function CanItemBeColored( item : SItemUniqueId) : bool
  3851. {
  3852. if ( RoundMath( CalculateAttributeValue( GetItemAttributeValue( item, 'quality' ) ) ) == 5 )
  3853. {
  3854. return true;
  3855. }
  3856. return false;
  3857. }
  3858.  
  3859. public final function IsItemSetItem(item : SItemUniqueId) : bool
  3860. {
  3861. return
  3862. ItemHasTag(item, theGame.params.ITEM_SET_TAG_BEAR) ||
  3863. ItemHasTag(item, theGame.params.ITEM_SET_TAG_GRYPHON) ||
  3864. ItemHasTag(item, theGame.params.ITEM_SET_TAG_LYNX) ||
  3865. ItemHasTag(item, theGame.params.ITEM_SET_TAG_WOLF) ||
  3866. ItemHasTag(item, theGame.params.ITEM_SET_TAG_RED_WOLF) ||
  3867. ItemHasTag( item, theGame.params.ITEM_SET_TAG_VAMPIRE ) ||
  3868. ItemHasTag(item, theGame.params.ITEM_SET_TAG_VIPER);
  3869. }
  3870.  
  3871. public function GetArmorType(item : SItemUniqueId) : EArmorType
  3872. {
  3873. var isItemEquipped : bool;
  3874.  
  3875. isItemEquipped = GetWitcherPlayer().IsItemEquipped(item);
  3876.  
  3877.  
  3878. if( thePlayer.HasAbility('Glyphword 2 _Stats', true) && isItemEquipped )
  3879. {return EAT_Light;}
  3880. if( thePlayer.HasAbility('Glyphword 3 _Stats', true) && isItemEquipped )
  3881. {return EAT_Medium;}
  3882. if( thePlayer.HasAbility('Glyphword 4 _Stats', true) && isItemEquipped )
  3883. {return EAT_Heavy;}
  3884.  
  3885. if(ItemHasTag(item, 'LightArmor'))
  3886. return EAT_Light;
  3887. else if(ItemHasTag(item, 'MediumArmor'))
  3888. return EAT_Medium;
  3889. else if(ItemHasTag(item, 'HeavyArmor'))
  3890. return EAT_Heavy;
  3891.  
  3892. return EAT_Undefined;
  3893. }
  3894.  
  3895. public final function GetAlchemyCraftableItems() : array<SItemUniqueId>
  3896. {
  3897. var items : array<SItemUniqueId>;
  3898. var i : int;
  3899.  
  3900. GetAllItems(items);
  3901.  
  3902. for(i=items.Size()-1; i>=0; i-=1)
  3903. {
  3904. if(!IsItemPotion(items[i]) && !IsItemBomb(items[i]) && !IsItemOil(items[i]))
  3905. items.EraseFast(i);
  3906. }
  3907.  
  3908. return items;
  3909. }
  3910.  
  3911. public function IsItemEncumbranceItem(item : SItemUniqueId) : bool
  3912. {
  3913. if(ItemHasTag(item, theGame.params.TAG_ENCUMBRANCE_ITEM_FORCE_YES))
  3914. return true;
  3915.  
  3916. if(ItemHasTag(item, theGame.params.TAG_ENCUMBRANCE_ITEM_FORCE_NO))
  3917. return false;
  3918.  
  3919.  
  3920. if (
  3921. IsRecipeOrSchematic( item )
  3922. || IsItemBody( item )
  3923.  
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935. )
  3936. return false;
  3937.  
  3938. return true;
  3939. }
  3940.  
  3941. public function GetItemEncumbrance(item : SItemUniqueId) : float
  3942. {
  3943. var itemCategory : name;
  3944. if ( IsItemEncumbranceItem( item ) )
  3945. {
  3946. itemCategory = GetItemCategory( item );
  3947. if ( itemCategory == 'quest' || itemCategory == 'key' )
  3948. {
  3949. return 0.01 * GetItemQuantity( item );
  3950. }
  3951. else if ( itemCategory == 'usable' || itemCategory == 'upgrade' || itemCategory == 'junk' )
  3952. {
  3953. return 0.01 + GetItemWeight( item ) * GetItemQuantity( item ) * 0.2;
  3954. }
  3955. else if ( IsItemAlchemyItem( item ) || IsItemIngredient( item ) || IsItemFood( item ) || IsItemReadable( item ) )
  3956. {
  3957. return 0.0;
  3958. }
  3959. else
  3960. {
  3961. return 0.01 + GetItemWeight( item ) * GetItemQuantity( item ) * 0.5;
  3962. }
  3963. }
  3964. return 0;
  3965. }
  3966.  
  3967. public function GetFilterTypeByItem( item : SItemUniqueId ) : EInventoryFilterType
  3968. {
  3969. var filterType : EInventoryFilterType;
  3970.  
  3971. if( ItemHasTag( item, 'Quest' ) )
  3972. {
  3973. return IFT_QuestItems;
  3974. }
  3975. else if( IsItemIngredient( item ) )
  3976. {
  3977. return IFT_Ingredients;
  3978. }
  3979. else if( IsItemAlchemyItem(item) )
  3980. {
  3981. return IFT_AlchemyItems;
  3982. }
  3983. else if( IsItemAnyArmor(item) )
  3984. {
  3985. return IFT_Armors;
  3986. }
  3987. else if( IsItemWeapon( item ) )
  3988. {
  3989. return IFT_Weapons;
  3990. }
  3991. else
  3992. {
  3993. return IFT_Default;
  3994. }
  3995. }
  3996.  
  3997.  
  3998. public function IsItemQuickslotItem(item : SItemUniqueId) : bool
  3999. {
  4000. return IsSlotQuickslot( GetSlotForItemId(item) );
  4001. }
  4002.  
  4003. public function GetCrossbowAmmo(id : SItemUniqueId) : int
  4004. {
  4005. if(!IsItemCrossbow(id))
  4006. return -1;
  4007.  
  4008. return (int)CalculateAttributeValue(GetItemAttributeValue(id, 'ammo'));
  4009. }
  4010.  
  4011.  
  4012.  
  4013. public function GetSlotForItemId(item : SItemUniqueId) : EEquipmentSlots
  4014. {
  4015. var tags : array<name>;
  4016. var player : W3PlayerWitcher;
  4017. var slot : EEquipmentSlots;
  4018.  
  4019. player = ((W3PlayerWitcher)GetEntity());
  4020.  
  4021. GetItemTags(item, tags);
  4022. slot = GetSlotForItem( GetItemCategory(item), tags, player );
  4023.  
  4024. if(!player)
  4025. return slot;
  4026.  
  4027. if(IsMultipleSlot(slot))
  4028. {
  4029. if(slot == EES_Petard1 && player.IsAnyItemEquippedOnSlot(slot))
  4030. {
  4031. if(!player.IsAnyItemEquippedOnSlot(EES_Petard2))
  4032. slot = EES_Petard2;
  4033. }
  4034. else if(slot == EES_Quickslot1 && player.IsAnyItemEquippedOnSlot(slot))
  4035. {
  4036. if(!player.IsAnyItemEquippedOnSlot(EES_Quickslot2))
  4037. slot = EES_Quickslot2;
  4038. }
  4039. else if(slot == EES_Potion1 && player.IsAnyItemEquippedOnSlot(EES_Potion1))
  4040. {
  4041. if(!player.IsAnyItemEquippedOnSlot(EES_Potion2))
  4042. {
  4043. slot = EES_Potion2;
  4044. }
  4045. else
  4046. {
  4047. if(!player.IsAnyItemEquippedOnSlot(EES_Potion3))
  4048. {
  4049. slot = EES_Potion3;
  4050. }
  4051. else
  4052. {
  4053. if(!player.IsAnyItemEquippedOnSlot(EES_Potion4))
  4054. {
  4055. slot = EES_Potion4;
  4056. }
  4057. }
  4058. }
  4059. }
  4060. else if(slot == EES_PotionMutagen1 && player.IsAnyItemEquippedOnSlot(slot))
  4061. {
  4062. if(!player.IsAnyItemEquippedOnSlot(EES_PotionMutagen2))
  4063. {
  4064. slot = EES_PotionMutagen2;
  4065. }
  4066. else
  4067. {
  4068. if(!player.IsAnyItemEquippedOnSlot(EES_PotionMutagen3))
  4069. {
  4070. slot = EES_PotionMutagen3;
  4071. }
  4072. else
  4073. {
  4074. if(!player.IsAnyItemEquippedOnSlot(EES_PotionMutagen4))
  4075. {
  4076. slot = EES_PotionMutagen4;
  4077. }
  4078. }
  4079. }
  4080. }
  4081. else if(slot == EES_SkillMutagen1 && player.IsAnyItemEquippedOnSlot(slot))
  4082. {
  4083. if(!player.IsAnyItemEquippedOnSlot(EES_SkillMutagen2))
  4084. {
  4085. slot = EES_SkillMutagen2;
  4086. }
  4087. else
  4088. {
  4089. if(!player.IsAnyItemEquippedOnSlot(EES_SkillMutagen3))
  4090. {
  4091. slot = EES_SkillMutagen3;
  4092. }
  4093. else
  4094. {
  4095. if(!player.IsAnyItemEquippedOnSlot(EES_SkillMutagen4))
  4096. {
  4097. slot = EES_SkillMutagen4;
  4098. } else slot = SSS_GetFirstAvailableMutagenSlot(slot, player); //zur13 modSSS mutTabs
  4099. }
  4100. }
  4101. }
  4102. }
  4103.  
  4104. return slot;
  4105. }
  4106.  
  4107.  
  4108.  
  4109. public function GetAllWeapons() : array<SItemUniqueId>
  4110. {
  4111. return GetItemsByTag('Weapon');
  4112. }
  4113.  
  4114.  
  4115. public function GetSpecifiedPlayerItemsQuest(steelSword, silverSword, armor, boots, gloves, pants, trophy, mask, bombs, crossbow, secondaryWeapon, equippedOnly : bool) : array<SItemUniqueId>
  4116. {
  4117. var items, allItems : array<SItemUniqueId>;
  4118. var i : int;
  4119.  
  4120. GetAllItems(allItems);
  4121.  
  4122. for(i=0; i<allItems.Size(); i+=1)
  4123. {
  4124. if(
  4125. (steelSword && IsItemSteelSwordUsableByPlayer(allItems[i])) ||
  4126. (silverSword && IsItemSilverSwordUsableByPlayer(allItems[i])) ||
  4127. (armor && IsItemChestArmor(allItems[i])) ||
  4128. (boots && IsItemBoots(allItems[i])) ||
  4129. (gloves && IsItemGloves(allItems[i])) ||
  4130. (pants && IsItemPants(allItems[i])) ||
  4131. (trophy && IsItemTrophy(allItems[i])) ||
  4132. (mask && IsItemMask(allItems[i])) ||
  4133. (bombs && IsItemBomb(allItems[i])) ||
  4134. (crossbow && (IsItemCrossbow(allItems[i]) || IsItemBolt(allItems[i]))) ||
  4135. (secondaryWeapon && IsItemSecondaryWeapon(allItems[i]))
  4136. )
  4137. {
  4138. if(!equippedOnly || (equippedOnly && ((W3PlayerWitcher)GetEntity()) && GetWitcherPlayer().IsItemEquipped(allItems[i])) )
  4139. {
  4140. if(!ItemHasTag(allItems[i], 'NoDrop'))
  4141. items.PushBack(allItems[i]);
  4142. }
  4143. }
  4144. }
  4145.  
  4146. return items;
  4147. }
  4148.  
  4149.  
  4150. event OnItemAboutToGive( itemId : SItemUniqueId, quantity : int )
  4151. {
  4152. if(GetEntity() == GetWitcherPlayer())
  4153. {
  4154. if( IsItemSteelSwordUsableByPlayer( itemId ) || IsItemSilverSwordUsableByPlayer( itemId ) )
  4155. {
  4156. RemoveAllOilsFromItem( itemId );
  4157. }
  4158. }
  4159. }
  4160.  
  4161.  
  4162. event OnItemRemoved( itemId : SItemUniqueId, quantity : int )
  4163. {
  4164. var ent : CGameplayEntity;
  4165. var crossbows : array<SItemUniqueId>;
  4166. var witcher : W3PlayerWitcher;
  4167. var refill : W3RefillableContainer;
  4168.  
  4169. witcher = GetWitcherPlayer();
  4170.  
  4171. if(GetEntity() == witcher)
  4172. {
  4173.  
  4174.  
  4175.  
  4176.  
  4177.  
  4178. if(IsItemCrossbow(itemId) && HasInfiniteBolts())
  4179. {
  4180. crossbows = GetItemsByCategory('crossbow');
  4181. crossbows.Remove(itemId);
  4182.  
  4183. if(crossbows.Size() == 0)
  4184. {
  4185. RemoveItemByName('Bodkin Bolt', GetItemQuantityByName('Bodkin Bolt'));
  4186. RemoveItemByName('Harpoon Bolt', GetItemQuantityByName('Harpoon Bolt'));
  4187. }
  4188. }
  4189. else if(IsItemBolt(itemId) && witcher.IsItemEquipped(itemId) && witcher.inv.GetItemQuantity(itemId) == quantity)
  4190. {
  4191.  
  4192. witcher.UnequipItem(itemId);
  4193. }
  4194.  
  4195.  
  4196. if(IsItemCrossbow(itemId) && witcher.IsItemEquipped(itemId) && witcher.rangedWeapon)
  4197. {
  4198. witcher.rangedWeapon.ClearDeployedEntity(true);
  4199. witcher.rangedWeapon = NULL;
  4200. }
  4201. if( GetItemCategory(itemId) == 'usable' )
  4202. {
  4203. if(witcher.IsHoldingItemInLHand() && itemId == witcher.currentlyEquipedItemL )
  4204. {
  4205. witcher.HideUsableItem(true);
  4206. }
  4207. }
  4208. if( IsItemSteelSwordUsableByPlayer( itemId ) || IsItemSilverSwordUsableByPlayer( itemId ) )
  4209. {
  4210. RemoveAllOilsFromItem( itemId );
  4211. }
  4212.  
  4213.  
  4214. if(witcher.IsItemEquipped(itemId) && quantity >= witcher.inv.GetItemQuantity(itemId))
  4215. witcher.UnequipItem(itemId);
  4216. }
  4217.  
  4218.  
  4219. if(GetEntity() == thePlayer && IsItemWeapon(itemId) && (IsItemHeld(itemId) || IsItemMounted(itemId) ))
  4220. {
  4221. thePlayer.OnHolsteredItem(GetItemCategory(itemId),'r_weapon');
  4222. }
  4223.  
  4224.  
  4225. ent = (CGameplayEntity)GetEntity();
  4226. if(ent)
  4227. ent.OnItemTaken( itemId, quantity );
  4228.  
  4229.  
  4230. if(IsLootRenewable())
  4231. {
  4232. refill = (W3RefillableContainer)GetEntity();
  4233. if(refill)
  4234. refill.AddTimer('Refill', 20, true);
  4235. }
  4236. }
  4237.  
  4238.  
  4239. function GenerateItemLevel( item : SItemUniqueId, rewardItem : bool )
  4240. {
  4241. var stat : SAbilityAttributeValue;
  4242. var playerLevel : int;
  4243. var lvl, i : int;
  4244. var quality : int;
  4245. var ilMin, ilMax : int;
  4246.  
  4247. playerLevel = GetWitcherPlayer().GetLevel();
  4248.  
  4249. lvl = playerLevel - 1;
  4250.  
  4251.  
  4252. if ( ( W3MerchantNPC )GetEntity() )
  4253. {
  4254. lvl = RoundF( playerLevel + RandRangeF( 2, 0 ) );
  4255. AddItemTag( item, 'AutogenUseLevelRange' );
  4256. }
  4257. else if ( rewardItem )
  4258. {
  4259. lvl = RoundF( playerLevel + RandRangeF( 1, 0 ) );
  4260. }
  4261. else if ( ItemHasTag( item, 'AutogenUseLevelRange') )
  4262. {
  4263. quality = RoundMath( CalculateAttributeValue( GetItemAttributeValue( item, 'quality' ) ) );
  4264. ilMin = RoundMath(CalculateAttributeValue( GetItemAttributeValue( item, 'item_level_min' ) ));
  4265. ilMax = RoundMath(CalculateAttributeValue( GetItemAttributeValue( item, 'item_level_max' ) ));
  4266.  
  4267. lvl += 1;
  4268. if ( !ItemHasTag( item, 'AutogenForceLevel') )
  4269. lvl += RoundMath(RandRangeF( 1, -1 ));
  4270.  
  4271. if ( FactsQuerySum("NewGamePlus") > 0 )
  4272. {
  4273. if ( lvl < ilMin + theGame.params.GetNewGamePlusLevel() ) lvl = ilMin + theGame.params.GetNewGamePlusLevel();
  4274. if ( lvl > ilMax + theGame.params.GetNewGamePlusLevel() ) lvl = ilMax + theGame.params.GetNewGamePlusLevel();
  4275. }
  4276. else
  4277. {
  4278. if ( lvl < ilMin ) lvl = ilMin;
  4279. if ( lvl > ilMax ) lvl = ilMax;
  4280. }
  4281.  
  4282. if ( quality == 5 ) lvl += 2;
  4283. if ( quality == 4 ) lvl += 1;
  4284. if ( (quality == 5 || quality == 4) && ItemHasTag(item, 'EP1') ) lvl += 1;
  4285. }
  4286. else if ( !ItemHasTag( item, 'AutogenForceLevel') )
  4287. {
  4288. quality = RoundMath( CalculateAttributeValue( GetItemAttributeValue( item, 'quality' ) ) );
  4289.  
  4290. if ( quality == 5 )
  4291. {
  4292. lvl = RoundF( playerLevel + RandRangeF( 2, 0 ) );
  4293. }
  4294. else if ( quality == 4 )
  4295. {
  4296. lvl = RoundF( playerLevel + RandRangeF( 1, -2 ) );
  4297. }
  4298. else if ( quality == 3 )
  4299. {
  4300. lvl = RoundF( playerLevel + RandRangeF( -1, -3 ) );
  4301.  
  4302. if ( RandF() > 0.9 )
  4303. {
  4304. lvl = playerLevel;
  4305. }
  4306. }
  4307. else if ( quality == 2 )
  4308. {
  4309. lvl = RoundF( playerLevel + RandRangeF( -2, -5 ) );
  4310.  
  4311. if ( RandF() > 0.95 )
  4312. {
  4313. lvl = playerLevel;
  4314. }
  4315. }
  4316. else
  4317. {
  4318. lvl = RoundF( playerLevel + RandRangeF( -2, -8 ) );
  4319.  
  4320. if ( RandF() == 0 )
  4321. {
  4322. lvl = playerLevel;
  4323. }
  4324. }
  4325. }
  4326.  
  4327. if (FactsQuerySum("StandAloneEP1") > 0)
  4328. lvl = GetWitcherPlayer().GetLevel() - 1;
  4329.  
  4330.  
  4331. if ( FactsQuerySum("NewGamePlus") > 0 && !ItemHasTag( item, 'AutogenUseLevelRange') )
  4332. {
  4333. if ( quality == 5 ) lvl += 2;
  4334. if ( quality == 4 ) lvl += 1;
  4335. }
  4336.  
  4337. if ( lvl < 1 ) lvl = 1;
  4338. if ( lvl > GetWitcherPlayer().GetMaxLevel() ) lvl = GetWitcherPlayer().GetMaxLevel();
  4339.  
  4340. if ( ItemHasTag( item, 'PlayerSteelWeapon' ) && !( ItemHasAbility( item, 'autogen_steel_base' ) || ItemHasAbility( item, 'autogen_fixed_steel_base' ) ) )
  4341. {
  4342. if ( ItemHasTag(item, 'AutogenUseLevelRange') && ItemHasAbility(item, 'autogen_fixed_steel_base') )
  4343. return;
  4344.  
  4345. if ( ItemHasTag(item, 'AutogenUseLevelRange') )
  4346. AddItemCraftedAbility(item, 'autogen_fixed_steel_base' );
  4347. else
  4348. AddItemCraftedAbility(item, 'autogen_steel_base' );
  4349.  
  4350. for( i=0; i<lvl; i+=1 )
  4351. {
  4352. if (FactsQuerySum("StandAloneEP1") > 0)
  4353. {
  4354. AddItemCraftedAbility(item, 'autogen_fixed_steel_dmg', true );
  4355. continue;
  4356. }
  4357.  
  4358. if ( ItemHasTag( item, 'AutogenForceLevel') || ItemHasTag(item, 'AutogenUseLevelRange') || FactsQuerySum("NewGamePlus") > 0 )
  4359. AddItemCraftedAbility(item, 'autogen_fixed_steel_dmg', true );
  4360. else
  4361. AddItemCraftedAbility(item, 'autogen_steel_dmg', true );
  4362. }
  4363. }
  4364. else if ( ItemHasTag( item, 'PlayerSilverWeapon' ) && !( ItemHasAbility( item, 'autogen_silver_base' ) || ItemHasAbility( item, 'autogen_fixed_silver_base' ) ) )
  4365. {
  4366. if ( ItemHasTag(item, 'AutogenUseLevelRange') && ItemHasAbility(item, 'autogen_fixed_silver_base') )
  4367. return;
  4368.  
  4369. if ( ItemHasTag(item, 'AutogenUseLevelRange') )
  4370. AddItemCraftedAbility(item, 'autogen_fixed_silver_base' );
  4371. else
  4372. AddItemCraftedAbility(item, 'autogen_silver_base' );
  4373.  
  4374. for( i=0; i<lvl; i+=1 )
  4375. {
  4376. if (FactsQuerySum("StandAloneEP1") > 0)
  4377. {
  4378. AddItemCraftedAbility(item, 'autogen_fixed_silver_dmg', true );
  4379. continue;
  4380. }
  4381.  
  4382. if ( ItemHasTag( item, 'AutogenForceLevel') || ItemHasTag(item, 'AutogenUseLevelRange') || FactsQuerySum("NewGamePlus") > 0 )
  4383. AddItemCraftedAbility(item, 'autogen_fixed_silver_dmg', true );
  4384. else
  4385. AddItemCraftedAbility(item, 'autogen_silver_dmg', true );
  4386. }
  4387. }
  4388. else if ( GetItemCategory( item ) == 'armor' && !( ItemHasAbility( item, 'autogen_armor_base' ) || ItemHasAbility( item, 'autogen_fixed_armor_base' ) ) )
  4389. {
  4390. if ( ItemHasTag(item, 'AutogenUseLevelRange') && ItemHasAbility(item, 'autogen_fixed_armor_base') )
  4391. return;
  4392.  
  4393. if ( ItemHasTag(item, 'AutogenUseLevelRange') )
  4394. AddItemCraftedAbility(item, 'autogen_fixed_armor_base' );
  4395. else
  4396. AddItemCraftedAbility(item, 'autogen_armor_base' );
  4397.  
  4398. for( i=0; i<lvl; i+=1 )
  4399. {
  4400. if (FactsQuerySum("StandAloneEP1") > 0)
  4401. {
  4402. AddItemCraftedAbility(item, 'autogen_fixed_armor_armor', true );
  4403. continue;
  4404. }
  4405.  
  4406. if ( ItemHasTag( item, 'AutogenForceLevel') || ItemHasTag( item, 'AutogenUseLevelRange') || FactsQuerySum("NewGamePlus") > 0 )
  4407. AddItemCraftedAbility(item, 'autogen_fixed_armor_armor', true );
  4408. else
  4409. AddItemCraftedAbility(item, 'autogen_armor_armor', true );
  4410. }
  4411. }
  4412. else if ( ( GetItemCategory( item ) == 'boots' || GetItemCategory( item ) == 'pants' ) && !( ItemHasAbility( item, 'autogen_pants_base' ) || ItemHasAbility( item, 'autogen_fixed_pants_base' ) ) )
  4413. {
  4414. if ( ItemHasTag(item, 'AutogenUseLevelRange') && ItemHasAbility(item, 'autogen_fixed_pants_base') )
  4415. return;
  4416.  
  4417. if ( ItemHasTag(item, 'AutogenUseLevelRange') )
  4418. AddItemCraftedAbility(item, 'autogen_fixed_pants_base' );
  4419. else
  4420. AddItemCraftedAbility(item, 'autogen_pants_base' );
  4421.  
  4422. for( i=0; i<lvl; i+=1 )
  4423. {
  4424. if (FactsQuerySum("StandAloneEP1") > 0)
  4425. {
  4426. AddItemCraftedAbility(item, 'autogen_fixed_pants_armor', true );
  4427. continue;
  4428. }
  4429.  
  4430. if ( ItemHasTag( item, 'AutogenForceLevel') || ItemHasTag( item, 'AutogenUseLevelRange') || FactsQuerySum("NewGamePlus") > 0 )
  4431. AddItemCraftedAbility(item, 'autogen_fixed_pants_armor', true );
  4432. else
  4433. AddItemCraftedAbility(item, 'autogen_pants_armor', true );
  4434. }
  4435. }
  4436. else if ( GetItemCategory( item ) == 'gloves' && !( ItemHasAbility( item, 'autogen_gloves_base' ) || ItemHasAbility( item, 'autogen_fixed_gloves_base' ) ) )
  4437. {
  4438. if ( ItemHasTag(item, 'AutogenUseLevelRange') && ItemHasAbility(item, 'autogen_fixed_gloves_base') )
  4439. return;
  4440.  
  4441. if ( ItemHasTag(item, 'AutogenUseLevelRange') )
  4442. AddItemCraftedAbility(item, 'autogen_fixed_gloves_base' );
  4443. else
  4444. AddItemCraftedAbility(item, 'autogen_gloves_base' );
  4445.  
  4446. for( i=0; i<lvl; i+=1 )
  4447. {
  4448. if (FactsQuerySum("StandAloneEP1") > 0)
  4449. {
  4450. AddItemCraftedAbility(item, 'autogen_fixed_gloves_armor', true );
  4451. continue;
  4452. }
  4453.  
  4454. if ( ItemHasTag( item, 'AutogenForceLevel') || ItemHasTag(item, 'AutogenUseLevelRange') || FactsQuerySum("NewGamePlus") > 0 )
  4455. AddItemCraftedAbility(item, 'autogen_fixed_gloves_armor', true );
  4456. else
  4457. AddItemCraftedAbility(item, 'autogen_gloves_armor', true );
  4458. }
  4459. }
  4460. }
  4461.  
  4462.  
  4463. event OnItemAdded(data : SItemChangedData)
  4464. {
  4465. var i, j : int;
  4466. var ent : CGameplayEntity;
  4467. var allCardsNames, foundCardsNames : array<name>;
  4468. var allStringNamesOfCards : array<string>;
  4469. var foundCardsStringNames : array<string>;
  4470. var gwintCards : array<SItemUniqueId>;
  4471. var itemName : name;
  4472. var witcher : W3PlayerWitcher;
  4473. var itemCategory : name;
  4474. var dm : CDefinitionsManagerAccessor;
  4475. var locKey : string;
  4476. var leaderCardsHack : array<name>;
  4477.  
  4478. var hud : CR4ScriptedHud;
  4479. var journalUpdateModule : CR4HudModuleJournalUpdate;
  4480. var itemId : SItemUniqueId;
  4481.  
  4482. var isItemShematic : bool;
  4483.  
  4484. var ngp : bool;
  4485.  
  4486. ent = (CGameplayEntity)GetEntity();
  4487.  
  4488. itemId = data.ids[0];
  4489.  
  4490.  
  4491. if( data.informGui )
  4492. {
  4493. recentlyAddedItems.PushBack( itemId );
  4494. if( ItemHasTag( itemId, 'FocusObject' ) )
  4495. {
  4496. GetWitcherPlayer().GetMedallion().Activate( true, 3.0);
  4497. }
  4498. }
  4499.  
  4500.  
  4501. if ( ItemHasTag(itemId, 'Autogen') )
  4502. {
  4503. GenerateItemLevel( itemId, false );
  4504. }
  4505.  
  4506. witcher = GetWitcherPlayer();
  4507.  
  4508.  
  4509. if(ent == witcher || ((W3MerchantNPC)ent) )
  4510. {
  4511. ngp = FactsQuerySum("NewGamePlus") > 0;
  4512. for(i=0; i<data.ids.Size(); i+=1)
  4513. {
  4514.  
  4515. if ( GetItemModifierInt(data.ids[i], 'ItemQualityModified') <= 0 )
  4516. AddRandomEnhancementToItem(data.ids[i]);
  4517.  
  4518. if ( ngp )
  4519. SetItemModifierInt(data.ids[i], 'DoNotAdjustNGPDLC', 1);
  4520.  
  4521. itemName = GetItemName(data.ids[i]);
  4522.  
  4523. if ( ngp && GetItemModifierInt(data.ids[i], 'NGPItemAdjusted') <= 0 && !ItemHasTag(data.ids[i], 'Autogen') )
  4524. {
  4525. IncreaseNGPItemlevel(data.ids[i]);
  4526. }
  4527.  
  4528. }
  4529. }
  4530. if(ent == witcher)
  4531. {
  4532. for(i=0; i<data.ids.Size(); i+=1)
  4533. {
  4534.  
  4535. if( ItemHasTag( itemId, theGame.params.GWINT_CARD_ACHIEVEMENT_TAG ) || !FactsDoesExist( "fix_for_gwent_achievement_bug_121588" ) )
  4536. {
  4537.  
  4538. leaderCardsHack.PushBack('gwint_card_emhyr_gold');
  4539. leaderCardsHack.PushBack('gwint_card_emhyr_silver');
  4540. leaderCardsHack.PushBack('gwint_card_emhyr_bronze');
  4541. leaderCardsHack.PushBack('gwint_card_foltest_gold');
  4542. leaderCardsHack.PushBack('gwint_card_foltest_silver');
  4543. leaderCardsHack.PushBack('gwint_card_foltest_bronze');
  4544. leaderCardsHack.PushBack('gwint_card_francesca_gold');
  4545. leaderCardsHack.PushBack('gwint_card_francesca_silver');
  4546. leaderCardsHack.PushBack('gwint_card_francesca_bronze');
  4547. leaderCardsHack.PushBack('gwint_card_eredin_gold');
  4548. leaderCardsHack.PushBack('gwint_card_eredin_silver');
  4549. leaderCardsHack.PushBack('gwint_card_eredin_bronze');
  4550.  
  4551. dm = theGame.GetDefinitionsManager();
  4552.  
  4553. allCardsNames = theGame.GetDefinitionsManager().GetItemsWithTag(theGame.params.GWINT_CARD_ACHIEVEMENT_TAG);
  4554.  
  4555.  
  4556. gwintCards = GetItemsByTag(theGame.params.GWINT_CARD_ACHIEVEMENT_TAG);
  4557.  
  4558.  
  4559. allStringNamesOfCards.PushBack('gwint_name_emhyr');
  4560. allStringNamesOfCards.PushBack('gwint_name_emhyr');
  4561. allStringNamesOfCards.PushBack('gwint_name_emhyr');
  4562. allStringNamesOfCards.PushBack('gwint_name_foltest');
  4563. allStringNamesOfCards.PushBack('gwint_name_foltest');
  4564. allStringNamesOfCards.PushBack('gwint_name_foltest');
  4565. allStringNamesOfCards.PushBack('gwint_name_francesca');
  4566. allStringNamesOfCards.PushBack('gwint_name_francesca');
  4567. allStringNamesOfCards.PushBack('gwint_name_francesca');
  4568. allStringNamesOfCards.PushBack('gwint_name_eredin');
  4569. allStringNamesOfCards.PushBack('gwint_name_eredin');
  4570. allStringNamesOfCards.PushBack('gwint_name_eredin');
  4571.  
  4572.  
  4573. for(j=0; j<allCardsNames.Size(); j+=1)
  4574. {
  4575. itemName = allCardsNames[j];
  4576. locKey = dm.GetItemLocalisationKeyName(allCardsNames[j]);
  4577. if (!allStringNamesOfCards.Contains(locKey))
  4578. {
  4579. allStringNamesOfCards.PushBack(locKey);
  4580. }
  4581. }
  4582.  
  4583.  
  4584. if(gwintCards.Size() >= allStringNamesOfCards.Size())
  4585. {
  4586. foundCardsNames.Clear();
  4587. for(j=0; j<gwintCards.Size(); j+=1)
  4588. {
  4589. itemName = GetItemName(gwintCards[j]);
  4590. locKey = dm.GetItemLocalisationKeyName(itemName);
  4591.  
  4592. if(!foundCardsStringNames.Contains(locKey) || leaderCardsHack.Contains(itemName))
  4593. {
  4594. foundCardsStringNames.PushBack(locKey);
  4595. }
  4596. }
  4597.  
  4598. if(foundCardsStringNames.Size() >= allStringNamesOfCards.Size())
  4599. {
  4600. theGame.GetGamerProfile().AddAchievement(EA_GwintCollector);
  4601. FactsAdd("gwint_all_cards_collected", 1, -1);
  4602. }
  4603. }
  4604.  
  4605. if(!FactsDoesExist("fix_for_gwent_achievement_bug_121588"))
  4606. FactsAdd("fix_for_gwent_achievement_bug_121588", 1, -1);
  4607. }
  4608.  
  4609. itemCategory = GetItemCategory( itemId );
  4610. isItemShematic = itemCategory == 'alchemy_recipe' || itemCategory == 'crafting_schematic';
  4611.  
  4612. if( isItemShematic )
  4613. {
  4614. ReadSchematicsAndRecipes( itemId );
  4615. }
  4616.  
  4617.  
  4618. if( ItemHasTag( data.ids[i], 'GwintCard'))
  4619. {
  4620. witcher.AddGwentCard(GetItemName(data.ids[i]), data.quantity);
  4621. }
  4622.  
  4623.  
  4624.  
  4625. if( !isItemShematic && ( this.ItemHasTag( itemId, 'ReadableItem' ) || this.ItemHasTag( itemId, 'Painting' ) ) && !this.ItemHasTag( itemId, 'NoNotification' ) )
  4626. {
  4627. hud = (CR4ScriptedHud)theGame.GetHud();
  4628. if( hud )
  4629. {
  4630. journalUpdateModule = (CR4HudModuleJournalUpdate)hud.GetHudModule( "JournalUpdateModule" );
  4631. if( journalUpdateModule )
  4632. {
  4633. journalUpdateModule.AddQuestBookInfo( itemId );
  4634. }
  4635. }
  4636. }
  4637. }
  4638. }
  4639.  
  4640.  
  4641. if( IsItemSingletonItem( itemId ) )
  4642. {
  4643. for(i=0; i<data.ids.Size(); i+=1)
  4644. {
  4645. if(!GetItemModifierInt(data.ids[i], 'is_initialized', 0))
  4646. {
  4647. SingletonItemRefillAmmo(data.ids[i]);
  4648. SetItemModifierInt(data.ids[i], 'is_initialized', 1);
  4649. }
  4650. }
  4651. }
  4652.  
  4653.  
  4654. if(ent)
  4655. ent.OnItemGiven(data);
  4656.  
  4657. // ======== modGearLevelScaling 1/1 BEGIN ========
  4658. if (ent == witcher)
  4659. singleItemLevelScaleHandling(itemId);
  4660. // ======== modGearLevelScaling 1/1 END ========
  4661. }
  4662.  
  4663. public function AddRandomEnhancementToItem(item : SItemUniqueId)
  4664. {
  4665. var itemCategory : name;
  4666. var itemQuality : int;
  4667. var ability : name;
  4668. var ent : CGameplayEntity;
  4669.  
  4670.  
  4671.  
  4672.  
  4673. if( ItemHasTag(item, 'DoNotEnhance') )
  4674. {
  4675. SetItemModifierInt(item, 'ItemQualityModified', 1);
  4676. return;
  4677. }
  4678.  
  4679. itemCategory = GetItemCategory(item);
  4680. itemQuality = RoundMath(CalculateAttributeValue(GetItemAttributeValue(item, 'quality' )));
  4681.  
  4682. if ( itemCategory == 'armor' )
  4683. {
  4684. switch ( itemQuality )
  4685. {
  4686. case 2 :
  4687. ability = 'quality_masterwork_armor';
  4688. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkArmorAbility(), true);
  4689. break;
  4690. case 3 :
  4691. ability = 'quality_magical_armor';
  4692. if ( ItemHasTag(item, 'EP1') )
  4693. {
  4694. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4695. break;
  4696. }
  4697.  
  4698. if ( RandF() > 0.5 )
  4699. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4700. else
  4701. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkArmorAbility(), true);
  4702.  
  4703. if ( RandF() > 0.5 )
  4704. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4705. else
  4706. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkArmorAbility(), true);
  4707. break;
  4708. default : break;
  4709. }
  4710. }
  4711. else if ( itemCategory == 'gloves' )
  4712. {
  4713. switch ( itemQuality )
  4714. {
  4715. case 2 :
  4716. ability = 'quality_masterwork_gloves';
  4717. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkGlovesAbility(), true);
  4718. break;
  4719. case 3 :
  4720. ability = 'quality_magical_gloves';
  4721. if ( ItemHasTag(item, 'EP1') )
  4722. {
  4723. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4724. break;
  4725. }
  4726.  
  4727. if ( RandF() > 0.5 )
  4728. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalGlovesAbility(), true);
  4729. else
  4730. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkGlovesAbility(), true);
  4731.  
  4732. if ( RandF() > 0.5 )
  4733. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalGlovesAbility(), true);
  4734. else
  4735. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkGlovesAbility(), true);
  4736. break;
  4737. default : break;
  4738. }
  4739. }
  4740. else if ( itemCategory == 'pants' )
  4741. {
  4742. switch ( itemQuality )
  4743. {
  4744. case 2 :
  4745. ability = 'quality_masterwork_pants';
  4746. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkPantsAbility(), true);
  4747. break;
  4748. case 3 :
  4749. ability = 'quality_magical_pants';
  4750. if ( ItemHasTag(item, 'EP1') )
  4751. {
  4752. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4753. break;
  4754. }
  4755.  
  4756. if ( RandF() > 0.5 )
  4757. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalPantsAbility(), true);
  4758. else
  4759. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkPantsAbility(), true);
  4760.  
  4761. if ( RandF() > 0.5 )
  4762. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalPantsAbility(), true);
  4763. else
  4764. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkPantsAbility(), true);
  4765. break;
  4766. default : break;
  4767. }
  4768. }
  4769. else if ( itemCategory == 'boots' )
  4770. {
  4771. switch ( itemQuality )
  4772. {
  4773. case 2 :
  4774. ability = 'quality_masterwork_boots';
  4775. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkBootsAbility(), true);
  4776. break;
  4777. case 3 :
  4778. ability = 'quality_magical_boots';
  4779. if ( ItemHasTag(item, 'EP1') )
  4780. {
  4781. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4782. break;
  4783. }
  4784.  
  4785. if ( RandF() > 0.5 )
  4786. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalBootsAbility(), true);
  4787. else
  4788. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkBootsAbility(), true);
  4789.  
  4790. if ( RandF() > 0.5 )
  4791. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalBootsAbility(), true);
  4792. else
  4793. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkBootsAbility(), true);
  4794. break;
  4795. default : break;
  4796. }
  4797. }
  4798. else if ( itemCategory == 'steelsword' )
  4799. {
  4800. switch ( itemQuality )
  4801. {
  4802. case 2 :
  4803. ability = 'quality_masterwork_steelsword';
  4804. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4805. break;
  4806. case 3 :
  4807. ability = 'quality_magical_steelsword';
  4808. if ( ItemHasTag(item, 'EP1') )
  4809. {
  4810. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4811. break;
  4812. }
  4813.  
  4814. if ( RandF() > 0.5 )
  4815. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalWeaponAbility(), true);
  4816. else
  4817. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4818.  
  4819. if ( RandF() > 0.5 )
  4820. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalWeaponAbility(), true);
  4821. else
  4822. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4823. break;
  4824. default : break;
  4825. }
  4826. }
  4827. else if ( itemCategory == 'silversword' )
  4828. {
  4829. switch ( itemQuality )
  4830. {
  4831. case 2 :
  4832. ability = 'quality_masterwork_silversword';
  4833. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4834. break;
  4835. case 3 :
  4836. ability = 'quality_magical_silversword';
  4837. if ( ItemHasTag(item, 'EP1') )
  4838. {
  4839. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalArmorAbility(), true);
  4840. break;
  4841. }
  4842.  
  4843. if ( RandF() > 0.5 )
  4844. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalWeaponAbility(), true);
  4845. else
  4846. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4847.  
  4848. if ( RandF() > 0.5 )
  4849. AddItemCraftedAbility(item, theGame.params.GetRandomMagicalWeaponAbility(), true);
  4850. else
  4851. AddItemCraftedAbility(item, theGame.params.GetRandomMasterworkWeaponAbility(), true);
  4852. break;
  4853.  
  4854. default : break;
  4855. }
  4856. }
  4857.  
  4858. if(IsNameValid(ability))
  4859. {
  4860. AddItemCraftedAbility(item, ability, false);
  4861. SetItemModifierInt(item, 'ItemQualityModified', 1);
  4862. }
  4863. }
  4864.  
  4865. public function IncreaseNGPItemlevel(item : SItemUniqueId)
  4866. {
  4867. var i, diff : int;
  4868.  
  4869. diff = theGame.params.NewGamePlusLevelDifference();
  4870.  
  4871. if (diff > 0)
  4872. {
  4873. if ( ItemHasTag( item, 'PlayerSteelWeapon' ) )
  4874. {
  4875. for( i=0; i<diff; i+=1 )
  4876. {
  4877. AddItemCraftedAbility(item, 'autogen_fixed_steel_dmg', true );
  4878. }
  4879. }
  4880. else if ( ItemHasTag( item, 'PlayerSilverWeapon' ) )
  4881. {
  4882. for( i=0; i<diff; i+=1 )
  4883. {
  4884. AddItemCraftedAbility(item, 'autogen_fixed_silver_dmg', true );
  4885. }
  4886. }
  4887. else if ( IsItemChestArmor(item) )
  4888. {
  4889. for( i=0; i<diff; i+=1 )
  4890. {
  4891. AddItemCraftedAbility(item, 'autogen_fixed_armor_armor', true );
  4892. }
  4893. }
  4894. else if ( IsItemBoots(item) || IsItemPants(item) )
  4895. {
  4896. for( i=0; i<diff; i+=1 )
  4897. {
  4898. AddItemCraftedAbility(item, 'autogen_fixed_pants_armor', true );
  4899. }
  4900. }
  4901. else if ( IsItemGloves(item) )
  4902. {
  4903. for( i=0; i<diff; i+=1 )
  4904. {
  4905. AddItemCraftedAbility(item, 'autogen_fixed_gloves_armor', true );
  4906. }
  4907. }
  4908. }
  4909.  
  4910. SetItemModifierInt(item, 'NGPItemAdjusted', 1);
  4911. }
  4912.  
  4913. public function GetItemQuality( itemId : SItemUniqueId ) : int
  4914. {
  4915. var itemQuality : float;
  4916. var itemQualityAtribute : SAbilityAttributeValue;
  4917. var excludedTags : array<name>;
  4918. var tempItemQualityAtribute : SAbilityAttributeValue;
  4919.  
  4920.  
  4921. excludedTags.PushBack(theGame.params.OIL_ABILITY_TAG);
  4922. itemQualityAtribute = GetItemAttributeValue( itemId, 'quality', excludedTags, true );
  4923.  
  4924. itemQuality = itemQualityAtribute.valueAdditive;
  4925. if( itemQuality == 0 )
  4926. {
  4927. itemQuality = 1;
  4928. }
  4929. return RoundMath(itemQuality);
  4930. }
  4931.  
  4932. public function GetItemQualityFromName( itemName : name, out min : int, out max : int)
  4933. {
  4934. var dm : CDefinitionsManagerAccessor;
  4935. var attributeName : name;
  4936. var attributes, itemAbilities : array<name>;
  4937. var attributeMin, attributeMax : SAbilityAttributeValue;
  4938.  
  4939. var tmpInt : int;
  4940. var tmpArray : array<float>;
  4941.  
  4942. dm = theGame.GetDefinitionsManager();
  4943.  
  4944. dm.GetItemAbilitiesWithWeights(itemName, GetEntity() == thePlayer, itemAbilities, tmpArray, tmpInt, tmpInt);
  4945. attributes = dm.GetAbilitiesAttributes(itemAbilities);
  4946. for (tmpInt = 0; tmpInt < attributes.Size(); tmpInt += 1)
  4947. {
  4948. if (attributes[tmpInt] == 'quality')
  4949. {
  4950. dm.GetAbilitiesAttributeValue(itemAbilities, 'quality', attributeMin, attributeMax);
  4951. min = RoundMath(CalculateAttributeValue(attributeMin));
  4952. max = RoundMath(CalculateAttributeValue(attributeMax));
  4953. break;
  4954. }
  4955. }
  4956. }
  4957.  
  4958. public function GetRecentlyAddedItems() : array<SItemUniqueId>
  4959. {
  4960. return recentlyAddedItems;
  4961. }
  4962.  
  4963. public function GetRecentlyAddedItemsListSize() : int
  4964. {
  4965. return recentlyAddedItems.Size();
  4966. }
  4967.  
  4968. public function RemoveItemFromRecentlyAddedList( itemId : SItemUniqueId ) : bool
  4969. {
  4970. var i : int;
  4971.  
  4972. for( i = 0; i < recentlyAddedItems.Size(); i += 1 )
  4973. {
  4974. if( recentlyAddedItems[i] == itemId )
  4975. {
  4976. recentlyAddedItems.EraseFast( i );
  4977. return true;
  4978. }
  4979. }
  4980.  
  4981. return false;
  4982. }
  4983.  
  4984.  
  4985.  
  4986.  
  4987. import final function NotifyScriptedListeners( notify : bool );
  4988.  
  4989. var listeners : array< IInventoryScriptedListener >;
  4990.  
  4991. function AddListener( listener : IInventoryScriptedListener )
  4992. {
  4993. if ( listeners.FindFirst( listener ) == -1 )
  4994. {
  4995. listeners.PushBack( listener );
  4996. if ( listeners.Size() == 1 )
  4997. {
  4998. NotifyScriptedListeners( true );
  4999. }
  5000. }
  5001. }
  5002.  
  5003. function RemoveListener( listener : IInventoryScriptedListener )
  5004. {
  5005. if ( listeners.Remove( listener ) )
  5006. {
  5007. if ( listeners.Size() == 0 )
  5008. {
  5009. NotifyScriptedListeners( false );
  5010. }
  5011. }
  5012. }
  5013.  
  5014. event OnInventoryScriptedEvent( eventType : EInventoryEventType, itemId : SItemUniqueId, quantity : int, fromAssociatedInventory : bool )
  5015. {
  5016. var i, size : int;
  5017.  
  5018. size = listeners.Size();
  5019. for (i=size-1; i>=0; i-=1 )
  5020. {
  5021. listeners[i].OnInventoryScriptedEvent( eventType, itemId, quantity, fromAssociatedInventory );
  5022. }
  5023.  
  5024.  
  5025. if(GetEntity() == GetWitcherPlayer() && (eventType == IET_ItemRemoved || eventType == IET_ItemQuantityChanged) )
  5026. GetWitcherPlayer().UpdateEncumbrance();
  5027. }
  5028.  
  5029.  
  5030.  
  5031.  
  5032. public final function GetMutationResearchPoints( color : ESkillColor, item : SItemUniqueId ) : int
  5033. {
  5034. var val : SAbilityAttributeValue;
  5035. var colorAttribute : name;
  5036.  
  5037.  
  5038. if( color == SC_None || color == SC_Yellow || !IsIdValid( item ) )
  5039. {
  5040. return 0;
  5041. }
  5042.  
  5043.  
  5044. switch( color )
  5045. {
  5046. case SC_Red:
  5047. colorAttribute = 'mutation_research_points_red';
  5048. break;
  5049. case SC_Blue:
  5050. colorAttribute = 'mutation_research_points_blue';
  5051. break;
  5052. case SC_Green:
  5053. colorAttribute = 'mutation_research_points_green';
  5054. break;
  5055. }
  5056.  
  5057.  
  5058. val = GetItemAttributeValue( item, colorAttribute );
  5059.  
  5060. return ( int )val.valueAdditive;
  5061. }
  5062.  
  5063. public function GetSkillMutagenColor(item : SItemUniqueId) : ESkillColor
  5064. {
  5065. var abs : array<name>;
  5066.  
  5067.  
  5068. if(!ItemHasTag(item, 'MutagenIngredient'))
  5069. return SC_None;
  5070.  
  5071. GetItemAbilities(item, abs);
  5072.  
  5073. if(abs.Contains('mutagen_color_green')) return SC_Green;
  5074. if(abs.Contains('mutagen_color_blue')) return SC_Blue;
  5075. if(abs.Contains('mutagen_color_red')) return SC_Red;
  5076. if(abs.Contains('lesser_mutagen_color_green')) return SC_Green;
  5077. if(abs.Contains('lesser_mutagen_color_blue')) return SC_Blue;
  5078. if(abs.Contains('lesser_mutagen_color_red')) return SC_Red;
  5079. if(abs.Contains('greater_mutagen_color_green')) return SC_Green;
  5080. if(abs.Contains('greater_mutagen_color_blue')) return SC_Blue;
  5081. if(abs.Contains('greater_mutagen_color_red')) return SC_Red;
  5082.  
  5083. return SC_None;
  5084. }
  5085.  
  5086.  
  5087.  
  5088.  
  5089.  
  5090.  
  5091.  
  5092.  
  5093.  
  5094. import final function GetItemEnhancementSlotsCount( itemId : SItemUniqueId ) : int;
  5095. import final function GetItemEnhancementItems( itemId : SItemUniqueId, out names : array< name > );
  5096. import final function GetItemEnhancementCount( itemId : SItemUniqueId ) : int;
  5097. import final function GetItemColor( itemId : SItemUniqueId ) : name;
  5098. import final function IsItemColored( itemId : SItemUniqueId ) : bool;
  5099. import final function SetPreviewColor( itemId : SItemUniqueId, colorId : int );
  5100. import final function ClearPreviewColor( itemId : SItemUniqueId ) : bool;
  5101. import final function ColorItem( itemId : SItemUniqueId, dyeId : SItemUniqueId );
  5102. import final function ClearItemColor( itemId : SItemUniqueId ) : bool;
  5103. import final function EnchantItem( enhancedItemId : SItemUniqueId, enchantmentName : name, enchantmentStat : name ) : bool;
  5104. import final function GetEnchantment( enhancedItemId : SItemUniqueId ) : name;
  5105. import final function IsItemEnchanted( enhancedItemId : SItemUniqueId ) : bool;
  5106. import final function UnenchantItem( enhancedItemId : SItemUniqueId ) : bool;
  5107. import private function EnhanceItem( enhancedItemId : SItemUniqueId, extensionItemId : SItemUniqueId ) : bool;
  5108. import private function RemoveItemEnhancementByIndex( enhancedItemId : SItemUniqueId, slotIndex : int ) : bool;
  5109. import private function RemoveItemEnhancementByName( enhancedItemId : SItemUniqueId, extensionItemName : name ) : bool;
  5110. import final function PreviewItemAttributeAfterUpgrade( baseItemId : SItemUniqueId, upgradeItemId : SItemUniqueId, attributeName : name, optional baseInventory : CInventoryComponent, optional upgradeInventory : CInventoryComponent ) : SAbilityAttributeValue;
  5111. import final function HasEnhancementItemTag( enhancedItemId : SItemUniqueId, slotIndex : int, tag : name ) : bool;
  5112.  
  5113.  
  5114. function NotifyEnhancedItem( enhancedItemId : SItemUniqueId )
  5115. {
  5116. var weapons : array<SItemUniqueId>;
  5117. var sword : CWitcherSword;
  5118. var i : int;
  5119.  
  5120. sword = (CWitcherSword) GetItemEntityUnsafe( enhancedItemId );
  5121. sword.UpdateEnhancements( this );
  5122. }
  5123.  
  5124. function EnhanceItemScript( enhancedItemId : SItemUniqueId, extensionItemId : SItemUniqueId ) : bool
  5125. {
  5126. var i : int;
  5127. var enhancements : array<name>;
  5128. var runeword : Runeword;
  5129.  
  5130. if ( EnhanceItem( enhancedItemId, extensionItemId ) )
  5131. {
  5132. NotifyEnhancedItem( enhancedItemId );
  5133.  
  5134. GetItemEnhancementItems( enhancedItemId, enhancements );
  5135. if ( theGame.runewordMgr.GetRuneword( enhancements, runeword ) )
  5136. {
  5137. for ( i = 0; i < runeword.abilities.Size(); i+=1 )
  5138. {
  5139. AddItemBaseAbility( enhancedItemId, runeword.abilities[i] );
  5140. }
  5141. }
  5142. return true;
  5143. }
  5144. return false;
  5145. }
  5146.  
  5147. function RemoveItemEnhancementByIndexScript( enhancedItemId : SItemUniqueId, slotIndex : int ) : bool
  5148. {
  5149. var i : int;
  5150. var enhancements : array<name>;
  5151. var runeword : Runeword;
  5152. var hasRuneword : bool;
  5153. var names : array< name >;
  5154.  
  5155. GetItemEnhancementItems( enhancedItemId, enhancements );
  5156. hasRuneword = theGame.runewordMgr.GetRuneword( enhancements, runeword );
  5157.  
  5158. GetItemEnhancementItems( enhancedItemId, names );
  5159.  
  5160. if ( RemoveItemEnhancementByIndex( enhancedItemId, slotIndex ) )
  5161. {
  5162. NotifyEnhancedItem( enhancedItemId );
  5163.  
  5164.  
  5165.  
  5166. if ( hasRuneword )
  5167. {
  5168.  
  5169. for ( i = 0; i < runeword.abilities.Size(); i+=1 )
  5170. {
  5171. RemoveItemBaseAbility( enhancedItemId, runeword.abilities[i] );
  5172. }
  5173. }
  5174. return true;
  5175. }
  5176. return false;
  5177. }
  5178.  
  5179.  
  5180. function RemoveItemEnhancementByNameScript( enhancedItemId : SItemUniqueId, extensionItemName : name ) : bool
  5181. {
  5182. var i : int;
  5183. var enhancements : array<name>;
  5184. var runeword : Runeword;
  5185. var hasRuneword : bool;
  5186.  
  5187. GetItemEnhancementItems( enhancedItemId, enhancements );
  5188. hasRuneword = theGame.runewordMgr.GetRuneword( enhancements, runeword );
  5189.  
  5190.  
  5191. if ( RemoveItemEnhancementByName( enhancedItemId, extensionItemName ) )
  5192. {
  5193. NotifyEnhancedItem( enhancedItemId );
  5194.  
  5195.  
  5196. AddAnItem( extensionItemName, 1, true, true );
  5197. if ( hasRuneword )
  5198. {
  5199.  
  5200. for ( i = 0; i < runeword.abilities.Size(); i+=1 )
  5201. {
  5202. RemoveItemBaseAbility( enhancedItemId, runeword.abilities[i] );
  5203. }
  5204. }
  5205. return true;
  5206. }
  5207. return false;
  5208. }
  5209.  
  5210. function RemoveAllItemEnhancements( enhancedItemId : SItemUniqueId )
  5211. {
  5212. var count, i : int;
  5213.  
  5214. count = GetItemEnhancementCount( enhancedItemId );
  5215. for ( i = count - 1; i >= 0; i-=1 )
  5216. {
  5217. RemoveItemEnhancementByIndexScript( enhancedItemId, i );
  5218. }
  5219. }
  5220.  
  5221. function GetHeldAndMountedItems( out items : array< SItemUniqueId > )
  5222. {
  5223. var allItems : array< SItemUniqueId >;
  5224. var i : int;
  5225. var itemName : name;
  5226.  
  5227. GetAllItems( allItems );
  5228.  
  5229. items.Clear();
  5230. for( i = 0; i < allItems.Size(); i += 1 )
  5231. {
  5232. if ( IsItemHeld( allItems[ i ] ) || IsItemMounted( allItems[ i ] ) )
  5233. {
  5234. items.PushBack( allItems[ i ] );
  5235. }
  5236. }
  5237. }
  5238.  
  5239.  
  5240. public function GetHasValidDecorationItems( items : array<SItemUniqueId>, decoration : W3HouseDecorationBase ) : bool
  5241. {
  5242. var i, size : int;
  5243.  
  5244. size = items.Size();
  5245.  
  5246.  
  5247. if(size == 0 )
  5248. {
  5249. LogChannel( 'houseDecorations', "No items with valid tag were found!" );
  5250. return false;
  5251. }
  5252.  
  5253.  
  5254. for( i=0; i < size; i+= 1 )
  5255. {
  5256.  
  5257. if( GetWitcherPlayer().IsItemEquipped( items[i] ) )
  5258. {
  5259. LogChannel( 'houseDecorations', "Found item is equipped, erasing..." );
  5260. continue;
  5261. }
  5262.  
  5263.  
  5264. if( IsItemQuest( items[i] ) && decoration.GetAcceptQuestItems() == false )
  5265. {
  5266. LogChannel( 'houseDecorations', "Found item is quest item, and quest items are not accepted, erasing..." );
  5267. continue;
  5268. }
  5269.  
  5270.  
  5271. if( decoration.GetItemHasForbiddenTag( items[i] ) )
  5272. {
  5273. LogChannel( 'houseDecorations', "Found item has a forbidden tag, erasing..." );
  5274. continue;
  5275. }
  5276.  
  5277. LogChannel( 'houseDecorations', "Item checks out: "+ GetItemName( items[i] ) );
  5278. return true;
  5279. }
  5280. LogChannel( 'houseDecorations', "No valid items were found!" );
  5281.  
  5282. return false;
  5283. }
  5284.  
  5285.  
  5286. function GetMissingCards() : array< name >
  5287. {
  5288. var defMgr : CDefinitionsManagerAccessor = theGame.GetDefinitionsManager();
  5289. var allCardNames : array< name > = defMgr.GetItemsWithTag(theGame.params.GWINT_CARD_ACHIEVEMENT_TAG);
  5290. var playersCards : array< SItemUniqueId > = GetItemsByTag(theGame.params.GWINT_CARD_ACHIEVEMENT_TAG);
  5291. var playersCardLocs : array< string >;
  5292. var missingCardLocs : array< string >;
  5293. var missingCards : array< name >;
  5294. var i, j : int;
  5295. var found : bool;
  5296.  
  5297.  
  5298. for ( i = 0; i < allCardNames.Size(); i+=1 )
  5299. {
  5300. found = false;
  5301.  
  5302. for ( j = 0; j < playersCards.Size(); j+=1 )
  5303. {
  5304. if ( allCardNames[i] == GetItemName( playersCards[j] ) )
  5305. {
  5306. found = true;
  5307. playersCardLocs.PushBack( defMgr.GetItemLocalisationKeyName ( allCardNames[i] ) );
  5308. break;
  5309. }
  5310. }
  5311.  
  5312. if ( !found )
  5313. {
  5314. missingCardLocs.PushBack( defMgr.GetItemLocalisationKeyName( allCardNames[i] ) );
  5315. missingCards.PushBack( allCardNames[i] );
  5316. }
  5317. }
  5318.  
  5319. if( missingCardLocs.Size() < 2 )
  5320. {
  5321. return missingCards;
  5322. }
  5323.  
  5324.  
  5325. for ( i = missingCardLocs.Size()-1 ; i >= 0 ; i-=1 )
  5326. {
  5327. for ( j = 0 ; j < playersCardLocs.Size() ; j+=1 )
  5328. {
  5329. if ( missingCardLocs[i] == playersCardLocs[j]
  5330. && missingCardLocs[i] != "gwint_name_emhyr" && missingCardLocs[i] != "gwint_name_foltest"
  5331. && missingCardLocs[i] != "gwint_name_francesca" && missingCardLocs[i] != "gwint_name_eredin" )
  5332. {
  5333. missingCardLocs.EraseFast( i );
  5334. missingCards.EraseFast( i );
  5335. break;
  5336. }
  5337. }
  5338. }
  5339.  
  5340. return missingCards;
  5341. }
  5342.  
  5343. public function FindCardSources( missingCards : array< name > ) : array< SCardSourceData >
  5344. {
  5345. var sourceCSV : C2dArray;
  5346. var sourceTable : array< SCardSourceData >;
  5347. var sourceRemaining : array< SCardSourceData >;
  5348. var sourceCount, i, j : int;
  5349.  
  5350. if ( theGame.IsFinalBuild() )
  5351. {
  5352. sourceCSV = LoadCSV("gameplay\globals\card_sources.csv");
  5353. }
  5354. else
  5355. {
  5356. sourceCSV = LoadCSV("qa\card_sources.csv");
  5357. }
  5358.  
  5359. sourceCount = sourceCSV.GetNumRows();
  5360. sourceTable.Resize(sourceCount);
  5361.  
  5362. for ( i = 0 ; i < sourceCount ; i+=1 )
  5363. {
  5364. sourceTable[i].cardName = sourceCSV.GetValueAsName("CardName",i);
  5365. sourceTable[i].source = sourceCSV.GetValue("Source",i);
  5366. sourceTable[i].originArea = sourceCSV.GetValue("OriginArea",i);
  5367. sourceTable[i].originQuest = sourceCSV.GetValue("OriginQuest",i);
  5368. sourceTable[i].details = sourceCSV.GetValue("Details",i);
  5369. sourceTable[i].coords = sourceCSV.GetValue("Coords",i);
  5370. }
  5371.  
  5372. for ( i = 0 ; i < missingCards.Size() ; i+=1 )
  5373. {
  5374. for ( j = 0 ; j < sourceCount ; j+=1 )
  5375. {
  5376. if ( sourceTable[j].cardName == missingCards[i] )
  5377. {
  5378. sourceRemaining.PushBack( sourceTable[j] );
  5379. }
  5380. }
  5381. }
  5382.  
  5383. return sourceRemaining;
  5384. }
  5385.  
  5386. public function GetGwentAlmanacContents() : string
  5387. {
  5388. var sourcesRemaining : array< SCardSourceData >;
  5389. var missingCards : array< string >;
  5390. var almanacContents : string;
  5391. var i : int;
  5392. var NML, Novigrad, Skellige, Prologue, Vizima, KaerMorhen, Random : int;
  5393.  
  5394. sourcesRemaining = FindCardSources( GetMissingCards() );
  5395.  
  5396. for ( i = 0 ; i < sourcesRemaining.Size() ; i+=1 )
  5397. {
  5398. switch ( sourcesRemaining[i].originArea )
  5399. {
  5400. case "NML":
  5401. NML += 1;
  5402. break;
  5403. case "Novigrad":
  5404. Novigrad += 1;
  5405. break;
  5406. case "Skellige":
  5407. Skellige += 1;
  5408. break;
  5409. case "Prologue":
  5410. Prologue += 1;
  5411. break;
  5412. case "Vizima":
  5413. Vizima += 1;
  5414. break;
  5415. case "KaerMorhen":
  5416. KaerMorhen += 1;
  5417. break;
  5418. case "Random":
  5419. Random += 1;
  5420. break;
  5421. default:
  5422. break;
  5423. }
  5424. }
  5425.  
  5426. if ( NML + Novigrad + Skellige + Prologue + Vizima + KaerMorhen + Random == 0 )
  5427. {
  5428. almanacContents = GetLocStringByKeyExt( "gwent_almanac_text" ) + "<br>";
  5429. almanacContents += GetLocStringByKeyExt( "gwent_almanac_completed_text" );
  5430. }
  5431. else
  5432. {
  5433. almanacContents = GetLocStringByKeyExt( "gwent_almanac_text" ) + "<br>";
  5434. if ( NML > 0 )
  5435. {
  5436. almanacContents += GetLocStringByKeyExt( "location_name_velen" ) + ": " + NML + "<br>";
  5437. }
  5438. if ( Novigrad > 0 )
  5439. {
  5440. almanacContents += GetLocStringByKeyExt( "map_location_novigrad" ) + ": " + Novigrad + "<br>";
  5441. }
  5442. if ( Skellige > 0 )
  5443. {
  5444. almanacContents += GetLocStringByKeyExt( "map_location_skellige" ) + ": " + Skellige + "<br>";
  5445. }
  5446. if ( Prologue > 0 )
  5447. {
  5448. almanacContents += GetLocStringByKeyExt( "map_location_prolog_village" ) + ": " + Prologue + "<br>";
  5449. }
  5450. if ( Vizima > 0 )
  5451. {
  5452. almanacContents += GetLocStringByKeyExt( "map_location_wyzima_castle" ) + ": " + Vizima + "<br>";
  5453. }
  5454. if ( KaerMorhen > 0 )
  5455. {
  5456. almanacContents += GetLocStringByKeyExt( "map_location_kaer_morhen" ) + ": " + KaerMorhen + "<br>";
  5457. }
  5458. almanacContents += GetLocStringByKeyExt( "gwent_source_random" ) + ": " + Random;
  5459. }
  5460.  
  5461. return almanacContents;
  5462. }
  5463.  
  5464. public function GetUnusedMutagensCount(itemName:name):int
  5465. {
  5466. var items : array<SItemUniqueId>;
  5467. var equippedOnSlot : EEquipmentSlots;
  5468. var availableCount : int;
  5469. var res, i : int = 0;
  5470.  
  5471. items = thePlayer.inv.GetItemsByName(itemName);
  5472.  
  5473. for(i=0; i<items.Size(); i+=1)
  5474. {
  5475. equippedOnSlot = GetWitcherPlayer().GetItemSlot( items[i] );
  5476.  
  5477. if(equippedOnSlot == EES_InvalidSlot)
  5478. {
  5479. availableCount = thePlayer.inv.GetItemQuantity( items[i] );
  5480. res = res + availableCount;
  5481. }
  5482. }
  5483.  
  5484. return res;
  5485. }
  5486.  
  5487. public function GetFirstUnusedMutagenByName( itemName : name ):SItemUniqueId
  5488. {
  5489. var items : array<SItemUniqueId>;
  5490. var equippedOnSlot : EEquipmentSlots;
  5491. var availableCount : int;
  5492. var res, i : int = 0;
  5493.  
  5494. items = thePlayer.inv.GetItemsByName(itemName);
  5495.  
  5496. for(i=0; i<items.Size(); i+=1)
  5497. {
  5498. equippedOnSlot = GetWitcherPlayer().GetItemSlot( items[i] );
  5499.  
  5500. if( equippedOnSlot == EES_InvalidSlot )
  5501. {
  5502. return items[i];
  5503. }
  5504. }
  5505.  
  5506. return GetInvalidUniqueId();
  5507. }
  5508.  
  5509. public function RemoveUnusedMutagensCountById( itemId:SItemUniqueId, count:int ):void
  5510. {
  5511. RemoveUnusedMutagensCount( thePlayer.inv.GetItemName( itemId ), count );
  5512. }
  5513.  
  5514. public function RemoveUnusedMutagensCount( itemName:name, count:int ):void
  5515. {
  5516. var items : array<SItemUniqueId>;
  5517. var curItem : SItemUniqueId;
  5518. var equippedOnSlot : EEquipmentSlots;
  5519.  
  5520. var i : int;
  5521. var itemRemoved : int;
  5522. var availableToRemoved : int;
  5523. var removedRes : bool;
  5524.  
  5525. itemRemoved = 0;
  5526. items = thePlayer.inv.GetItemsByName( itemName );
  5527.  
  5528. for( i=0; i < items.Size(); i+=1 )
  5529. {
  5530. curItem = items[ i ];
  5531. equippedOnSlot = GetWitcherPlayer().GetItemSlot( curItem );
  5532.  
  5533. if( equippedOnSlot == EES_InvalidSlot )
  5534. {
  5535. availableToRemoved = Min( thePlayer.inv.GetItemQuantity( curItem ), ( count - itemRemoved ) );
  5536. removedRes = thePlayer.inv.RemoveItem(items[i], availableToRemoved);
  5537.  
  5538. if (removedRes)
  5539. {
  5540. itemRemoved = itemRemoved + availableToRemoved;
  5541.  
  5542. if (itemRemoved >= count)
  5543. {
  5544. return;
  5545. }
  5546. }
  5547.  
  5548. }
  5549. }
  5550. }
  5551.  
  5552. }
  5553.  
  5554. exec function findMissingCards( optional card : name )
  5555. {
  5556. var inv : CInventoryComponent = thePlayer.GetInventory();
  5557. var sourcesRemaining : array< SCardSourceData >;
  5558. var missingCards : array< name >;
  5559. var i : int;
  5560. var sourceLogString : string;
  5561.  
  5562. if ( card != '' )
  5563. {
  5564. missingCards.PushBack( card );
  5565. }
  5566. else
  5567. {
  5568. missingCards = inv.GetMissingCards();
  5569. }
  5570.  
  5571. sourcesRemaining = inv.FindCardSources( missingCards );
  5572.  
  5573. for ( i = 0 ; i < sourcesRemaining.Size() ; i+=1 )
  5574. {
  5575. sourceLogString = sourcesRemaining[i].cardName + " is a " + sourcesRemaining[i].source ;
  5576. if ( sourcesRemaining[i].originArea == "Random" )
  5577. {
  5578. sourceLogString += " card from a random merchant.";
  5579. }
  5580. else
  5581. {
  5582. sourceLogString += " item in " + sourcesRemaining[i].originArea + " from ";
  5583.  
  5584. if ( sourcesRemaining[i].originQuest != "" )
  5585. {
  5586. sourceLogString += sourcesRemaining[i].originQuest + " , ";
  5587. }
  5588.  
  5589. sourceLogString += sourcesRemaining[i].details;
  5590. }
  5591. Log( sourceLogString );
  5592.  
  5593. if ( sourcesRemaining[i].coords != "" )
  5594. {
  5595. Log( sourcesRemaining[i].coords );
  5596. }
  5597. }
  5598. }
  5599.  
  5600. exec function slotTest()
  5601. {
  5602. var inv : CInventoryComponent = thePlayer.inv;
  5603. var weaponItemId : SItemUniqueId;
  5604. var upgradeItemId : SItemUniqueId;
  5605. var i : int;
  5606.  
  5607. LogChannel('SlotTest', "----------------------------------------------------------------");
  5608.  
  5609.  
  5610. inv.AddAnItem( 'Perun rune', 1);
  5611. inv.AddAnItem( 'Svarog rune', 1);
  5612.  
  5613.  
  5614. for ( i = 0; i < 2; i += 1 )
  5615. {
  5616.  
  5617. if ( !GetItem( inv, 'steelsword', weaponItemId ) ||
  5618. !GetItem( inv, 'upgrade', upgradeItemId ) )
  5619. {
  5620. return;
  5621. }
  5622.  
  5623.  
  5624. PrintItem( inv, weaponItemId );
  5625.  
  5626.  
  5627. if ( inv.EnhanceItemScript( weaponItemId, upgradeItemId ) )
  5628. {
  5629. LogChannel('SlotTest', "Enhanced item");
  5630. }
  5631. else
  5632. {
  5633. LogChannel('SlotTest', "Failed to enhance item!");
  5634. }
  5635. }
  5636.  
  5637.  
  5638. if ( !GetItem( inv, 'steelsword', weaponItemId ) )
  5639. {
  5640. return;
  5641. }
  5642.  
  5643.  
  5644. PrintItem( inv, weaponItemId );
  5645.  
  5646.  
  5647. if ( inv.RemoveItemEnhancementByNameScript( weaponItemId, 'Svarog rune' ) )
  5648. {
  5649. LogChannel('SlotTest', "Removed enhancement");
  5650. }
  5651. else
  5652. {
  5653. LogChannel('SlotTest', "Failed to remove enhancement!");
  5654. }
  5655.  
  5656.  
  5657. if ( !GetItem( inv, 'steelsword', weaponItemId ) )
  5658. {
  5659. return;
  5660. }
  5661.  
  5662.  
  5663. PrintItem( inv, weaponItemId );
  5664.  
  5665.  
  5666. if ( inv.RemoveItemEnhancementByIndexScript( weaponItemId, 0 ) )
  5667. {
  5668. LogChannel('SlotTest', "Removed enhancement");
  5669. }
  5670. else
  5671. {
  5672. LogChannel('SlotTest', "Failed to remove enhancement!");
  5673. }
  5674.  
  5675.  
  5676. if ( !GetItem( inv, 'steelsword', weaponItemId ) )
  5677. {
  5678. return;
  5679. }
  5680.  
  5681.  
  5682. PrintItem( inv, weaponItemId );
  5683. }
  5684.  
  5685. function GetItem( inv : CInventoryComponent, category : name, out itemId : SItemUniqueId ) : bool
  5686. {
  5687. var itemIds : array< SItemUniqueId >;
  5688.  
  5689. itemIds = inv.GetItemsByCategory( category );
  5690. if ( itemIds.Size() > 0 )
  5691. {
  5692. itemId = itemIds[ 0 ];
  5693. return true;
  5694. }
  5695. LogChannel( 'SlotTest', "Failed to get item with GetItemsByCategory( '" + category + "' )" );
  5696. return false;
  5697. }
  5698.  
  5699. function PrintItem( inv : CInventoryComponent, weaponItemId : SItemUniqueId )
  5700. {
  5701. var names : array< name >;
  5702. var tags : array< name >;
  5703. var i : int;
  5704. var line : string;
  5705. var attribute : SAbilityAttributeValue;
  5706.  
  5707. LogChannel('SlotTest', "Slots: " + inv.GetItemEnhancementCount( weaponItemId ) + "/" + inv.GetItemEnhancementSlotsCount( weaponItemId ) );
  5708. inv.GetItemEnhancementItems( weaponItemId, names );
  5709. if ( names.Size() > 0 )
  5710. {
  5711. for ( i = 0; i < names.Size(); i += 1 )
  5712. {
  5713. if ( i == 0 )
  5714. {
  5715. line += "[";
  5716. }
  5717. line += names[ i ];
  5718. if ( i < names.Size() - 1 )
  5719. {
  5720. line += ", ";
  5721. }
  5722. if ( i == names.Size() - 1 )
  5723. {
  5724. line += "]";
  5725. }
  5726. }
  5727. }
  5728. else
  5729. {
  5730. line += "[]";
  5731. }
  5732. LogChannel('SlotTest', "Upgrade item names " + line );
  5733.  
  5734. tags.PushBack('Upgrade');
  5735.  
  5736. attribute = inv.GetItemAttributeValue( weaponItemId, 'PhysicalDamage' );
  5737. LogChannel('SlotTest', "Attribute '" + 'PhysicalDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5738. attribute = inv.GetItemAttributeValue( weaponItemId, 'SilverDamage' );
  5739. LogChannel('SlotTest', "Attribute '" + 'SilverDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5740.  
  5741. attribute = inv.GetItemAttributeValue( weaponItemId, 'PhysicalDamage', tags, true );
  5742. LogChannel('SlotTest', "Attribute '" + 'PhysicalDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5743. attribute = inv.GetItemAttributeValue( weaponItemId, 'SilverDamage', tags, true );
  5744. LogChannel('SlotTest', "Attribute '" + 'SilverDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5745.  
  5746. attribute = inv.GetItemAttributeValue( weaponItemId, 'PhysicalDamage', tags );
  5747. LogChannel('SlotTest', "Attribute '" + 'PhysicalDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5748. attribute = inv.GetItemAttributeValue( weaponItemId, 'SilverDamage', tags );
  5749. LogChannel('SlotTest', "Attribute '" + 'SilverDamage' + "' " + attribute.valueBase + " " + attribute.valueMultiplicative + " " + attribute.valueAdditive );
  5750.  
  5751. }
  5752.  
  5753. function PlayItemEquipSound( itemCategory : name ) : void
  5754. {
  5755. switch( itemCategory )
  5756. {
  5757. case 'steelsword' :
  5758. theSound.SoundEvent("gui_inventory_steelsword_attach");
  5759. return;
  5760. case 'silversword' :
  5761. theSound.SoundEvent("gui_inventory_silversword_attach");
  5762. return;
  5763. case 'secondary' :
  5764. theSound.SoundEvent("gui_inventory_weapon_attach");
  5765. return;
  5766. case 'armor' :
  5767. theSound.SoundEvent("gui_inventory_armor_attach");
  5768. return;
  5769. case 'pants' :
  5770. theSound.SoundEvent("gui_inventory_pants_attach");
  5771. return;
  5772. case 'boots' :
  5773. theSound.SoundEvent("gui_inventory_boots_attach");
  5774. return;
  5775. case 'gloves' :
  5776. theSound.SoundEvent("gui_inventory_gauntlet_attach");
  5777. return;
  5778. case 'potion' :
  5779. theSound.SoundEvent("gui_inventory_potion_attach");
  5780. return;
  5781. case 'petard' :
  5782. theSound.SoundEvent("gui_inventory_bombs_attach");
  5783. return;
  5784. case 'ranged' :
  5785. theSound.SoundEvent("gui_inventory_ranged_attach");
  5786. return;
  5787. case 'herb' :
  5788. theSound.SoundEvent("gui_pick_up_herbs");
  5789. return;
  5790. case 'trophy' :
  5791. case 'horse_bag' :
  5792. theSound.SoundEvent("gui_inventory_horse_bage_attach");
  5793. return;
  5794. case 'horse_blinder' :
  5795. theSound.SoundEvent("gui_inventory_horse_blinder_attach");
  5796. return;
  5797. case 'horse_saddle' :
  5798. theSound.SoundEvent("gui_inventory_horse_saddle_attach");
  5799. return;
  5800. default :
  5801. theSound.SoundEvent("gui_inventory_other_attach");
  5802. return;
  5803. }
  5804. }
  5805.  
  5806. function PlayItemUnequipSound( itemCategory : name ) : void
  5807. {
  5808. switch( itemCategory )
  5809. {
  5810. case 'steelsword' :
  5811. theSound.SoundEvent("gui_inventory_steelsword_back");
  5812. return;
  5813. case 'silversword' :
  5814. theSound.SoundEvent("gui_inventory_silversword_back");
  5815. return;
  5816. case 'secondary' :
  5817. theSound.SoundEvent("gui_inventory_weapon_back");
  5818. return;
  5819. case 'armor' :
  5820. theSound.SoundEvent("gui_inventory_armor_back");
  5821. return;
  5822. case 'pants' :
  5823. theSound.SoundEvent("gui_inventory_pants_back");
  5824. return;
  5825. case 'boots' :
  5826. theSound.SoundEvent("gui_inventory_boots_back");
  5827. return;
  5828. case 'gloves' :
  5829. theSound.SoundEvent("gui_inventory_gauntlet_back");
  5830. return;
  5831. case 'petard' :
  5832. theSound.SoundEvent("gui_inventory_bombs_back");
  5833. return;
  5834. case 'potion' :
  5835. theSound.SoundEvent("gui_inventory_potion_back");
  5836. return;
  5837. case 'ranged' :
  5838. theSound.SoundEvent("gui_inventory_ranged_back");
  5839. return;
  5840. case 'trophy' :
  5841. case 'horse_bag' :
  5842. theSound.SoundEvent("gui_inventory_horse_bage_back");
  5843. return;
  5844. case 'horse_blinder' :
  5845. theSound.SoundEvent("gui_inventory_horse_blinder_back");
  5846. return;
  5847. case 'horse_saddle' :
  5848. theSound.SoundEvent("gui_inventory_horse_saddle_back");
  5849. return;
  5850. default :
  5851. theSound.SoundEvent("gui_inventory_other_back");
  5852. return;
  5853. }
  5854. }
  5855.  
  5856. function PlayItemConsumeSound( item : SItemUniqueId ) : void
  5857. {
  5858. if( thePlayer.GetInventory().ItemHasTag( item, 'Drinks' ) || thePlayer.GetInventory().ItemHasTag( item, 'Alcohol' ) )
  5859. {
  5860. theSound.SoundEvent('gui_inventory_drink');
  5861. }
  5862. else
  5863. {
  5864. theSound.SoundEvent('gui_inventory_eat');
  5865. }
  5866. }
  5867.  
  5868.  
  5869.  
  5870.  
  5871.  
Add Comment
Please, Sign In to add comment