GameplayEffectsComponent.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <GameplayEffectsNotificationBus.h>
  9. #include <IAudioSystem.h>
  10. #include <Source/AutoGen/GameplayEffectsComponent.AutoComponent.h>
  11. namespace MultiplayerSample
  12. {
  13. class GameplayEffectsComponent
  14. : public GameplayEffectsComponentBase
  15. , public Audio::AudioTriggerNotificationBus::MultiHandler
  16. , public LocalOnlyGameplayEffectsNotificationBus::Handler
  17. {
  18. public:
  19. AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::GameplayEffectsComponent, s_gameplayEffectsComponentConcreteUuid, MultiplayerSample::GameplayEffectsComponentBase);
  20. static void Reflect(AZ::ReflectContext* context);
  21. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  22. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  23. #if AZ_TRAIT_CLIENT
  24. void HandleRPC_OnEffect(AzNetworking::IConnection* invokingConnection, const SoundEffect& effect) override;
  25. void HandleRPC_OnPositionalEffect(AzNetworking::IConnection* invokingConnection, const SoundEffect& effect, const AZ::Vector3& soundLocation) override;
  26. #endif
  27. // AudioTriggerNotificationBus overrides ...
  28. void ReportTriggerFinished(Audio::TAudioControlID triggerId) override;
  29. #if AZ_TRAIT_CLIENT
  30. // LocalOnlyGameplayEffectsNotificationBus overrides ...
  31. void OnPositionalEffect(SoundEffect effect, const AZ::Vector3& position) override;
  32. void OnEffect(SoundEffect effect) override;
  33. #endif
  34. private:
  35. AZStd::vector<AZStd::string> m_soundTriggerNames;
  36. AZStd::unordered_map<AZ::EntityId, AZStd::shared_ptr<AzFramework::EntitySpawnTicket>> m_spawnedEffects;
  37. void SpawnEffect(SoundEffect effect, const AZ::Vector3& position);
  38. };
  39. class GameplayEffectsComponentController
  40. : public GameplayEffectsComponentControllerBase
  41. , public GameplayEffectsNotificationBus::Handler
  42. {
  43. public:
  44. explicit GameplayEffectsComponentController(GameplayEffectsComponent& parent);
  45. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  46. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  47. #if AZ_TRAIT_SERVER
  48. // GameplayEffectsNotificationBus overrides ...
  49. void OnEffect(SoundEffect effect) override;
  50. void OnPositionalEffect(SoundEffect effect, const AZ::Vector3& position) override;
  51. #endif
  52. };
  53. }