Correcting the character stats when equipping

The last thing that we need to do is adding some logic to make sure that the base stats do not continue to climb if the equipment is chosen more than once from the equipment screen. To do this, we need to create two variables in the FieldPlayer Blueprint. One variable will be a Boolean that keeps track of whether the soldier has a weapon equipped. The other will be an integer to keep track of the soldier's base attack stat. These elements together will allow us to create the logic in our weapon button that prevents the attack stat from climbing every time we click on a weapon.

So, first navigate to the FieldPlayer Blueprint and create a Boolean called soldierWeaponEquipped. Then, create an integer called soldierbaseAtk:

Correcting the character stats when equipping

We specify these stats to be of a specific character and weapon equipment because if your game has more characters in your party, along with both weapons and armor for each character, you will need to differentiate between all the characters' statuses. Moreover, you may want to create a base status for every statistic because some equipment may change stats other than attack.

We can now create the logic using the new variables that we created. Navigate to the Weapon Widget Blueprint Event Graph. We need to modify some of our logic to tell when a weapon is equipped on the soldier. Create a SET Soldier Weapon Equipped function and set it to true after you have equipped the weapon (or pressed the button for the weapon):

Correcting the character stats when equipping

Remember that since this particular button equips the soldier's weapon only when it is pressed, if you have additional characters and/or different types of equipment, you need to create a different Widget Blueprint to accommodate these characters and equipment types.

Next, we need to create the logic to calculate the base attack. Since we have already used the Boolean to differentiate between when the soldier is equipping a weapon or not, we can use this logic to calculate the base attack stat. What we know in our game, by default, is that the character does not have a weapon equipped. So, what we can do is define the base attack stat as soon as we construct this Widget Blueprint, but specifically, when the soldier does not have a weapon equipped.

At this point, when the Widget Blueprint is constructed, get all the actors of the Field Player class using the Get All Actors Of Class function. After we have got all the actors of this class, get the soldierWeaponEquipped variable. Let's allow the Get All Actors Of Class function to fire off a branch that checks whether the soldierWeaponEquipped variable is true or false:

Correcting the character stats when equipping

If the condition is false, set the soldierbaseAtk to the ATK variable of the character. When choosing a weapon, instead of adding the ATK of ItemData and the ATK of the current character's ATK stat, add the ATK of ItemData and soldierbaseAtk so that we can always use the base ATK variable when equipping a weapon rather than the current stat. This will prevent the ATK variable from climbing:

Correcting the character stats when equipping

One major problem you will notice is that the attack stat will continue to grow if we exit the equipment screen and come back to equip an item. This is because we do not have logic in place for when a weapon is already equipped. So, when soldierWeaponEquipped is true, we need to find which weapon is currently equipped, and subtract its stats from the soldier's base stats in order to reset the base stats.

To do this, we will simply use the Get Data Table Row Names function to get the names of the items in the Weapons Data Table. For each name in the Data Table, we need to compare the name to the soldierWeapon variable from the Field Player class. If the names are equal, we get the row name from the Weapons Data Table using the Get Data Table Row function, subtract the ATK stat of the weapon from the soldierbaseAtk stat, find the absolute value of that operation using the Absolute (Int) function, and finally, set that number to the soldierbaseAtk stat:

Correcting the character stats when equipping

At this point, if you test the equipping of weapons, the attack stat will no longer climb.

This method will work since we do not have a leveling system in place yet. However, when we do have a leveling system in place, we will want to replace this ATK variable with the base ATK variable that we create for the leveling.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.171.212