Adventure Kit  4.16
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AAdvKitWeapon Class Reference

Base weapon class. Has some basic replicated handling on start-/stop firing and fire modes, as well as base methods to implement custom behaviors. More...

#include <AdvKitWeapon.h>

Inheritance diagram for AAdvKitWeapon:
AAdvKitInventoryItem AAdvKitWeaponTracing

Public Member Functions

 AAdvKitWeapon (const FObjectInitializer &ObjectInitializer)
 
void StartFire (uint8 FireModeIndex=0)
 
virtual void StartFire_Implementation (uint8 FireModeIndex=0)
 
void StopFire ()
 
virtual void StopFire_Implementation ()
 
void StartReload ()
 
virtual void StartReload_Implementation ()
 
void StopReload ()
 
virtual void StopReload_Implementation ()
 
void ConsumeAmmunition ()
 
virtual void ConsumeAmmunition_Implementation ()
 
void HandleFiringPrerequisites ()
 
virtual void HandleFiringPrerequisites_Implementation ()
 
void FireAmmunition ()
 
virtual void FireAmmunition_Implementation ()
 
void FireInstant ()
 
virtual void FireInstant_Implementation ()
 
class AAdvKitProjectileFireProjectile ()
 
virtual class AAdvKitProjectileFireProjectile_Implementation ()
 
void FireCustom ()
 
virtual void FireCustom_Implementation ()
 
virtual void StartRefireTimer (float Duration)
 
virtual void StopRefireTimer ()
 
virtual void RefireTimer ()
 
virtual bool IsMagazineEmpty ()
 
virtual bool HasAmmunition (int32 Amount=1)
 
virtual bool HasAmmunitionInMagazine (int32 Amount=1)
 
virtual bool IsIdle ()
 
virtual bool IsFiring ()
 
virtual bool IsReloading ()
 
FVector GetMuzzleLocation (uint8 FireModeIndex=0)
 
virtual FVector GetMuzzleLocation_Implementation (uint8 FireModeIndex=0)
 
FVector GetTraceStart (uint8 FireModeIndex=0)
 
virtual FVector GetTraceStart_Implementation (uint8 FireModeIndex=0)
 
virtual FRotator GetAdjustedAim (FVector StartFireLocation, uint8 FireModeIndex=0)
 
virtual FRotator AddSpread (FRotator OriginalAim, uint8 FireModeIndex=0)
 
bool CanFire ()
 
virtual bool CanFire_Implementation ()
 
void AddAmmunition (int32 Amount)
 
virtual void AddAmmunition_Implementation (int32 Amount)
 
float BlockDamage (float Damage, FDamageEvent const &DamageEvent, AController *EventInstigator, AActor *DamageCauser)
 
virtual float BlockDamage_Implementation (float Damage, FDamageEvent const &DamageEvent, AController *EventInstigator, AActor *DamageCauser)
 
void BlockedBy (AActor *By, float BlockedDamage)
 
virtual void BlockedBy_Implementation (AActor *By, float BlockedDamage)
 
void OnFireBegin ()
 
virtual void OnFireBegin_Implementation ()
 
void OnFireShot ()
 
virtual void OnFireShot_Implementation ()
 
void OnFireEnd ()
 
virtual void OnFireEnd_Implementation ()
 
void OnReloadBegin ()
 
virtual void OnReloadBegin_Implementation ()
 
void OnReloaded ()
 
void OnReloaded_Implementation ()
 
void OnReloadEnd ()
 
virtual void OnReloadEnd_Implementation ()
 
void OnMagazineEmpty ()
 
virtual void OnMagazineEmpty_Implementation ()
 
void OnWeaponEmpty ()
 
virtual void OnWeaponEmpty_Implementation ()
 
virtual void Uneqiup (bool bInstant=false) override
 
- Public Member Functions inherited from AAdvKitInventoryItem
 AAdvKitInventoryItem (const FObjectInitializer &ObjectInitializer)
 
virtual void BeginPlay () override
 
virtual void Tick (float DeltaSeconds) override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
bool CanBeCombinedWith (class AAdvKitInventoryItem *With)
 
virtual bool CanBeCombinedWith_Implementation (class AAdvKitInventoryItem *With)
 
class AAdvKitInventoryItemCombinedWith (class AAdvKitInventoryItem *With)
 
virtual class AAdvKitInventoryItemCombinedWith_Implementation (class AAdvKitInventoryItem *With)
 
void OwnerDied ()
 
