Skip to content

Fixed calculation problems when deconstruct #10897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ankando
Copy link

@ankando ankando commented Jun 4, 2025

  • I have read the contribution guidelines.
  • I have ensured that my code compiles, if applicable.
  • I have ensured that any new features in this PR function correctly in-game, if applicable.

I get the amount obtained in the process through

refundedItems[i] += accepting;

Because itemsLeft[i] = totalCost[i] - usedItems[i] + refundedItems[i]
So I get usedItems[i], and then I get the total amount that should be given to you, that is, totalRefundItems[i] = usedItems[i] * deconstructMultiplier, and then I use totalRefundItems[i - refundedItems[i] to get the most accurate amount of compensation.

But even so, I found other problems. For example, if deconstructMultiplier = 2, I spent 7 coppers to build it, and refundedItems[i] = 15, it gave me one more, which means that I can't give it, but I have to reduce it by one.

@ankando
Copy link
Author

ankando commented Jun 4, 2025

@Anuken The original remaining is not accurate. You should use "the total materials that should be given to you" - "the materials currently given to you" instead of "total cost x refund multiplier" - "total cost - construction cost + materials currently given to you".

@@ -171,6 +172,7 @@ public class ConstructBuild extends Building{
private @Nullable float[] accumulator;
private @Nullable float[] totalAccumulator;
private @Nullable int[] itemsLeft;
private @Nullable int[] refundedItems;
Copy link
Owner

Choose a reason for hiding this comment

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

Why add a new array? As far as I can tell, you're always incrementing refundedItems and itemsLeft by the same amount, so their values should be identical at the end.

Copy link
Author

Choose a reason for hiding this comment

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

Why add a new array? As far as I can tell, you're always incrementing refundedItems and itemsLeft by the same amount, so their values should be identical at the end.

Besides this, itemsLeft has an initial value, so it is not equal to the amount of materials given to you during the process. It is also not equal to refundItems

Copy link
Author

Choose a reason for hiding this comment

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

@Anuken
I found that the initial value of itemsLeft[i] is equal to total construction cost - construction cost, meaning it is 0 when you have fully built it, but not otherwise.

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.

2 participants