Welcome back.
Now that we have damage effect params, it's time to start using them.
So the first place I'd like to start is our aura projectile spell.
If we go into our aura projectile spell, I'm just going to go straight to the private folder and ability
system abilities and open are a projectile spell.
We see that we're spawning a projectile and setting its damage effect spec handle.
So we're assigning set by color magnitudes already here.
Now we don't need to do any of that.
All we have to do is make use of some of these functions and types that we've created to make our lives
easier.
So from the point where we spawn the projectile using spawn actor deferred to the point where we finish
spawning, we can refactor some of this stuff.
In fact, a lot of this stuff is going to be different.
When we were learning about effect context handles.
We set a bunch of things on the effect context handle just because we could for educational purposes.
Now, we don't need to do any of that.
In fact, our projectile doesn't even need a spec handle anymore.
All it really needs is damage effect params that we can set on it.
So here's what I'm going to do.
I'm going to gut out all of this code between spawn actor deferred and finish spawning.
I'm just going to delete it.
We're going to do things a bit differently and projectile can now have some damage effect params instead
of a gameplay effect spec.
The params can contain the gameplay effect class.
So I'm going to go into my actor folder in the public folder in actor, and I'm going to take a projectile
and open it up.
And I think what I'd like to do is close some of these tabs I don't need.
So I don't need most of these.
I just need aura, projectile spell and aura Projectile.
Now aura projectile has damage effect spec handle.
But I'm going to replace this now.
I'm going to replace this with an EF damage effect params and I'm going to add the include for it here
and it's going to be called damage effect params.
Now in my includes I don't need gameplay effect types h so I can remove it and now I have aura ability
types instead and damage effect params can be set in aura projectile spell and then we can go and fix
up aura projectile upkeep because now it's going to have some red text.
Right?
So we'll get to that.
We're going to take aura projectile upkeep and we'll move them off to the left and Aura projectile spell
is going to fill in some information here.
So first we can make some damage effect.
Params we can call this damage effect params and now our damage gameplay ability has a make damage effect
params from class defaults function.
Now it requires the target actor and at this point in the aura projectile spell, we don't know who
the target actor is, so we're going to pass in a null pointer.
In fact, that's null by default.
We don't even have to pass that in.
We just have to make sure that that target actor gets set as soon as our aura projectile overlaps with
it.
Now that we have these damage effect params, we can set the damage effect params on aura projectile
so we can take the projectile that we've just spawned and we can set its damage effect params to our
damage effect params.
And in fact we don't need a local variable for it.
We can just set it equal to the result of make damage effect params from class defaults.
Now the projectile will have its own damage effect params and then we can finish spawning.
So make damage effect params from class defaults and setting damage effect params on the projectile
has reduced our code by quite a great deal.
So it's a nice refactor and it also makes this easy for future gameplay abilities as we don't have to
repeat ourselves a lot.
So now we just have to make sure we're using these effect params in our projectile.
So let's go to Aura Projectile CP and see what we're doing here.
Now, the first thing I'm noticing is about four lines of repeated code here and here.
And I think that would be good to just abstract.
These are things that happen on hit, so I'd like this to be abstracted.
I'm going to go to refactor.
Here it is.
Refactor this and extract method and call this on hit and click next and now on hit is called right
there.
But also that's what these lines are doing.
So we're going to call on hit here.
Now this allows me to condense my code a lot because there's a lot of lines of code but not doing much.
Right.
So we're going to fix it.
In fact, in Destroyed, this is one of those situations where we could just put this all on a single
line.
We don't need four lines to do what one line of code would suffice for.
And now for on sphere Overlap, it's checking.
Let's see what it was doing before it was taking damage effect spec handle, making sure that it was
valid.
Also making sure that the context had an effect causer that was not the other actor.
So the other actor is the actor being overlapped with We're making sure that the effect causer and the
spec handle is not that other actor.
Right?
Well, now things are a little different because we don't even have an effect spec handle.
Instead we have damage effect params and we can check some things in that.
For example, we could check to see if the effect causer or at least the source is not the other actor
because we could take damage effect params dot and we can get the source ability system component and
call get avatar actor.
Now if we store that in a const a actor pointer called source Avatar actor.
Then we can make sure that that source avatar actor isn't the other actor being overlapped with.
Now we don't need to check the effect spec handle.
In fact, one doesn't exist yet.
It's the ability system blueprint library that's going to create all that for us.
So at this point it's too early to check.
All we have to do is see if source Avatar actor is the other actor.
If it is, we can return.
And I'm going to place this all on a single line.
Now we're also checking is not friend.
Remember this checks a couple of tags, not gameplay tags, but name based actor tags to see if it's
friendly fire or not.
Right.
So we're checking is not friend.
And what were we checking before we were checking the effect.
Spec handles Context effect causer.
Against the other actor.
So again, that's the same as our source avatar actor.
So we can check the source Avatar actor here and of course is not friend is not going to be happy with
a const actor.
So we're going to pass in a non const and I'll go ahead and take this return and stick that right there.
And now we have even less lines of code.
Now, if not be hit on hit, that could also be on a single line too.
I'm starting to like how this looks now.
Not so much code.
We can even put this else on a single line like this.
Now all we have to worry about is when we have authority applying the gameplay effect.
So how are we going to do that?
Well, we made a function in our ability system function library.
Let's just open that up.
It's called Apply Damage Effect.
We can call that.
Now, we can't forget the target ability system component hasn't been set on it.
We didn't know until now who the target was.
Now we do.
It's Target ASC.
We're getting it here.
So this is where we can set that on our damage effect.
Params we can take damage effect, params dot target ability system component and set it to target ASC.
And in the future if we add anything else in effect params that needs to be set here, we'll set it
here.
But for now that's all we care about.
That's the only thing that wasn't set because when we made this damage effect params and set it to the
projectile here in aura projectile spell, we made it passing in nothing.
Which means that that target actor has a default null pointer.
And we can just really quickly remind ourselves in or a damage gameplay ability in this make damage
effect params from class defaults.
The target ability system component was set using get ability system component which will return a null
pointer if target actor is null.
So that's something to keep in mind.
Right?
And we kept that in mind and that's why we set the target ASC here.
After that, we can apply the effect by using you or a ability system library apply damage effect passing
in the damage effect params and that should result in the damage being caused.
Now so far, this shouldn't change any behavior we've already been seeing, but the difference is now
this spec, as we can see in Aura ability system library has all these set by color magnitudes in addition
to damage, including all the debuff parameters which we can then use anywhere along the pipeline where
we have the spec.
So we'll use these parameters soon enough.
For now we need to compile and launch the editor and see if our code still works, if we can still cause
damage.
So I'm just going to dig right in and go into combat.
Okay, so I got a breakpoint in exec calc damage.
So this is the whole point of testing, right?
We hit this check right here that says tags to capture defs doesn't contain tag and exec calc damage.
So here in the exec calc, we're taking our damage statics dot tags to capture defs because we created
these resistance tags.
And by the time the exec calc catches wind of this ability, it's going to loop over damage types to
resistances.
Now we see that right here.
Resistance tag is the pair value.
So our damage types to resistance is t map it appears has a debuff tag in it.
That sounds a lot like an error.
So we need to go look at damage types to resistances in for a gameplay tags.
So I'm going to go into aura gameplay tags and here's damage types to resistances.
It appears that I must have put all those debuff tags in the wrong map, so let's make sure that's not
the case.
Oh, look at that.
Wow.
I actually put the arcane debuff and damage types to debuffs, but I didn't actually put the other three.
I must have just kind of replaced this one and neglected the others.
So that's an easy fix.
I'm going to go ahead and replace those and put these tags where they belong and you'll likely have
seen some kind of text and an arrow pointing to this on the screen back when I did this saying, Hey,
don't forget, this is the map that you should use.
So with that, we should be good.
And it's good that we used a check F right?
Because this is telling us really what's going on.
Tags to capture defs doesn't contain that tag.
And then we looked and saw that our damage types to resistances team map contained a debuff tag which
doesn't belong there.
Okay.
So we can try this again.
And we're causing damage as we should.
We can also make sure that the enemies can cause damage to us.
And it looks like they can.
And those slingshot goblins really are ruthless, aren't they?
Look at that.
Look at this little guy.
Let's just roast him.
Yeah.
Take that goblin.
That goblin didn't give me much XP, but that's because we set our XP reward for the spear goblins to
a ridiculously high number.
I believe it was 300.
We did no such thing for the Slingshot Goblin.
So it's not a mistake that the Slingshot goblin didn't give us that much XP, so don't worry.
That was correct.
All right.
Just spending a spell point because I can equipping that next ability.
Because I can.
Because why not soon?
We'll actually be making that ability soon enough.
But for now we have achieved an important milestone and that is to use the damage effect params struct
we created.
And not only that but our gameplay ability, at least those that do damage now has damage effect params
and those are being passed along.
And because they're being passed along we can then take a look at those effect params and use them.
Now the only thing special so far are the debuff params, so we want to see if a successful debuff should
happen.
So we'll be using those debuff params to determine if we got a successful debuff and we'll be doing
that next.
I'll see you soon.