Welcome back.
Now, we had our game plan for experience and we're up to the point where we need to reward experience
points.
So basically we need an amount of XP that each enemy gives based on its level and class.
And we also need to actually award XP when killing an enemy.
Now, once we've gotten that handled, we can handle leveling up.
But first we need to handle actually gaining experience.
So this is a system that we're going to need to put some thought into.
And in order to put some thought into it, let's just walk through the process of what happens when
a player gains experience, specifically when it comes to combat.
So we'll have a player, let's say they're controlling some pawn or character and that character attacks
an enemy.
Now, when this happens, typically the enemy will take some damage.
And this act of taking damage is going to trigger a response in the attribute set as they've just received
damage.
The damage meta attribute is going to trigger a response, at which point the attribute set decides
what happens.
And the attribute set knows at this point whether this damage was fatal or not.
Now we need to gain experience.
If the damage was fatal, we've just slain an enemy, which means the enemy needs an amount of experience
to reward the attacker with.
So we already knew that that was a crucial part of all this.
But at this point, the attribute set needs to know how much experience to award and for that matter,
how to award that experience.
Now we know that we can wait for gameplay events and we can send gameplay events to actors.
If our attribute set knows that this damage was fatal and knows how much experience to give to the attacker,
it can send a gameplay event and send that reward value along with it.
Now if we're sending a gameplay event to the attacker, the attacker needs to be able to receive it.
Now we can receive gameplay events if we have some kind of gameplay ability that's waiting for one.
So we can create a gameplay ability.
This can be a passive gameplay ability in a sense that we can activate it at the beginning of the game
and keep it active throughout the game.
We can call this listen for events and this gameplay ability can use wait gameplay event to wait for
any gameplay events that get sent its way and as soon as it receives a gameplay event it can then get
that XP reward and do something with it.
Now what can we do with the XP reward?
Well, our XP is on the player state and we chose not to make it an attribute, but it would be very
convenient if attribute sets could respond to changes in incoming experience points so that it could
act accordingly.
So if we could create a gameplay effect and make a gameplay effect spec that can carry that XP reward,
we can apply that to the self to the ability system component that owns this gameplay ability.
Now if we're using gameplay effects, those are meant to affect attributes, right?
But we chose not to make our XP an attribute.
Rather it's a variable on the player state.
But that doesn't mean that we can't set some kind of attribute.
This is actually a great example of when to use a meta attribute, just like our incoming damage meta
attribute.
This is an attribute that gets consumed.
It's zeroed out and then used to change something.
So if we're setting this incoming XP attribute on the attacker, then its own attribute set can then
add to the XP on the attacker's player state.
Now this can be done through an interface or any other way that we see fit, but this is how the player
state can then get its XP increased and once that happens, the player state will in turn broadcast
its delegate to the widget controller that's responsible for updating widgets such as the XP bar.
So as you can see in an RPG game involving experience, we have a number of moving parts that we need
to set up here.
So for our next steps forward, we have another game plan.
We first need an XP reward on our enemies and a way to get it.
So this could be a variable on the enemy class.
But then we should create some kind of access or function probably on the enemy interface that we can
easily get.
Then after that we need a meta attribute for incoming XP and this is so that we can respond to things
in the attributes set.
Now we're also going to create a gameplay ability that will be passive.
We can call this listen for events and granted in the beginning of the game and this can be something
that we never deactivate.
It's just always going, listening for events.
And as soon as it receives an event with a specific set of data perhaps identified by a gameplay tag,
then it can apply a gameplay effect in response to that event setting that incoming XP.
Now we also need to award the XP and the attribute set whenever the damage is fatal.
So for enemies taking damage as soon as they've taken fatal damage, we need to award the XP by sending
that gameplay event and we also need to handle that incoming XP and the attribute set and increase the
XP on the player state.
So the attribute set will be responsible for changes to XP and two capacities.
One is sending a gameplay event when damage is fatal and two is handling the incoming XP meta attribute
and increasing the real XP on the player state.
Once we've tied all this together, then when slaying an enemy which has its own XP amount, we should
see XP increase on the XP bar.
But most importantly we'll have our XP kept track of and the next step will be handling the situation
when XP rises above that level up requirement for the current level where we can increase the player's
level and reward them for leveling up.
So now that we know the steps forward, let's continue in the next video.