virtual void OwnerDied_Implementation ()
 
void Drop (FVector Velocity=FVector::ZeroVector)
 
virtual void Drop_Implementation (FVector Velocity=FVector::ZeroVector)
 
EAdvKitInventoryState GetItemState ()
 
virtual void Equip (bool bInstant=false)
 
bool CanEquip (bool bInstant=false)
 
virtual bool CanEquip_Implementation (bool bInstant=false)
 
bool CanUneqiup (bool bInstant=false)
 
virtual bool CanUneqiup_Implementation (bool bInstant=false)
 

Static Public Member Functions

static UTexture2D * GetWeaponCrosshairTexture (TSubclassOf< AAdvKitWeapon > WeaponClass)
 
- Static Public Member Functions inherited from AAdvKitInventoryItem
static UTexture2D * GetInventoryIconTexture (TSubclassOf< AAdvKitInventoryItem > InventoryClass)
 

Protected Member Functions

void StartFireInternal ()
 
virtual void StartFireInternal_Implementation ()
 
void StopFireInternal ()
 
virtual void StopFireInternal_Implementation ()
 
bool CanReload ()
 
virtual bool CanReload_Implementation ()
 
void StartReloadInternal ()
 
virtual void StartReloadInternal_Implementation ()
 
void StopReloadInternal ()
 
virtual void StopReloadInternal_Implementation ()
 
void ReloadAmmunition ()
 
virtual void ReloadAmmunition_Implementation ()
 
void StartReloadTimer ()
 
virtual void StartReloadTimer_Implementation ()
 
void StopReloadTimer ()
 
virtual void StopReloadTimer_Implementation ()
 
virtual void ReloadedTimer ()
 
virtual bool HasFireMode (uint8 FireModeIndex)
 
UAdvKitFireModeConfigurationGetFireModeBP (uint8 FireModeIndex)
 
virtual const UAdvKitFireModeConfigurationGetFireMode (uint8 FireModeIndex)
 
virtual TSubclassOf< UAdvKitFireModeConfigurationGetFireModeClass (uint8 FireModeIndex)
 
virtual bool GetFireMode (uint8 FireModeIndex, const UAdvKitFireModeConfiguration **OutFireMode)
 
virtual void PostInitializeComponents () override
 
void StartFireServer (uint8 FireModeIndex=0)
 
virtual void StartFireServer_Implementation (uint8 FireModeIndex=0)
 
void StopFireServer ()
 
virtual void StopFireServer_Implementation ()
 
void StartReloadServer ()
 
virtual void StartReloadServer_Implementation ()
 
void StopReloadServer ()
 
virtual void StopReloadServer_Implementation ()
 
virtual void OnRep_WeaponState (FAdvKitWeaponState OldState)
 
virtual void OnRep_BurstCounter (int32 OldBurstCounter)
 
- Protected Member Functions inherited from AAdvKitInventoryItem
void AttachToCharacter ()
 
virtual void AttachToCharacter_Implementation ()
 
void DetachFromCharacter ()
 
virtual void DetachFromCharacter_Implementation ()
 
void SetItemState (EAdvKitInventoryState NewState, bool bInstant=false)
 
virtual void OnRep_ItemState (FRepAdvKitInventoryState PreviousRepItemState)
 
virtual void Equipped (bool bInstant=false)
 
virtual void Uneqiupped (bool bInstant=false)
 
void UneqiupServer (bool bInstant=false)
 
virtual void UneqiupServer_Implementation (bool bInstant=false)
 
void EquipServer (bool bInstant=false)
 
virtual void EquipServer_Implementation (bool bInstant=false)
 
void OnEquip (bool bInstant=false)
 
virtual void OnEquip_Implementation (bool bInstant=false)
 
void OnEquipped (bool bInstant=false)
 
virtual void OnEquipped_Implementation (bool bInstant=false)
 
void OnUneqiup (bool bInstant=false)
 
virtual void OnUneqiup_Implementation (bool bInstant=false)
 
void OnUneqiupped (bool bInstant=false)
 
virtual void OnUneqiupped_Implementation (bool bInstant=false)
 

Protected Attributes

FAdvKitWeaponState WeaponState
 
int32 BurstCounter
 
class USceneComponent * DefaultRootComponent
 
int32 AmmunitionPerMagazine
 
int32 AmmunitionInMagazine
 
int32 Ammunition
 
int32 MaxAmmunition
 
bool bHasInfiniteAmmunition
 
TArray< TSubclassOf< class UAdvKitFireModeConfiguration > > DefaultFireModes
 
TArray< class UAdvKitFireModeConfiguration * > FireModes_OLD
 
UAnimMontage * CharacterReloadMontage
 
int32 AmmoByReloading
 
float ReloadTime
 
UTexture2D * Crosshair
 
FTimerHandle RefireTimerHandle
 
FTimerHandle ReloadTimerHandle
 
- Protected Attributes inherited from AAdvKitInventoryItem
FRepAdvKitInventoryState RepItemState
 

Additional Inherited Members

- Public Attributes inherited from AAdvKitInventoryItem
FText ItemName
 
FText ItemDescription
 
UTexture2D * Icon
 
TSubclassOf< class AAdvKitPickupDroppedPickupClass
 
bool bDropOnDeath
 
bool bUseAimOffset
 
float EquipTime
 
UAnimMontage * EquipMontage
 
float UneqiupTime
 
UAnimMontage * UneqiupMontage
 
FName AttachmentSocketName
 
FTimerHandle EquipTimerHandle
 

Detailed Description

Base weapon class. Has some basic replicated handling on start-/stop firing and fire modes, as well as base methods to implement custom behaviors.

For this explanation the weapon is described like a gun, even though the weapon functionality is not limited to guns. Calling StartFire implies that the trigger has been pulled. If the gun is currently firing on an alternate mode it will stop doing that and start the new mode by calling StartFireInternal. Here last checks are done, e.g. if there is enough ammunition and the weapon will be reloaded if there isn't. If all prerequisites are met the weapon will actually fire by calling FireAmmunition and then start a refire timer if configured.

StopFire works in a similar matter. You should see Start-/StopFire as intents of the player, while the corresponding internal methods are the actual clockwork that govern what the weapon does.

Constructor & Destructor Documentation

AAdvKitWeapon::AAdvKitWeapon ( const FObjectInitializer &  ObjectInitializer)

Constructor

Member Function Documentation

void AAdvKitWeapon::AddAmmunition ( int32  Amount)

Adds ammunition to the weapon

Parameters
AmountHow much to add.
FRotator AAdvKitWeapon::AddSpread ( FRotator  OriginalAim,
uint8  FireModeIndex = 0 
)
virtual

Add spread to a fire orientation.

Parameters
OriginalAimOriginal fire orientation.
FireModeIndexDifferent fire modes can have different spreads.
Returns
Modified aim rotation.
float AAdvKitWeapon::BlockDamage ( float  Damage,
FDamageEvent const &  DamageEvent,
AController *  EventInstigator,
AActor *  DamageCauser 
)

Weapons like swords have the ability to block damage. The parameters are from the actor's take damage event.

