Fixed failing tests + improved support for Xbows/Tridents

This commit is contained in:
nossr50 2023-04-08 16:30:32 -07:00
parent 8bb50fb53c
commit 2c49f8ffeb
4 changed files with 56 additions and 20 deletions

View File

@ -276,6 +276,8 @@ public class FlatFileDataProcessor {
case SKILLS_TAMING: case SKILLS_TAMING:
case SKILLS_FISHING: case SKILLS_FISHING:
case SKILLS_ALCHEMY: case SKILLS_ALCHEMY:
case SKILLS_CROSSBOWS:
case SKILLS_TRIDENTS:
case COOLDOWN_BERSERK: case COOLDOWN_BERSERK:
case COOLDOWN_GIGA_DRILL_BREAKER: case COOLDOWN_GIGA_DRILL_BREAKER:
case COOLDOWN_TREE_FELLER: case COOLDOWN_TREE_FELLER:
@ -286,6 +288,8 @@ public class FlatFileDataProcessor {
case COOLDOWN_BLAST_MINING: case COOLDOWN_BLAST_MINING:
case SCOREBOARD_TIPS: case SCOREBOARD_TIPS:
case COOLDOWN_CHIMAERA_WING: case COOLDOWN_CHIMAERA_WING:
case COOLDOWN_SUPER_SHOTGUN:
case COOLDOWN_TRIDENTS:
return ExpectedType.INTEGER; return ExpectedType.INTEGER;
case EXP_MINING: case EXP_MINING:
case EXP_WOODCUTTING: case EXP_WOODCUTTING:
@ -300,6 +304,8 @@ public class FlatFileDataProcessor {
case EXP_TAMING: case EXP_TAMING:
case EXP_FISHING: case EXP_FISHING:
case EXP_ALCHEMY: case EXP_ALCHEMY:
case EXP_CROSSBOWS:
case EXP_TRIDENTS:
return ExpectedType.FLOAT; return ExpectedType.FLOAT;
case UUID_INDEX: case UUID_INDEX:
return ExpectedType.UUID; return ExpectedType.UUID;

View File

@ -611,8 +611,7 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
continue; continue;
} }
// we found the player
//If we couldn't find anyone
if(playerName.equalsIgnoreCase(rawSplitData[USERNAME_INDEX])) { if(playerName.equalsIgnoreCase(rawSplitData[USERNAME_INDEX])) {
return loadFromLine(rawSplitData); return loadFromLine(rawSplitData);
} }
@ -988,6 +987,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
List<PlayerStat> taming = new ArrayList<>(); List<PlayerStat> taming = new ArrayList<>();
List<PlayerStat> fishing = new ArrayList<>(); List<PlayerStat> fishing = new ArrayList<>();
List<PlayerStat> alchemy = new ArrayList<>(); List<PlayerStat> alchemy = new ArrayList<>();
List<PlayerStat> crossbows = new ArrayList<>();
List<PlayerStat> tridents = new ArrayList<>();
BufferedReader in = null; BufferedReader in = null;
String playerName = null; String playerName = null;
@ -1021,6 +1022,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
powerLevel += putStat(taming, playerName, skills.get(PrimarySkillType.TAMING)); powerLevel += putStat(taming, playerName, skills.get(PrimarySkillType.TAMING));
powerLevel += putStat(unarmed, playerName, skills.get(PrimarySkillType.UNARMED)); powerLevel += putStat(unarmed, playerName, skills.get(PrimarySkillType.UNARMED));
powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.WOODCUTTING)); powerLevel += putStat(woodcutting, playerName, skills.get(PrimarySkillType.WOODCUTTING));
powerLevel += putStat(crossbows, playerName, skills.get(PrimarySkillType.CROSSBOWS));
powerLevel += putStat(tridents, playerName, skills.get(PrimarySkillType.TRIDENTS));
putStat(powerLevels, playerName, powerLevel); putStat(powerLevels, playerName, powerLevel);
} }
@ -1056,6 +1059,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
taming.sort(c); taming.sort(c);
fishing.sort(c); fishing.sort(c);
alchemy.sort(c); alchemy.sort(c);
crossbows.sort(c);
tridents.sort(c);
powerLevels.sort(c); powerLevels.sort(c);
playerStatHash.put(PrimarySkillType.MINING, mining); playerStatHash.put(PrimarySkillType.MINING, mining);
@ -1071,6 +1076,8 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
playerStatHash.put(PrimarySkillType.TAMING, taming); playerStatHash.put(PrimarySkillType.TAMING, taming);
playerStatHash.put(PrimarySkillType.FISHING, fishing); playerStatHash.put(PrimarySkillType.FISHING, fishing);
playerStatHash.put(PrimarySkillType.ALCHEMY, alchemy); playerStatHash.put(PrimarySkillType.ALCHEMY, alchemy);
playerStatHash.put(PrimarySkillType.CROSSBOWS, crossbows);
playerStatHash.put(PrimarySkillType.TRIDENTS, tridents);
return LeaderboardStatus.UPDATED; return LeaderboardStatus.UPDATED;
} }
@ -1281,12 +1288,15 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
return new PlayerProfile(username, uuid, skills, skillsXp, skillsDATS, scoreboardTipsShown, uniquePlayerDataMap, lastLogin); return new PlayerProfile(username, uuid, skills, skillsXp, skillsDATS, scoreboardTipsShown, uniquePlayerDataMap, lastLogin);
} }
private void tryLoadSkillCooldownFromRawData(@NotNull Map<SuperAbilityType, Integer> cooldownMap, @NotNull String[] character, @NotNull SuperAbilityType superAbilityType, int cooldownSuperBreaker, @NotNull String userName) { private void tryLoadSkillCooldownFromRawData(@NotNull Map<SuperAbilityType, Integer> cooldownMap, @NotNull String[] splitData, @NotNull SuperAbilityType superAbilityType, int index, @NotNull String userName) {
try { try {
cooldownMap.put(superAbilityType, Integer.valueOf(character[cooldownSuperBreaker])); cooldownMap.put(superAbilityType, Integer.valueOf(splitData[index]));
} catch (IndexOutOfBoundsException e) {
// TODO: Add debug message
// set to 0 when data not found
cooldownMap.put(superAbilityType, 0);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.severe("Data corruption when trying to load the value for skill "+superAbilityType+" for player named " + userName+ " setting value to zero"); throw new NumberFormatException("Data corruption when trying to load the cooldown for skill "+superAbilityType+" for player named " + userName);
e.printStackTrace();
} }
} }
@ -1305,6 +1315,10 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
try { try {
int valueFromString = Integer.parseInt(character[index]); int valueFromString = Integer.parseInt(character[index]);
skillMap.put(primarySkillType, valueFromString); skillMap.put(primarySkillType, valueFromString);
} catch (ArrayIndexOutOfBoundsException e ) {
// TODO: Add debug message
// set to 0 when data not found
skillMap.put(primarySkillType, 0);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
skillMap.put(primarySkillType, 0); skillMap.put(primarySkillType, 0);
logger.severe("Data corruption when trying to load the value for skill "+primarySkillType+" for player named " + userName+ " setting value to zero"); logger.severe("Data corruption when trying to load the value for skill "+primarySkillType+" for player named " + userName+ " setting value to zero");

View File

@ -79,6 +79,8 @@ public class FlatFileDataUtil {
case SKILLS_TAMING: case SKILLS_TAMING:
case SKILLS_FISHING: case SKILLS_FISHING:
case SKILLS_ALCHEMY: case SKILLS_ALCHEMY:
case SKILLS_CROSSBOWS:
case SKILLS_TRIDENTS:
return String.valueOf(startingLevel); return String.valueOf(startingLevel);
case OVERHAUL_LAST_LOGIN: case OVERHAUL_LAST_LOGIN:
return String.valueOf(-1L); return String.valueOf(-1L);
@ -90,6 +92,8 @@ public class FlatFileDataUtil {
case COOLDOWN_SKULL_SPLITTER: case COOLDOWN_SKULL_SPLITTER:
case COOLDOWN_SUPER_BREAKER: case COOLDOWN_SUPER_BREAKER:
case COOLDOWN_BLAST_MINING: case COOLDOWN_BLAST_MINING:
case COOLDOWN_SUPER_SHOTGUN:
case COOLDOWN_TRIDENTS:
case SCOREBOARD_TIPS: case SCOREBOARD_TIPS:
case COOLDOWN_CHIMAERA_WING: case COOLDOWN_CHIMAERA_WING:
case EXP_MINING: case EXP_MINING:
@ -105,6 +109,8 @@ public class FlatFileDataUtil {
case EXP_TAMING: case EXP_TAMING:
case EXP_FISHING: case EXP_FISHING:
case EXP_ALCHEMY: case EXP_ALCHEMY:
case EXP_CROSSBOWS:
case EXP_TRIDENTS:
return "0"; return "0";
case UUID_INDEX: case UUID_INDEX:
throw new IndexOutOfBoundsException(); //TODO: Add UUID recovery? Might not even be worth it. throw new IndexOutOfBoundsException(); //TODO: Add UUID recovery? Might not even be worth it.

View File

@ -39,7 +39,7 @@ class FlatFileDatabaseManagerTest {
public static final @NotNull String BAD_DATA_FILE_LINE_TWENTY_THREE = "nossr51:baddata:::baddata:baddata:640:baddata:1000:1000:1000:baddata:baddata:baddata:baddata:16:0:500:20273:0:0:0:0::1000:0:0:baddata:1593543012:0:0:0:0::1000:0:0:baddata:IGNORED:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1:0:"; public static final @NotNull String BAD_DATA_FILE_LINE_TWENTY_THREE = "nossr51:baddata:::baddata:baddata:640:baddata:1000:1000:1000:baddata:baddata:baddata:baddata:16:0:500:20273:0:0:0:0::1000:0:0:baddata:1593543012:0:0:0:0::1000:0:0:baddata:IGNORED:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1:0:";
public static final @NotNull String DB_BADDATA = "baddatadb.users"; public static final @NotNull String DB_BADDATA = "baddatadb.users";
public static final @NotNull String DB_HEALTHY = "healthydb.users"; public static final @NotNull String DB_HEALTHY = "healthydb.users";
public static final @NotNull String HEALTHY_DB_LINE_1 = "nossr50:1:IGNORED:IGNORED:10:2:20:3:4:5:6:7:8:9:10:30:40:50:60:70:80:90:100:IGNORED:11:110:111:222:333:444:555:666:777:IGNORED:12:120:888:IGNORED:HEARTS:13:130:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1111:999:2020:"; public static final @NotNull String HEALTHY_DB_LINE_1 = "nossr50:1:IGNORED:IGNORED:10:2:20:3:4:5:6:7:8:9:10:30:40:50:60:70:80:90:100:IGNORED:11:110:111:222:333:444:555:666:777:IGNORED:12:120:888:IGNORED:HEARTS:13:130:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1111:999:2020:140:14:150:15:1111:2222:";
public static final @NotNull String HEALTHY_DB_LINE_ONE_UUID_STR = "588fe472-1c82-4c4e-9aa1-7eefccb277e3"; public static final @NotNull String HEALTHY_DB_LINE_ONE_UUID_STR = "588fe472-1c82-4c4e-9aa1-7eefccb277e3";
public static final String DB_MISSING_LAST_LOGIN = "missinglastlogin.users"; public static final String DB_MISSING_LAST_LOGIN = "missinglastlogin.users";
public static final String LINE_TWO_FROM_MISSING_DB = "nossr50:1:IGNORED:IGNORED:10:2:20:3:4:5:6:7:8:9:10:30:40:50:60:70:80:90:100:IGNORED:11:110:111:222:333:444:555:666:777:IGNORED:12:120:888:0:HEARTS:13:130:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1111:999:"; public static final String LINE_TWO_FROM_MISSING_DB = "nossr50:1:IGNORED:IGNORED:10:2:20:3:4:5:6:7:8:9:10:30:40:50:60:70:80:90:100:IGNORED:11:110:111:222:333:444:555:666:777:IGNORED:12:120:888:0:HEARTS:13:130:588fe472-1c82-4c4e-9aa1-7eefccb277e3:1111:999:";
@ -64,7 +64,7 @@ class FlatFileDatabaseManagerTest {
long expectedBerserkCd = 111, expectedGigaDrillBreakerCd = 222, expectedTreeFellerCd = 333, long expectedBerserkCd = 111, expectedGigaDrillBreakerCd = 222, expectedTreeFellerCd = 333,
expectedGreenTerraCd = 444, expectedSerratedStrikesCd = 555, expectedSkullSplitterCd = 666, expectedGreenTerraCd = 444, expectedSerratedStrikesCd = 555, expectedSkullSplitterCd = 666,
expectedSuperBreakerCd = 777, expectedBlastMiningCd = 888, expectedChimaeraWingCd = 999, expectedSuperBreakerCd = 777, expectedBlastMiningCd = 888, expectedChimaeraWingCd = 999,
expectedSSGCd = 1111, expectedTridentSuperCd = 2222; expectedSuperShotgunCd = 1111, expectedTridentSuperCd = 2222;
int expectedScoreboardTips = 1111; int expectedScoreboardTips = 1111;
Long expectedLastLogin = 2020L; Long expectedLastLogin = 2020L;
@ -229,7 +229,6 @@ class FlatFileDatabaseManagerTest {
logger.info("File Path: "+healthyDB.getAbsolutePath()); logger.info("File Path: "+healthyDB.getAbsolutePath());
assertArrayEquals(HEALTHY_DB_LINE_1.split(":"), dataFromFile.get(0)); assertArrayEquals(HEALTHY_DB_LINE_1.split(":"), dataFromFile.get(0));
assertEquals(dataFromFile.get(0)[FlatFileDatabaseManager.UUID_INDEX], HEALTHY_DB_LINE_ONE_UUID_STR); assertEquals(dataFromFile.get(0)[FlatFileDatabaseManager.UUID_INDEX], HEALTHY_DB_LINE_ONE_UUID_STR);
UUID healthDBEntryOneUUID = UUID.fromString(HEALTHY_DB_LINE_ONE_UUID_STR);
db = new FlatFileDatabaseManager(healthyDB, logger, PURGE_TIME, 0, true); db = new FlatFileDatabaseManager(healthyDB, logger, PURGE_TIME, 0, true);
List<FlatFileDataFlag> flagsFound = db.checkFileHealthAndStructure(); List<FlatFileDataFlag> flagsFound = db.checkFileHealthAndStructure();
@ -454,14 +453,13 @@ class FlatFileDatabaseManagerTest {
if(SkillTools.isChildSkill(primarySkillType)) if(SkillTools.isChildSkill(primarySkillType))
continue; continue;
// logger.info("Checking expected values for: "+primarySkillType); int expectedLevelHealthyDBEntryOne = getExpectedLevelHealthyDBEntryOne(primarySkillType);
// logger.info("Profile Level Value: "+profile.getSkillLevel(primarySkillType)); int skillLevel = profile.getSkillLevel(primarySkillType);
// logger.info("Expected Lvl Value: "+getExpectedLevelHealthyDBEntryOne(primarySkillType)); assertEquals(expectedLevelHealthyDBEntryOne, skillLevel);
// logger.info("Profile Exp Value: "+profile.getSkillXpLevelRaw(primarySkillType));
// logger.info("Expected Exp Value: "+getExpectedExperienceHealthyDBEntryOne(primarySkillType));
assertEquals(getExpectedLevelHealthyDBEntryOne(primarySkillType), profile.getSkillLevel(primarySkillType)); float expectedExperienceHealthyDBEntryOne = getExpectedExperienceHealthyDBEntryOne(primarySkillType);
assertEquals(getExpectedExperienceHealthyDBEntryOne(primarySkillType), profile.getSkillXpLevelRaw(primarySkillType), 0); float skillXpLevelRaw = profile.getSkillXpLevelRaw(primarySkillType);
assertEquals(expectedExperienceHealthyDBEntryOne, skillXpLevelRaw, 0);
} }
//Check the other things //Check the other things
@ -486,18 +484,22 @@ class FlatFileDatabaseManagerTest {
return expectedGreenTerraCd; return expectedGreenTerraCd;
case SKULL_SPLITTER: case SKULL_SPLITTER:
return expectedSkullSplitterCd; return expectedSkullSplitterCd;
case SUPER_SHOTGUN:
return expectedSuperShotgunCd;
case TREE_FELLER: case TREE_FELLER:
return expectedTreeFellerCd; return expectedTreeFellerCd;
case SERRATED_STRIKES: case SERRATED_STRIKES:
return expectedSerratedStrikesCd; return expectedSerratedStrikesCd;
case BLAST_MINING: case BLAST_MINING:
return expectedBlastMiningCd; return expectedBlastMiningCd;
case TRIDENT_ABILITY:
return expectedTridentSuperCd;
} }
return -1; throw new RuntimeException("Values not defined for super ability not defined please add " +
"values for " + superAbilityType.toString() + " to the test");
} }
//TODO: Why is this stuff a float?
private float getExpectedExperienceHealthyDBEntryOne(@NotNull PrimarySkillType primarySkillType) { private float getExpectedExperienceHealthyDBEntryOne(@NotNull PrimarySkillType primarySkillType) {
switch(primarySkillType) { switch(primarySkillType) {
case ACROBATICS: case ACROBATICS:
@ -508,6 +510,8 @@ class FlatFileDatabaseManagerTest {
return expectedExpArchery; return expectedExpArchery;
case AXES: case AXES:
return expectedExpAxes; return expectedExpAxes;
case CROSSBOWS:
return expectedExpCrossbows;
case EXCAVATION: case EXCAVATION:
return expectedExpExcavation; return expectedExpExcavation;
case FISHING: case FISHING:
@ -525,13 +529,15 @@ class FlatFileDatabaseManagerTest {
return expectedExpSwords; return expectedExpSwords;
case TAMING: case TAMING:
return expectedExpTaming; return expectedExpTaming;
case TRIDENTS:
return expectedExpTridents;
case UNARMED: case UNARMED:
return expectedExpUnarmed; return expectedExpUnarmed;
case WOODCUTTING: case WOODCUTTING:
return expectedExpWoodcutting; return expectedExpWoodcutting;
} }
return -1; throw new RuntimeException("Values for skill not defined, please add values for " + primarySkillType.toString() + " to the test");
} }
private int getExpectedLevelHealthyDBEntryOne(@NotNull PrimarySkillType primarySkillType) { private int getExpectedLevelHealthyDBEntryOne(@NotNull PrimarySkillType primarySkillType) {
@ -544,6 +550,8 @@ class FlatFileDatabaseManagerTest {
return expectedLvlArchery; return expectedLvlArchery;
case AXES: case AXES:
return expectedLvlAxes; return expectedLvlAxes;
case CROSSBOWS:
return expectedLvlCrossbows;
case EXCAVATION: case EXCAVATION:
return expectedLvlExcavation; return expectedLvlExcavation;
case FISHING: case FISHING:
@ -561,13 +569,15 @@ class FlatFileDatabaseManagerTest {
return expectedLvlSwords; return expectedLvlSwords;
case TAMING: case TAMING:
return expectedLvlTaming; return expectedLvlTaming;
case TRIDENTS:
return expectedLvlTridents;
case UNARMED: case UNARMED:
return expectedLvlUnarmed; return expectedLvlUnarmed;
case WOODCUTTING: case WOODCUTTING:
return expectedLvlWoodcutting; return expectedLvlWoodcutting;
} }
return -1; throw new RuntimeException("Values for skill not defined, please add values for " + primarySkillType.toString() + " to the test");
} }
@Test @Test