123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <GameplayEffectsNotificationBus.h>
- #include <MultiplayerSampleTypes.h>
- #include <AzCore/Component/ComponentApplicationBus.h>
- #include <AzCore/Component/TransformBus.h>
- #include <AzCore/Settings/SettingsRegistry.h>
- #include <Source/Components/Multiplayer/EnergyBallComponent.h>
- #include <Source/Components/Multiplayer/EnergyCannonComponent.h>
- namespace MultiplayerSample
- {
- void EnergyCannonComponent::Reflect(AZ::ReflectContext* context)
- {
- AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
- if (serializeContext)
- {
- serializeContext->Class<EnergyCannonComponent, EnergyCannonComponentBase>()
- ->Version(1);
- }
- EnergyCannonComponentBase::Reflect(context);
- }
- void EnergyCannonComponent::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
- {
- m_effect = GetFiringEffect();
- m_effect.Initialize();
- }
- void EnergyCannonComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
- {
- }
- #if AZ_TRAIT_CLIENT
- void EnergyCannonComponent::HandleRPC_BallLaunched([[maybe_unused]] AzNetworking::IConnection* invokingConnection)
- {
- m_effect.TriggerEffect(GetEntity()->GetTransform()->GetWorldTM());
- }
- #endif
- EnergyCannonComponentController::EnergyCannonComponentController(EnergyCannonComponent& parent)
- : EnergyCannonComponentControllerBase(parent)
- {
- }
- void EnergyCannonComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
- {
- #if AZ_TRAIT_SERVER
- if (GetRateOfFireMs() > AZ::TimeMs{ 0 })
- {
- m_firingEvent.Enqueue(GetRateOfFireMs(), true);
- }
- #endif
- }
- void EnergyCannonComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
- {
- #if AZ_TRAIT_SERVER
- m_firingEvent.RemoveFromQueue();
- #endif
- }
- #if AZ_TRAIT_SERVER
- void EnergyCannonComponentController::OnFireEnergyBall()
- {
- // Re-using the same ball entity.
- AZ::Entity* ball = nullptr;
- AZ::ComponentApplicationBus::BroadcastResult(ball, &AZ::ComponentApplicationBus::Events::FindEntity, GetEnergyBallEntity());
- if (ball)
- {
- if (EnergyBallComponent* ballComponent = ball->FindComponent<EnergyBallComponent>())
- {
- const AZ::Transform& cannonTm = GetEntity()->GetTransform()->GetWorldTM();
- const AZ::Vector3 forward = cannonTm.TransformVector(AZ::Vector3::CreateAxisY(-1.f));
- const AZ::Vector3 effectOffset = GetFiringEffect().GetEffectOffset();
- ballComponent->RPC_LaunchBall(cannonTm.GetTranslation() + effectOffset, forward, GetNetEntityId());
- RPC_BallLaunched();
- // Enqueue our ball kill event
- m_killEvent.Enqueue(GetBallLifetimeMs(), false);
- }
- }
- }
- void EnergyCannonComponentController::OnKillEnergyBall()
- {
- // Re-using the same ball entity.
- AZ::Entity* ball = nullptr;
- AZ::ComponentApplicationBus::BroadcastResult(ball, &AZ::ComponentApplicationBus::Events::FindEntity, GetEnergyBallEntity());
- if (ball)
- {
- if (EnergyBallComponent* ballComponent = ball->FindComponent<EnergyBallComponent>())
- {
- ballComponent->RPC_KillBall();
- }
- }
- }
- #endif
- }
|