You are not updating the RemainingDamage variable. There are many ways around this but what I would do is something like:
int DamageToInflict = Min(RemainingDamage, Barrier).
Barrier = Barrier - DamageToInflict.
RemainingDamage = RemainingDamage - DamageToInflict.
Then do your Barrier <= 0 check stuff.
This approach is also a lot simpler than the approach you did. No need to do so much branching.