top of page

MFP: Ability Effects

Abilities dealing instant damage is key, but not enough to make an RPG interesting. For that you need "Effects", a blanket term I will be using to refer to something which impacts a character for a period of time. These come in three main varieties; buffs, debuffs, and DoTs. Buffs are positive effects such as increased movement speed. Debuffs are negative effects like decreased damage. DoTs are damage over time effects which deal damage continuously to the target until they are removed. Effects can work in a variety of interesting ways which I aim to implement later. For now though I have added functionality for the most common type of effect. Effects can be applied by an ability and last for a certain amount of time before being removed.

I created an effect prefab which is a game object containing nothing but my newly created effect script. This prefab is kept in a folder named Resources, which is in the assets folder. This is done so that the prefab can be instantiated (spawned) later. The effect script features the following variables:


















I added an "applies effect" bool to the ability script and added the following code to the apply effects function which previously just dealt damage:

This instantiates the effect object as a child of the target and ensures it knows what ability it was created by, what character it was created by, and what character it is attached to. The character it is attached to will be its target. Once this is done and the effect has had its duration set, the ready to apply function is called, allowing the effect to kick into action:

This takes info from the ability about which stats on the target should be modified and by how much, according to the base value of the ability, and the power level of the applying character. It also determines how much DoT the effect should deal if any. The mod stats function is then called and the DoT and Duration coroutines are started. Mod stats is a lengthy function but it is largely repeats of two if statements which attempt to change the target's stats based on the corresponding percent mod and flat mod values. A percent mod statement looks like this:

This takes away or adds a value to a given stat equal to a percentage of that stat's current value. This means the higher the stat is already, the greater the impact of the effect. We record the mod applied so that even if there are changes to the stat between the effect's application and removal, we can still ensure that we properly revert the effect.

The flat mod statements just mod the stat by a "flat" value rather than a percentage. These mods can be simply reverted at the end so we don't need to track our applied mod value separately here. Percent and flat mods have different use cases from a player perspective so having both just adds more tactical choice on their part. Against an enemy with 1000 armour, a 10 armour debuff will do very little but a 10% debuff will reduce their armour by 100, making them much more vulnerable. At the other end of the spectrum, applying a 10% armour debuff to a target with only 10 armour won't have much effect. But a flat 10 armour debuff will reduce their armour to 0, greatly increasing your damage dealt to them.





If the effect has a DoT value then the DoT coroutine will have been started. This applies a small fraction of its total damage every 0.1 seconds throughout the effects duration. Each of these damage instances is called a tick.





This duration coroutine waits for the amount of time we set on application and then triggers the remove effect function. In the remove effect function is a series of if statements similar to the apply effect function, except this time we are reverting the changes made by the effect. Percent mods are reverted by using the applied value we saved. Flat mods are simply reverted by taking away the value we added. Once this is done to every effected stat, the effect object destroys itself.


Here is a video of an enemy using using an ability on the player which deals instant damage and applies a DoT and a movement speed debuff:



Commenti


bottom of page