Welcome back.
So we know that we're actually setting our incoming exp meta attribute as a response to causing lethal
damage.
Now, once we've done that, we need our player state to receive that incoming exp value so that it
can increase its own exp.
But the thing is, our player state if we go to aura player state, it depends on our attribute set
and we don't want our attribute set dependent on the player state.
I think the attribute set should be independent of that.
Now what we can do is create an interface function.
If we go into our interaction folder, we have an enemy interface and a combat interface, and we're
about to want our attributes set to set lots of things that only have to do with the player as in a
human controlled character.
So while we have an enemy only interface and we have a combat interface, one that's used by both human
controlled players and enemies together, we don't have one specifically for the player, we don't have
a player interface.
So we're going to need one of those so that our attribute set can use that.
Instead of being dependent directly on our aura player state.
We don't want tight coupling and circular dependencies.
So what we're going to do is create a new interface class.
We're going to put that right there in our interaction folder.
So we'll go to C plus plus classes or a public interaction where our other interfaces are will make
a new C plus plus class and this can be an unreal interface.
And we're going to call this one player interface.
So let's create that class.
Close the editor and we'll go ahead and open it up.
So here it is.
And the first thing I'd like is a function that we can use to add to our XP.
So in the public section, we're going to make a void function and we'll just call it add to XP and
it'll take an INT 32 called in XP.
And I'm going to make this a new function blueprint native event.
And for now I don't see a need to make it blueprint callable.
And I'd like to implement this interface on aura specifically and override add to XP implementation.
So I'm going to go to the public character folder and open aura character and inherit from a public
AI player interface and we've got that header included automatically there and we're going to override
this function.
So I'm going to go ahead and make a multi-line comment here.
I'm going to make two of them actually.
But this will say player interface instead and end player interface and we're going to override virtual
void add to XP.
Implementation.
Now we can implement this.
And what it's going to do is access the player state and call the player states add to exp function
so or a character can access the player state much like it's doing so down here in get player level.
So I'm going to just copy the lines where we get our player state and check it and we're going to take
our player state and call add to Exp.
Now I'm not seeing anything pop up, and that's usually because we made this const.
It cannot be const as we're going to add to the exp, we're going to pass in NXP there.
So now we have add to NXP implementation implemented in Aura character.
And now that we have that we can add to the exp in the aura attribute set.
Now right here when incoming exp is changed, I want to see if we should level up, but we're going
to make that a to do so we're going to say to do see if we should level up.
But in the meantime we'll just call that add to exp.
So what we can do is we can take I player interface and we can call the execute add to exp, but we
have to pass in props dot source character along with an exp amount.
Well that's going to be our local incoming exp.
So we've cashed it off before we zeroed it out.
And now we're going to execute this function.
And we know that the source character should only be aura, as none of our enemies are listening for
events which will result in this attribute being changed.
But we can also place the If check in place just in case we can say if props dot source character implements
and we can check to see if it implements you.
Player interface.
So it's a good way to keep that check in place.
But by definition, we called it player interface specifically so that it's only made for human players.
But we can check nonetheless.
Now we're not checking to see if we should level up, but we are adding exp.
Now this should result in our player state having its exp added to and the player state broadcast a
delegate that our widget controller receives and it in turn broadcast the delegate of its own.
We can go to our private UI widget controller folder and open overlay widget controller.
We have this on Exp change.
It actually broadcasts an exp bar percent so we can listen for that in our exp bar.
So let's go ahead and see if we can listen for that and update our exp bar when gaining experience.
Okay, so the next thing we need to do is go to our XP bar.
So that's going to be in Blueprints UI.
Progress bar, WP XP bar.
And by default I'd like this XP bar to be empty.
So we'll start off empty and as we gain experience we should see it start increasing.
Now we're going to need to not only listen for an event, but we also need to set our XP bars widget
controller, which we should probably do first.
Now the overlay is what can do this because the overlay has the XP bar here.
So while the overlay is setting the widget controller for its health mana spells, it should also set
the widget controller for the progress bar too.
And that progress bar.
Therefore the XP bar must be marked as variable.
And once we do that we can bring it in and we can call set widget controller for it.
Passing in widget controller.
So once that happens, we know that our XP bar will have its event widget controller set fired off.
Once that happens, we can take widget controller.
We can get that and cast it to the overlay widget controller.
We'll cast it to BP overlay widget controller, and we'll promote that to a variable called BP Overlay
widget controller.
And once we have this, we can bind to the event.
So I'll just make a sequence.
And then take BP overlay widget controller and type on XRP and we can assign on XRP percent change Delegate.
And this just broadcasts the XP.
We already went through the trouble to calculate it.
All we need to do is take our progress bar which we can call progress bar underscore XP.
Let's give it a good name and check is variable.
We can drag that in.
And we can call set percent directly.
That function.
And now we should be able to see that percent increase.
So moment of truth.
A lot of work led up to this point.
Hopefully it works without any issues, but let's see.
We'll go ahead and destroy this goblin.
Keeping my eye on that XP bar.
Let's see if this does it.
Okay so on XP changed has triggered.
We have a check here for level up info and it looks like the aura player state may not have level up
info.
I'm not sure if I remembered to set that, so I'm going to hit stop and we're going to have to run this
again and make sure that our player state has that level up info data asset and that's okay.
This is the kind of thing that happens as you're putting a lot of moving parts together.
Now before we go and check the player state, I do want to make sure my changes were implemented here
in Blueprint.
Sometimes crashes can undo things you've done.
Looks like my setting.
The widget controller is there under blueprints UI progress bar.
I'm going to open XP progress bar.
Looks like I am assigning an event to my delegate.
So those look good.
Now I can go to blueprints.
Player or a player state and see if I set my data asset.
It looks like I actually forgot that step.
So easy to forget.
One or more steps.
Let's press play and see now if it works.
I think I might actually lower that cooldown because it's a little too long, but one more hit.
Look at that.
We got XP.
Wow.
What a satisfying feeling to see that XP bar go up.
You know, we have to do more enemies, right?
You know, we're going to have to drag in a bunch of enemies and watch that thing fill up First.
I'm going to lower my cooldown so I can launch a lot more abilities.
So let's go into my cooldown, firebolt, and I'm going to set that from two seconds down to 0.5.
I'd like to have some fun and we're going to put quite a few more enemies in here.
And at this point I think I can start letting them run at me.
So I'm going to let my nav mesh bounds volume finally cover the whole thing, drag it over to the center
there.
We can see that now those enemies should be running at us.
Here they come.
But they're doomed.
They're going to die before they get me.
Most of them.
Oh, wait.
Looks like I ran out of mana.
We're going to need mana.
I'm going to just drag in a couple potions here.
So blueprints, actor potion, BP, mana, and.
I DON'trillionEMEMBER.
How much mana a level one potion gives me.
But the actor level is one.
Let's just see.
I'm going to see what it looks like.
It fills it up just barely.
So.
That's okay.
There are a number of variables we can tweak, but perhaps the easiest way to have fun with this would
be to go to my.
Cost for the firebolt.
Which is using a curved table.
But at level one, it costs 20.
What we can actually do is change my curve table set cost for firebolt and for level one.
We can change this to perhaps five mana or even 2.5.
We can make it really cheap and just lower this curve a bit and even take the whole thing and just drag
it down.
So anyway, it's going to be a lot cheaper now.
This should be a lot more fun.
Much better.
All right, so I got some XP for the first one.
Got some XP for the second one.
Kind of cool how 20 XP is just enough for one of these little mini bars.
There's three of them.
And there's four and our XP bar is working.
How cool.
Yeah, we're going to need to tweak some levels because I think two and a half mana is a lot better
than what I had before.
I think it was 20.
Our man is steadily going down.
But.
Not too fast.
Awesome.
So that's really satisfying to see our XP bar go up.
Really, really cool.
So as we're killing enemies, we're getting experience.
The only thing missing, of course, is leveling up.
Because once this thing fills up, we're not doing anything to handle level ups.
So of course, that's one of the next things.
I think I'm done with my fire there.
I think I might also want to tweak some settings on my mana potion, but until we get to that, I'm
going to delete that too.
And I'll go ahead and just let my goblins remain.
I'm going to rotate two of them to face forward though.
I think, and bring them both forward this way and set them on either side of the doorway so they're
guarding it.
How cool is that?
Look at that.
We'll set them like this and.
That looks pretty good.
All right.
How exciting is this?
This is starting to look like an actual RPG.
Still some work to go, but we're getting experience.
Amazing.
Excellent job.
And I'll see you in the next video.