So, I’ve started designing a weapon/ability/effect system from scratch. (2nd go at it)
This is for a multiplayer game, so keep that in mind when I’m talking about the base classes. I know some are easier to setup replication with.
This is what I’ve come up with so far, but I need some input.
Ability: Something a player/weapon is able to do to effect other players or himself. (Think MOBA abilities)
Some abilities are equippable. Others are executed instantly via a keypress. Abilities cannot be dropped or picked up (unless they are attached to a weapon).
Examples: FireRaycast, FireProjectile, Teleport, ShoulderRam (Melee), Smoke (AoE), Spawn Companion, etc.
Weapon: A weapon is useless without abilities attached to it that make it function. A weapon unlocks the ability.
All weapons are equippable (I think). Weapons can be dropped and picked up. If you pickup a weapon that has an ability attached to it the ability comes with it obviously.
For example if you pickup a shotgun the FireRaycast ability will come with it.
Examples: Shotgun, Pistol, Sword, etc.
Effect: A list of things that happen to other actors (or self) when the ability is executed.
Effects are attached to the Ability. For example, a Shotgun could have a Damage effect.
Examples: Damage, Buff, Debuff, etc.
So I figured a component system would be the best way to go about coding this in c++. I also want to use BP for some of the high level things.
So I’ve made the following classes
AWeapon::AActor
UWeaponComponent::UActorComponent
UAbilityComponent::UActorComponent
UEffectComponent::UActorComponent
Within my Character class I then have the following
// Inventory
UPROPERTY(Transient, Replicated)
TArray<UActorComponent*> Inventory;
// Default Inventory List
UPROPERTY(EditDefaultsOnly, Category = Inventory)
TArray<TSubclassOf<UActorComponent>> DefaultInventoryClasses;
// Currently equipped weapon/ability
UPROPERTY(Transient)
UActorComponent* CurrentActionComponent; // TODO: possibly name better
So, since I made both my abilities and weapons UActorComponent’s I can use a single Inventory array to store them.
I am planning on switching weapons/abilities via 1,2,3,4 keys. If the player presses 2 and that ability isn’t equippable it will be executed immediately. If it is equippable it will be equipped and the current weapon/ability will be unequipped. In a lot of cases the weapons will be equippable and the abilities will just be keypress executed.
However, weapons need to exist in the world when dropped and also when picked up. For example, a shotgun exists on the ground before you pick it up. And once you pick it up it exists in your hands.
This is why I was thinking of also having a AWeapon class (Actor).
I was thinking of having the AActor exist when the weapon is on the ground. This AActor has a reference to the UWeaponComponent that it represents. Once the player picks up the weapon the AActor will be destroyed and the UWeaponComponent will be attached to the player.
However, even when the weapon is picked up it needs a mesh that is rendered in the players hands.
The main advantage I see of making both weapons and abilities inherit from UActorComponent is that I can use a single inventory (as shown above).
I also need to figure out how this would work with networking.
However, I could be wrong. It may be better to just have a AWeapon. However, I’m not sure how I would do the inventory in this case.
I would love some input (code encouraged as well).
Thanks!