Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 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. enum EFocusModeChooseEntityStrategy
  7. {
  8. FMCES_ChooseNearest,
  9. FMCES_ChooseMostIntense,
  10. }
  11.  
  12. import class CFocusActionComponent extends CComponent
  13. {
  14. import var actionName : name;
  15. };
  16.  
  17. class W3FocusModeEffectIntensity
  18. {
  19. var chooseEntityStrategy : EFocusModeChooseEntityStrategy;
  20. var bestEntity : CEntity;
  21. var bestDistance : float;
  22. var lastDistance : float;
  23. var bestIntensity : float;
  24. var lastIntensity : float;
  25.  
  26. public function Init( strategy : EFocusModeChooseEntityStrategy )
  27. {
  28. chooseEntityStrategy = strategy;
  29. bestEntity = NULL;
  30. bestDistance = 0.0f;
  31. lastDistance = 0.0f;
  32. bestIntensity = 0.0f;
  33. lastIntensity = 0.0f;
  34. }
  35.  
  36. public function Update( entity : CEntity, distance : float, intensity : float )
  37. {
  38. if ( IsBestEntity( distance, intensity ) )
  39. {
  40. bestEntity = entity;
  41. bestDistance = distance;
  42. bestIntensity = intensity;
  43. }
  44. }
  45.  
  46. public function ForceUpdate( entity : CEntity, distance : float, intensity : float )
  47. {
  48. bestEntity = entity;
  49. bestDistance = distance;
  50. bestIntensity = intensity;
  51. }
  52.  
  53. public function ValueChanged() : bool
  54. {
  55. return ( bestIntensity != lastIntensity );
  56. }
  57.  
  58. public function GetValue( optional reset : bool ) : float
  59. {
  60. return lastIntensity;
  61. }
  62.  
  63. public function GetBestEntity() : CEntity
  64. {
  65. return bestEntity;
  66. }
  67.  
  68. public function Reset()
  69. {
  70. lastIntensity = bestIntensity;
  71. bestIntensity = 0.0f;
  72. bestDistance = 0.0f;
  73. bestEntity = NULL;
  74. }
  75.  
  76. function IsBestEntity( distance : float, intensity : float ) : bool
  77. {
  78. if ( !bestEntity )
  79. {
  80. return true;
  81. }
  82. if ( chooseEntityStrategy == FMCES_ChooseMostIntense )
  83. {
  84. return ( intensity > bestIntensity );
  85. }
  86. else
  87. {
  88. return ( distance < bestDistance );
  89. }
  90. }
  91. }
  92.  
  93. import class CFocusSoundParam extends CGameplayEntityParam
  94. {
  95. import final function GetEventStart() : name;
  96. import final function GetEventStop() : name;
  97. import final function GetHearingAngle() : float;
  98. import final function GetVisualEffectBoneName() : name;
  99. }
  100.  
  101. import class CFocusModeController extends IGameSystem
  102. {
  103. import final function SetActive( active : bool );
  104. import final function IsActive() : bool;
  105. import final function GetIntensity() : float;
  106. import final function EnableVisuals( enable : bool, optional desaturation : float , optional highlightBoos : float );
  107. import final function SetFadeParameters( NearFadeDistance : float, FadeDistanceRange : float, dimmingTIme : Float, dimmingSpeed : Float );
  108. import final function EnableExtendedVisuals( enable : bool, fadeTime : float );
  109. import final function SetDimming( enable : bool );
  110. import final function SetSoundClueEventNames( entity : CGameplayEntity, eventStart : name, eventStop : name, effectType : int ) : bool;
  111. import final function ActivateScentClue( entity : CEntity, effectName : name, duration : float );
  112. import final function DeactivateScentClue( entity : CEntity );
  113.  
  114. saved var detectedCluesTags : array< name >;
  115.  
  116. var medallionIntensity : W3FocusModeEffectIntensity;
  117. var dimmingClue : W3MonsterClue;
  118.  
  119. var blockVibrations : bool;
  120.  
  121. var focusAreaIntensity : float;
  122. default focusAreaIntensity = 0.0f;
  123.  
  124. const var effectFadeTime : float;
  125. default effectFadeTime = 1.0f;
  126.  
  127.  
  128.  
  129.  
  130. const var controllerVibrationFactor : float;
  131. default controllerVibrationFactor = 0.2f;
  132. const var controllerVibrationDuration : float;
  133. default controllerVibrationDuration = 0.5f;
  134.  
  135.  
  136. var activationSoundTimer : float;
  137. const var activationSoundInterval : float;
  138. default activationSoundTimer = 0.0f;
  139. default activationSoundInterval = 0.4f;
  140.  
  141.  
  142. var fastFocusTimer : float;
  143. var activateAfterFastFocus : bool;
  144. const var fastFocusDuration : float;
  145. default fastFocusTimer = 0.0f;
  146. default activateAfterFastFocus = false;
  147. default fastFocusDuration = 0.0f;
  148.  
  149.  
  150. private var isUnderwaterFocus : bool;
  151. default isUnderwaterFocus = false;
  152. private var isInCombat : bool;
  153. default isInCombat = false;
  154. private var isNight : bool;
  155. default isNight = false;
  156.  
  157.  
  158. private var lastDarkPlaceCheck : float;
  159. private const var DARK_PLACE_CHECK_INTERVAL : float;
  160. default DARK_PLACE_CHECK_INTERVAL = 2.f;
  161.  
  162. public function Activate()
  163. {
  164. //---=== modFriendlyHUD ===---
  165. if( GetFHUDConfig().enableWitcherSensesModules )
  166. {
  167. ToggleWSModules( true, "WitcherSensesActive" );
  168. }
  169. //---=== modFriendlyHUD ===---
  170.  
  171. lastDarkPlaceCheck = DARK_PLACE_CHECK_INTERVAL;
  172.  
  173. if ( !ActivateFastFocus( true ) )
  174. {
  175. ActivateInternal();
  176. }
  177. }
  178.  
  179. public function GetBlockVibrations() : bool
  180. {
  181. return blockVibrations;
  182. }
  183.  
  184. public function SetBlockVibrations( newState : bool )
  185. {
  186. blockVibrations = newState;
  187. }
  188.  
  189. function ActivateFastFocus( activate : bool ) : bool
  190. {
  191. activateAfterFastFocus = activate;
  192. if ( activate && fastFocusDuration > 0.0f )
  193. {
  194.  
  195.  
  196. fastFocusTimer = fastFocusDuration;
  197. return true;
  198. }
  199. return false;
  200. }
  201.  
  202. private function ActivateInternal()
  203. {
  204. if ( IsActive() || !CanUseFocusMode() )
  205. {
  206. return;
  207. }
  208.  
  209. SetActive( true );
  210. EnableVisuals( true );
  211. EnableExtendedVisuals( true, effectFadeTime );
  212.  
  213. thePlayer.BlockAction( EIAB_Jump, 'focus' );
  214. theTelemetry.LogWithName( TE_HERO_FOCUS_ON );
  215.  
  216.  
  217. if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  218. {
  219. activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  220. theSound.SoundEvent( 'expl_focus_start' );
  221. }
  222.  
  223. // FCR3 --
  224. if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  225. //if( GetWitcherPlayer().IsInDarkPlace() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  226. // -- FCR3
  227. {
  228. thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  229. }
  230. }
  231.  
  232. public function Deactivate()
  233. {
  234. var hud : CR4ScriptedHud;
  235. var module : CR4HudModuleInteractions;
  236. //---=== modFriendlyHUD ===---
  237. if( GetFHUDConfig().enableWitcherSensesModules )
  238. {
  239. ToggleWSModules( false, "WitcherSensesActive" );
  240. }
  241. //---=== modFriendlyHUD ===---
  242. //---=== modFriendlyHUD ===---
  243.  
  244. ActivateFastFocus( false );
  245.  
  246. if ( !IsActive() )
  247. {
  248. return;
  249. }
  250. SetActive( false );
  251. EnableVisuals( false );
  252. EnableExtendedVisuals( false, effectFadeTime );
  253.  
  254. if( isUnderwaterFocus )
  255. {
  256. isUnderwaterFocus = false;
  257. if( isInCombat )
  258. {
  259. theSound.LeaveGameState( ESGS_FocusUnderwaterCombat );
  260. }
  261. else
  262. {
  263. theSound.LeaveGameState( ESGS_FocusUnderwater );
  264. }
  265. }
  266. else
  267. {
  268. if( isNight )
  269. {
  270. theSound.LeaveGameState( ESGS_FocusNight );
  271. }
  272. else
  273. {
  274. theSound.LeaveGameState( ESGS_Focus );
  275. }
  276. }
  277.  
  278. isInCombat = false;
  279. isUnderwaterFocus = false;
  280. isNight = false;
  281.  
  282. thePlayer.UnblockAction( EIAB_Jump, 'focus' );
  283. theTelemetry.LogWithName( TE_HERO_FOCUS_OFF );
  284. theSound.SoundEvent( 'expl_focus_stop' );
  285.  
  286.  
  287. if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  288. {
  289. activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  290. theSound.SoundEvent( 'expl_focus_stop_sfx' );
  291. }
  292.  
  293. hud = ( CR4ScriptedHud )theGame.GetHud();
  294. if ( hud )
  295. {
  296. module = (CR4HudModuleInteractions)hud.GetHudModule( "InteractionsModule" );
  297. if ( module )
  298. {
  299. module.RemoveAllFocusInteractionIcons();
  300. }
  301. }
  302.  
  303. // FCR3 --
  304. if( thePlayer.IsInCombat() && GetWitcherPlayer().IsInDarkPlace() )
  305. {
  306. //
  307. }
  308. else
  309. {
  310. //thePlayer.RemoveBuff( EET_Mutation12Cat );
  311. if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  312. {
  313. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  314. }
  315. else
  316. {
  317. if ( !thePlayer.HasBuff( EET_Cat ) )
  318. {
  319. DisableCatViewFx( 1.0f );
  320. }
  321. }
  322. }
  323.  
  324. // thePlayer.RemoveBuff( EET_Mutation12Cat );
  325. // -- FCR3
  326. }
  327.  
  328. function CanUseFocusMode() : bool
  329. {
  330. var stateName : name;
  331.  
  332. if ( theGame && theGame.IsDialogOrCutscenePlaying() )
  333. {
  334. return false;
  335. }
  336.  
  337. if ( thePlayer )
  338. {
  339. stateName = thePlayer.GetCurrentStateName();
  340. return ( stateName == 'Exploration' || stateName == 'Swimming' || stateName == 'HorseRiding' || stateName == 'Sailing' || stateName == 'SailingPassive' ) && thePlayer.IsActionAllowed(EIAB_ExplorationFocus);
  341. }
  342.  
  343. return false;
  344. }
  345.  
  346. function Init()
  347. {
  348. medallionIntensity = new W3FocusModeEffectIntensity in this;
  349. medallionIntensity.Init( FMCES_ChooseNearest );
  350. dimmingClue = NULL;
  351. focusAreaIntensity = 0.0f;
  352. activationSoundTimer = 0.f;
  353. }
  354.  
  355. function DeInit()
  356. {
  357. var i, size : int;
  358.  
  359. delete medallionIntensity;
  360. medallionIntensity = NULL;
  361. }
  362.  
  363. event OnGameStarted()
  364. {
  365. Init();
  366. SetFadeParameters( 10.0, 30.0f, 16.0f, 40.0f );
  367. }
  368.  
  369. event OnGameEnded()
  370. {
  371. detectedCluesTags.Clear();
  372. DeInit();
  373. }
  374.  
  375. event OnTick( timeDelta : float )
  376. {
  377. var desiredAudioState : ESoundGameState;
  378. var focusModeIntensity : float;
  379.  
  380.  
  381. if ( fastFocusTimer > 0.0f )
  382. {
  383. fastFocusTimer -= timeDelta;
  384. if ( fastFocusTimer < 0.0f )
  385. {
  386. fastFocusTimer = 0.0f;
  387. if ( activateAfterFastFocus )
  388. {
  389. activateAfterFastFocus = false;
  390. ActivateInternal();
  391. }
  392. }
  393. }
  394.  
  395. if( IsActive() )
  396. {
  397. if( CanUseFocusMode() )
  398. {
  399. isInCombat = false;
  400. isUnderwaterFocus = thePlayer.OnIsCameraUnderwater();
  401. if( isUnderwaterFocus )
  402. {
  403. isInCombat = thePlayer.ShouldEnableCombatMusic();
  404. if( isInCombat )
  405. {
  406. desiredAudioState = ESGS_FocusUnderwaterCombat;
  407. }
  408. else
  409. {
  410. desiredAudioState = ESGS_FocusUnderwater;
  411. }
  412. }
  413. else
  414. {
  415. isNight = theGame.envMgr.IsNight();
  416. if( isNight )
  417. {
  418. desiredAudioState = ESGS_FocusNight;
  419. }
  420. else
  421. {
  422. desiredAudioState = ESGS_Focus;
  423. }
  424. }
  425.  
  426. if( theSound.GetCurrentGameState() != desiredAudioState )
  427. {
  428. theSound.EnterGameState( desiredAudioState );
  429. }
  430.  
  431. // FCR3 --
  432. //if( GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) )
  433. //{
  434. // -- FCR3
  435. lastDarkPlaceCheck -= timeDelta;
  436. if( lastDarkPlaceCheck <= 0.f )
  437. {
  438. lastDarkPlaceCheck = DARK_PLACE_CHECK_INTERVAL;
  439.  
  440. if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  441. {
  442. thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  443. }
  444. // FCR3 --
  445. /*
  446. else if( !GetWitcherPlayer().IsInDarkPlace() && thePlayer.HasBuff( EET_Mutation12Cat ) )
  447. {
  448. //thePlayer.RemoveBuff( EET_Mutation12Cat );
  449. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat ); // FCR3
  450. }
  451. */
  452. else if( !GetWitcherPlayer().IsInDarkPlace() )
  453. {
  454. if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  455. {
  456. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  457. }
  458. else
  459. {
  460. if ( !thePlayer.HasBuff( EET_Cat ) )
  461. {
  462. DisableCatViewFx( 1.0f );
  463. }
  464. */
  465. else if( !GetWitcherPlayer().IsInDarkPlace() )
  466. {
  467. if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  468. {
  469. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  470. }
  471. else
  472. {
  473. if ( !thePlayer.HasBuff( EET_Cat ) )
  474. {
  475. DisableCatViewFx( 1.0f );
  476. }
  477. }
  478. }
  479. // -- FCR3
  480. }
  481. //}
  482. }
  483. else
  484. {
  485. Deactivate();
  486. }
  487. }
  488.  
  489. focusModeIntensity = GetIntensity();
  490. UpdateMedallion( focusModeIntensity );
  491. }
  492. }
  493.  
  494. public function SetDimmingForClue( clue : W3MonsterClue )
  495. {
  496. dimmingClue = clue;
  497. SetDimming( true );
  498. }
  499.  
  500. event OnFocusModeDimmingFinished( timeDelta : float )
  501. {
  502. if ( dimmingClue )
  503. {
  504. dimmingClue.OnDimmingFinished();
  505. dimmingClue = NULL;
  506. }
  507. }
  508.  
  509. function UseControllerVibration( focusModeIntensity : float ) : bool
  510. {
  511. return ( focusAreaIntensity > 0.0f && focusModeIntensity < 1.0f && controllerVibrationFactor > 0.0f && thePlayer.GetCurrentStateName() == 'Exploration' );
  512. }
  513.  
  514. function UpdateMedallion( focusModeIntensity : float )
  515. {
  516. var intensity : float;
  517.  
  518. intensity = focusAreaIntensity;
  519.  
  520.  
  521. if ( UseControllerVibration( focusModeIntensity ) )
  522. {
  523. theGame.VibrateController( 0, intensity * ( 1.0f - focusModeIntensity ) * controllerVibrationFactor, controllerVibrationDuration );
  524.  
  525. focusAreaIntensity = 0.0f;
  526. }
  527.  
  528. if ( medallionIntensity )
  529. {
  530. if ( medallionIntensity.ValueChanged() )
  531. {
  532. intensity = MaxF( intensity, medallionIntensity.GetValue() );
  533. }
  534. medallionIntensity.Reset();
  535. }
  536.  
  537. GetWitcherPlayer().GetMedallion().SetInstantIntensity( intensity );
  538. GetWitcherPlayer().GetMedallion().SetFocusModeFactor( 1.0f - focusModeIntensity );
  539. }
  540.  
  541. public function SetMedallionIntensity( entity : CEntity, distance : float, intensity : float )
  542. {
  543. if ( medallionIntensity )
  544. {
  545. medallionIntensity.Update( entity, distance, intensity );
  546. }
  547. }
  548.  
  549. public function SetFocusAreaIntensity( intensity : float )
  550. {
  551. focusAreaIntensity = intensity;
  552. }
  553.  
  554. public function ReusableClueDetected( clue : W3MonsterClue )
  555. {
  556. var i, j : int;
  557. var tags : array< name >;
  558.  
  559. tags = clue.GetTags();
  560. for ( i = 0; i < tags.Size(); i += 1 )
  561. {
  562. j = detectedCluesTags.FindFirst( tags[i] );
  563. if ( j == -1 )
  564. {
  565. detectedCluesTags.PushBack( tags[i] );
  566. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnReusableClueUsed, SET_Unknown, tags[i] );
  567. }
  568. }
  569. }
  570.  
  571. public function WasReusableClueDetected( tag : name ) : bool
  572. {
  573. return detectedCluesTags.FindFirst( tag ) != -1;
  574. }
  575.  
  576. public function ResetClue( tag : name, removeFacts : bool, leaveVisible : bool )
  577. {
  578. var nodes : array< CNode >;
  579. var clue : W3MonsterClue;
  580. var i, size : int;
  581.  
  582. if ( tag == '' )
  583. {
  584. LogQuest( "CFocusModeController.ResetClue: empty tag!");
  585. return;
  586. }
  587.  
  588. theGame.GetNodesByTag( tag, nodes );
  589. size = nodes.Size();
  590. for ( i = 0; i < size; i += 1 )
  591. {
  592. clue = (W3MonsterClue)nodes[i];
  593. if ( clue )
  594. {
  595. clue.ResetClue( removeFacts, leaveVisible );
  596. }
  597. }
  598.  
  599. i = detectedCluesTags.FindFirst( tag );
  600. if ( i != -1 )
  601. {
  602. detectedCluesTags.Erase( i );
  603. }
  604. }
  605.  
  606. var focusInteractionsInterval : float; default focusInteractionsInterval = 0;
  607.  
  608. public function UpdateFocusInteractions( deltaTime : float)
  609. {
  610. var entities : array< CGameplayEntity >;
  611. var size : int;
  612. var i : int;
  613. var focusComponent : CFocusActionComponent;
  614. var hud : CR4ScriptedHud;
  615. var module : CR4HudModuleInteractions;
  616. var actionName : name;
  617.  
  618. if ( IsActive() )
  619. {
  620. focusInteractionsInterval -= deltaTime;
  621. if ( focusInteractionsInterval < 0 )
  622. {
  623. hud = ( CR4ScriptedHud )theGame.GetHud();
  624. module = ( CR4HudModuleInteractions )hud.GetHudModule( "InteractionsModule" );
  625. module.InvalidateAllFocusInteractionIcons();
  626. focusInteractionsInterval = module.GetFocusInteractionUpdateInterval();
  627.  
  628. FindGameplayEntitiesInRange( entities, thePlayer, module.GetFocusInteractionRadius(), 1000 );
  629. size = entities.Size();
  630. for ( i = 0; i < size; i += 1 )
  631. {
  632. if ( entities[ i ].CanShowFocusInteractionIcon() )
  633. {
  634. actionName = entities[ i ].GetFocusActionName();
  635. if ( IsNameValid( actionName ) )
  636. {
  637. module.AddFocusInteractionIcon( entities[ i ], actionName );
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644.  
  645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement