Welcome back.
Now we're gaining experience and we made a level up function which currently does nothing, but we'll
fill that in with functionality, but we currently don't know when we should level up.
That's something we should figure out.
So I'm going to close the editor.
I'm going to go to my aura attribute set and close all other tabs and right here in post gameplay effect
execute.
As we're checking the incoming exp, we have a to do to check to see if we should level up.
So we have to decide if we should level up and we're going to do that inside of our if statement.
Once we know that our source character implements the player interface because if the source character
doesn't implement the player interface, there's no point as my enemies aren't going to level up in
your game.
That might be different.
You may wish to level up your enemies, which would require a minor adjustment.
What I would like my enemies to not level up so only my character.
And for incoming exp that's going to be the source character as the source character is the one applying
the gameplay effect.
Remember we have a passive gameplay ability with a gameplay effect and we're applying the spec to self.
In case this might be something you may be confused with.
I'm just going to clarify that in a comment here.
We're going to say source character is the owner.
Since gar listen for events applies g event based effect adding to incoming exp.
So this just makes it clear in case we get confused.
All right, so how do we check to see if we should level up?
Well, I'm going to check before we add to our exp, we want to add to our exp regardless, but I want
to know if a level up is in order.
Now.
Now in order to check to see if we should level up, we need to know our current level so I'm going
to make a const int 32 called current level and we're going to use a combat interface and call execute
get player level passing in props dot source character.
Now we have our current level.
I'd also like to get our current exp, so I'm going to make a const int 32 called current exp as well.
And for this we need to get our exp.
Now how do we get our exp?
What's an easy way to do it?
Because our exp exists on the player state, right?
And we can't really just dig into the player state.
The player state already depends on our attribute set.
We don't want a circular dependency.
Let's take a look at what our player interface has.
Oh look at this.
We have an add to exp.
We could easily have a get exp.
That's what I'd like to do.
So let's make a getter for our exp.
I'm just going to copy add to exp and paste up here and change this from a void function to an int 32
returning function called get exp.
It does not need to take any input parameters, it can even be const.
So now that we have this blueprint native events, we can override the implementation version of it
in our character.
So let's go to our character and implement it here in the player interface.
Looks like my comment says Player's interface.
I'm going to change that to player interface and we're going to override virtual int 32 get Exp implementation
and this will be pretty simple.
We're going to generate the definition and get our player state just like we did in get player level
implementation.
And after checking the player state, we're going to get our player state and call get exp.
And this is what we can return from the function.
So now we have git exp implementation.
So back in our attribute set we can call that I player interface.
Execute.
Get exp.
Passing in Props.
Source Character.
Now I just noticed we're checking if we implement you player interface.
We're not checking for combat interface.
We know that if we implement player interface, we definitely do implement combat interface because
players and enemies both implement it.
But we could just place a check here just to show that we care about checking.
So we're going to say props, dot source character implements.
And we can use you combat interface as well.
Okay.
So once we have our current level and current XP, what we should do is we should see what level corresponds
to our new XP amount.
In other words, if we take our current XP and we add this incoming XP to it, what level would that
correspond to?
In other words, if we make a const int 32 called new level, what would that be?
Well, we have the capability to find that out because we created a data asset that can do that.
If we go into our public folder, into ability system data and find level up info, we have this find
level for XP.
Now our level up info exists on our player state.
If we go to player or a player state, we have that level up info data asset right here.
And once again ora attribute set does not depend on the player state.
So what we can do is just make a function on our interface for performing that lookup.
We can go into interaction player interface and just create a function that can do this for us.
So we can call this function find level for XP.
It can take an INT 32 called NXP.
It can also be const and we can implement this in a character.
So virtual int 32 find level for NXP implementation and we can go ahead and generate the definition.
We can get our player state.
So copying that from get XP implementation.
After we get our aura player state, we can take Aura player state.
Get level up info and we can call find level for exp passing in NXP and we can return this value.
And now we have an interface function we can call an attribute set.
So new level is going to be a player interface.
Execute find level for XP.
Now we want to find the new level.
The level for the amount of XP that we would have after adding incoming XP to current XP.
So the amount we're going to pass in here is current XP plus our local incoming XP.
And of course the first input has to be props source character, doesn't it?
So first we pass in the source character.
Then we pass in the N 32.
So this is the new amount of XP that we're going to add to our XP.
So now that we know the new level, this is how we're going to know if we should level up because we
know our current level and the new level that corresponds to our new amount of XP that we're about to
have, we can take the difference between these and that will tell us how many times we should level
up.
So we can make a const int 32 called number of level ups or even just num level ups.
And that's equal to new level minus current level.
Now, if we call this function with not enough XP to level up, let's say we were at 100 and we only
went up to 120, we need 300 to go up to level two.
Well, this will return the same level that we're at, which would be one and new level minus current
level would be zero.
So the number of times we've leveled up was zero.
So we know based on this value, if we leveled up or not, it's if this value is greater than zero.
So we can say if num level ups oops writer auto completed and auto included something for me.
Looks like I have several dead includes that I can remove here.
I don't need gameplay statics currently I don't need or log channels and I don't need this header that
was just auto included.
So all right.
Back to what I was doing though.
We need to check num level ups and if that's greater than zero, we're leveling up potentially multiple
times, right?
So what do we do in that case?
Well, for one, we can call our characters level up function so we can take AI player interface.
Execute level up passing in props source character.
That's one thing that functions currently empty and doesn't do anything.
But since we're leveling up, we can call that and then we can do any other mathematical perks that
we want.
For one, we're going to have an attribute point reward and a spell point reward.
We're also going to add to our player level on our player state.
We're going to add to all of those things.
So what I'd like to do is, first of all, get our level up info to tell us what our attribute point
and spell point rewards are.
Let's make a Todo here.
We'll say get attribute points, reward and spell points reward and we'll continue this comment and
say add to player level.
We'll have another one to add to attribute points and spell points and we also need to add to XP, but
we're doing that already, so that's taken care of.
But we want to add to player level attribute points and spell points and of course execute level up.
Now when we level up, we typically fill up the health and mana.
So we'll also say fill up health and mana.
So quite a few things to do when we level up.
Right now, if we want to get our attribute points, reward and spell points reward those exist on level
up info which exists on the player state.
So these would be good interface functions to have.
Adding to the player level attribute points, spell points, all of that stuff is also stuff that requires
the player state.
So we need functions on our player interface for all of these.
In other words, get attribute points, reward and get spell points.
Reward should be functions.
So in our to do, I'm just going to list the functions we need to make get attribute points reward.
I'm just going to say we need to make that function.
Get spell points reward.
I'm going to say that we need that.
Add to player level.
That should be a function.
Add to player level.
And then of course add to attribute points.
Add to spell points.
So we'll say add two attribute points.
Add to spell points.
So these can all be functions on our player interface.
So let's start at the top.
We need get attribute points and spell points rewards.
We'll go into player interface and make getters for those.
I'm going to put all my getters together, so I'm going to put it right under get exp.
So this will be an int 32, not 4332 called get attribute points reward.
And it can be const.
So I'd like this to be a blueprint native event.
I'd also like the spell points version of this, so I'm going to copy and paste it.
And this one will be get spell points reward.
So we're going to have to implement those, but I'm going to go ahead and declare all the functions
we should implement.
So we got these two.
We need add to player level and the add to attribute points and spell points.
Let's declare those.
So just after add to XP, we are going to have three more.
We'll start with add to player level.
We'll call the input in player level.
And then we'll have add to attribute points.
And the input will be in attribute points.
And we'll have an ad to spell points.
So we'll call this add to spell points and the input will be called in spell points.
Okay, so we have a number of functions we should implement the implementation versions of in or a character
that will be here in the player interface.
So I can look at my comment here.
We have get attribute points reward, let's implement that.
So virtual int 32 get attribute points reward implementation.
Next we have get spell points reward.
Virtual and 32.
Get spell points Reward implementation.
Next we have add to player level.
Add to attribute points add to spell points so we have virtual void add to player level.
Virtual void add to spell points and add to attribute points.
I'm going to put that one first.
After fixing my typo.
So virtual void add to attribute points.
All right, let's get those definitions generated.
And these are going to all just get our aura player state.
So I'm going to get those two lines.
And then get attribute points.
Reward is going to return or a player state or a player state level up info level up information.
And we actually need to know the level to get the attribute points reward, don't we?
So get attribute points, reward and spell points reward need to take in an int 32 for the level.
So let's do that.
We'll go back to the player interface, get attribute points.
Reward needs to take in an int 32 called level.
Get spell points.
Reward needs an N 32 called level as well.
So we'll fix that.
We'll go to our character and make sure these two functions take in 30 twos and then back in the CPP
file.
We'll make sure that they take in 30 twos and level up.
Information can be indexed at level.
We can use Dot and get attribute point reward.
So this will be similar and get spell point reward.
We're going to paste that all.
The only difference is we're going to get our spell point reward instead for that level.
Now for add to player level, this is going to get our player state and we're going to add to the player
level and or a player state has add to level so we can handle that here.
So first we're going to get our player state, take our player state and call add to level.
And of course this cannot be const if we're going to call add to level and we're going to pass in in
player level, really this should be called in level amount to add or something like that.
But add to implies that well we're adding to the level now, add to attribute points and add to spell
points.
Let's see if we had created those.
We don't have add to attribute points or spell points.
In fact, our aura player state doesn't have attribute points and spell points, so we'll go ahead and
create those later.
And for now we'll just put a to do on these.
We'll say comment to do add attribute points to player state.
I'd like those to be variables on the player state.
We'll do the same thing for to do add spell points.
Two player state.
So only so much we can do all at once.
We can't go on too many tangents right now.
For now, though, we have these interface functions and they're implemented.
So back in attribute set, we can take care of this.
To do so, we created get attribute points, reward and spell points, rewards.
We can get those so we can say in 32 attribute points
reward and we can use AI player interface.
Execute get attribute points reward passing in props dot source character.
And we can pass in the level for the attribute points reward.
So for each level in our data asset, we put an attribute points reward for leveling up at that level
so we can pass in our current level here and that can be const.
We can also make a const int 32 called spell points reward.
And we can use AI player interface.
Execute Get spell points reward passing in both props, dot source character and current level here
as well.
Now that we have those, we can do these other things like add to player level so we can take our AI
player interface and execute.
Add to player level.
So first we pass in props dot source character and we want to add to the current level how much?
Well, the number of level ups.
So num level ups.
So that takes care of that to do.
And then we want to add to our attribute points and spell points.
And again, our character doesn't do anything for this yet, but we'll go ahead and call those functions.
So we'll say AI player interface.
Execute add to attribute points and we're going to go ahead and pass in props, dot source character.
And how much do we want to add to our attribute points?
We want to add our attribute points, reward that we looked up and then we can take AI player interface
and execute add to spell points.
And again, we're going to pass in props dot source character and our spell points reward.
So that takes care of those.
Now we can fill up our health and mana and that is actually something we already can do.
From here.
We can just call set health and we can set it to the max health, get max health like so, and we can
set mana to its max as well.
Set mana to get max mana.
That way.
We're all filled up.
We're topped off Our health and Mana globes will be filled.
So now we're handling all the level up stuff, so we don't need this to do to see if we should level
up.
Now post gameplay effect execute is looking a little unruly so we could really refactor these into each
their own functions.
That's fine for now.
We'll refactor it in a little bit because this video is getting long, but at least now we're executing
this level up capability and really all we're doing here is executing these interface functions and
or a character implements them such that we're calling functions on the player state, such as add to
player level.
So we're going to want to show our player level in the HUD and our player state.
If we go to our player state and take a look at its add to player level and other add to functions where
broadcasting delegates.
So it's already set up so that once we add to the player level, those delegates will be broadcast and
then we can very easily respond to these in our widget controller and therefore our widgets.
So this is a great stopping point.
Let's just compile, make sure that there's no compiler errors we might have missed.
And with a successful compile.
We'll continue in the next video.
I'll see you soon.