/* Spawn Weapon actor to Right hand and assign it to ActiveRightHandWeapon, Then attach weapon to socket of current character. When ActiveRightHandWeapon is set, it is replicated back to all clients, and SetAttachWeapon is called again to attach weapon mesh. */ void UAREquipmentComponent::SetRightWeapon(FInventorySlot Weapon, class AARWeapon* PrevWeapon) { if (PrevWeapon) { PrevWeapon->Destroy(); } FString usless; FARItemData* data = WeaponItemDataTable->FindRow<FARItemData>(Weapon.ItemID, usless); if (data) { UBlueprint* gen = LoadObject<UBlueprint>(NULL, *data->ItemBlueprint.ToStringReference().ToString(), NULL, LOAD_None, NULL); if (!gen) return; AARCharacter* MyChar = Cast<AARCharacter>(GetOwner()); //AARCharacter* MyChar = Cast<AARCharacter>(GetOuterAARPlayerController()->GetPawn()); FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = MyChar; AARWeapon* weaponBase = GetWorld()->SpawnActor<AARWeapon>(gen->GeneratedClass, SpawnInfo); weaponBase->ItemName = Weapon.ItemID; weaponBase->SetOwner(MyChar); weaponBase->Instigator = MyChar; weaponBase->WeaponOwner = MyChar; weaponBase->OwningController = TargetController; ActiveRightHandWeapon = weaponBase; OnRightWeaponActive.Broadcast(ActiveRightHandWeapon); SetAttachWeapon(ActiveRightHandWeapon, RightWeaponSocket); } }
/* Left hand weapons - right attachment slots. Right Hand weapons - left attachment slots. */ void UAREquipmentComponent::AttacheSheathedWeapon(TArray<FARDragDropInfo> WeaponsIn, TArray<FARAttachmentSocket> WeaponSocketsIn, int32 HandIn) { FString usless = ""; for (FARDragDropInfo& Weapon : WeaponsIn) { //if (Weapon.IsAttached) //{ FARItemInfo* data = TestItems->GetItemDataFromArrayPtr(Weapon.ItemIndex); if (data) { FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = TargetCharacter; AARWeapon* weaponBase; if (data->DefaultClass) weaponBase = GetWorld()->SpawnActor<AARWeapon>(data->DefaultClass, SpawnInfo); else weaponBase = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); weaponBase->ItemName = Weapon.ItemKey; weaponBase->ItemID = Weapon.ItemKey; weaponBase->ItemIndex = Weapon.ItemIndex; weaponBase->ItemInfo = data->ItemInfo; weaponBase->SetOwner(TargetCharacter); weaponBase->Instigator = TargetCharacter; weaponBase->WeaponOwner = TargetCharacter; if (HandIn == 0) weaponBase->WeaponHand = EWeaponHand::WeaponLeft; else if (HandIn == 1) weaponBase->WeaponHand = EWeaponHand::WeaponRight; /* I definetly need more nested if's here! */ for (FARAttachmentSocket& socket : WeaponSockets) { if (weaponBase->AttachmentType == socket.AttachType) { if (socket.IsSlotAvailable) { if (socket.SocketSide != HandIn) { socket.IsSlotAvailable = false; socket.LastItemID = Weapon.ItemKey; EquipedWeapons.Add(weaponBase); Weapon.IsAttached = true; SetSeathedWeapon(weaponBase, socket.SocketName); weaponBase->LastAttachmentSocket = socket.SocketName; } } } } } } }
void UAREquipmentComponent::MulticastAttacheSheathedWeapon_Implementation(FARDragDropInfo WeaponIn, int32 HandIn) { //FARItemData* data = WeaponItemDataTable->FindRow<FARItemData>(WeaponIn.ItemID, usless); FARItemInfo* data = TestItems->GetItemDataFromArrayPtr(WeaponIn.ItemIndex); if (data) { //UBlueprint* gen = LoadObject<UBlueprint>(NULL, *data->ItemBlueprint.ToStringReference().ToString(), NULL, LOAD_None, NULL); //if (!gen) // return; FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = TargetCharacter; AARWeapon* weaponBase; if (data->DefaultClass) weaponBase = GetWorld()->SpawnActor<AARWeapon>(data->DefaultClass, SpawnInfo); else weaponBase = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); weaponBase->ItemName = WeaponIn.ItemKey; weaponBase->ItemID = WeaponIn.ItemKey; weaponBase->ItemIndex = WeaponIn.ItemIndex; weaponBase->SetOwner(TargetCharacter); weaponBase->Instigator = TargetCharacter; weaponBase->WeaponOwner = TargetCharacter; weaponBase->ItemInfo = data->ItemInfo; if (HandIn == 0) weaponBase->WeaponHand = EWeaponHand::WeaponLeft; else if (HandIn == 1) weaponBase->WeaponHand = EWeaponHand::WeaponRight; /* I definetly need more nested if's here! */ for (FARAttachmentSocket& socket : WeaponSockets) { if (weaponBase->AttachmentType == socket.AttachType) { if (socket.IsSlotAvailable) { if (socket.SocketSide != HandIn) { socket.IsSlotAvailable = false; socket.LastItemID = WeaponIn.ItemKey; EquipedWeapons.Add(weaponBase); //WeaponIn.IsAttached = true; SetSeathedWeapon(weaponBase, socket.SocketName); weaponBase->LastAttachmentSocket = socket.SocketName; } } } } } }
void UAREquipmentComponent::AttachSheathhWeaponOnSwap_Implementation(class AARWeapon* LastWeapon, const TArray<FARAttachmentSocket>& WeaponSocketsIn, int32 HandIn) { //FString usless = ""; //if (!WeaponIn.IsAttached) //{ //FARItemData* data = WeaponItemDataTable->FindRow<FARItemData>(LastWeapon->ItemID, usless); FARItemInfo* data = TestItems->GetItemDataFromArrayPtr(LastWeapon->ItemIndex); if (data) { FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = TargetCharacter; AARWeapon* weaponBase; if (data->DefaultClass) weaponBase = GetWorld()->SpawnActor<AARWeapon>(data->DefaultClass, SpawnInfo); else weaponBase = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); weaponBase->ItemName = LastWeapon->ItemID; weaponBase->ItemID = LastWeapon->ItemID; weaponBase->ItemIndex = LastWeapon->ItemIndex; weaponBase->SetOwner(TargetCharacter); weaponBase->Instigator = TargetCharacter; weaponBase->WeaponOwner = TargetCharacter; weaponBase->WeaponHand = EWeaponHand::WeaponLeft; weaponBase->ItemInfo = data->ItemInfo; for (FARAttachmentSocket& socket : WeaponSockets) { if (weaponBase->AttachmentType == socket.AttachType) { if (socket.IsSlotAvailable) { if (socket.SocketSide != HandIn) { socket.IsSlotAvailable = false; socket.LastItemID = LastWeapon->ItemID; EquipedWeapons.Add(weaponBase); //Weapon.IsAttached = true; SetSeathedWeapon(weaponBase, socket.SocketName); weaponBase->LastAttachmentSocket = socket.SocketName; } } } } } //} }
void UAREquipmentComponent::SetWeapon(FARDragDropInfo Weapon, class AARWeapon* PrevWeapon, int32 Hand) { if (Hand == 0) { if (PrevWeapon) { AttachSheathhWeaponOnSwap(PrevWeapon, WeaponSockets, Hand); PrevWeapon->Destroy(); } FARItemInfo* data = TestItems->GetItemDataFromArrayPtr(Weapon.ItemIndex); if (data) { AARCharacter* MyChar = Cast<AARCharacter>(GetOwner()); //AARCharacter* MyChar = Cast<AARCharacter>(GetOuterAARPlayerController()->GetPawn()); FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = MyChar; AARWeapon* weaponBase; if (data->DefaultClass) weaponBase = GetWorld()->SpawnActor<AARWeapon>(data->DefaultClass, SpawnInfo); else weaponBase = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); weaponBase->ItemName = Weapon.ItemKey; weaponBase->ItemID = Weapon.ItemKey; weaponBase->ItemIndex = Weapon.ItemIndex; weaponBase->SetOwner(MyChar); weaponBase->Instigator = MyChar; weaponBase->WeaponOwner = MyChar; weaponBase->WeaponHand = EWeaponHand::WeaponLeft; weaponBase->ItemInfo = data->ItemInfo; ActiveLeftHandWeapon = weaponBase; //ActiveLeftHandWeapon->OnWeaponActive(); //OnRightWeaponActive.Broadcast(ActiveLeftHandWeapon); ActiveLeftHandWeapon->Initialize(); OnLeftWeaponActive.Broadcast(ActiveLeftHandWeapon); MulticastDetachWeaponSlotSwap(Weapon.ItemKey, Hand); SetAttachWeapon(ActiveLeftHandWeapon, LeftWeaponSocket); } } else if (Hand == 1) { if (PrevWeapon) { PrevWeapon->Destroy(); } FARItemInfo* data = TestItems->GetItemDataFromArrayPtr(Weapon.ItemIndex); if (data) { AARCharacter* MyChar = Cast<AARCharacter>(GetOwner()); //AARCharacter* MyChar = Cast<AARCharacter>(GetOuterAARPlayerController()->GetPawn()); FActorSpawnParameters SpawnInfo; SpawnInfo.bNoCollisionFail = true; SpawnInfo.Owner = MyChar; AARWeapon* weaponBase; if (data->DefaultClass) weaponBase = GetWorld()->SpawnActor<AARWeapon>(data->DefaultClass, SpawnInfo); else weaponBase = GetWorld()->SpawnActor<AARWeapon>(AARWeapon::StaticClass(), SpawnInfo); weaponBase->ItemName = Weapon.ItemKey; weaponBase->ItemID = Weapon.ItemKey; weaponBase->ItemIndex = Weapon.ItemIndex; weaponBase->SetOwner(MyChar); weaponBase->Instigator = MyChar; weaponBase->WeaponOwner = MyChar; //weaponBase->OwningController = TargetController; weaponBase->WeaponHand = EWeaponHand::WeaponRight; weaponBase->ItemInfo = data->ItemInfo; ActiveRightHandWeapon = weaponBase; ActiveRightHandWeapon->Initialize(); OnRightWeaponActive.Broadcast(ActiveRightHandWeapon); //ActiveLeftHandWeapon->OnWeaponActive(); //OnRightWeaponActive.Broadcast(ActiveRightHandWeapon); MulticastDetachWeaponSlotSwap(Weapon.ItemKey, Hand); SetAttachWeapon(ActiveRightHandWeapon, RightWeaponSocket); } } }