void ASCharacter::DestroyInventory()
{
	if (Role < ROLE_Authority)
	{	
		return;
	}

	for (int32 i = Inventory.Num() - 1; i >= 0; i--)
	{
		ASWeapon* Weapon = Inventory[i];
		if (Weapon)
		{
			RemoveWeapon(Weapon, true);
		}
	}
}
void AAmethystCharacter::DestroyInventory()
{
	if (Role < ROLE_Authority)
	{
		return;
	}

	// remove all weapons from inventory and destroy them
	for (int32 i = Inventory.Num() - 1; i >= 0; i--)
	{
		AAmethystWeapon* Weapon = Inventory[i];
		if (Weapon)
		{
			RemoveWeapon(Weapon);
			Weapon->Destroy();
		}
	}
}
void FPSPlayerComponent::_OnKeyDown(const OIS::KeyEvent& event) {
    switch(event.key) {
    case OIS::KC_1:
        ChangeWeapon(0);
        break;
    case OIS::KC_2:
        ChangeWeapon(1);
        break;
    case OIS::KC_3:
        ChangeWeapon(2);
        break;
    case OIS::KC_4:
        ChangeWeapon(3);
        break;
    case OIS::KC_5:
        ChangeWeapon(4);
        break;
    case OIS::KC_6:
        ChangeWeapon(5);
        break;
    case OIS::KC_7:
        ChangeWeapon(6);
        break;
    case OIS::KC_8:
        ChangeWeapon(7);
        break;
    case OIS::KC_9:
        ChangeWeapon(8);
        break;
    case OIS::KC_G:
        if(mWeaponInUse != nullptr)
            RemoveWeapon(mWeaponInUse->GetType());
        break;
    case OIS::KC_R:
        if(mWeaponInUse != nullptr)
            mWeaponInUse->Reload();
        break;
    case OIS::KC_E:
        mGrabber->Check();
        break;
    default:
        return;
    }
}
void ASCharacter::DropWeapon()
{
	if (Role < ROLE_Authority)
	{
		ServerDropWeapon();
		return;
	}

	if (CurrentWeapon)
	{
		FVector CamLoc;
		FRotator CamRot;

		if (Controller == nullptr)
			return;

		/* Find a location to drop the item, slightly in front of the player. */
		Controller->GetPlayerViewPoint(CamLoc, CamRot);
		const FVector Direction = CamRot.Vector();
		const FVector SpawnLocation = GetActorLocation() + (Direction * DropItemDistance);

		FActorSpawnParameters SpawnInfo;
		SpawnInfo.bNoCollisionFail = true;
		ASWeaponPickup* NewWeaponPickup = GetWorld()->SpawnActor<ASWeaponPickup>(CurrentWeapon->WeaponPickupClass, SpawnLocation, FRotator::ZeroRotator, SpawnInfo);

		if (NewWeaponPickup)
		{
			/* Apply torque to make it spin when dropped. */
			UStaticMeshComponent* MeshComp = NewWeaponPickup->GetMeshComponent();
			if (MeshComp)
			{
				MeshComp->SetSimulatePhysics(true);
				MeshComp->AddTorque(FVector(1, 1, 1) * 4000000);
			}
		}

		RemoveWeapon(CurrentWeapon);
	}
}
示例#5
0
void ANimModCharacter::DestroyInventory()
{
	for (ANimModWeapon *nimModWeapon : Inventory)
	{
		if (nimModWeapon)
		{
			RemoveWeapon(nimModWeapon);
			if (Role == ROLE_Authority)
				nimModWeapon->Destroy();
		}
		/*InventorySlot slot = slotKVP.Value;
		while (slot.Num() != 0)
		{
			InventorySlot::TIterator iter = slot.CreateIterator();
			ANimModWeapon *weapon = iter.Value;
			if (weapon)
			{
				RemoveWeapon(weapon);
				weapon->Destroy();
			}
		}*/
	}
}
void ASCharacter::DropWeapon()
{
	if (Role < ROLE_Authority)
	{
		ServerDropWeapon();
		return;
	}

	if (CurrentWeapon)
	{
		FVector CamLoc;
		FRotator CamRot;

		if (Controller == nullptr)
		{
			return;
		}		
		
		/* Find a location to drop the item, slightly in front of the player.
			Perform ray trace to check for blocking objects or walls and to make sure we don't drop any item through the level mesh */
		Controller->GetPlayerViewPoint(CamLoc, CamRot);
		FVector SpawnLocation;
		FRotator SpawnRotation = CamRot;

		const FVector Direction = CamRot.Vector();
		const FVector TraceStart = GetActorLocation();
		const FVector TraceEnd = GetActorLocation() + (Direction * DropWeaponMaxDistance);

		/* Setup the trace params, we are only interested in finding a valid drop position */
		FCollisionQueryParams TraceParams;
		TraceParams.bTraceComplex = false;
		TraceParams.bReturnPhysicalMaterial = false;
		TraceParams.AddIgnoredActor(this);

		FHitResult Hit;
		GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_WorldDynamic, TraceParams);

		/* Find farthest valid spawn location */
		if (Hit.bBlockingHit)
		{
			/* Slightly move away from impacted object */
			SpawnLocation = Hit.ImpactPoint + (Hit.ImpactNormal * 20);
		}
		else
		{
			SpawnLocation = TraceEnd;
		}

		/* Spawn the "dropped" weapon */
		FActorSpawnParameters SpawnInfo;
		SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		ASWeaponPickup* NewWeaponPickup = GetWorld()->SpawnActor<ASWeaponPickup>(CurrentWeapon->WeaponPickupClass, SpawnLocation, FRotator::ZeroRotator, SpawnInfo);

		if (NewWeaponPickup)
		{
			/* Apply torque to make it spin when dropped. */
			UStaticMeshComponent* MeshComp = NewWeaponPickup->GetMeshComponent();
			if (MeshComp)
			{
				MeshComp->SetSimulatePhysics(true);
				MeshComp->AddTorque(FVector(1, 1, 1) * 4000000);
			}
		}

		RemoveWeapon(CurrentWeapon, true);
	}
}
void UAREquipmentComponent::ServerRemoveWeapon_Implementation(FName Weapon, int32 SlotID, int32 Hand)
{
	RemoveWeapon(Weapon, SlotID, Hand);
}