I want a weapon system were Ammunitions are independent: that means multiple weapons can use the same kind of ammo.
Let’s say I have these 4 kind of Ammunitions:
Each one has its own ammount of munitions that, during the game, can be picked up from the ground.
Now let’s say I have two weapons:
- A pistol which uses SingleBullets
- A special pistol which uses **SingleBullets as PrimaryFire **and Electricity as SecondaryFire
As you can see, I have two weapons and both share the same kind of Ammo: the SingleBullets.
So if either the ‘pistol’ or the ‘special pistol’ shoot their PrimaryFire, ammos are taken from the SingleBullet munitions.
I started making this.
AAmmunition is an Actor-derived class which basically has two variables: **EAmmoType **(enumeration) and **CurrentAmmo **(int32, which stores the ammount of ammo during the game).
In the PlayerCharacter, I made an Inventory of TSubclassOf<AAmmunition>.
I create as many Blueprint-classes as the kind of AAmmunitions there are in my game (all derived from AAmmunition c++ class)
My Weapon class has its own attributes that describe which kind of Ammo to use for the Primary and the Secondary fire: TSubclassOf<AAmmunition>
The problem is right here.
How do I decrease the CurrentAmmo in the PlayerCharacter AmmoInventory from the Weapon class??? (when the player shoots the primary/secondary fire)
The PlayerCharacter has a DefaultAmmoInventory, which is an array of TSubclassOf<Ammunition> that I set in the blueprint.
When the game starts, those SubclassesOf<Ammunition> are spawned in another array called AmmoInventory
So you understand where the problem is?
The Character has an inventory of Ammunition* while in the Weapon class I have two SubclassesOf<Ammunition>, one for the Primary and one for the Secondary fire.
When I shoot from the Weapon->PrimaryFire() method, I want to decrease ammunitions from the Character::AmmoInventory that are the same type of Weapon::PrimaryAmmo
Also, is there a more efficient way to achieve this system?