Welcome back.
Now things are coming along pretty nicely.
We have a nice HUD.
We're showing the abilities that we have.
And now that we have the capability to visualize certain things, it's time to get a little bit deeper
with a couple of important aspects of gameplay abilities, cost and cooldown.
Now, when we launch a fireball, our fireball doesn't actually have a gameplay ability cost.
In other words, in most games you would expect your mana to go down as you spend mana as a resource
to cast a spell so we can implement a cost and a cooldown is also something we're not implementing.
Sure, we can't spam it, but that's only because we're putting a delay in place for our gameplay ability.
Firebolt At the very end, before we end the ability we delay by half a second.
So this is basically a hack.
Without the delay, we could spam this ability as quickly as we want it.
In fact, we could spam it so fast that we could.
Well, do that.
So cooldowns are important and a delay is not a cooldown.
So we're going to implement those in these next couple of videos and we're going to start with a cost.
As a cost is important and we have a mana resource.
So it only makes sense that we spend mana to cast spells so our mana can be affected by a cost and we
implement cost in the gameplay ability itself.
If we click on class defaults and scroll all the way down to the bottom, we have a costs section and
a cooldowns section and notice that both of these have gameplay effects.
That's how cost and Cooldowns are implemented.
They're implemented with gameplay effects.
A cost gameplay effect can be created and assigned right here, and it'll automatically work in a way
that you would expect a gameplay cost to work.
So how do we implement a gameplay cost effect?
Well, we first create the effect and I'm going to create one for our firebolt ability right here in
the Firebolt folder.
I'm going to right click, create a new Blueprint class, search for gameplay effect and choose the
gameplay effect class and call this g underscore cost underscore firebolt.
So we can open the firebolt gameplay effect and all we need to do is leave its duration policy at instant
and add a modifier so we can click plus for the modifiers array, expand it and for the attribute we
choose which attribute is the resource that should be spent to cast this ability.
So in our case we're going to choose Mana.
So we need to find Aura attribute Setmana.
We choose that and we leave the modifier OP at Add and choose a modifier magnitude.
Now we could hardcode a value in here and if we're spending the resource, it has to be negative.
So we're going to put, say, -20 mana.
Now of course you could use a curve table for this and scale it based on the gameplay effects level
as well.
But I'm just going to Hardcode 20 and, and in order to implement this as a cost gameplay effect, all
we do is go over to the Firebolt gameplay ability and set the cost gameplay effect class.
Here we're going to choose GE cost Firebolt.
Now we've assigned a cost gameplay effect.
Now how does this actually get enforced?
Well, there's a function on our gameplay ability that we have to call in order to commit that cost
and we can call that function immediately after activating the ability and it's called commit ability.
Now notice there are several versions we have commit ability, we have commit ability cooldown and commit
ability, cost commit ability will commit both the cooldown and the cost.
And what that means is it will attempt to spend the resources.
In other words, this can fail if we call commit ability and we don't have the proper resources, we
will be prevented from activating the ability.
And this does return a boolean.
And what we can do with this boolean is just print a message.
We're going to print a string and pass that boolean in and see what that boolean value is after calling
commit ability.
So I'm going to compile press play and cast the spell.
Now take a look at our mana.
It has gone down and the server has printed the message true to the screen.
Look at that.
True.
That means that our gay firebolt has reached this commit ability and it has succeeded because there's
enough resources to pay for the spell.
Now we're getting low.
Soon we won't be able to cast it.
It looks like right about here.
Where out of mana or just about out of mana.
It doesn't look like we have enough to pay for the ability.
I'm going to attempt to cast the ability and nothing happens.
Interesting, right?
We don't even get that string printed.
So the return value returns true if the commit ability succeeds.
But if the commit ability does not succeed, it doesn't even reach any farther.
We don't even hit that print string.
Now we can add a print string at the beginning and say ability activated.
And let's see what happens if we spend up all of our mana.
All the way to that last bit of mana.
And now if we attempt to cast.
Look at this, it doesn't even cast.
So even though it's kind of paradoxical, but even though we reach the commit ability, otherwise we
wouldn't be able to check to see if we have any mana if commit ability fails.
This act is undone.
It's as if we never even activated the ability at all.
Kind of crazy right now.
Commit ability, as I said, commits both the cost and the cooldown.
So if we're interested in committing the cost at one point in the ability and the cooldown later on,
we could do that because we have commit ability, cost and commit ability cooldown as well.
But commit ability will do both in one fell swoop if that's what you want.
So I'm going to get rid of those print strings.
And now we're committing an ability cost.
And if we wanted to, we could have that ability.
Cost depend on the level of our ability.
Now game play abilities themselves have a level, and if we use a scalable float, they'll use their
level.
So the question is, is the cost gameplay effect applied at the level of our ability?
Right.
Because we're not applying this gameplay effect, the ability does it automatically with commit ability
cost.
So to answer that question, I'd like to dive into C plus plus and take a look at commit ability cost.
Now here we see it in gameplay ability and I've opened the CPP file and let's see what it does.
It first checks if it should ignore costs which should ignore costs.
And if it does then well, we just succeed.
We don't check the cost.
But then it calls check cost and apply cost.
Now check Cost has a comment that says Last chance to fail.
Maybe we no longer have resources to commit since after we started this ability activation and then
we have apply cost.
Now I'd like to take a look at apply cost.
Here we see apply gameplay effect to owner and here's where we can see what level we're passing in for
the gameplay effect.
And take a look.
We're passing in get ability level, so sure enough that gameplay effect will be applied at the level
of our current ability.
So if we want to, we can have a scalable float, we can have a curve table that will scale our cost
depending on the ability level.
Kind of cool.
And that's going to be your quest.
I'd like you to create a curve table for gameplay ability costs so you can create this curve table.
You can call it cost curve table if you like, and add a cost curve for the firebolt ability and make
sure you scale that manacost based on the level as you see fit.
Pause the video and make this curve table now.
Okay, so I'm going to make a curved table and I'm going to stick it in ability system data.
And this means I need to go to miscellaneous Choose Curve table and this can be a constant curve table.
I'm going to call this city underscore cost.
We could call it ability cost.
I'm just going to call it cost.
Open that up.
We have a curve.
I'm going to rename it to Fire Dot Fire Bolt.
And selecting it, I can click to add my level one value and I'm going to use positive numbers here.
My first manacost will be 20.
I'm going to keep it at 20.
Actually, we'll go up to 25 at level two.
35 at level three.
Let's do 50 at level four, 91, 2150.
We'll do two more.
180 and 200.
And we can take a look at the curve.
And here's what it looks like, a nice step curve.
So now that we have that, we can go back to cost firebolt and for the scalable float, we can use the
curve table CT cost and instead of -20, we are going to use the scale value of negative one as our
CT cost values are all positive, right?
And for the curve, we're going to choose fire firebolt and we can see what that cost is at the levels
zero through ten.
Okay.
Now our ability is given at level one, isn't it?
So really, if we want that ability given at a higher level, let's go and look at where we're giving
that ability.
Here in the ability system component, when we create the ability spec, we're creating it at level
one.
So if we change this to two now, we can take a look at how that affects our cost.
It should go from 20 to 25.
So I'm going to close the editor.
And you know what?
Just to see a more dramatic change, let's put it at a higher level.
Let's do five and we'll go ahead and compile and launch.
And hopefully I have enough mana to pay for this cost at level five.
That's going to be 70 mana.
Let's see if it goes down more.
Sure enough, it goes down a lot more.
So our cost is scaled by the level according to our firebolt step curve.
So that's looking great.
I'm going to go ahead and close out of these.
Tabs will open things again if we need to.
And we have a cost.
Excellent.
Excellent job.
I'm going to change this back so that we're applying the ability spec at level one.
Go ahead and compile that great job and I'll see you in the next video.