Advertisement
Guest User

focus.ws

a guest
Sep 1st, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.58 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. //Alt Horse Controls++
  211. if( !thePlayer.motionSicknessFocusMode )
  212. {
  213. EnableVisuals( true );
  214. EnableExtendedVisuals( true, effectFadeTime );
  215. }
  216. //Alt Horse Controls--
  217.  
  218. thePlayer.BlockAction( EIAB_Jump, 'focus' );
  219. theTelemetry.LogWithName( TE_HERO_FOCUS_ON );
  220.  
  221.  
  222. if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  223. {
  224. activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  225. theSound.SoundEvent( 'expl_focus_start' );
  226. }
  227.  
  228. // FCR3 --
  229. if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  230. //if( GetWitcherPlayer().IsInDarkPlace() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  231. // -- FCR3
  232. {
  233. thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  234. }
  235. }
  236.  
  237. public function Deactivate()
  238. {
  239. var hud : CR4ScriptedHud;
  240. var module : CR4HudModuleInteractions;
  241.  
  242. //---=== modFriendlyHUD ===---
  243. if( GetFHUDConfig().enableWitcherSensesModules )
  244. {
  245. ToggleWSModules( false, "WitcherSensesActive" );
  246. }
  247. //---=== modFriendlyHUD ===---
  248.  
  249. ActivateFastFocus( false );
  250.  
  251. if ( !IsActive() )
  252. {
  253. return;
  254. }
  255. SetActive( false );
  256. EnableVisuals( false );
  257. EnableExtendedVisuals( false, effectFadeTime );
  258.  
  259. if( isUnderwaterFocus )
  260. {
  261. isUnderwaterFocus = false;
  262. if( isInCombat )
  263. {
  264. theSound.LeaveGameState( ESGS_FocusUnderwaterCombat );
  265. }
  266. else
  267. {
  268. theSound.LeaveGameState( ESGS_FocusUnderwater );
  269. }
  270. }
  271. else
  272. {
  273. if( isNight )
  274. {
  275. theSound.LeaveGameState( ESGS_FocusNight );
  276. }
  277. else
  278. {
  279. theSound.LeaveGameState( ESGS_Focus );
  280. }
  281. }
  282.  
  283. isInCombat = false;
  284. isUnderwaterFocus = false;
  285. isNight = false;
  286.  
  287. thePlayer.UnblockAction( EIAB_Jump, 'focus' );
  288. theTelemetry.LogWithName( TE_HERO_FOCUS_OFF );
  289. theSound.SoundEvent( 'expl_focus_stop' );
  290.  
  291.  
  292. if ( theGame.GetEngineTimeAsSeconds() - activationSoundTimer > activationSoundInterval )
  293. {
  294. activationSoundTimer = theGame.GetEngineTimeAsSeconds();
  295. theSound.SoundEvent( 'expl_focus_stop_sfx' );
  296. }
  297.  
  298. hud = ( CR4ScriptedHud )theGame.GetHud();
  299. if ( hud )
  300. {
  301. module = (CR4HudModuleInteractions)hud.GetHudModule( "InteractionsModule" );
  302. if ( module )
  303. {
  304. module.RemoveAllFocusInteractionIcons();
  305. }
  306. }
  307.  
  308. // FCR3 --
  309. if( thePlayer.IsInCombat() && GetWitcherPlayer().IsInDarkPlace() )
  310. {
  311. //
  312. }
  313. else
  314. {
  315. //thePlayer.RemoveBuff( EET_Mutation12Cat );
  316. if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  317. {
  318. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  319. }
  320. else
  321. {
  322. if ( !thePlayer.HasBuff( EET_Cat ) )
  323. {
  324. DisableCatViewFx( 1.0f );
  325. }
  326. }
  327. }
  328.  
  329. // thePlayer.RemoveBuff( EET_Mutation12Cat );
  330. // -- FCR3
  331. }
  332.  
  333. function CanUseFocusMode() : bool
  334. {
  335. var stateName : name;
  336.  
  337. if ( theGame && theGame.IsDialogOrCutscenePlaying() )
  338. {
  339. return false;
  340. }
  341.  
  342. if ( thePlayer )
  343. {
  344. stateName = thePlayer.GetCurrentStateName();
  345. return ( stateName == 'Exploration' || stateName == 'Swimming' || stateName == 'HorseRiding' || stateName == 'Sailing' || stateName == 'SailingPassive' ) && thePlayer.IsActionAllowed(EIAB_ExplorationFocus);
  346. }
  347.  
  348. return false;
  349. }
  350.  
  351. function Init()
  352. {
  353. medallionIntensity = new W3FocusModeEffectIntensity in this;
  354. medallionIntensity.Init( FMCES_ChooseNearest );
  355. dimmingClue = NULL;
  356. focusAreaIntensity = 0.0f;
  357. activationSoundTimer = 0.f;
  358. }
  359.  
  360. function DeInit()
  361. {
  362. var i, size : int;
  363.  
  364. delete medallionIntensity;
  365. medallionIntensity = NULL;
  366. }
  367.  
  368. event OnGameStarted()
  369. {
  370. Init();
  371. SetFadeParameters( 10.0, 30.0f, 16.0f, 40.0f );
  372. }
  373.  
  374. event OnGameEnded()
  375. {
  376. detectedCluesTags.Clear();
  377. DeInit();
  378. }
  379.  
  380. event OnTick( timeDelta : float )
  381. {
  382. var desiredAudioState : ESoundGameState;
  383. var focusModeIntensity : float;
  384.  
  385.  
  386. if ( fastFocusTimer > 0.0f )
  387. {
  388. fastFocusTimer -= timeDelta;
  389. if ( fastFocusTimer < 0.0f )
  390. {
  391. fastFocusTimer = 0.0f;
  392. if ( activateAfterFastFocus )
  393. {
  394. activateAfterFastFocus = false;
  395. ActivateInternal();
  396. }
  397. }
  398. }
  399.  
  400. if( IsActive() )
  401. {
  402. if( CanUseFocusMode() )
  403. {
  404. isInCombat = false;
  405. isUnderwaterFocus = thePlayer.OnIsCameraUnderwater();
  406. if( isUnderwaterFocus )
  407. {
  408. isInCombat = thePlayer.ShouldEnableCombatMusic();
  409. if( isInCombat )
  410. {
  411. desiredAudioState = ESGS_FocusUnderwaterCombat;
  412. }
  413. else
  414. {
  415. desiredAudioState = ESGS_FocusUnderwater;
  416. }
  417. }
  418. else
  419. {
  420. isNight = theGame.envMgr.IsNight();
  421. if( isNight )
  422. {
  423. desiredAudioState = ESGS_FocusNight;
  424. }
  425. else
  426. {
  427. desiredAudioState = ESGS_Focus;
  428. }
  429. }
  430.  
  431. if( theSound.GetCurrentGameState() != desiredAudioState )
  432. {
  433. theSound.EnterGameState( desiredAudioState );
  434. }
  435.  
  436. // FCR3 --
  437. //if( GetWitcherPlayer().IsMutationActive( EPMT_Mutation12 ) )
  438. //{
  439. // -- FCR3
  440. lastDarkPlaceCheck -= timeDelta;
  441. if( lastDarkPlaceCheck <= 0.f )
  442. {
  443. lastDarkPlaceCheck = DARK_PLACE_CHECK_INTERVAL;
  444.  
  445. if( GetWitcherPlayer().IsInDarkPlace() && !thePlayer.HasBuff( EET_Mutation12Cat ) )
  446. {
  447. thePlayer.AddEffectDefault( EET_Mutation12Cat, thePlayer, "Mutation12 Senses", false );
  448. }
  449. // FCR3 --
  450. /*
  451. else if( !GetWitcherPlayer().IsInDarkPlace() && thePlayer.HasBuff( EET_Mutation12Cat ) )
  452. {
  453. //thePlayer.RemoveBuff( EET_Mutation12Cat );
  454. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat ); // FCR3
  455. }
  456. */
  457. else if( !GetWitcherPlayer().IsInDarkPlace() )
  458. {
  459. if ( thePlayer.HasBuff( EET_Mutation12Cat ) )
  460. {
  461. thePlayer.RemoveAllBuffsOfType( EET_Mutation12Cat );
  462. }
  463. else
  464. {
  465. if ( !thePlayer.HasBuff( EET_Cat ) )
  466. {
  467. DisableCatViewFx( 1.0f );
  468. }
  469. else
  470. {
  471. if ( !thePlayer.HasBuff( EET_Cat ) )
  472. {
  473. DisableCatViewFx( 1.0f );
  474. }
  475. }
  476. // -- FCR3
  477. }
  478. //}
  479. //}
  480. //}
  481. }
  482. else
  483. {
  484. Deactivate();
  485. }
  486. }
  487.  
  488. focusModeIntensity = GetIntensity();
  489. UpdateMedallion( focusModeIntensity );
  490. }
  491.  
  492. public function SetDimmingForClue( clue : W3MonsterClue )
  493. {
  494. dimmingClue = clue;
  495. SetDimming( true );
  496. }
  497.  
  498. event OnFocusModeDimmingFinished( timeDelta : float )
  499. {
  500. if ( dimmingClue )
  501. {
  502. dimmingClue.OnDimmingFinished();
  503. dimmingClue = NULL;
  504. }
  505. }
  506.  
  507. function UseControllerVibration( focusModeIntensity : float ) : bool
  508. {
  509. return ( focusAreaIntensity > 0.0f && focusModeIntensity < 1.0f && controllerVibrationFactor > 0.0f && thePlayer.GetCurrentStateName() == 'Exploration' );
  510. }
  511.  
  512. function UpdateMedallion( focusModeIntensity : float )
  513. {
  514. var intensity : float;
  515.  
  516. intensity = focusAreaIntensity;
  517.  
  518.  
  519. if ( UseControllerVibration( focusModeIntensity ) )
  520. {
  521. theGame.VibrateController( 0, intensity * ( 1.0f - focusModeIntensity ) * controllerVibrationFactor, controllerVibrationDuration );
  522.  
  523. focusAreaIntensity = 0.0f;
  524. }
  525.  
  526. if ( medallionIntensity )
  527. {
  528. if ( medallionIntensity.ValueChanged() )
  529. {
  530. intensity = MaxF( intensity, medallionIntensity.GetValue() );
  531. }
  532. medallionIntensity.Reset();
  533. }
  534.  
  535. GetWitcherPlayer().GetMedallion().SetInstantIntensity( intensity );
  536. GetWitcherPlayer().GetMedallion().SetFocusModeFactor( 1.0f - focusModeIntensity );
  537. }
  538.  
  539. public function SetMedallionIntensity( entity : CEntity, distance : float, intensity : float )
  540. {
  541. if ( medallionIntensity )
  542. {
  543. medallionIntensity.Update( entity, distance, intensity );
  544. }
  545. }
  546.  
  547. public function SetFocusAreaIntensity( intensity : float )
  548. {
  549. focusAreaIntensity = intensity;
  550. }
  551.  
  552. public function ReusableClueDetected( clue : W3MonsterClue )
  553. {
  554. var i, j : int;
  555. var tags : array< name >;
  556.  
  557. tags = clue.GetTags();
  558. for ( i = 0; i < tags.Size(); i += 1 )
  559. {
  560. j = detectedCluesTags.FindFirst( tags[i] );
  561. if ( j == -1 )
  562. {
  563. detectedCluesTags.PushBack( tags[i] );
  564. theGame.GetGlobalEventsManager().OnScriptedEvent( SEC_OnReusableClueUsed, SET_Unknown, tags[i] );
  565. }
  566. }
  567. }
  568.  
  569. public function WasReusableClueDetected( tag : name ) : bool
  570. {
  571. return detectedCluesTags.FindFirst( tag ) != -1;
  572. }
  573.  
  574. public function ResetClue( tag : name, removeFacts : bool, leaveVisible : bool )
  575. {
  576. var nodes : array< CNode >;
  577. var clue : W3MonsterClue;
  578. var i, size : int;
  579.  
  580. if ( tag == '' )
  581. {
  582. LogQuest( "CFocusModeController.ResetClue: empty tag!");
  583. return;
  584. }
  585.  
  586. theGame.GetNodesByTag( tag, nodes );
  587. size = nodes.Size();
  588. for ( i = 0; i < size; i += 1 )
  589. {
  590. clue = (W3MonsterClue)nodes[i];
  591. if ( clue )
  592. {
  593. clue.ResetClue( removeFacts, leaveVisible );
  594. }
  595. }
  596.  
  597. i = detectedCluesTags.FindFirst( tag );
  598. if ( i != -1 )
  599. {
  600. detectedCluesTags.Erase( i );
  601. }
  602. }
  603.  
  604. var focusInteractionsInterval : float; default focusInteractionsInterval = 0;
  605.  
  606. public function UpdateFocusInteractions( deltaTime : float)
  607. {
  608. var entities : array< CGameplayEntity >;
  609. var size : int;
  610. var i : int;
  611. var focusComponent : CFocusActionComponent;
  612. var hud : CR4ScriptedHud;
  613. var module : CR4HudModuleInteractions;
  614. var actionName : name;
  615.  
  616. if ( IsActive() )
  617. {
  618. focusInteractionsInterval -= deltaTime;
  619. if ( focusInteractionsInterval < 0 )
  620. {
  621. hud = ( CR4ScriptedHud )theGame.GetHud();
  622. module = ( CR4HudModuleInteractions )hud.GetHudModule( "InteractionsModule" );
  623. module.InvalidateAllFocusInteractionIcons();
  624. focusInteractionsInterval = module.GetFocusInteractionUpdateInterval();
  625.  
  626. FindGameplayEntitiesInRange( entities, thePlayer, module.GetFocusInteractionRadius(), 1000 );
  627. size = entities.Size();
  628. for ( i = 0; i < size; i += 1 )
  629. {
  630. if ( entities[ i ].CanShowFocusInteractionIcon() )
  631. {
  632. actionName = entities[ i ].GetFocusActionName();
  633. if ( IsNameValid( actionName ) )
  634. {
  635. module.AddFocusInteractionIcon( entities[ i ], actionName );
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642.  
  643. }
  644.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement