PseudoCode Weapons - Milowan/WarChildPort GitHub Wiki

PseudoCode for all Weapons Scripts

Weapon : public AActor

  • WeaponStats* stats
  • BulletPool* pool
  • bool active
  • bool reloading
  • float reloadTimer
  • int currentClip
  • float cooldown
  • float cdTimer
  • bool unlocked (Post Port)

Weapon()

initialize attributes

virtual SetStats()

to be overriden

Update()

if reloading reload

Fire()

get bullet from pool initialize and activate bullet decrement currentClip

Trigger()

if currentClip > 0 fire at firerate else reloading = true

Reload()

if reloadTimer >= reloadTime reloaded else keep reloading

GetStats()

return stats

InClip()

return currentClip

Unlock() (Post Port)

unlock the weapon

IsUnlocked() (Post Port)

return unlocked

BasicRifle : public Weapon

BasicRifle()

stats = new BasicRifleStats()

AdvancedRifle : public Weapon

AdvancedRifle()

stats = new AdvancedRifleStats()

MachinePistol : public Weapon

MachinePistol()

stats = new MachinePistolStats()

Bullet : AActor

float flightSpeed float movFraction float damage Vector3D forward float lifespan float age

OnStart

disable object and set lifespan

Update

if younger than lifespan move forward else despawn

Initialize(transform startPoint, Vector3D direction, float speed, float dmg)

initialize bullet using provided variables

Despawn

hide the Actor

BulletPool

TArray<Bullet*> pool

BulletPool()

initialize the pool

GetFreeBullet()

return inactive bullet

⚠️ **GitHub.com Fallback** ⚠️