class SpeakerController extends ScriptableDeviceComponent { public const override function GetPS() : SpeakerControllerPS { return ( ( SpeakerControllerPS )( GetBasePS() ) ); } } struct SpeakerSetup { instanceeditable var m_defaultMusic : ERadioStationList; instanceeditable var m_distractionMusic : ERadioStationList; instanceeditable var m_range : Float; default m_range = 10.0f; [ customEditor = "AudioEvent" ] instanceeditable var m_glitchSFX : CName; default m_glitchSFX = 'dev_radio_ditraction_glitching'; instanceeditable var m_useOnlyGlitchSFX : Bool; } class SpeakerControllerPS extends ScriptableDeviceComponentPS { default m_deviceName = "LocKey#166"; default m_tweakDBRecord = T"Devices.Speaker"; default m_tweakDBDescriptionRecord = T"device_descriptions.Speaker"; protected instanceeditable var m_speakerSetup : SpeakerSetup; private var m_currentValue : CName; private var m_previousValue : CName; protected event OnInstantiated() { super.OnInstantiated(); if( !( IsStringValid( m_deviceName ) ) ) { m_deviceName = "LocKey#166"; } } protected override function Initialize() { super.Initialize(); } protected override function GameAttached() { m_currentValue = RadioStationDataProvider.GetStationName( m_speakerSetup.m_defaultMusic ); } protected const override function CanCreateAnyQuickHackActions() : Bool { return true; } protected override function GetQuickHackActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > ) { var currentAction : ScriptableDeviceAction; currentAction = ActionQuickHackDistraction(); currentAction.SetObjectActionID( T"DeviceAction.MalfunctionClassHack" ); actions.PushBack( currentAction ); if( IsGlitching() || IsDistracting() ) { SetActionsInactiveAll( actions, "LocKey#7004" ); } if( !( IsPowered() ) ) { SetActionsInactiveAll( actions, "LocKey#7013" ); } FinalizeGetQuickHackActions( actions, context ); } public function GetGlitchSFX() : CName { return m_speakerSetup.m_glitchSFX; } public function UseOnlyGlitchSFX() : Bool { return m_speakerSetup.m_useOnlyGlitchSFX; } public function GetCurrentStation() : CName { return m_currentValue; } public function SetCurrentStation( station : CName ) { m_currentValue = station; } public function GetRange() : Float { return m_speakerSetup.m_range; } protected override function ActionQuickHackDistraction() : QuickHackDistraction { var action : QuickHackDistraction; action = new QuickHackDistraction; action.SetUp( this ); action.SetProperties(); action.AddDeviceName( m_deviceName ); action.SetObjectActionID( T"DeviceAction.MalfunctionClassHack" ); action.CreateInteraction(); action.SetDurationValue( GetDistractionDuration( action ) ); return action; } public override function OnQuickHackDistraction( evt : QuickHackDistraction ) : EntityNotificationType { var type : EntityNotificationType; type = super.OnQuickHackDistraction( evt ); if( type == EntityNotificationType.DoNotNotifyEntity ) { return type; } if( IsOFF() ) { ExecutePSAction( ActionToggleON() ); } if( evt.IsStarted() ) { m_previousValue = m_currentValue; m_currentValue = RadioStationDataProvider.GetStationName( m_speakerSetup.m_distractionMusic ); } else { m_currentValue = m_previousValue; } return EntityNotificationType.SendThisEventToEntity; } public export function OnChangeMusicAction( evt : ChangeMusicAction ) : EntityNotificationType { var notifier : ActionNotifier; if( IsPowered() ) { notifier = new ActionNotifier; notifier.SetNone(); if( IsOFF() ) { ExecutePSAction( ActionToggleON() ); } Notify( notifier, evt ); return EntityNotificationType.SendThisEventToEntity; } else { return EntityNotificationType.DoNotNotifyEntity; } } protected function CreateDeafeningMusic() : MusicSettings { var music : PlayRadio; music = new PlayRadio; music.SetStatusEffect( ESoundStatusEffects.DEAFENED ); music.SetSoundName( m_speakerSetup.m_distractionMusic ); return ( ( MusicSettings )( music ) ); } protected override function GetDeviceIconTweakDBID() : TweakDBID { return T"DeviceIcons.RadioDeviceIcon"; } protected override function GetBackgroundTextureTweakDBID() : TweakDBID { return T"DeviceIcons.RadioDeviceBackground"; } }