Hanter-19 / bb-legends-favoured-enemy-refund

A submod for the Battle Brothers Legends Mod.
0 stars 0 forks source link

Potion of Oblivion vs FE Refund #8

Open Hanter-19 opened 1 year ago

Hanter-19 commented 1 year ago

Reported by Bella'kor on Discord: https://discord.com/channels/547043336465154049/1088956924516634707/1112341341452640316

To summarize the issue:

Current Behaviour

Expected Behaviour

Code Analysis and Proposed Fix

Currently the FE Perk refund process checks for the existence of a flag in the actor, and will only refund the point if the flag is not already present. (see legend_favoured_enemy_skill.onUpdate())

When drinking Potion of Oblivion, the flags are not removed, so when the Player picks the FE Perk again, this check will detect the flags and not refund the Perk Point.

I propose we hook the entity/tactical/actor.resetPerks() function to also remove all FE Perk-related flags in the actor.

Hanter-19 commented 1 year ago

First attempt to fix was tested by Bella'kor.

This time, we detected a bug where drinking the Potion of Oblivion resulted in the character getting refunded more points than they were supposed to based on the number of times they leveled up.

Suspected Cause

The resetPerks function iterates over all of the character's skills and counts any Skill object that is the Perk type. This means that additional Perks added after refunding FE perks will get included in this count, therefore inflating the number of perk points refunded by resetPerks

Proposed Solution

In the same hook that I wrote for resetPerks, add some logic to reduce the actor's total perk points (after resetPerks has been called). We will reduce the amount by the number of FE flags that we removed (therefore accounting for the inflated points)

Possible Edge Case?

My brain is too tired to work out the details right now, but we will need to consider what is the effect of the Proposed Solution for the following edge case:

Will revisit this potential edge case next time and analyse the impact.

Hanter-19 commented 1 year ago

Edge Case Considered

By following the Proposed Solution outlined in the previous comment, the Possible Edge Case raised would be handled.

Consider the following example:

Thus, we have successfully started with 2 Perks Owned and ended with 2 Available Perk Points.

The above illustration shows that our Edge Case is handled by the Proposed Solution