void AShooterWeapon_Instant::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread) { if (MyPawn && MyPawn->IsLocallyControlled() && GetNetMode() == NM_Client) { // if we're a client and we've hit something that is being controlled by the server if (Impact.GetActor() && Impact.GetActor()->GetRemoteRole() == ROLE_Authority) { // notify the server of the hit ServerNotifyHit(Impact, ShootDir, RandomSeed, ReticleSpread); } else if (Impact.GetActor() == NULL) { if (Impact.bBlockingHit) { // notify the server of the hit ServerNotifyHit(Impact, ShootDir, RandomSeed, ReticleSpread); } else { // notify server of the miss ServerNotifyMiss(ShootDir, RandomSeed, ReticleSpread); } } } // process a confirmed hit ProcessInstantHit_Confirmed(Impact, Origin, ShootDir, RandomSeed, ReticleSpread); }
void UGISInventoryBaseComponent::AddItemOnSlot(const FGISSlotInfo& TargetSlotType, const FGISSlotInfo& LastSlotType) { //Before we start swapping item, let's check if tags match! if (!TargetSlotType.CurrentInventoryComponent->RequiredTags.MatchesAny(LastSlotType.CurrentInventoryComponent->OwnedTags, false)) return; //next check should be against item tags, but that's later! //Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotTabIndex].ItemData if (TargetSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData == nullptr) { TWeakObjectPtr<UGISItemData> TargetItem = LastSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[LastSlotType.SlotTabIndex].TabSlots[LastSlotType.SlotIndex].ItemData; TWeakObjectPtr<UGISItemData> LastItem = TargetSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData; //Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData; TargetSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData = TargetItem; LastSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[LastSlotType.SlotTabIndex].TabSlots[LastSlotType.SlotIndex].ItemData = nullptr; TargetItem->OnItemAddedToSlot(); //FGISSlotSwapInfo SlotSwapInfo; SlotSwapInfo.LastSlotIndex = LastSlotType.SlotIndex; SlotSwapInfo.LastTabIndex = LastSlotType.SlotTabIndex; SlotSwapInfo.LastSlotData = LastItem; SlotSwapInfo.LastSlotComponent = LastSlotType.CurrentInventoryComponent; SlotSwapInfo.TargetSlotIndex = TargetSlotType.SlotIndex; SlotSwapInfo.TargetTabIndex = TargetSlotType.SlotTabIndex; SlotSwapInfo.TargetSlotData = TargetItem; SlotSwapInfo.TargetSlotComponent = TargetSlotType.CurrentInventoryComponent; if (GetNetMode() == ENetMode::NM_Standalone) OnItemSlotSwapped.Broadcast(SlotSwapInfo); ClientSlotSwap(SlotSwapInfo); } else { TWeakObjectPtr<UGISItemData> TargetItem = LastSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[LastSlotType.SlotTabIndex].TabSlots[LastSlotType.SlotIndex].ItemData; TWeakObjectPtr<UGISItemData> LastItem = TargetSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData; //Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData; TargetSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[TargetSlotType.SlotTabIndex].TabSlots[TargetSlotType.SlotIndex].ItemData = TargetItem; LastSlotType.CurrentInventoryComponent->Tabs.InventoryTabs[LastSlotType.SlotTabIndex].TabSlots[LastSlotType.SlotIndex].ItemData = LastItem; TargetItem->OnItemAddedToSlot(); LastItem->OnItemAddedToSlot(); //FGISSlotSwapInfo SlotSwapInfo; SlotSwapInfo.LastSlotIndex = LastSlotType.SlotIndex; SlotSwapInfo.LastTabIndex = LastSlotType.SlotTabIndex; SlotSwapInfo.LastSlotData = LastItem; SlotSwapInfo.LastSlotComponent = LastSlotType.CurrentInventoryComponent; SlotSwapInfo.TargetSlotIndex = TargetSlotType.SlotIndex; SlotSwapInfo.TargetTabIndex = TargetSlotType.SlotTabIndex; SlotSwapInfo.TargetSlotData = TargetItem; SlotSwapInfo.TargetSlotComponent = TargetSlotType.CurrentInventoryComponent; if (GetNetMode() == ENetMode::NM_Standalone) OnItemSlotSwapped.Broadcast(SlotSwapInfo); ClientSlotSwap(SlotSwapInfo); } }
void AARCharacter::PossessedBy(AController* NewController) { ARPController = Cast<AARPlayerController>(NewController); if ((GetNetMode() == ENetMode::NM_Standalone || GetNetMode() == ENetMode::NM_Client) && ARPController) { Abilities->PCOwner = ARPController; Abilities->InitializeGUI(); } Super::PossessedBy(NewController); }
void AShooterWeapon_Instant::ProcessInstantHit_Confirmed(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread) { // handle damage if (ShouldDealDamage(Impact.GetActor())) { DealDamage(Impact, ShootDir); } // play FX on remote clients if (Role == ROLE_Authority) { HitNotify.Origin = Origin; HitNotify.RandomSeed = RandomSeed; HitNotify.ReticleSpread = ReticleSpread; } // play FX locally if (GetNetMode() != NM_DedicatedServer) { const FVector EndTrace = Origin + ShootDir * InstantConfig.WeaponRange; const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace; SpawnTrailEffect(EndPoint); SpawnImpactEffects(Impact); } }
void APawn::PostInitializeComponents() { Super::PostInitializeComponents(); if (!IsPendingKill()) { GetWorld()->AddPawn( this ); // Automatically add Controller to AI Pawns if we are allowed to. if (AutoPossessPlayer == EAutoReceiveInput::Disabled) { if (AutoPossessAI != EAutoPossessAI::Disabled && Controller == NULL && GetNetMode() != NM_Client) { const bool bPlacedInWorld = (GetWorld()->bStartup); if ((AutoPossessAI == EAutoPossessAI::PlacedInWorldOrSpawned) || (AutoPossessAI == EAutoPossessAI::PlacedInWorld && bPlacedInWorld) || (AutoPossessAI == EAutoPossessAI::Spawned && !bPlacedInWorld)) { SpawnDefaultController(); } } } // update movement component's nav agent values UpdateNavAgent(); } }
void APawn::PreInitializeComponents() { Super::PreInitializeComponents(); if (Instigator == nullptr) { Instigator = this; } if (AutoPossessPlayer != EAutoReceiveInput::Disabled && GetNetMode() != NM_Client ) { const int32 PlayerIndex = int32(AutoPossessPlayer.GetValue()) - 1; APlayerController* PC = UGameplayStatics::GetPlayerController(this, PlayerIndex); if (PC) { PC->Possess(this); } else { GetWorld()->PersistentLevel->RegisterActorForAutoReceiveInput(this, PlayerIndex); } } UpdateNavigationRelevance(); }
void APawn::PossessedBy(AController* NewController) { AController* const OldController = Controller; Controller = NewController; ForceNetUpdate(); if (Controller->PlayerState != NULL) { PlayerState = Controller->PlayerState; } if (APlayerController* PlayerController = Cast<APlayerController>(Controller)) { if (GetNetMode() != NM_Standalone) { SetReplicates(true); SetAutonomousProxy(true); } } else { CopyRemoteRoleFrom(GetDefault<APawn>()); } // dispatch Blueprint event if necessary if (OldController != NewController) { ReceivePossessed(Controller); } }
void AWorldSettings::PreInitializeComponents() { Super::PreInitializeComponents(); // create the emitter pool // we only need to do this for the persistent level's WorldSettings as sublevel actors will have their WorldSettings set to it on association if (GetNetMode() != NM_DedicatedServer && IsInPersistentLevel()) { UWorld* World = GetWorld(); check(World); // only create once - if (World->MyParticleEventManager == NULL && !GEngine->ParticleEventManagerClassPath.IsEmpty()) { TSubclassOf<AParticleEventManager> ParticleEventManagerClass = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), NULL, *GEngine->ParticleEventManagerClassPath, NULL, LOAD_NoWarn, NULL)); if (ParticleEventManagerClass != NULL) { FActorSpawnParameters SpawnParameters; SpawnParameters.Owner = this; SpawnParameters.Instigator = Instigator; World->MyParticleEventManager = World->SpawnActor<AParticleEventManager>(ParticleEventManagerClass, SpawnParameters ); } } } }
void UGISInventoryBaseComponent::CopyItemsFromOtherInventoryTab(class UGISInventoryBaseComponent* OtherIn, int32 OtherTabIndex, int32 TargetTabIndex) { if (OtherIn) { int32 OtherSlotCount = OtherIn->GetSlotsInTab(OtherTabIndex); int32 TargetSlotCount = GetSlotsInTab(TargetTabIndex); if (OtherSlotCount > TargetSlotCount) { for (int32 Index = 0; Index < TargetSlotCount; Index++) { SetItemDataInSlot(TargetTabIndex, Index, OtherIn->GetItemDataInSlot(OtherTabIndex,Index)); OnCopyItemsFromOtherInventoryTab(Tabs.InventoryTabs[TargetTabIndex].TabSlots[Index].ItemData); } } else { for (int32 Index = 0; Index < OtherSlotCount; Index++) { SetItemDataInSlot(TargetTabIndex, Index, OtherIn->GetItemDataInSlot(OtherTabIndex, Index)); OnCopyItemsFromOtherInventoryTab(Tabs.InventoryTabs[TargetTabIndex].TabSlots[Index].ItemData); } } TabUpdateInfo.ReplicationCounter++; TabUpdateInfo.TargetTabIndex = TargetTabIndex; if (GetNetMode() == ENetMode::NM_Standalone) OnTabChanged.ExecuteIfBound(TabUpdateInfo.TargetTabIndex); } }
void UGISInventoryBaseComponent::CopyItemsToTab(int32 OriginalTab, int32 TargetTab) { int32 OrignalItemCount = GetSlotsInTab(OriginalTab); int32 TargetItemCount = GetSlotsInTab(TargetTab); //check which item count is bigger //to avoid copying into non existend array elements. //we always count against smaller. if (OrignalItemCount > TargetItemCount) { for (int32 Index = 0; Index < TargetItemCount; Index++) { CopyItemsFromTab(TargetTab, Index, OriginalTab, Index); } } else { for (int32 Index = 0; Index < OrignalItemCount; Index++) { CopyItemsFromTab(TargetTab, Index, OriginalTab, Index); } } TabUpdateInfo.ReplicationCounter++; TabUpdateInfo.TargetTabIndex = TargetTab; //I will need to call it on client. But how do I determine //changed tab index on client after tab is replicated ? //replicate index separatetly ? if (GetNetMode() == ENetMode::NM_Standalone) OnTabChanged.ExecuteIfBound(TabUpdateInfo.TargetTabIndex); }
void UGISInventoryBaseComponent::InitializeWidgets(APlayerController* PCIn) { ENetRole CurrentRole = GetOwnerRole(); ENetMode CurrentNetMode = GetNetMode(); if (CurrentRole < ROLE_Authority || CurrentNetMode == ENetMode::NM_Standalone) { if (InventoryConfiguration.IsValid()) { InventoryContainer = CreateWidget<UGISContainerBaseWidget>(PCIn, InventoryConfiguration.InventoryContainerClass); if (InventoryContainer) { InventoryContainer->InitializeContainer(InventoryConfiguration, this, PCIn); InventoryContainer->SetVisibility(InventoryConfiguration.InventoryVisibility); //call last } } if (LootConfiguration.IsValid()) { LootWidget = CreateWidget<UGISLootContainerBaseWidget>(PCIn, LootConfiguration.LootWidgetClass); if (LootWidget) { LootWidget->InitializeLootWidget(LootConfiguration, this, PCIn); LootWidget->SetVisibility(LootConfiguration.LootWindowVisibility); } } } }
void ANTPlayerController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); AccumulativeDeltaTime += DeltaSeconds; // If we're the Client and we haven't updated Ping in a while, try to get a ping update const float LocTimeSec = GetWorld()->GetTimeSeconds(); if (((LocTimeSec - LastPingCalcTime) > 0.5f) && (GetNetMode() == NM_Client)) { LastPingCalcTime = LocTimeSec; ServerBouncePing(LocTimeSec); } if (PlayerState) { if (Role == ROLE_Authority && !IsLocalController()) { GEngine->AddOnScreenDebugMessage(-1, DeltaSeconds, FColor::Blue, FString::Printf(TEXT("Server Ping %f - TimeStamp %i"), PlayerState->ExactPing, GetLocalTime())); } else if (Role < ROLE_Authority) { GEngine->AddOnScreenDebugMessage(-1, DeltaSeconds, FColor::Green, FString::Printf(TEXT("Client Ping %f - TimeStamp %i"), PlayerState->ExactPing, GetNetworkTime())); } } }
void AFPSGWeapon::onPickedUp(class AActor* otherActor) { GEngine->AddOnScreenDebugMessage(-1, 6.0f, FColor::Red, "AFPSGWeapon::onPickedUp"); /* * Overlaps on AFPSGWeapon will only be executed on the server since only the server owns the boxCollisionComponent */ //Just return if we are a client (should not happen, but checks just in case) if (Role < ROLE_Authority && GetNetMode() == NM_Client) { return; } // Get the character that picked up the weapon AFPSGCharacter* theCharacter = Cast<AFPSGCharacter>(otherActor); if (theCharacter != NULL) { if (GEngine != NULL) { //GEngine->AddOnScreenDebugMessage(-1, 6.0f, FColor::Red, TEXT("AFPSGWeapon::onPickedUp")); } theCharacter->manageWeapon(this); } }
void AGameplayDebuggingReplicator::TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) { Super::TickActor(DeltaTime, TickType, ThisTickFunction); #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) UWorld* World = GetWorld(); if (!IsGlobalInWorld() || !World || GetNetMode() == ENetMode::NM_Client || !IGameplayDebugger::IsAvailable()) { // global level replicator don't have any local player and it's prepared to work only on servers return; } UGameInstance* GameInstance = World->GetGameInstance(); if (!GameInstance || !World->IsGameWorld()) { return; } PlayerControllersUpdateDelay -= DeltaTime; if (PlayerControllersUpdateDelay <= 0) { for (FConstPlayerControllerIterator Iterator = World->GetPlayerControllerIterator(); Iterator; Iterator++) { APlayerController* PC = *Iterator; if (PC) { IGameplayDebugger& Debugger = IGameplayDebugger::Get(); Debugger.CreateGameplayDebuggerForPlayerController(PC); } } PlayerControllersUpdateDelay = 5; } #endif }
void AGWWeaponRanged::EndReload() { if (Role < ROLE_Authority) { if (!CheckIfCanReload()) return; CalculateReloadAmmo(); ServerEndReload(); } else { /* Impelemtnsome reload mechanic.. 1. Where is ammo coming from ? 2. How it is setup ? 3. Does weapon have it's own magazine max ammo count, or is it stored externally ? */ if (!CheckIfCanReload()) return; CalculateReloadAmmo(); ReloadEndCount++; if (GetNetMode() == ENetMode::NM_Standalone) OnRep_ReloadEnd(); } }
void AFPSGPlayerController::onClickEndGame() const { //Make sure it is the server calling the function if (Role < ROLE_Authority && GetNetMode() == NM_Client) return; //GEngine->AddOnScreenDebugMessage(-1, 40.0f, FColor::Cyan, "AFPSGPlayerController::onClickEndGame"); IOnlineSubsystem* onlineSubsystem = IOnlineSubsystem::Get(); IOnlineSessionPtr sessions = onlineSubsystem != NULL ? onlineSubsystem->GetSessionInterface() : NULL; if (sessions.IsValid()) { UWorld* world = GetWorld(); AFPSGGameState* gameState = world != NULL ? world->GetGameState<AFPSGGameState>() : NULL; if (gameState != NULL) { //Retrieve the session state and match state EOnlineSessionState::Type sessionState = sessions->GetSessionState(GameSessionName); FName matchState = gameState->GetMatchState(); //Only attempt to end the game if both the session and match are in progress if (sessionState == EOnlineSessionState::Type::InProgress && matchState == MatchState::InProgress) { gameState->onClickEndGame(); } } } }
void ANimModCharacter::PostInitializeComponents() { Super::PostInitializeComponents(); if (Role == ROLE_Authority) { Health = GetMaxHealth(); SpawnDefaultInventory(); } // set initial mesh visibility (3rd person view) UpdatePawnMeshes(); // create material instance for setting team colors (3rd person view) for (int32 iMat = 0; iMat < GetMesh()->GetNumMaterials(); iMat++) { MeshMIDs.Add(GetMesh()->CreateAndSetMaterialInstanceDynamic(iMat)); } // play respawn effects if (GetNetMode() != NM_DedicatedServer) { if (RespawnFX) { UGameplayStatics::SpawnEmitterAtLocation(this, RespawnFX, GetActorLocation(), GetActorRotation()); } if (RespawnSound) { UGameplayStatics::PlaySoundAtLocation(this, RespawnSound, GetActorLocation()); } } }
void UGISInventoryBaseComponent::AddItemToInventory(class UGISItemData* ItemIn) { if (GetOwnerRole() < ROLE_Authority) { ServerAddItemToInventory(ItemIn); } else { //add item to first empty slot in first matching tab. for (FGISTabInfo& TabInfo : Tabs.InventoryTabs) { for (FGISSlotInfo& Slot : TabInfo.TabSlots) { if (Slot.ItemData == nullptr) { Slot.ItemData = ItemIn; //Slot.ItemData->OnItemRemovedFromSlot(); SlotUpdateInfo.TabIndex = TabInfo.TabIndex; SlotUpdateInfo.SlotIndex = Slot.SlotIndex; SlotUpdateInfo.SlotData = Slot.ItemData; SlotUpdateInfo.SlotComponent = this; if (GetNetMode() == ENetMode::NM_Standalone) OnItemAdded.Broadcast(SlotUpdateInfo); ClientUpdateInventory(SlotUpdateInfo); return; } } } } }
void AController::InitPlayerState() { if ( GetNetMode() != NM_Client ) { UWorld* const World = GetWorld(); AGameMode* const GameMode = World ? World->GetAuthGameMode() : NULL; if (GameMode != NULL) { FActorSpawnParameters SpawnInfo; SpawnInfo.Owner = this; SpawnInfo.Instigator = Instigator; SpawnInfo.bNoCollisionFail = true; SpawnInfo.ObjectFlags |= RF_Transient; // We never want player states to save into a map PlayerState = World->SpawnActor<APlayerState>(GameMode->PlayerStateClass, SpawnInfo ); // force a default player name if necessary if (PlayerState && PlayerState->PlayerName.IsEmpty()) { // don't call SetPlayerName() as that will broadcast entry messages but the GameMode hasn't had a chance // to potentially apply a player/bot name yet PlayerState->PlayerName = GameMode->DefaultPlayerName.ToString(); } } } }
void ARadiantWebViewActor::BindDynamicMaterial() { if ((GetNetMode() != NM_DedicatedServer) && MeshComponent && (WebViewRenderComponent->WebView->WebViewCanvas)) { if (OldMeshMaterial) { MeshComponent->SetMaterial(OldMaterialIndex, OldMeshMaterial); } OldMeshMaterial = MeshComponent->GetMaterial(MaterialIndex); if (WebViewMID) { WebViewMID->MarkPendingKill(); } if (ReplaceMaterial) { WebViewMID = UMaterialInstanceDynamic::Create(ReplaceMaterial, GetTransientPackage()); } else if (OldMeshMaterial) { WebViewMID = UMaterialInstanceDynamic::Create(OldMeshMaterial, GetTransientPackage()); } if (WebViewMID) { WebViewMID->SetTextureParameterValue(TEXT("WebViewTexture"), WebViewRenderComponent->WebView->WebViewCanvas->RenderTargetTexture); } } }
void AGameNetworkManager::UpdateNetSpeeds(bool bIsLanMatch) { // Don't adjust net speeds for LAN matches or dedicated servers ENetMode NetMode = GetNetMode(); if ( (NetMode == NM_DedicatedServer) || (NetMode == NM_Standalone) || bIsLanMatch ) { return; } if ( GetWorld()->TimeSeconds - LastNetSpeedUpdateTime < 1.0f ) { GetWorldTimerManager().SetTimer(TimerHandle_UpdateNetSpeedsTimer, this, &AGameNetworkManager::UpdateNetSpeedsTimer, 1.0f); return; } LastNetSpeedUpdateTime = GetWorld()->TimeSeconds; int32 NewNetSpeed = CalculatedNetSpeed(); UE_LOG(LogNet, Log, TEXT("New Dynamic NetSpeed %i vs old %i"), NewNetSpeed, AdjustedNetSpeed); if ( AdjustedNetSpeed != NewNetSpeed ) { AdjustedNetSpeed = NewNetSpeed; for( FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator ) { (*Iterator)->SetNetSpeed(AdjustedNetSpeed); } } }
void UGSAbilitiesComponent::GiveAbilityAndInsert(TSubclassOf<class UGSAbility> AbilityIn) { if (GetOwnerRole() < ROLE_Authority) { ServerGiveAbilityAndInsert(AbilityIn); } else { int32 abIndex = AddAbilityToActiveList(AbilityIn); if (abIndex != -1) { for (FGSAbilitiesSets& set : AbilitySets) { for (FGSAbilitySlot& slot : set.AbilitySlots) { if (slot.AbilityIndex == -1) { set.RepMe++; slot.AbilityIndex = abIndex; if (GetNetMode() == ENetMode::NM_Standalone) OnAbilityAddedToSet.ExecuteIfBound(); return; } } } } } }
void UGSAbilitiesComponent::GiveAbility(TSubclassOf<class UGSAbility> AbilityIn) { if (GetOwnerRole() < ROLE_Authority) { ServerGiveAbility(AbilityIn); } else { //ok this is very basic implementation, which will simply add ability to the first available slot. for (FGSAbilityBookTab& tab : OwnedAbilities.AbilitiesTab) { for (FGSAbilityBookSlot& slot : tab.Abilities) { if (slot.AbilityClass == nullptr) { slot.AbilityClass = AbilityIn; slot.bIsAbilityActive = true; slot.bIsAbilityVisible = true; break; } } } //make sure changes are replicated back. OwnedAbilities.ForceRep++; if (GetNetMode() == ENetMode::NM_Standalone) OnRep_OwnedAbilities(); } }
void AGameSession::UpdateSessionJoinability(FName InSessionName, bool bPublicSearchable, bool bAllowInvites, bool bJoinViaPresence, bool bJoinViaPresenceFriendsOnly) { if (GetNetMode() != NM_Standalone) { UOnlineEngineInterface::Get()->UpdateSessionJoinability(GetWorld(), InSessionName, bPublicSearchable, bAllowInvites, bJoinViaPresence, bJoinViaPresenceFriendsOnly); } }
void ACharacter::PostInitializeComponents() { Super::PostInitializeComponents(); if (!IsPendingKill()) { if (Mesh) { BaseTranslationOffset = Mesh->RelativeLocation; BaseRotationOffset = Mesh->RelativeRotation.Quaternion(); // force animation tick after movement component updates if (Mesh->PrimaryComponentTick.bCanEverTick && CharacterMovement) { Mesh->PrimaryComponentTick.AddPrerequisite(CharacterMovement, CharacterMovement->PrimaryComponentTick); } } if (CharacterMovement && CapsuleComponent) { CharacterMovement->UpdateNavAgent(*CapsuleComponent); } if (Controller == NULL && GetNetMode() != NM_Client) { if (CharacterMovement && CharacterMovement->bRunPhysicsWithNoController) { CharacterMovement->SetDefaultMovementMode(); } } } }
void ASWeaponInstant::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir) { if (MyPawn && MyPawn->IsLocallyControlled() && GetNetMode() == NM_Client) { // If we are a client and hit something that is controlled by server if (Impact.GetActor() && Impact.GetActor()->GetRemoteRole() == ROLE_Authority) { // Notify the server of our local hit to validate and apply actual hit damage. ServerNotifyHit(Impact, ShootDir); } else if (Impact.GetActor() == nullptr) { if (Impact.bBlockingHit) { ServerNotifyHit(Impact, ShootDir); } else { ServerNotifyMiss(ShootDir); } } } // Process a confirmed hit. ProcessInstantHitConfirmed(Impact, Origin, ShootDir); }
void APlayerCameraManager::AssignViewTarget(AActor* NewTarget, FTViewTarget& VT, struct FViewTargetTransitionParams TransitionParams) { if( !NewTarget || (NewTarget == VT.Target) ) { return; } // UE_LOG(LogPlayerCameraManager, Log, TEXT("%f AssignViewTarget OldTarget: %s, NewTarget: %s, BlendTime: %f"), GetWorld()->TimeSeconds, VT.Target ? *VT.Target->GetFName().ToString() : TEXT("NULL"), // NewTarget ? *NewTarget->GetFName().ToString() : TEXT("NULL"), // TransitionParams.BlendTime); AActor* OldViewTarget = VT.Target; VT.Target = NewTarget; // Use default FOV and aspect ratio. VT.POV.AspectRatio = DefaultAspectRatio; VT.POV.FOV = DefaultFOV; if (OldViewTarget) { OldViewTarget->EndViewTarget(PCOwner); } VT.Target->BecomeViewTarget(PCOwner); if (!PCOwner->IsLocalPlayerController() && (GetNetMode() != NM_Client)) { PCOwner->ClientSetViewTarget(VT.Target, TransitionParams); } }
void AAWeapon::HandleFiring() { if (CurrentAmmoInClip > 0 && CanFire()) { if (GetNetMode() != NM_DedicatedServer) { SimulateWeaponFire(); } if (MyPawn && MyPawn->IsLocallyControlled()) { FireWeapon(); UseAmmo(); BurstCounter++; } } else if (CanReload()) { StartReload(); } else if (MyPawn && MyPawn->IsLocallyControlled()) { if (GetCurrentAmmo() == 0 && !bRefiring) { PlayWeaponSound(OutOfAmmoSound); } /* Reload after firing last round */ if (CurrentAmmoInClip <= 0 && CanReload()) { StartReload(); } /* Stop weapon fire FX, but stay in firing state */ if (BurstCounter > 0) { OnBurstFinished(); } } if (MyPawn && MyPawn->IsLocallyControlled()) { if (Role < ROLE_Authority) { ServerHandleFiring(); } /* Retrigger HandleFiring on a delay for automatic weapons */ bRefiring = (CurrentState == EWeaponState::Firing && TimeBetweenShots > 0.0f); if (bRefiring) { GetWorldTimerManager().SetTimer(TimerHandle_HandleFiring, this, &AAWeapon::HandleFiring, TimeBetweenShots, false); } } LastFireTime = GetWorld()->GetTimeSeconds(); }
void UGripMotionControllerComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // Moved this here instead of in the polling function, it was ticking once per frame anyway so no loss of perf // It doesn't need to be there and now I can pre-check // Also epics implementation in the polling function didn't work anyway as it was based off of playercontroller which is not the owner of this controller // Cache state from the game thread for use on the render thread // No need to check if in game thread here as tick always is bHasAuthority = IsLocallyControlled(); bIsServer = IsServer(); // Server/remote clients don't set the controller position in VR // Don't call positional checks and don't create the late update scene view if (bHasAuthority) { if (!ViewExtension.IsValid() && GEngine) { TSharedPtr< FViewExtension, ESPMode::ThreadSafe > NewViewExtension(new FViewExtension(this)); ViewExtension = NewViewExtension; GEngine->ViewExtensions.Add(ViewExtension); } // This is the owning player, now you can get the controller's location and rotation from the correct source FVector Position; FRotator Orientation; bTracked = PollControllerState(Position, Orientation); if (bTracked) { SetRelativeLocationAndRotation(Position, Orientation); } if (!bTracked && !bUseWithoutTracking) return; // Don't update anything including location // Don't bother with any of this if not replicating transform if (bReplicates && bTracked) { ReplicatedControllerTransform.Position = Position; ReplicatedControllerTransform.Orientation = Orientation; if (GetNetMode() == NM_Client)//bReplicateControllerTransform) { ControllerNetUpdateCount += DeltaTime; if (ControllerNetUpdateCount >= (1.0f / ControllerNetUpdateRate)) { ControllerNetUpdateCount = 0.0f; Server_SendControllerTransform(ReplicatedControllerTransform); } } } } // Process the gripped actors TickGrip(); }
void AUTBetrayalPlayerState::UpdateTeam(AUTBetrayalTeam* Team) { if (GetNetMode() != NM_DedicatedServer) { // for listen server support, call notify team change locally NotifyTeamChanged(); } }