Parameters
DamageAmount of damage taken.
DamageEventData package that fully describes the damage received
EventInstigatorThe Controller responsible for the damage
DamageCauserThe Actor that directly caused the damage (e.g. the projectile that exploded, or the enemy's sword)
Returns
The remaining amount of damage after it's potential block.
void AAdvKitWeapon::BlockedBy ( AActor *  By,
float  BlockedDamage 
)

Callback if an attack of this weapon was blocked by something

Parameters
ByThe actor that blocked the attack
BlockedDamageHow much damage was blocked
bool AAdvKitWeapon::CanFire ( )

Check if the weapon can fire.

Returns
True if it can, false if not
bool AAdvKitWeapon::CanReload ( )
protected

Check if weapon can be reloaded.

Returns
True if it can be reloaded.
void AAdvKitWeapon::ConsumeAmmunition ( )

Called when a shot is fired to use up ammunition.

void AAdvKitWeapon::FireAmmunition ( )

Called when firing to actually shoot. Depending on the fire type of the active mode it delegates firing to FireInstant, FireProjectile or FireCustom.

void AAdvKitWeapon::FireCustom ( )

Custom fire hook, for other implementations.

void AAdvKitWeapon::FireInstant ( )

Fires instant trace, applies damage to hit target.

class AAdvKitProjectile* AAdvKitWeapon::FireProjectile ( )

Fires a projectile configured by the current firing mode.

Returns
The fired projectile, if successful
FRotator AAdvKitWeapon::GetAdjustedAim ( FVector  StartFireLocation,
uint8  FireModeIndex = 0 
)
virtual

Gets the direction in which to fire. Adds spread to it.

Parameters
StartFireLocationWorld space location to fire (bullet) from.
FireModeIndexFire mode might change the direction.
Returns
Rotation with X axis facing in direction of fire.
const UAdvKitFireModeConfiguration * AAdvKitWeapon::GetFireMode ( uint8  FireModeIndex)
protectedvirtual

Query a specific fire mode.

Parameters
FireModeIndexThe mode to get
Returns
Pointer to the fire mode if it exists, nullptr otherwise
bool AAdvKitWeapon::GetFireMode ( uint8  FireModeIndex,
const UAdvKitFireModeConfiguration **  OutFireMode 
)
protectedvirtual

Query a specific fire mode.

Parameters
FireModeIndexThe mode to get
[out]OutFireModePointer to the fire mode if it exists, nullptr otherwise
Returns
True if out fire mode was set, false otherwise
UAdvKitFireModeConfiguration * AAdvKitWeapon::GetFireModeBP ( uint8  FireModeIndex)
protected

Query a specific fire mode.

Parameters
FireModeIndexThe mode to get
Returns
Pointer to the fire mode if it exists, nullptr otherwise
TSubclassOf< UAdvKitFireModeConfiguration > AAdvKitWeapon::GetFireModeClass ( uint8  FireModeIndex)
protectedvirtual

Query a specific fire mode.

Parameters
FireModeIndexThe mode to get
Returns
Pointer to the class of the fire mode if it exists, nullptr otherwise
FVector AAdvKitWeapon::GetMuzzleLocation ( uint8  FireModeIndex = 0)

Get the muzzle point of the weapon to spawn a projectile

Parameters
FireModeIndexIf the weapon has more than one muzzle it can return different ones
Returns
World space location of the muzzle
FVector AAdvKitWeapon::GetTraceStart ( uint8  FireModeIndex = 0)

Get the starting location for a trace for projectile/instant fire mode. The default implementation traces from the character's viewpoint to determine the target and then fires form the muzzle location to the hit.

Parameters
FireModeIndexDepending on fire mode the weapon can have different start locations.
Returns
World space location of where to begin the trace
UTexture2D * AAdvKitWeapon::GetWeaponCrosshairTexture ( TSubclassOf< AAdvKitWeapon WeaponClass)
static

Get the crosshair texture of a weapon class without the need to instantiate it.

Parameters
WeaponClassClass of the weapon item to get the crosshair from.
Returns
Crosshair texture of the weapon.
void AAdvKitWeapon::HandleFiringPrerequisites ( )

Called if player wants to but the weapon cannot fire, e.g. to check if it needs to be reloaded.

bool AAdvKitWeapon::HasAmmunition ( int32  Amount = 1)
virtual

Check if the weapon has a given amount of ammunition (disregarding if in magazine or not)

Parameters
AmountHow much ammunition to ask for
Returns
True if the weapon has at least the specified amount, false otherwise
bool AAdvKitWeapon::HasAmmunitionInMagazine ( int32  Amount = 1)
virtual

Check if the weapon has a given amount of ammunition in the current magazine

Parameters
AmountHow much ammunition to ask for
Returns
True if the weapon has at least the specified amount, false otherwise
bool AAdvKitWeapon::HasFireMode ( uint8  FireModeIndex)
protectedvirtual

Check if the weapon has a specified fire mode.

Parameters
FireModeIndexThe mode to check for
Returns
True if mode exists, false otherwise
bool AAdvKitWeapon::IsFiring ( )
virtual

Check if the weapon is currently firing

Returns
True if firing
bool AAdvKitWeapon::IsIdle ( )
virtual

Check if the weapon is currently doing nothing

Returns
True if doing nothing
bool AAdvKitWeapon::IsMagazineEmpty ( )
virtual

Query if the magazine is empty

Returns
True if empty
bool AAdvKitWeapon::IsReloading ( )
virtual

Check if the weapon is currently reloading

Returns
True if reloading
void AAdvKitWeapon::OnFireBegin ( )

Callback event when the weapon starts firing.

void AAdvKitWeapon::OnFireEnd ( )

Callback event when firing stops.

void AAdvKitWeapon::OnFireShot ( )

Callback event when FireAmmunition was called.

void AAdvKitWeapon::OnMagazineEmpty ( )

Callback event when the weapon wants to fire but there is no ammo left in the current magazine.

void AAdvKitWeapon::OnReloadBegin ( )

Callback event when the weapon starts to reload.

void AAdvKitWeapon::OnReloaded ( )

Callback event when the weapon has finished reloading.

void AAdvKitWeapon::OnReloadEnd ( )

Callback event when reloading was aborted.

void AAdvKitWeapon::OnRep_BurstCounter ( int32  OldBurstCounter)
protectedvirtual

Callback method when the server burst counter changes

Parameters
OldBurstCounterCounter before the change
void AAdvKitWeapon::OnRep_WeaponState ( FAdvKitWeaponState  OldState)
protectedvirtual

Callback method when the server state changes

Parameters
OldStateState before the change
void AAdvKitWeapon::OnWeaponEmpty ( )

Callback event when the weapon wants to fire but has no mor ammunition.

void AAdvKitWeapon::RefireTimer ( )
virtual

Callback method for refire timer

void AAdvKitWeapon::ReloadAmmunition ( )
protected

Called when reloading succeeded. Moves ammunition from store to magazine.

void AAdvKitWeapon::ReloadedTimer ( )
protectedvirtual

Callback method for the reload timer.

void AAdvKitWeapon::StartFire ( uint8  FireModeIndex = 0)

Tell the weapon to start firing (even though the weapon may not be able to)

Parameters
FireModeIndexWhich mode to start firing in
void AAdvKitWeapon::StartFireInternal ( )
protected

Internal method to actually start firing the pending or current fire mode.

void AAdvKitWeapon::StartFireServer ( uint8  FireModeIndex = 0)
protected

Server callback to tell the weapon to start firing (even though the weapon may not be able to)

Parameters
FireModeIndexWhich mode to start firing in
void AAdvKitWeapon::StartRefireTimer ( float  Duration)
virtual

Starts the timer to do refires

Parameters
DurationHow long to wait between fire calls
void AAdvKitWeapon::StartReload ( )

Initiates a reload

void AAdvKitWeapon::StartReloadInternal ( )
protected

Internal method to start reloading timer and animations.

void AAdvKitWeapon::StartReloadServer ( )
protected

Server callback to initiate a reload

void AAdvKitWeapon::StartReloadTimer ( )
protected

Start the timer for the reloading process. When the timer fires the reload is complete.

void AAdvKitWeapon::StopFire ( )

Stop firing, the weapon may however still continue (e.g. because it needs to calm down first)

void AAdvKitWeapon::StopFireInternal ( )
protected

Internal method to actually stop firing the active mode.

void AAdvKitWeapon::StopFireServer ( )
protected

Server callback to stop firing, the weapon may however still continue (e.g. because it needs to calm down first)

void AAdvKitWeapon::StopRefireTimer ( )
virtual

Stops refiring

void AAdvKitWeapon::StopReload ( )

Stops a reload in progress without reloading ammo

void AAdvKitWeapon::StopReloadInternal ( )
protected

Internal method to abort reload.

void AAdvKitWeapon::StopReloadServer ( )
protected

Server callback to stop a reload in progress without reloading ammo

void AAdvKitWeapon::StopReloadTimer ( )
protected

Stops the reload timer (aborting it).

void AAdvKitWeapon::Uneqiup ( bool  bInstant = false)
overridevirtual

Tell the item to unequip.

Parameters
bInstantTrue to unequip instantly, otherwise regular unequipment time and animations

Reimplemented from AAdvKitInventoryItem.

Member Data Documentation

int32 AAdvKitWeapon::AmmoByReloading
protected

How much ammunition is added with each reload.

int32 AAdvKitWeapon::BurstCounter
protected

Shot counter to replicate weapon effects

UAnimMontage* AAdvKitWeapon::CharacterReloadMontage
protected

Optional anim montage to play character animation when reloading.

UTexture2D* AAdvKitWeapon::Crosshair
protected

Optional texture to display on the HUD

TArray< TSubclassOf<class UAdvKitFireModeConfiguration> > AAdvKitWeapon::DefaultFireModes
protected

Which fire modes the weapon should have, will be instantiated on startup

TArray<class UAdvKitFireModeConfiguration*> AAdvKitWeapon::FireModes_OLD
protected

List of fire modes the weapon has

FTimerHandle AAdvKitWeapon::RefireTimerHandle
protected

Handle to keep track of refiring.

float AAdvKitWeapon::ReloadTime
protected

How long a reload takes.

FTimerHandle AAdvKitWeapon::ReloadTimerHandle
protected

Handle to keep track of reloading.

FAdvKitWeaponState AAdvKitWeapon::WeaponState
protected

Struct holding all state variables of the weapon


The documentation for this class was generated from the following files: