Repository navigation
feat: the craft roll gives a hit clue instead of blocking Masterworks #42
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/net/tfminecraft/advancedcrafting/utils/HitClue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package net.tfminecraft.advancedcrafting.utils; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.Map; | ||
|
|
||
| import net.tfminecraft.advancedcrafting.objects.crafting.hits.CraftingHit; | ||
| import net.tfminecraft.tlibs.objects.utils.IntCounter; | ||
|
|
||
| /** | ||
| * The hint a crafter may get after finishing an imperfect piece. It names the hit that was closest to right | ||
| * without being right, and says only which way it was off and roughly how far, never the needed count. | ||
| */ | ||
| public final class HitClue { | ||
|
|
||
| public static final String PREFIX = "§7Looking the piece over, "; | ||
| public static final String NO_CLUE = PREFIX + "you can't tell what went wrong with it."; | ||
|
|
||
| private HitClue() { | ||
| } | ||
|
|
||
| /** The clue line, or null when every hit was done exactly. */ | ||
| public static String clueFor(Map<CraftingHit, IntCounter> hits) { | ||
| Map.Entry<CraftingHit, IntCounter> closest = hits.entrySet().stream() | ||
| .filter(e -> e.getValue().getCurrent() != e.getValue().getNeeded()) | ||
| .min(Comparator.<Map.Entry<CraftingHit, IntCounter>>comparingInt(e -> difference(e.getValue())) | ||
| .thenComparingDouble(e -> relativeError(e.getValue())) | ||
| .thenComparing(e -> e.getKey().getId())) | ||
| .orElse(null); | ||
| if (closest == null) return null; | ||
| IntCounter c = closest.getValue(); | ||
| String name = closest.getKey().getName() + "§7"; | ||
| if (c.getCurrent() == 0) return PREFIX + "you sense it needed some " + name + " work."; | ||
| if (c.getNeeded() == 0) return PREFIX + "you sense it took " + name + " work it didn't need."; | ||
| boolean little = difference(c) == 1 || relativeError(c) <= 0.25; | ||
| boolean far = relativeError(c) > 0.75; | ||
| if (c.getCurrent() < c.getNeeded()) { | ||
| String amount = little ? "a little more" : far ? "much more" : "more"; | ||
| return PREFIX + "you sense it needed " + amount + " " + name + " work."; | ||
| } | ||
| String amount = little ? "a little too much" : far ? "far too much" : "too much"; | ||
| return PREFIX + "you sense it took " + amount + " " + name + " work."; | ||
| } | ||
|
|
||
| private static int difference(IntCounter c) { | ||
| return Math.abs(c.getCurrent() - c.getNeeded()); | ||
| } | ||
|
|
||
| /** How far off a hit is for its size; any use of a hit the piece did not need is fully wrong. */ | ||
| private static double relativeError(IntCounter c) { | ||
| if (c.getNeeded() <= 0) return Double.POSITIVE_INFINITY; | ||
| return (double) difference(c) / c.getNeeded(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.