void UARAttributeBaseComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); /* Client only. When client get replicaated version of ActivePeriodicEffects, we run simulation on it. so we don't need to get timing from server each time. */ if (GetOwnerRole() < ROLE_Authority) { for (auto It = ActivePeriodicEffects.ActiveEffects.CreateIterator(); It; ++It) { //if (ActivePeriodicEffects.ActiveEffects[It.GetIndex()].PeriodicEffect == PeriodicEffect) //{ //if (effect.IsEffectActive) //{ ActivePeriodicEffects.ActiveEffects[It.GetIndex()].ClientCurrentDuration += DeltaTime; if (ActivePeriodicEffects.ActiveEffects[It.GetIndex()].ClientCurrentDuration >= ActivePeriodicEffects.ActiveEffects[It.GetIndex()].MaxDuration) { ActivePeriodicEffects.ActiveEffects[It.GetIndex()].ClientCurrentDuration = 0; ActivePeriodicEffects.ActiveEffects[It.GetIndex()].IsEffectActive = false; } //} //} } //for (FPeriodicEffect& effect : ActivePeriodicEffects.ActiveEffects) //{ // //if (effect.IsEffectActive) // //{ // effect.ClientCurrentDuration += DeltaTime; // if (effect.ClientCurrentDuration >= effect.MaxDuration) // { // effect.ClientCurrentDuration = 0; // effect.IsEffectActive = false; // } // //} //} } //so we tick effects in struct. Maybe it's not best idea, but it's the only one I have right now... //we need to tick them on client for cosmetic as well if (GetOwnerRole() == ROLE_Authority) { for (FPeriodicEffect& effect : ActivePeriodicEffects.ActiveEffects) { effect.Tick(DeltaTime); } } }
void UAREquipmentComponent::AddItemToInventory(FInventorySlot NewItem) { if (GetOwnerRole() < ROLE_Authority) { ServerAddItemToInventory(NewItem); } else { //if (TargetController) //{ // if (ItemSlot == EItemSlot::Item_Chest) // { // UARItemDataAsset* ItemDataAsset = Cast<UARItemDataAsset>(StaticLoadObject(UARItemDataAsset::StaticClass(), NULL, *ChestItemDataAssetPath, NULL, LOAD_None, NULL)); // if (ItemDataAsset && ItemDataAsset->Items.Num() > 0) // { // for (FARItemInfo& item : ItemDataAsset->Items) // { // if (item.ItemID == ItemID) // { // FInventorySlot it; // it.ItemID = item.ItemID; // it.ItemSlot = item.ItemSlot; // TargetController->InventorySmall.Add(it); // //TargetController->Inventory.Add(item); // break; // } // } // } // } //} } }
void UARAttributeBaseComponent::AddPeriodicEffect(FEffectSpec& PeriodicEffect) { /* there are two solutions. Create client only effect and just create server only and replicate it back to client. */ if (GetOwnerRole() < ROLE_Authority) { //server function here should be - Yoda //PeriodicEffect.PeriodicEffect->Initialze(); //PeriodicEffect.IsEffectActive = true; //ActiveClientEffects.AddUnique(PeriodicEffect); } else { PeriodicEffect.ActorEffect->Initialze(); ActiveEffects.Effects.Add(PeriodicEffect); PeriodicEffect.IsActive = true; AttachEffectCue(PeriodicEffect); if (PeriodicEffect.ActorEffect) { UARAttributeBaseComponent* causerCauserAttr = PeriodicEffect.ActorEffect->EffectCauser->FindComponentByClass<UARAttributeBaseComponent>(); if (causerCauserAttr) { causerCauserAttr->OnPeriodicEffectInstigated.Broadcast(PeriodicEffect.OwnedTags); } } OnPeriodicEffectAppiled.Broadcast(PeriodicEffect.OwnedTags); } }
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 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 UAREquipmentComponent::InitializeComponent() { Super::InitializeComponent(); if (GetOwnerRole() == ROLE_Authority) { if (ActiveLeftHandWeapon) { } if (!ActiveRightHandWeapon) { AARCharacter* MyChar = Cast<AARCharacter>(GetOwner()); //AARCharacter* MyChar = Cast<AARCharacter>(GetOuterAARPlayerController()->GetPawn()); FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = MyChar; ActiveRightHandWeapon = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); if (ActiveRightHandWeapon) { //ActiveRightHandWeapon->ItemName = Weapon.ItemID; ActiveRightHandWeapon->SetOwner(MyChar); ActiveRightHandWeapon->Instigator = MyChar; ActiveRightHandWeapon->WeaponOwner = MyChar; ActiveRightHandWeapon->OwningController = TargetController; } } } }
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; } } } } } }
bool UAREquipmentComponent::ChangeChestItem(FARDragDropInfo ItemIn) { FStreamableManager& Loader = UARSingleton::Get().AssetLoader; TArray<FStringAssetReference> ObjToLoad; //UBlueprint* gen = Cast<UBlueprint>(itemObj); //this can be called by both client and server //server need to do it, to propagate mesh change //to other players. //and client FString usless; FARItemData* data = ChestItemDataTable->FindRow<FARItemData>(ItemIn.ItemKey, usless); if (data) { UBlueprint* gen = LoadObject<UBlueprint>(NULL, *data->ItemBlueprint.ToStringReference().ToString(), NULL, LOAD_None, NULL); if (!gen) return false; TArray<FStringAssetReference> ObjToLoad; FStreamableManager& Loader = UARSingleton::Get().AssetLoader; AARCharacter* MyChar = Cast<AARCharacter>(GetOwner()); FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = MyChar; AARArmor* itemBase = GetWorld()->SpawnActor<AARArmor>(gen->GeneratedClass, SpawnInfo); itemBase->SetOwner(MyChar); itemBase->Instigator = MyChar; itemBase->ItemID = ItemIn.ItemKey; itemBase->ItemSlotEquipped = ItemIn.ItemSlot; if (itemBase) { for (int32 itemIdx = 0; itemIdx < EquippedItems.Num(); itemIdx++) { if (EquippedItems[itemIdx]->IsA(itemBase->GetClass())) { EquippedItems[itemIdx]->Destroy(); EquippedItems.RemoveAt(itemIdx); } } EquippedItems.AddUnique(itemBase); ChestMeshToLoad = itemBase->ArmorMesh.ToStringReference(); ObjToLoad.AddUnique(ChestMeshToLoad); Loader.RequestAsyncLoad(ObjToLoad, FStreamableDelegate::CreateUObject(this, &UAREquipmentComponent::DoAsyncChestChange)); ChestItem = ItemIn; return true; } //this is only for server //because here we will be changing character stats if (GetOwnerRole() == ROLE_Authority) { } } return false; }
void UGISInventoryBaseComponent::LootOneItem(int32 ItemIndex) { if (GetOwnerRole() < ROLE_Authority) { SeverLootOneItem(ItemIndex); } else { if (CurrentPickupActor) { // UGISItemData* test = ConstructObject<UGISItemData>(CurrentPickupActor->ItemToLoot[ItemIndex]->GetClass(), this, NAME_None, RF_NoFlags, CurrentPickupActor->ItemToLoot[ItemIndex]); //if it is not valid index both arrays, then something is wrong. if (LootedItems.IsValidIndex(ItemIndex) && CurrentPickupActor->ItemToLoot.IsValidIndex(ItemIndex)) { AddItemToInventory(LootedItems[ItemIndex]); //ok we removed one item. We need to rconstruct widgets, indexes etc, to make sure arry //have proper indexes in first place. LootedItems.RemoveAt(ItemIndex, 1, true); CurrentPickupActor->ItemToLoot.RemoveAt(ItemIndex, 1, true); } //reconstruct widget. // CurrentPickupActor->ItemToLoot = LootedItems; // ClientReconstructLootWidget(); } } }
void UARAbilityComponent::InitializeComponent() { Super::InitializeComponent(); if (GetOwnerRole() == ROLE_Authority) { ActionBars.ActionBars.Empty(ActionBars.ActionBars.Num()); FActionSlotContainer asc; asc.ActionBarIndex = 0; for (int32 Idx = 0; Idx < 5; Idx++) { FActionSlotInfo asi; asi.SlotIndex = Idx; asi.ActionBarIndex = 0; asc.ActionSlots.Add(asi); } ActionBars.ActionBars.Add(asc); FActionSlotInfo abTest; abTest.ActionIndex = 0; AbilityBook.Add(abTest); } }
void UAREquipmentComponent::ChangeLegItem(FName ItemName) { //this can be called by both client and server //server need to do it, to propagate mesh change //to other players. //and client UARItemDataAsset* ItemDataAsset = Cast<UARItemDataAsset>(StaticLoadObject(UARItemDataAsset::StaticClass(), NULL, *LegItemDataAssetPath, NULL, LOAD_None, NULL)); if (ItemDataAsset && ItemDataAsset->Items.Num() > 0) { TArray<FStringAssetReference> ObjToLoad; FStreamableManager& Loader = UARSingleton::Get().AssetLoader; //do it this way until I figure out predicate... for (FARItemInfo& item : ItemDataAsset->Items) { if (item.ItemName == ItemName) { LegMeshToLoad = item.ItemMesh.ToStringReference(); ObjToLoad.AddUnique(LegMeshToLoad); Loader.RequestAsyncLoad(ObjToLoad, FStreamableDelegate::CreateUObject(this, &UAREquipmentComponent::DoAsyncChestChange)); //ChestItem = item.ItemName; return; } } } //this is only for server //because here we will be changing character stats if (GetOwnerRole() == ROLE_Authority) { } //return false; }
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 UGASAbilitiesComponent::InputPressed(int32 AbilityId) { //if we can't activate ability there is no reason to go further. if (AbilityId < 0) return; if (!CanActivateAbility()) return; if (GetOwnerRole() < ENetRole::ROLE_Authority) { //no ability on client. No RPC. if (InstancedAbilities[AbilityId].ActiveAbility) { InstancedAbilities[AbilityId].ActiveAbility->InputPressed(); ServerInputPressed(AbilityId); } //right now we will use simple prediction, which means just run ability on client //and then use RPCs/repnotifies from server to controll it state on clien, //so we won't get out of sync to much. } else { if (InstancedAbilities[AbilityId].ActiveAbility) InstancedAbilities[AbilityId].ActiveAbility->InputPressed(); } }
// Called every frame void UAimPredictionSC::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); ///Apply Smooth Rotation if in Clients if (GetOwnerRole() == ROLE_SimulatedProxy) { smoothRotation(); } else { ///Manual set Replicated Rotation if (GetOwnerRole() == ROLE_Authority) { replicatedRotation = RelativeRotation; } } }
void UAimPredictionSC::OnRep_setNewCurrentRotation() { if (GetOwnerRole() == ROLE_SimulatedProxy) { ///set and swap new rotation //currentRotation = RelativeRotation; nextRotation = replicatedRotation; if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("AAAAAA")); } }
void UGASAbilitiesComponent::InputReleased(int32 AbilityId) { if (GetOwnerRole() < ENetRole::ROLE_Authority) { ServerInputReleased(AbilityId); } else { } }
void UAREquipmentComponent::EquipItem(FARDragDropInfo ItemIn) { if (GetOwnerRole() < ROLE_Authority) { ServerEquipItem(ItemIn); } else { } }
void UGISInventoryBaseComponent::CopyItemsFromOtherInventoryTab(class UGISInventoryBaseComponent* OtherIn, int32 TargetTabIndex) { if (GetOwnerRole() < ROLE_Authority) { ServerCopyItemsFromOtherInventoryTab(OtherIn, TargetTabIndex); } else { if (OtherIn) { OtherIn->SetLastTargetTab(TargetTabIndex); OtherIn->SetLastOtherOriginInventory(this); LastTargetTab = TargetTabIndex; LastOtherOriginInventory = OtherIn; int32 OtherTabCount = OtherIn->Tabs.InventoryTabs.Num(); for (int32 TabIndex = 0; TabIndex < OtherTabCount; TabIndex++) { if (LastOtherOriginTab != TabIndex) { OtherIn->SetLastOtherOriginTab(TabIndex); LastOtherOriginTab = TabIndex; int32 TargetItemCount = GetSlotsInTab(TargetTabIndex); int32 OtherItemCount = Tabs.InventoryTabs[TabIndex].TabSlots.Num(); //check which item count is bigger //to avoid copying into non existend array elements. //we always count against smaller. if (OtherItemCount > TargetItemCount) { for (int32 Index = 0; Index < TargetItemCount; Index++) { SetItemDataInSlot(TargetTabIndex, Index, OtherIn->GetItemDataInSlot(TabIndex, Index)); OnCopyItemsFromOtherInventoryTab(Tabs.InventoryTabs[TargetTabIndex].TabSlots[Index].ItemData); } } else { for (int32 Index = 0; Index < OtherItemCount; Index++) { SetItemDataInSlot(TargetTabIndex, Index, OtherIn->GetItemDataInSlot(TabIndex, Index)); OnCopyItemsFromOtherInventoryTab(Tabs.InventoryTabs[TargetTabIndex].TabSlots[Index].ItemData); } } TabUpdateInfo.ReplicationCounter++; TabUpdateInfo.TargetTabIndex = TargetTabIndex; if (GetNetMode() == ENetMode::NM_Standalone) OnTabChanged.ExecuteIfBound(TabUpdateInfo.TargetTabIndex); return; } } } } }
void UARAbilityComponent::SetActiveAbility(int32 SlotID, int32 ActionBarIndex) { if (GetOwnerRole() < ROLE_Authority) { ServerSetActiveAbility(SlotID, ActionBarIndex); } else { ActiveAction = ActionBars.ActionBars[ActionBarIndex].ActionSlots[SlotID]; } }
void UARActionStateComponent::StopAction() { if (GetOwnerRole() < ROLE_Authority) { ServerStopAction(); EndActionSequence(); } else { EndActionSequence(); } }
void UGISInventoryBaseComponent::LootOneItem(int32 ItemIndex) { if (GetOwnerRole() < ROLE_Authority) { //if (LootFromPickup.Loot.IsValidIndex(ItemIndex) && CurrentPickupActor->ItemToLoot.IsValidIndex(ItemIndex)) // CurrentPickupActor->ItemToLoot.RemoveAt(ItemIndex); SeverLootOneItem(ItemIndex); } else { if (CurrentPickupActor) { //if it is not valid index both arrays, then something is wrong. if (LootFromPickup.Loot.IsValidIndex(ItemIndex) && CurrentPickupActor->ItemToLoot.IsValidIndex(ItemIndex)) { AddItemToInventory(LootFromPickup.Loot[ItemIndex].SlotData); //ok we removed one item. We need to rconstruct widgets, indexes etc, to make sure arry //have proper indexes in first place. //LootFromPickup.Loot.RemoveAtSwap(ItemIndex, 1, false); LootFromPickup.Loot.RemoveAt(ItemIndex); CurrentPickupActor->ItemToLoot.RemoveAt(ItemIndex); int32 ItemNum = CurrentPickupActor->ItemToLoot.Num(); LootFromPickup.Loot.Empty(); for (int32 ItemIdx = 0; ItemIdx < ItemNum; ItemIdx++) { FGISLootSlotInfo lootInfo; UGISItemData* dataDuplicate = ConstructObject<UGISItemData>(CurrentPickupActor->ItemToLoot[ItemIdx]->GetClass(), this, NAME_None, RF_NoFlags, CurrentPickupActor->ItemToLoot[ItemIdx]); lootInfo.OwningPickupActor = CurrentPickupActor; lootInfo.SlotComponent = this; lootInfo.SlotIndex = ItemIdx; lootInfo.SlotData = dataDuplicate; LootFromPickup.Loot.Add(lootInfo); } //if there is nothing to loot, and looting widget is visible, this will hide it. if (LootFromPickup.Loot.Num() == 0) { SetComponentTickEnabled(false); ClientSwitchLootingWidget(); } LootFromPickup.ForceRep++; CurrentPickupActor->OnLooted(); } //reconstruct widget. if (GetNetMode() == ENetMode::NM_Standalone) { OnRep_LootedItems(); } } } }
void UAREquipmentComponent::ChangeItem(FARDragDropInfo ItemIn, int32 OldItemSlotID) { bool itemRemoved = false; if (GetOwnerRole() < ROLE_Authority) { ServerChangeItem(ItemIn, OldItemSlotID); } else { //check if there is something in that particular slot for (AARItem* eqItem : EquippedItems) { if (eqItem->ItemSlotEquipped == ItemIn.ItemSlot) { FARDragDropInfo tempItem; tempItem.ItemKey = eqItem->ItemID; tempItem.ItemSlot = eqItem->ItemSlotEquipped; //if there is, Unequip it. Before we proceed. UnEquipItem(ItemIn); itemRemoved = Inventory->RemoveItemFromInventory(ItemIn.ItemKey, ItemIn.SlotIndex); Inventory->AddItemToInventoryOnSlot(tempItem, OldItemSlotID); } } switch (ItemIn.DragDropSlot) { case EDragDropSlot::Chest: { if (ChangeChestItem(ItemIn)) { if (!itemRemoved) { Inventory->RemoveItemFromInventory(ItemIn.ItemKey, ItemIn.SlotIndex); break; } } break; } case EDragDropSlot::LeftHand: { AddWeapon(ItemIn, OldItemSlotID, 0); } case EDragDropSlot::RightHand: { AddWeapon(ItemIn, OldItemSlotID, 1); } default: break; } } }
void UGISInventoryBaseComponent::InitializeComponent() { Super::InitializeComponent(); ENetRole CurrentRole = GetOwnerRole(); ENetMode CurrentNetMode = GetNetMode(); //PrimaryComponentTick.bStartWithTickEnabled = bTickInventory; if (CurrentRole == ROLE_Authority || CurrentNetMode == ENetMode::NM_Standalone) { InitializeInventoryTabs(); } }
bool UAREquipmentComponent::RemoveWeapon(FName Weapon, int32 SlotID, int32 Hand) { if (GetOwnerRole() < ROLE_Authority) { ServerRemoveWeapon(Weapon, SlotID, Hand); } else { if (Hand == 0) { for (FARDragDropInfo& item : LeftHandWeapons) { if (item.SlotIndex == SlotID && item.ItemKey != NAME_None) { //we don't remove actually anything from array. //just change ID and slot types, to match an "empty" slot // in inventory. item.ItemKey = NAME_None; item.ItemIndex = INDEX_NONE; item.ItemSlot = EItemSlot::Item_Inventory; item.DragDropSlot = EDragDropSlot::LeftHand; LeftHandWeaponsUpdated = true; MulticastDetachWeaponSlotSwap(Weapon, Hand); return true; } } } else if (Hand == 1) { for (FARDragDropInfo& item : RightHandWeapons) { if (item.SlotIndex == SlotID && item.ItemKey != NAME_None) { //we don't remove actually anything from array. //just change ID and slot types, to match an "empty" slot // in inventory. item.ItemKey = NAME_None; item.ItemIndex = INDEX_NONE; item.ItemSlot = EItemSlot::Item_Inventory; item.DragDropSlot = EDragDropSlot::RightHand; RightHandWeaponsUpdated = true; MulticastDetachWeaponSlotSwap(Weapon, Hand); return true; } } } } return false; }
void UARActionStateComponent::StartAction() { //BeginActionSequence(); ENetRole rul = GetOwnerRole(); if (rul < ROLE_Authority) { ServerStartAction(); BeginActionSequence(); } else { OnActionPreCast.Broadcast(OwnedTags); BeginActionSequence(); } }
void UGISInventoryBaseComponent::PickItem(AActor* PickupItemIn) { if (GetOwnerRole() < ROLE_Authority) { ServerPickItem(PickupItemIn); } else { IIGISPickupItem* pickupItem = Cast<IIGISPickupItem>(PickupItemIn); if (pickupItem) { //do something, I'm not sure what yet. } } }
void UGISInventoryBaseComponent::InitializeComponent() { Super::InitializeComponent(); //if (!bHasBeenInitialized) //{ ENetRole CurrentRole = GetOwnerRole(); ENetMode CurrentNetMode = GetNetMode(); //PrimaryComponentTick.bStartWithTickEnabled = bTickInventory; if (CurrentRole == ROLE_Authority || CurrentNetMode == ENetMode::NM_Standalone) InitializeInventoryTabs(); if (CurrentRole < ROLE_Authority || CurrentNetMode == ENetMode::NM_Standalone) { if (InventoryContainerClass) { UObject* Outer = GetWorld()->GetGameInstance() ? StaticCast<UObject*>(GetWorld()->GetGameInstance()) : StaticCast<UObject*>(GetWorld()); InventoryContainer = ConstructObject<UGISContainerBaseWidget>(InventoryContainerClass, Outer); if (InventoryContainer) { ULocalPlayer* Player = World->GetFirstLocalPlayerFromController(); //temporary InventoryContainer->SetPlayerContext(FLocalPlayerContext(Player)); //temporary InventoryContainer->Initialize(); InventoryContainer->InventoryComponent = this; //call last InventoryContainer->InitializeContainer(); } } UObject* Outer = GetWorld()->GetGameInstance() ? StaticCast<UObject*>(GetWorld()->GetGameInstance()) : StaticCast<UObject*>(GetWorld()); if (LootWidgetClass) { LootWidget = ConstructObject<UGISLootContainerBaseWidget>(LootWidgetClass, Outer); if (LootWidget) { ULocalPlayer* Player = GetWorld()->GetFirstLocalPlayerFromController(); //temporary LootWidget->SetPlayerContext(FLocalPlayerContext(Player)); //temporary LootWidget->Initialize(); LootWidget->SetVisibility(ESlateVisibility::Hidden); } } } if (CurrentRole == ROLE_Authority || CurrentNetMode == ENetMode::NM_Standalone) ClientLoadInventory(); //} }
void UAREquipmentComponent::ChangeItem(FInventorySlot ItemIn, int32 OldItemSlotID) { bool itemRemoved = false; if (GetOwnerRole() < ROLE_Authority) { ServerChangeItem(ItemIn, OldItemSlotID); } else { //check if there is something in that particular slot for (AARItem* eqItem : EquippedItems) { if (eqItem->ItemSlotEquipped == ItemIn.ItemSlot) { FInventorySlot tempItem; tempItem.ItemID = eqItem->ItemID; tempItem.ItemSlot = eqItem->ItemSlotEquipped; //if there is, Unequip it. Before we proceed. UnEquipItem(ItemIn); itemRemoved = TargetController->RemoveItemFromInventory(ItemIn.ItemID, ItemIn.SlotID); TargetController->AddItemToInventoryOnSlot(tempItem, OldItemSlotID); } } switch (ItemIn.EEquipmentSlot) { case EEquipmentSlot::Item_Chest: { if (ChangeChestItem(ItemIn)) { if (!itemRemoved) { TargetController->RemoveItemFromInventory(ItemIn.ItemID, ItemIn.SlotID); break; } } break; } case EEquipmentSlot::Item_LeftHandOne: { AddLeftHandWeapon(ItemIn.ItemID); } default: break; } } }
FGAEffectHandle UGAAttributeComponent::ApplyEffectToSelf(const FGAEffectSpec& SpecIn, const FGAEffectContext& Context) { FGAEffectHandle handle; if (GetOwnerRole() < ROLE_Authority) { } else { handle = ActiveEffects.ApplyEffect(SpecIn, Context); } if (GetNetMode() == ENetMode::NM_Standalone) OnRep_ActiveEffects(); return handle; }
void UARAbilityComponent::AddAbilityToActionBar(FActionSlotInfo AbilityIn, int32 SlotID, int32 ActionBarIndex) { if (GetOwnerRole() < ROLE_Authority) { ServerAddAbilityToActionBar(AbilityIn, SlotID, ActionBarIndex); } else { ActionBars.ActionBars[ActionBarIndex].ActionSlots[SlotID].ActionIndex = AbilityIn.ActionIndex; ClientOnAbilityAdded(SlotID, ActionBarIndex); //if (ActionBarOne.Num() <= 5) //{ // //for (FAbilityInfo& ability : OwningController->AbilityInventory) // //{ // //if (ability.AbilityName == AbilityIn.AbilityName) // //{ // for (FAbilityInfo& abilityBar : ActionBarOne) // { // if (abilityBar.SlotID == SlotID) // { // if (abilityBar.Ability.IsValid()) // { // abilityBar.Ability->Destroy(); // abilityBar.Ability.Reset(); // } // if (!AbilityIn.AbilityType) // return; // FActorSpawnParameters SpawnInfo; // SpawnInfo.bNoCollisionFail = true; // AARAbility* tempAbi = GetWorld()->SpawnActor<AARAbility>(AbilityIn.AbilityType, SpawnInfo); // tempAbi->SetOwner(GetOwner()); // // abilityBar.AbilityName = AbilityIn.AbilityName; // abilityBar.Ability = tempAbi; // } // } // //} // //} //} } }