Skip to content

Commit

Permalink
Fix infinite ammo nade (#201)
Browse files Browse the repository at this point in the history
* #200 Fixed Grenade InfiniteAmmo command
  • Loading branch information
xthebat authored Feb 17, 2024
1 parent 7d613d6 commit 1103bc8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
Binary file modified Content/Blueprints/Character/Ball/BP_Ball.uasset
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ void UCloud9CharacterHealthComponent::OnRegister()
MyOwner->OnTakeRadialDamage.AddUniqueDynamic(this, &UCloud9CharacterHealthComponent::OnTakeRadialDamage);
}

void UCloud9CharacterHealthComponent::CheckIfDeath(const AActor* DamagedActor, const AController* InstigatedBy)
{
if (DamagedActor->IsPendingKill())
{
if (not IsValid(InstigatedBy))
{
log(Error, "[Component = %s] InstigatedBy is invalid", *GetName());
return;
}

// TODO: Make score component
if (let Character = Cast<ACloud9Character>(InstigatedBy->GetCharacter()); IsValid(Character))
{
Character->AddScore();
}
}
}

bool UCloud9CharacterHealthComponent::ChangeHasHelmet(bool NewState)
{
if (bHasHelmet != NewState)
Expand All @@ -114,15 +132,7 @@ void UCloud9CharacterHealthComponent::OnTakePointDamage(
{
TakeHealthDamage(Damage); // TODO: Add factor by armor
TakeArmorDamage(0.0f); // TODO: Add armor damage calc

if (DamagedActor->IsPendingKill())
{
// TODO: Make score component
if (let Character = Cast<ACloud9Character>(DamageCauser->GetOwner()); IsValid(Character))
{
Character->AddScore();
}
}
CheckIfDeath(DamagedActor, InstigatedBy);
}

void UCloud9CharacterHealthComponent::OnTakeRadialDamage(
Expand All @@ -136,4 +146,5 @@ void UCloud9CharacterHealthComponent::OnTakeRadialDamage(
{
TakeHealthDamage(Damage); // TODO: Add factor by armor
TakeArmorDamage(0.0f); // TODO: Add armor damage calc
CheckIfDeath(DamagedActor, InstigatedBy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class CLOUD9_API UCloud9CharacterHealthComponent

virtual void OnRegister() override;

void CheckIfDeath(const AActor* DamagedActor, const AController* InstigatedBy);

protected:
UPROPERTY(BlueprintAssignable, meta=(AllowPrivateAccess), Category=Events)
FOnHealthChange OnHealthChange;
Expand Down
2 changes: 1 addition & 1 deletion Source/Cloud9/Character/Components/Cloud9Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool UCloud9Inventory::SelectWeaponImpl(EWeaponSlot Slot, bool Instant, bool For
return false;
}

if (Slot == SelectedWeaponSlot)
if (not Force and Slot == SelectedWeaponSlot)
{
log(Warning, "[Inventory='%s'] No switching will be performed", *GetName());
return false;
Expand Down
11 changes: 5 additions & 6 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ bool ACloud9WeaponBase::AddToInventory(ACloud9Character* Character, EWeaponSlot

SetOwner(Character);

// Set new instigator for this weapon so When weapon thrown owner will be changed
// to nothing but we need to know who do it (throw a weapon)
// This is important for nades to get handle number of kills for player
SetInstigator(Character);

if (not UpdateWeaponAttachment(NewSlot, EWeaponBond::Holstered))
{
log(Error, "Failed to update attachment for weapon '%s' slot '%s'", *GetName(), SLOT_NAME);
Expand Down Expand Up @@ -434,12 +439,6 @@ bool ACloud9WeaponBase::ChangeState(EWeaponBond NewBond, bool Instant, bool Forc
return false;
}

if (WeaponState.IsWeaponBond(NewBond))
{
log(Error, "[Weapon='%s' Bond='%s'] Weapon will remain the same", *GetName(), BOND_NAME);
return false;
}

if (not Force and IsAnyMontagePlaying())
{
log(Verbose, "[Weapon='%s' Bond='%s'] Montage is playing now", *GetName(), BOND_NAME);
Expand Down
15 changes: 5 additions & 10 deletions Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ void ACloud9WeaponGrenade::Tick(float DeltaSeconds)
}
else if (WeaponState.IsActionActive(EWeaponAction::PrimaryStart))
{
log(Display, "EWeaponAction::Primary");

ExecuteAction(
EWeaponAction::PrimaryStart,
GetWeaponInfo()->PinpullTime,
Expand All @@ -180,8 +178,6 @@ void ACloud9WeaponGrenade::Tick(float DeltaSeconds)
}
else if (WeaponState.IsActionActive(EWeaponAction::PrimaryLoop))
{
log(Display, "EWeaponAction::PrimaryLoop");

// Play hold frame of montage
PlayAnimMontage(
PoseMontages->PinpullPrimaryActionMontage,
Expand All @@ -202,8 +198,6 @@ void ACloud9WeaponGrenade::Tick(float DeltaSeconds)
}
else if (WeaponState.IsActionActive(EWeaponAction::PrimaryEnd))
{
log(Display, "EWeaponAction::PrimaryEnd");

ExecuteAction(
EWeaponAction::PrimaryEnd,
GetWeaponInfo()->ThrowTime,
Expand All @@ -225,7 +219,6 @@ bool ACloud9WeaponGrenade::OnGrenadeActionFinished()
{
if (IsValid(this))
{
log(Display, "OnGrenadeActionFinished()")
Destroy();
SetActorTickEnabled(false);
return true;
Expand Down Expand Up @@ -269,6 +262,8 @@ bool ACloud9WeaponGrenade::OnGrenadeActionLoop()

let IgnoredActors = TArray<AActor*>{};

let InstigatorController = GetInstigatorController();

// TODO: Handle other types of nades if required
UGameplayStatics::ApplyRadialDamage(
GetWorld(),
Expand All @@ -278,7 +273,7 @@ bool ACloud9WeaponGrenade::OnGrenadeActionLoop()
UDamageType::StaticClass(),
IgnoredActors,
this,
nullptr,
InstigatorController,
false,
ECC_Visibility);
Explosion->FireImpulse();
Expand Down Expand Up @@ -356,8 +351,6 @@ bool ACloud9WeaponGrenade::OnGrenadeThrown()
return false;
}

log(Display, "OnGrenadeThrown()")

DetonationTimerHandle = GetWorld()
| EUWorld::AsyncAfter{
[this] { WeaponState.GrenadeActionLoop(); },
Expand Down Expand Up @@ -419,6 +412,8 @@ bool ACloud9WeaponGrenade::Throw() const
if (IsInfiniteAmmo)
{
Inventory->AddWeapon(GrenadeConfig);
// need to force select for valid grenade state
Inventory->SelectWeapon(GrenadeConfig.GetWeaponSlot(), true, true);
}

return true;
Expand Down

0 comments on commit 1103bc8

Please sign in to comment.