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 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(); } } } }