Skip to content
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

Research unlock with vault economy provider #4002

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

Conversation

misdocumeno
Copy link

@misdocumeno misdocumeno commented Oct 20, 2023

Description

Adds the option to use money instead of experience to unlock research, without major changes in the codebase or config files.

Proposed changes

I added two new keys to config.yml inside researches. enable-vault-economy and economy-price-multiplier. If enable-vault-economy is true, money will be used instead of experience, and to avoid having to define the prices again for each investigation, the price is calculated by doing xp levels cost times economy-price-multiplier, that way the ratio between prices is the same as the previous exp cost system.
I created a VaultIntegration class with a few methods, in case anyone wants to mess with the economy in the future.
The lore that shows the cost of unlocking a research shows the price formatted correctly as a currency.

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@misdocumeno misdocumeno requested review from a team as code owners October 20, 2023 07:02
@github-actions github-actions bot added the 🎈 Feature This Pull Request adds a new feature. label Oct 20, 2023
@github-actions
Copy link
Contributor

Your Pull Request was automatically labelled as: "🎈 Feature"
Thank you for contributing to this project! ❤️

@ybw0014
Copy link
Contributor

ybw0014 commented Oct 20, 2023

Duplicate of #3942

@TheBusyBot TheBusyBot added the 🚩 Duplicate This Issue is a duplicate. label Oct 20, 2023
@misdocumeno
Copy link
Author

Duplicate of #3942

not the same thing, this implementation is much simpler, and it only adds two new optional settings, the other one creates an unlock provider and what not, i guess it depends on the way you want to add this feature, this is quick and simple, the other one is more scalable probably

Comment on lines +34 to +35
enable-vault-economy: false
economy-price-multiplier: 1000.0
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be grouped and simplified

Suggested change
enable-vault-economy: false
economy-price-multiplier: 1000.0
vault-integration
enabled: false
cost-multiplier: 1000.0

Copy link
Author

Choose a reason for hiding this comment

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

do you mean you want vault-integration to be inside researches? or you want it at the top level?

Comment on lines 251 to 254
boolean creativeResearch = p.getGameMode() == GameMode.CREATIVE && Slimefun.getRegistry().isFreeCreativeResearchingEnabled();
return creativeResearch || p.getLevel() >= cost;
boolean economyResearch = Slimefun.getIntegrations().isVaultInstalled() && Slimefun.getIntegrations().getVaultIntegration().hasBalanceForResearch(p, cost);
boolean expResearch = !Slimefun.getRegistry().isVaultEconomyEnabled() && p.getLevel() >= cost;
return creativeResearch || economyResearch || expResearch;
Copy link
Member

Choose a reason for hiding this comment

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

This is a method with high traffic, so think about if we really need to calculate all of this everytime...
If you split this into smaller methods then the || operator would ensure that the sub-methods are not called unnecessarily.

@TheBusyBiscuit TheBusyBiscuit removed the 🚩 Duplicate This Issue is a duplicate. label Oct 21, 2023
@TheBusyBiscuit
Copy link
Member

TheBusyBiscuit commented Oct 21, 2023

Duplicate of #3942

not the same thing, this implementation is much simpler, and it only adds two new optional settings, the other one creates an unlock provider and what not, i guess it depends on the way you want to add this feature, this is quick and simple, the other one is more scalable probably

Agreed.

Also @ybw0014 we don't really mark PRs as duplicates unless absolutely obvious. The same feature can be implement in numerous ways and we may choose one implementation over the other for reasons.

@TheBusyBot TheBusyBot added the 🚩 Duplicate This Issue is a duplicate. label Oct 21, 2023
@TheBusyBiscuit TheBusyBiscuit removed the 🚩 Duplicate This Issue is a duplicate. label Oct 21, 2023
@github-actions
Copy link
Contributor

Slimefun preview build

A Slimefun preview build is available for testing!
Commit: ff5f2648

https://preview-builds.walshy.dev/download/Slimefun/4002/ff5f2648

Note: This is not a supported build and is only here for the purposes of testing.
Do not run this on a live server and do not report bugs anywhere but this PR!

@TheBusyBot TheBusyBot added the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Dec 27, 2023
@TheBusyBot TheBusyBot removed the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈 Feature This Pull Request adds a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants