Skip to content

Prevent variable-cost spells being made free with very small inputs - #1308

Open
Robotgiggle wants to merge 5 commits into
mainfrom
clamp-min-cost
Open

Robotgiggle wants to merge 5 commits into
mainfrom
clamp-min-cost

Conversation

@Robotgiggle

@Robotgiggle Robotgiggle commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

This PR adds a new toLongNonzero() method to convert a Double to a Long while ensuring the output is at minimum 1. This is used to prevent spells with costs based on player input (Impulse, Blink, Explode/Fireball, Anchorite/Wayfarer, and the Zeniths/Nadirs) from being made free by providing an input value so small it gets rounded to zero when converted to a Long.

This also makes those spells have a nonzero cost even when the input value actually is zero, since there is still a world interaction in that case and thus the spell should not be infinitely spammable for free.

Also, entirely unrelated to the cost clamping, this PR fixes #941 - I was changing stuff in OpPotion anyway, so I figured I'd toss in a fix here rather than making a separate PR for a single-character change.

@github-project-automation github-project-automation Bot moved this to 📋 Backlog in Hex Casting Sep 22, 2026
@Robotgiggle Robotgiggle added 1.20 optimization Improvement to existing features or performance (no new features or design work) labels Sep 22, 2026
RenderedSpell {
override fun cast(env: CastingEnvironment) {
if (duration > 1.0 / 20.0) {
if (duration >= 1.0 / 20.0) {

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.

Why was this originally a >?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Honestly, no idea. Might have just been an oversight from whoever originally wrote it, since the intent seems to pretty clearly be "minimum duration of 1 tick".

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.

Yep, it was a misimpl: 81e5f85

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20 optimization Improvement to existing features or performance (no new features or design work)

Projects

Status: 📋 Backlog

Development

Successfully merging this pull request may close these issues.

1 tick potions dont work

2 participants