Skip to content

[core] Unify more Core/Lua TP Gain Functions#9859

Open
UmeboshiXI wants to merge 1 commit intoLandSandBoat:basefrom
UmeboshiXI:Fix_TPReturn_Precision
Open

[core] Unify more Core/Lua TP Gain Functions#9859
UmeboshiXI wants to merge 1 commit intoLandSandBoat:basefrom
UmeboshiXI:Fix_TPReturn_Precision

Conversation

@UmeboshiXI
Copy link
Copy Markdown
Contributor

@UmeboshiXI UmeboshiXI commented Apr 24, 2026

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my PR will be ignored.
  • I understand I should leave resolving conversations to the LandSandBoat team so that reviewers won't miss what was said.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have tested my code and the things my code has changed since the last commit in the PR and will test after any later commits.

What does this pull request do?

  1. Unifies more TP functions in core to use existing lua functions relating to TP gain.
  • getBaseDelay()/getBaseRangedDelay() in lua_baseentity had formulas used in lua based TP functions. I moved the formulas over to Battleutils and pointed the lua binding to use this instead.
  • CalculateTPFromDamageTaken() added. It links to xi.combat.tp.calculateTPGainOnPhysicalDamage()
  • CalculateTPFromDamageDealt() added. It links to xi.combat.tp.getSingleWeaponTPReturn()
  1. Adds a command to get a target's TP and print it in your chat log(Useful for testing).
  • If no target is selected or you have yourself selected, it only prints your TP.
  • If you are selecting another target such as a mob, it will print both your TP and the mob's current TP.

Steps to test these changes

  1. Hit stuff. See that TP gains are the same as before.
  2. Use a weaponskill, see expected TP returns for yourself and the mob.
  3. See no crashes.

TP Returns based on this PR:

(Hit message came in late but it matched)
image

image image

TP Returns from base LSB:

image image image

Comment thread src/map/utils/battleutils.cpp Outdated
@@ -2421,4 +2421,4 @@
((baseTp + 30) * sBlowMult *
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this truncation also happening here?

((baseTp + 30) * sBlowMult *
(1.0f + 0.01f * (float)PDefender->getMod(Mod::STORETP))))); // subtle blow also reduces the "+30" on mob tp gain
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is very hard to read, could you break out the additional terms like it does above:

        // account for attacker's subtle blow which reduces the baseTP gain for the defender
        float sBlow1    = std::clamp((float)(PAttacker->getMod(Mod::SUBTLE_BLOW) + sBlowMerit), -50.0f, 50.0f);
        float sBlow2    = std::clamp((float)(PAttacker->getMod(Mod::SUBTLE_BLOW_II) + tandemBlowBonus), -50.0f, 50.0f);
        float sBlowMult = (100.0f - std::clamp(sBlow1 + sBlow2, -75.0f, 75.0f)) / 100.0f;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually, I might sit down today and see about getting this working with our lua global. I hate this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to hook up our TP lua functions to their equivalents in TakePhysicalDamage and TakeWeaponskillDamage.

@UmeboshiXI UmeboshiXI marked this pull request as draft April 24, 2026 14:23
@UmeboshiXI UmeboshiXI force-pushed the Fix_TPReturn_Precision branch from 7dede6d to b0e02c1 Compare April 25, 2026 00:17
@UmeboshiXI UmeboshiXI force-pushed the Fix_TPReturn_Precision branch from b0e02c1 to 9a2000d Compare April 25, 2026 00:28
@UmeboshiXI UmeboshiXI changed the title [core] Defender TP Return Precision Fix [core] Unify more Core/Lua TP Gain Functions Apr 25, 2026
@UmeboshiXI UmeboshiXI marked this pull request as ready for review April 26, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants