Advertisement
Guest User

container_class.ws

a guest
Jul 19th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.88 KB | None | 0 0
  1. ///////////////////////////////////
  2. // CONTAINER CLASS //
  3. ///////////////////////////////////
  4. //Enhancement Pack by Demoniko v1.3
  5. // returns the maximum load (max weight that player can carry)
  6. import function GetMaxWeight() : float;
  7. // returns the current player load (the sum of all carried items weights)
  8. import function GetCurrentWeight() : float;
  9. //Enhancement Pack by Demoniko v1.3
  10. class CContainer extends CGameplayEntity
  11. {
  12. //editable var loot_table : string; // not used
  13. editable var isDynamic : bool;
  14.  
  15. editable var onlyOneTheSameType : bool;
  16.  
  17. editable var lockedByKey : bool;
  18. editable var keyItemName : name;
  19.  
  20. editable var showInventoryAfterUse : bool;
  21. editable var hideInteractionIfEmpty : bool;
  22.  
  23. editable var isNotEnabledOnSpawn : bool;
  24.  
  25. var m_isBlocked : bool;
  26. var m_saveLock : int;
  27.  
  28. default isDynamic = false;
  29. default isNotEnabledOnSpawn = false;
  30. default m_isBlocked = false;
  31.  
  32. var m_isHighlighted : bool;//Enhancement Pack by Demoniko v1.3
  33. default m_isHighlighted = false;//Enhancement Pack by Demoniko v1.3
  34.  
  35. //saved var wasUsed : bool;
  36.  
  37. //default wasUsed = false;
  38. //Enhancement Pack by Demoniko v1.3 - start
  39. var sourceInv : CInventoryComponent;
  40. var targetInv : CInventoryComponent;
  41.  
  42. var arrayData : array < CFlashValueScript >;
  43.  
  44. var itemId : SItemUniqueId;
  45. var allItems : array< SItemUniqueId >;
  46.  
  47. var i : int;
  48. //Enhancement Pack by Demoniko v1.3 - end
  49. // Entity was dynamically spawned
  50. event OnSpawned( spawnData : SEntitySpawnData )
  51. {
  52. this.GetInventory().UpdateLoot();
  53. if ( IsLootable() )
  54. {
  55. if ( isDynamic )//Enhancement Pack by Demoniko v1.3 - start
  56. {
  57. if (VecDistanceSquared(this.GetWorldPosition(), thePlayer.GetWorldPosition()) < 30.f)
  58. {
  59. sourceInv = this.GetInventory();
  60. targetInv = thePlayer.GetInventory();
  61.  
  62. sourceInv.GetAllItems( allItems );
  63.  
  64. for ( i = allItems.Size()-1; i >= 0; i-=1 )
  65. {
  66. itemId = allItems[i];
  67. if ( sourceInv.GetItemAttributeAdditive( itemId, 'item_weight' ) == 0 && !sourceInv.ItemHasTag( itemId, 'Quest' ) && !sourceInv.ItemHasTag( itemId, 'NoDrop' ) ) {
  68. if ( AllowItemDarkDiff( sourceInv, itemId ) ) Helper_TransferItemFromContainerToPlayer( itemId, targetInv, sourceInv, isDynamic );
  69. theSound.PlaySound( "gui/hud/itemlooted" );
  70. }
  71. }
  72. }//Enhancement Pack by Demoniko v1.3 - end
  73. }//Enhancement Pack by Demoniko v1.3
  74. }//Enhancement Pack by Demoniko v1.3
  75.  
  76. if ( ! IsLootable() ) {//Enhancement Pack by Demoniko v1.3
  77. SetVisualsEmpty();
  78. DestroyIt();//Enhancement Pack by Demoniko v1.3
  79. GetComponent("Loot").SetEnabled( false );
  80. HideLootWindow();//Enhancement Pack by Demoniko v1.3 - start
  81. } else {
  82. SetVisualsFull();
  83.  
  84. if (!isNotEnabledOnSpawn) {
  85. GetComponent("Loot").SetEnabled( true );//Enhancement Pack by Demoniko v1.3 - end
  86. }//Enhancement Pack by Demoniko v1.3
  87. }
  88. }
  89.  
  90. event OnInteractionActivated( interactionName : name, activator : CEntity )
  91. {
  92. var allItems : array< SItemUniqueId >;
  93. var i : int;
  94. var isAnything : bool;
  95.  
  96. if ( activator == thePlayer )
  97. {
  98. //SetGameplayParameter( 0, true, 1.f );
  99. theHud.HudTargetEntityEx( this, NAPK_Container );
  100.  
  101. if ( ! lockedByKey || thePlayer.GetInventory().HasItem( keyItemName ) )//Enhancement Pack by Demoniko v1.3
  102. {
  103. if ( !m_isHighlighted )//Enhancement Pack by Demoniko v1.3
  104. {
  105. m_isHighlighted = true;//Enhancement Pack by Demoniko v1.3
  106. // PlayEffect( 'target_glow_fx' );//Enhancement Pack by Demoniko v1.3
  107. }//Enhancement Pack by Demoniko v1.3
  108.  
  109. ShowLootPreview();
  110. }
  111. }
  112. }
  113.  
  114. public function Closed()
  115. {
  116. if ( m_isBlocked )
  117. {
  118. theGame.EnableButtonInteractions( true );
  119. if(!theHud.CanShowMainMenu())
  120. {
  121. theHud.AllowOpeningMainMenu();
  122. }
  123. theGame.ReleaseNoSaveLock( m_saveLock );
  124. m_saveLock = -1;
  125. m_isBlocked = false;
  126. }
  127. }
  128.  
  129. function IsLootable() : bool
  130. {
  131. var allItems : array< SItemUniqueId >;
  132. var i : int;
  133. var isAnything : bool;
  134.  
  135. GetInventory().GetAllItems( allItems );
  136. isAnything = false;
  137.  
  138. for ( i=0; i<allItems.Size(); i+=1 )
  139. {
  140. if ( !GetInventory().ItemHasTag( allItems[i], 'NoDrop' ) && GetInventory().GetItemQuantity( allItems[i] ) > 0 )
  141. {
  142. isAnything = true;
  143. break;//Enhancement Pack by Demoniko v1.3
  144. }
  145. }
  146.  
  147. return isAnything;
  148. }
  149.  
  150. event OnInteractionDeactivated( interactionName : name, activator : CEntity )
  151. {
  152. if ( activator == thePlayer || thePlayer.IsNotGeralt() )
  153. {
  154. if ( m_isHighlighted )//Enhancement Pack by Demoniko v1.3 - start
  155. {
  156. // StopEffect( 'target_glow_fx' );
  157. m_isHighlighted = false;
  158. }//Enhancement Pack by Demoniko v1.3 - end
  159. HideLootPreview();
  160. //SetGameplayParameter( 0, false, 1.f );
  161. theHud.HudTargetEntityEx( NULL );
  162. }
  163. }
  164.  
  165. function ShowLootWindow() : bool
  166. {
  167. if ( thePlayer.GetLastContainer() ) return false;
  168.  
  169. if(thePlayer.GetCurrentPlayerState() == PS_Exploration)
  170. {
  171. thePlayer.RaiseForceEvent('Idle');
  172. }
  173. else
  174. {
  175. thePlayer.RaiseForceEvent('GlobalEnd');
  176. }
  177.  
  178. thePlayer.SetCanUseHud( false );
  179. thePlayer.SetHotKeysBlocked( true );
  180. thePlayer.SetCombatHotKeysBlocked( true );
  181. thePlayer.SetLastContainer( this );
  182. thePlayer.SetManualControl(false, false);
  183. theHud.Invoke("LoadLootWindow");
  184. theHud.EnableInput( true, true, true, false );
  185. HideLootPreview();
  186. theGame.SetTimeScale(0.05);
  187.  
  188. }
  189.  
  190. event OnInteraction( actionName : name, activator : CEntity )
  191. {
  192. var sourceInv : CInventoryComponent;
  193. var targetInv : CInventoryComponent;
  194.  
  195. var arrayData : array < CFlashValueScript >;
  196.  
  197. var itemId : SItemUniqueId;
  198. var allItems : array< SItemUniqueId >;
  199. var lootedItems : array< SItemUniqueId >;
  200.  
  201. var i : int;
  202. var quantity : int;
  203. var itemName : name;
  204.  
  205. if ( m_isBlocked ) return false;
  206.  
  207. if ( activator != thePlayer || thePlayer.IsNotGeralt() )
  208. return false;
  209.  
  210. //if( !theGame.tutorialenabled )
  211. //{
  212. //theHud.m_hud.ShowTutorial("tut29", "tut29_333x166", false); // <-- tutorial content is present in external tutorial - disabled
  213. //theHud.ShowTutorialPanelOld( "tut29", "tut29_333x166" );
  214. //}
  215.  
  216. // Check for key
  217. if ( lockedByKey && ! thePlayer.GetInventory().HasItem( keyItemName ) )
  218. {
  219. if( !theGame.tutorialenabled )
  220. {
  221. theHud.m_hud.ShowTutorial("tut52", "", false);
  222. //theHud.ShowTutorialPanelOld( "tut52", "" );
  223. }
  224. theHud.m_messages.ShowInformationText( GetLocStringByKeyExt( "You need a key" ));
  225. return false;
  226. }
  227. if ( lockedByKey && thePlayer.GetInventory().HasItem( keyItemName ) )
  228. {
  229. theHud.m_messages.ShowInformationText( GetLocStringByKeyExt( "Opened by key" ));
  230. }
  231.  
  232. if ( actionName != 'Container' )
  233. return false;
  234.  
  235. if ( !IsLootable() )
  236. {
  237. MakeContainerEmpty();
  238. GetComponent("Loot").SetEnabled( false );
  239. return false;
  240. }
  241.  
  242. if ( thePlayer.IsDead() ) return false;
  243.  
  244. if ( theGame.IsUsingPad() || showInventoryAfterUse )
  245. {
  246. TakeAllItems();
  247. QuestItemGlow();
  248. if ( !IsLootable() ) GetComponent("Loot").SetEnabled( false );
  249. SetVisualsEmpty();
  250. DestroyIt();
  251. HideLootPreview();
  252. } else
  253. {
  254. if(theHud.CanShowMainMenu())
  255. {
  256. theHud.ForbidOpeningMainMenu();
  257. }
  258. theGame.EnableButtonInteractions( false );
  259. m_saveLock = -1;
  260. theGame.CreateNoSaveLock( "container_loot_opened", m_saveLock );
  261. m_isBlocked = true;
  262.  
  263. FillLootWindow();
  264. ShowLootWindow();
  265. }
  266. }
  267.  
  268. function TakeAllItems()
  269. {
  270. var sourceInv : CInventoryComponent;
  271. var targetInv : CInventoryComponent;
  272.  
  273. var arrayData : array < CFlashValueScript >;
  274.  
  275. var itemId : SItemUniqueId;
  276. var allItems : array< SItemUniqueId >;
  277.  
  278. var i : int;
  279.  
  280. // Transfer items
  281. sourceInv = this.GetInventory();
  282. targetInv = thePlayer.GetInventory();
  283.  
  284. sourceInv.GetAllItems( allItems );
  285.  
  286. for ( i = allItems.Size()-1; i >= 0; i-=1 )
  287. {
  288. itemId = allItems[i];
  289. if ( !isDynamic || !sourceInv.ItemHasTag( itemId, 'NoDrop' ) )
  290. {
  291. if( !theGame.tutorialenabled )
  292. {
  293. CheckForTutorial(itemId, sourceInv);
  294. }
  295.  
  296. if ( AllowItemDarkDiff( sourceInv, itemId ) ) Helper_TransferItemFromContainerToPlayer( itemId, targetInv, sourceInv, isDynamic );
  297. }
  298. }
  299.  
  300. theSound.PlaySound( "gui/hud/manyitemslooted" );
  301.  
  302. MakeContainerEmpty();
  303.  
  304. if (showInventoryAfterUse) theHud.ShowInventory();
  305. }
  306.  
  307. function FillLootWindow( optional closeAfter : bool )
  308. {
  309. var i : int;
  310. var itemId : SItemUniqueId;
  311. var itemName : string;
  312. var allItems : array< SItemUniqueId >;
  313. var itemTags : array< name >;
  314. var args : array <CFlashValueScript>;
  315. var numShownItems : int = 0;
  316. var inventory : CInventoryComponent = GetInventory();
  317. var isAnything : bool;
  318. var add_quantity : int;
  319.  
  320. inventory.GetAllItems( allItems );
  321. numShownItems = 1;
  322. args.PushBack( FlashValueFromInt( RoundF( thePlayer.GetCurrentWeight() ) ) );
  323. args.PushBack( FlashValueFromInt( RoundF( thePlayer.GetMaxWeight() ) ) );
  324. args.PushBack( FlashValueFromString( GetLocStringByKeyExt("ContTakeAll") ) );
  325.  
  326. if ( numShownItems< 8 ) // panel loot - quest items
  327. for ( i = allItems.Size()-1; i >= 0; i -= 1 )
  328. {
  329. add_quantity = 0;
  330. itemId = allItems[i];
  331. inventory.GetItemTags( itemId, itemTags );
  332.  
  333. Log( inventory.GetItemName( itemId ) + " x" + inventory.GetItemQuantity( itemId ) );
  334.  
  335. if ( itemTags.Contains( 'Quest' ) && !itemTags.Contains( 'NoDrop' ) )
  336. {
  337. itemName = inventory.GetItemName( itemId );
  338.  
  339. add_quantity = 0;
  340.  
  341. if ( inventory.ItemHasTag( itemId, 'AlchemyIngridient' ) && !isDynamic )
  342. {
  343. add_quantity = RoundF( thePlayer.GetCharacterStats().GetAttribute( 'loot_alchemy_bonus' ) );
  344. }
  345.  
  346. args.PushBack( FlashValueFromString( itemName ) );
  347. args.PushBack( FlashValueFromString( GetLocStringByKeyExt( itemName ) ) );
  348. args.PushBack( FlashValueFromInt( add_quantity + inventory.GetItemQuantity( itemId ) ) );
  349. args.PushBack( FlashValueFromString( UniqueIdToString( itemId ) ) );
  350. args.PushBack( FlashValueFromString( "<img src='img://globals/gui/icons/items/" + StrReplaceAll( StrReplaceAll( itemName , " ", ""), "'", "" ) + "_64x64.dds' width='30' height='30'>" ) ) ;
  351. args.PushBack( FlashValueFromFloat( inventory.GetItemAttributeAdditive( itemId, 'item_weight' ) ) );
  352. args.PushBack( FlashValueFromInt( 1 ) );
  353.  
  354. isAnything = true;
  355.  
  356. // Send only first 8 items
  357. numShownItems += 1;
  358. if ( numShownItems == 8 )
  359. break;
  360. }
  361. }
  362.  
  363. if ( numShownItems< 8 ) // panel loot - not quest items
  364. for ( i = allItems.Size()-1; i >= 0; i -= 1 )
  365. {
  366. add_quantity = 0;
  367. itemId = allItems[i];
  368. inventory.GetItemTags( itemId, itemTags );
  369.  
  370. Log( inventory.GetItemName( itemId ) + " x" + inventory.GetItemQuantity( itemId ) );
  371.  
  372. if ( !itemTags.Contains( 'NoDrop' ) && !itemTags.Contains( 'Quest' ))
  373. {
  374. itemName = inventory.GetItemName( itemId );
  375.  
  376. add_quantity = 0;
  377.  
  378. if ( inventory.ItemHasTag( itemId, 'AlchemyIngridient' ) && !isDynamic )
  379. {
  380. add_quantity = RoundF( thePlayer.GetCharacterStats().GetAttribute( 'loot_alchemy_bonus' ) );
  381. }
  382.  
  383. args.PushBack( FlashValueFromString( itemName ) );
  384. args.PushBack( FlashValueFromString( GetLocStringByKeyExt( itemName ) ) );
  385. args.PushBack( FlashValueFromInt( add_quantity + inventory.GetItemQuantity( itemId ) ) );
  386. args.PushBack( FlashValueFromString( UniqueIdToString( itemId ) ) );
  387. args.PushBack( FlashValueFromString( "<img src='img://globals/gui/icons/items/" + StrReplaceAll( StrReplaceAll( itemName , " ", ""), "'", "" ) + "_64x64.dds' width='30' height='30'>" ) ) ;
  388. args.PushBack( FlashValueFromFloat( inventory.GetItemAttributeAdditive( itemId, 'item_weight' ) ) );
  389. args.PushBack( FlashValueFromInt( 0 ) );
  390.  
  391. isAnything = true;
  392.  
  393. // Send only first 8 items
  394. numShownItems += 1;
  395. if ( numShownItems == 8 )
  396. break;
  397. }
  398. }
  399.  
  400.  
  401. if ( !isAnything )
  402. {
  403. args.Clear();
  404. args.PushBack( FlashValueFromInt( RoundF( thePlayer.GetCurrentWeight() ) ) );
  405. args.PushBack( FlashValueFromInt( RoundF( thePlayer.GetMaxWeight() ) ) );
  406. args.PushBack( FlashValueFromString( GetLocStringByKeyExt("ContEmpty") ) );
  407. }
  408.  
  409. theHud.InvokeManyArgs("uiLootTable.setItems", args);
  410.  
  411. if ( closeAfter && !isAnything ) HideLootWindow();
  412. }
  413.  
  414. function ShowLootPreview()
  415. {
  416. var AS_lootTable : int = theHud.CreateAnonymousArray();
  417. var AS_item : int;
  418.  
  419. var inventory : CInventoryComponent = GetInventory();
  420. var allItems : array< SItemUniqueId >;
  421.  
  422. var i : int;
  423. var itemId : SItemUniqueId;
  424. var itemName : string;
  425. var itemTags : array< name >;
  426. var numShownItems : int = 0;
  427.  
  428. var args : array <CFlashValueScript>;
  429.  
  430. var isAnything : bool;
  431.  
  432. Log( "-------------------------------------- ");
  433. Log( "CONTAINER ITEM LIST : ");
  434. Log( "-------------------------------------- ");
  435.  
  436. if( !theGame.tutorialenabled )
  437. {
  438. //if (!theHud.m_hud.ShowTutorial("tut17", "", false)) // <-- tutorial content is present in external tutorial - disabled
  439. //{
  440. if (IsQuestItem()) theHud.m_hud.ShowTutorial("tut51", "tut51_333x166", false);
  441. //}
  442. //if (!theHud.ShowTutorialPanelOld( "tut17", "" )) { if (IsQuestItem()) theHud.ShowTutorialPanelOld( "tut51", "tut51_333x166" ); }
  443. /*
  444. if ( theGame.IsUsingPad() ) // <-- tutorial content is present in external tutorial - disabled
  445. {
  446. theHud.m_hud.ShowTutorial("tut172", "tut72_333x166", false);
  447. //theHud.ShowTutorialPanelOld( "tut172", "tut72_333x166" );
  448. }
  449. else
  450. {
  451. theHud.m_hud.ShowTutorial("tut72", "tut72_333x166", false);
  452. //theHud.ShowTutorialPanelOld( "tut72", "tut72_333x166" );
  453. }
  454. */
  455. }
  456.  
  457. inventory.GetAllItems( allItems );
  458.  
  459. for ( i = allItems.Size()-1; i >= 0; i -= 1 ) // questowe
  460. {
  461. itemId = allItems[i];
  462. inventory.GetItemTags( itemId, itemTags );
  463.  
  464. Log( inventory.GetItemName( itemId ) + " x" + inventory.GetItemQuantity( itemId ) );
  465.  
  466. if ( ! itemTags.Contains( 'NoDrop' ) && itemTags.Contains( 'Quest' ) )
  467. {
  468. AS_item = theHud.CreateAnonymousObject();
  469.  
  470. itemName = inventory.GetItemName( itemId );
  471. theHud.SetString( "Name", GetLocStringByKeyExt( itemName ), AS_item );
  472. theHud.SetString( "Icon", "img://globals/gui/icons/items/" + StrReplaceAll(itemName, " ", "") + "_64x64.dds", AS_item );
  473. theHud.SetFloat ( "Class", (int)inventory.GetItemClass( itemId ), AS_item );
  474.  
  475. theHud.PushObject( AS_lootTable, AS_item );
  476. theHud.ForgetObject( AS_item );
  477. isAnything = true;
  478.  
  479. // Send only first 5 items
  480. numShownItems += 1;
  481. if ( numShownItems == 4 )
  482. break;
  483. }
  484. }
  485.  
  486. if ( numShownItems< 4 ) // nie questowe
  487. for ( i = allItems.Size()-1; i >= 0; i -= 1 )
  488. {
  489. itemId = allItems[i];
  490. inventory.GetItemTags( itemId, itemTags );
  491.  
  492. Log( inventory.GetItemName( itemId ) + " x" + inventory.GetItemQuantity( itemId ) );
  493.  
  494. if ( ! itemTags.Contains( 'NoDrop' ) && !itemTags.Contains( 'Quest' ))
  495. {
  496. AS_item = theHud.CreateAnonymousObject();
  497.  
  498. itemName = inventory.GetItemName( itemId );
  499. theHud.SetString( "Name", GetLocStringByKeyExt( itemName ), AS_item );
  500. theHud.SetString( "Icon", "img://globals/gui/icons/items/" + StrReplaceAll(itemName, " ", "") + "_64x64.dds", AS_item );
  501. theHud.SetFloat ( "Class", (int)inventory.GetItemClass( itemId ), AS_item );
  502.  
  503. theHud.PushObject( AS_lootTable, AS_item );
  504. theHud.ForgetObject( AS_item );
  505. isAnything = true;
  506.  
  507. // Send only first 5 items
  508. numShownItems += 1;
  509. if ( numShownItems == 4 )
  510. break;
  511. }
  512. }
  513.  
  514. //if ( isAnything )
  515. theHud.m_hud.SetLootTable( AS_lootTable );
  516. theHud.ForgetObject( AS_lootTable );
  517. }
  518.  
  519. function HideLootPreview()
  520. {
  521. theHud.m_hud.SetLootTable( -1 );
  522. }
  523.  
  524. function MakeContainerEmpty() : bool
  525. {
  526. var loottable : C2dArray;
  527. var respawn_time : int;
  528. var i : int;
  529.  
  530. //ShowLootPreview();
  531.  
  532. if ( !IsLootable() )//Enhancement Pack by Demoniko v1.3
  533. {
  534. SetVisualsEmpty();
  535. //if ( hideInteractionIfEmpty )
  536. GetComponent("Loot").SetEnabled( false );
  537.  
  538. // Destroy empty dynamic container (loot dropped by npc)
  539. if ( isDynamic)
  540. {
  541. HideLootPreview();
  542. Destroy();
  543. }
  544. }
  545.  
  546.  
  547. return true;
  548. }
  549.  
  550. function DestroyIt( ) : bool
  551. {
  552. var inv : CInventoryComponent;
  553.  
  554. inv = GetInventory();
  555.  
  556. if ( !IsLootable() )
  557. {
  558. if ( isDynamic) Destroy();
  559. }
  560.  
  561. return true;
  562. }
  563.  
  564.  
  565. function IsQuestItem() : bool
  566. {
  567. var allItems : array< SItemUniqueId >;
  568. var isQuest : bool;
  569. var i : int;
  570.  
  571. GetInventory().GetAllItems( allItems );
  572.  
  573. for ( i=0; i<allItems.Size(); i+=1 )
  574. {
  575. if ( GetInventory().ItemHasTag(allItems[i], 'Quest') )
  576. {
  577. isQuest = true;
  578. break;//Enhancement Pack by Demoniko v1.3
  579. }
  580. }
  581.  
  582. return isQuest;
  583. }
  584.  
  585. // Podswietlenie kontenera, gdy jest w nim quest item
  586. function QuestItemGlow()
  587. {
  588. StopEffect( 'quest_glow' );
  589.  
  590. if ( IsQuestItem() )
  591. {
  592. PlayEffect( 'quest_glow' );
  593. }
  594. }
  595.  
  596. function SetVisualsFull()
  597. {
  598. ApplyAppearance( "1_full" );
  599. // PlayEffect( 'container_border_fx' );//Enhancement Pack by Demoniko v1.3
  600. PlayEffect( 'medalion_detection_fx' );//Enhancement Pack by Demoniko v1.3
  601. PlayEffect( 'glow' );
  602. QuestItemGlow();
  603. isHighlightedByMedallion = false;//Enhancement Pack by Demoniko v1.3
  604. }
  605.  
  606. function SetVisualsEmpty()
  607. {
  608. ApplyAppearance( "2_empty" );
  609. StopEffect( 'glow' );
  610. StopEffect( 'quest_glow' );
  611. StopEffect( 'medalion_detection_fx' );
  612. // StopEffect( 'container_border_fx' );//Enhancement Pack by Demoniko v1.3
  613. isHighlightedByMedallion = false;
  614. QuestItemGlow();
  615. if ( hideInteractionIfEmpty ) GetComponent("Loot").SetEnabled( false );
  616. }
  617. }
  618.  
  619. // BE CAREFUL WITH INVENTORY COMPONENTS ORDER
  620. function Helper_TransferItemFromContainerToPlayer( itemId : SItemUniqueId, targetInv, sourceInv : CInventoryComponent, isDynamic : bool )
  621. {
  622. var quantity : int;
  623. var itemName : name;
  624.  
  625. itemName = sourceInv.GetItemName( itemId );
  626. quantity = sourceInv.GetItemQuantity( itemId );
  627.  
  628. if ( sourceInv.ItemHasTag( itemId, 'AlchemyIngridient' ) && !isDynamic )
  629. {
  630. // Quantity alteration possible, use modified routine. For ingredients it is safe, but not for upgradeable items.
  631. quantity = quantity + RoundF( thePlayer.GetCharacterStats().GetAttribute( 'loot_alchemy_bonus' ) );
  632. targetInv.AddItem( StringToName( itemName ), quantity, true );
  633. sourceInv.RemoveItem( itemId, quantity );
  634. }
  635. else
  636. {
  637. // Transfer item normally. For many items this is the only proper way, as it won't drop any specific item info like runes imprinted.
  638. sourceInv.GiveItem( targetInv, itemId, quantity );
  639. }
  640.  
  641. Log( "Transfering item " + itemName + " to player's inventory in quantity " + quantity );
  642. }
  643.  
  644. exec function HideLootWindow( optional noinput : bool )
  645. {
  646. if ( thePlayer.GetLastContainer() )
  647. {
  648. thePlayer.SetManualControl(true, true);
  649. theHud.Invoke("uiLootTable.Close");
  650. theHud.Invoke("UnLoadLootWindow");
  651. theHud.EnableInput( false, false, false, false );
  652. thePlayer.SetCanUseHud( true );
  653. thePlayer.SetHotKeysBlocked( false );
  654. thePlayer.SetCombatHotKeysBlocked( false );
  655. if ( thePlayer.GetCombatBlockTriggerActive() )
  656. {
  657. thePlayer.SetCombatHotKeysBlocked( true );
  658. }
  659. theGame.SetTimeScale(1.0);
  660. if ( !thePlayer.GetLastContainer().IsLootable() ) thePlayer.GetLastContainer().GetComponent("Loot").SetEnabled( false );
  661. thePlayer.GetLastContainer().Closed();
  662. thePlayer.SetLastContainer( NULL );
  663. }
  664. }
  665.  
  666. exec function LootItem( itemName : string, quantity : int )
  667. {
  668. var itemId : SItemUniqueId;
  669. if ( thePlayer.GetLastContainer() )
  670. {
  671. itemId = thePlayer.GetLastContainer().GetInventory().GetItemId( StringToName( itemName ) );
  672.  
  673. CheckForTutorial(itemId, thePlayer.GetLastContainer().GetInventory() );
  674.  
  675. if ( AllowItemDarkDiff( thePlayer.GetLastContainer().GetInventory(), itemId ) )
  676. {
  677. Helper_TransferItemFromContainerToPlayer( itemId, thePlayer.GetInventory(), thePlayer.GetLastContainer().GetInventory(), thePlayer.GetLastContainer().isDynamic );
  678. }
  679.  
  680. theSound.PlaySound( "gui/hud/itemlooted" );
  681. thePlayer.GetLastContainer().QuestItemGlow();
  682. if ( thePlayer.GetLastContainer().IsLootable() )
  683. {
  684. thePlayer.GetLastContainer().SetVisualsFull();
  685. thePlayer.GetLastContainer().FillLootWindow( true );
  686. }
  687. else
  688. {
  689. thePlayer.GetLastContainer().SetVisualsEmpty();
  690. thePlayer.GetLastContainer().DestroyIt();
  691. thePlayer.GetLastContainer().GetComponent("Loot").SetEnabled( false );
  692. HideLootWindow();
  693. }
  694. }
  695. }
  696.  
  697. exec function LootAll( )
  698. {
  699. if ( thePlayer.GetLastContainer() )
  700. {
  701. thePlayer.GetLastContainer().QuestItemGlow();
  702. thePlayer.GetLastContainer().TakeAllItems();
  703. thePlayer.GetLastContainer().QuestItemGlow();
  704. if ( !thePlayer.GetLastContainer().IsLootable() ) thePlayer.GetLastContainer().GetComponent("Loot").SetEnabled( false );
  705. thePlayer.GetLastContainer().SetVisualsEmpty();
  706. thePlayer.GetLastContainer().DestroyIt();
  707.  
  708. // It must be called last, because it resets GetLastContainer()!
  709. HideLootWindow();
  710. }
  711. //thePlayer.GetLastContainer().GetInventory().GiveItem( thePlayer.GetInventory(), NameToUniqueId( StringToName( itemId ) ), quantity );
  712. }
  713.  
  714. function CheckForTutorial(itemId : SItemUniqueId, sourceInv : CInventoryComponent )
  715. {
  716. //if ( sourceInv.GetItemCategory(itemId ) == 'alchemyingredient' ) { theHud.m_hud.ShowTutorial("tut24", "", false); }; // <-- tutorial content is present in external tutorial - disabled
  717. //if ( sourceInv.GetItemCategory(itemId ) == 'alchemyingredient' ) { theHud.ShowTutorialPanelOld( "tut24", "" ); };
  718. //if ( sourceInv.GetItemCategory(itemId ) == 'skillupgrade' ) { theHud.m_hud.ShowTutorial("tut25", "", false); }; // <-- tutorial content is present in external tutorial - disabled
  719. //if ( sourceInv.GetItemCategory(itemId ) == 'skillupgrade' ) { theHud.ShowTutorialPanelOld( "tut25", "" ); };
  720. if ( sourceInv.GetItemCategory(itemId ) == 'armorupgrade' ) { theHud.m_hud.ShowTutorial("tut26", "", false); };
  721. //if ( sourceInv.GetItemCategory(itemId ) == 'armorupgrade' ) { theHud.ShowTutorialPanelOld( "tut26", "" ); };
  722. //if ( sourceInv.GetItemCategory(itemId ) == 'rangedweapon' ) { theHud.m_hud.ShowTutorial("tut42", "", false); }; // <-- tutorial content is present in external tutorial - disabled
  723. //if ( sourceInv.GetItemCategory(itemId ) == 'rangedweapon' ) { theHud.ShowTutorialPanelOld( "tut42", "" ); };
  724. //if ( sourceInv.GetItemCategory(itemId ) == 'petard' ) { theHud.m_hud.ShowTutorial("tut43", "", false); };
  725. //if ( sourceInv.GetItemCategory(itemId ) == 'petard' ) { theHud.ShowTutorialPanelOld( "tut43", "" ); };
  726. //if ( sourceInv.GetItemCategory(itemId ) == 'trap' ) { theHud.m_hud.ShowTutorial("tut44", "", false); }; // <-- tutorial content is present in external tutorial - disabled
  727. //if ( sourceInv.GetItemCategory(itemId ) == 'trap' ) { theHud.ShowTutorialPanelOld( "tut44", "" ); };
  728. if ( sourceInv.GetItemCategory(itemId ) == 'lure' ) { theHud.m_hud.ShowTutorial("tut45", "", false); };
  729. //if ( sourceInv.GetItemCategory(itemId ) == 'lure' ) { theHud.ShowTutorialPanelOld( "tut45", "" ); };
  730. if ( sourceInv.ItemHasTag( itemId, 'Rune' ) || sourceInv.ItemHasTag( itemId, 'Oil' ) ) { theHud.m_hud.ShowTutorial("tut27", "", false); };
  731. //if ( sourceInv.ItemHasTag( itemId, 'Rune' ) || sourceInv.ItemHasTag( itemId, 'Oil' ) ) { theHud.ShowTutorialPanelOld( "tut27", "" ); };
  732. }
  733.  
  734. function AllowItemDarkDiff( sourceInv : CInventoryComponent, itemId : SItemUniqueId ) : bool
  735. {
  736.  
  737. if ( ( sourceInv.ItemHasTag(itemId, 'DarkDiffA1') || sourceInv.ItemHasTag(itemId, 'DarkDiffA2') || sourceInv.ItemHasTag(itemId, 'DarkDiffA3') || sourceInv.ItemHasTag(itemId, 'DarkDiff') ) && theGame.GetDifficultyLevel() < 4 )
  738. {
  739. return false;
  740. } else
  741. {
  742. return true;
  743. }
  744. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement