-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: Mob Override Level Mapping #21
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 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c10f805
feat: Enhance environment level computation by incorporating NPC enti…
dfcb579
Merge branch 'main' of github.com:GlobalHive/LevelingCore
dbe8a5e
Update .vscode/settings.json
047c3e8
feat: Add mob level override mapping functionality and default config…
cfc4b9c
feat: Add mob override mapping to Bootstrap initialization
56c9be0
feat: Add level variance configuration to GUI settings
62cd7a8
feat: Enhance mob level computation with NPC entity integration and r…
b480e1f
fix: Add .vscode directory to .gitignore
2219dbd
refactor: Improve code readability by formatting method parameters an…
38d6903
Stop tracking .vscode
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "java.configuration.updateBuildConfiguration": "interactive" | ||
| } |
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
108 changes: 108 additions & 0 deletions
108
src/main/java/com/azuredoom/levelingcore/level/mobs/mapping/MobOverrideMapping.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,108 @@ | ||
| package com.azuredoom.levelingcore.level.mobs.mapping; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.logging.Level; | ||
|
|
||
| import com.azuredoom.levelingcore.LevelingCore; | ||
| import com.azuredoom.levelingcore.config.internal.ConfigManager; | ||
| import com.azuredoom.levelingcore.exceptions.LevelingCoreException; | ||
|
|
||
| public class MobOverrideMapping { | ||
|
|
||
| public static final String FILE_NAME = "moboverridemapping.csv"; | ||
|
|
||
| public static final String RESOURCE_DEFAULT = "/defaultmoboverridemapping.csv"; | ||
|
|
||
| private MobOverrideMapping() {} | ||
|
|
||
| public static Map<String, Integer> loadOrCreate(Path dataDir) { | ||
| try { | ||
| Files.createDirectories(dataDir); | ||
| var configPath = dataDir.resolve(FILE_NAME); | ||
|
|
||
| if (Files.notExists(configPath)) { | ||
| try (InputStream in = ConfigManager.class.getResourceAsStream(RESOURCE_DEFAULT)) { | ||
| if (in == null) { | ||
| throw new LevelingCoreException( | ||
| "defaultmoboverridemapping.csv not found in resources (expected at " + RESOURCE_DEFAULT | ||
| + ")" | ||
| ); | ||
| } | ||
| LevelingCore.LOGGER.at(Level.INFO) | ||
| .log("Creating default Mob Override Levels Mapping config at " + configPath); | ||
| Files.copy(in, configPath, StandardCopyOption.REPLACE_EXISTING); | ||
| } | ||
| } | ||
|
|
||
| var mapping = readXpCsv(configPath); | ||
|
|
||
| LevelingCore.LOGGER.at(Level.INFO) | ||
| .log( | ||
| "Loaded Mob Override Levels Mapping mapping from " + configPath + " " + mapping.size() + " entries)" | ||
| ); | ||
| return mapping; | ||
|
|
||
| } catch (Exception e) { | ||
| throw new LevelingCoreException("Failed to load Mob Override Levels Mapping config", e); | ||
| } | ||
| } | ||
|
|
||
| private static Map<String, Integer> readXpCsv(Path csvPath) throws Exception { | ||
| Map<String, Integer> out = new LinkedHashMap<>(); | ||
|
|
||
| try (var reader = Files.newBufferedReader(csvPath, StandardCharsets.UTF_8)) { | ||
| String line; | ||
| var firstNonEmptyLine = true; | ||
|
|
||
| while ((line = reader.readLine()) != null) { | ||
| line = line.trim(); | ||
| if (line.isEmpty()) | ||
| continue; | ||
| if (line.startsWith("#")) | ||
| continue; | ||
|
|
||
| if (firstNonEmptyLine) { | ||
| firstNonEmptyLine = false; | ||
| if (line.equalsIgnoreCase("npc_id,lvl")) { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| var parts = line.split(",", 2); | ||
| if (parts.length != 2) { | ||
| LevelingCore.LOGGER.at(Level.WARNING).log("Skipping invalid CSV line: " + line); | ||
| continue; | ||
| } | ||
|
|
||
| var npcId = parts[0].trim(); | ||
| var lvlStr = parts[1].trim(); | ||
|
|
||
| if (npcId.isEmpty()) { | ||
| LevelingCore.LOGGER.at(Level.WARNING).log("Skipping CSV line with empty NPC ID: " + line); | ||
| continue; | ||
| } | ||
|
|
||
| int lvl; | ||
| try { | ||
| lvl = Integer.parseInt(lvlStr); | ||
| } catch (NumberFormatException nfe) { | ||
| LevelingCore.LOGGER.at(Level.WARNING) | ||
| .log( | ||
| "Invalid NPC ID value for " + npcId + ": " + lvlStr + " (line: " + line + ")" | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| out.put(npcId, lvl); | ||
| } | ||
| } | ||
|
|
||
| return out; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| npc_id,lvl | ||
| bunny,5 |
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.