Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ server:

#Quest Configuration
USE_QUEST_RATE: false #Exp/Meso gained by quests uses fixed server exp/meso rate times quest rate as multiplier, instead of player rates.
QUEST_MOB_COUNT_MODIFIER: 1 #Multiplier for how many 1 monster kill will count toward monster kill quests

#Quest Points Configuration
QUEST_POINT_REPEATABLE_INTERVAL: 25 #Minimum interval between repeatable quest completions for quest points to be awarded.
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/client/QuestStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.List;
import java.util.Map;

import config.YamlConfig;

/**
* @author Matze
*/
Expand Down Expand Up @@ -60,6 +62,7 @@ public static Status getById(int id) {
}

private final short questID;
private final Quest quest;
private Status status;
//private boolean updated; //maybe this can be of use for someone?
private final Map<Integer, String> progress = new LinkedHashMap<>();
Expand All @@ -70,6 +73,7 @@ public static Status getById(int id) {
private String customData;

public QuestStatus(Quest quest, Status status) {
this.quest = quest;
this.questID = quest.getId();
this.setStatus(status);
this.completionTime = System.currentTimeMillis();
Expand All @@ -81,6 +85,7 @@ public QuestStatus(Quest quest, Status status) {
}

public QuestStatus(Quest quest, Status status, int npc) {
this.quest = quest;
this.questID = quest.getId();
this.setStatus(status);
this.setNpc(npc);
Expand All @@ -93,7 +98,7 @@ public QuestStatus(Quest quest, Status status, int npc) {
}

public Quest getQuest() {
return Quest.getInstance(questID);
return this.quest;
}

public short getQuestID() {
Expand Down Expand Up @@ -131,7 +136,7 @@ public final void setNpc(int npc) {
}

private void registerMobs() {
for (int i : Quest.getInstance(questID).getRelevantMobs()) {
for (int i : this.quest.getRelevantMobs()) {
progress.put(i, "000");
}
//this.setUpdated();
Expand Down Expand Up @@ -161,13 +166,19 @@ public boolean progress(int id) {
}

int current = Integer.parseInt(currentStr);
if (current >= this.getQuest().getMobAmountNeeded(id)) {
return false;
int maxNeeded = this.getQuest().getMobAmountNeeded(id);

int multiplier = YamlConfig.config.server.QUEST_MOB_COUNT_MODIFIER;

int newCount = current + multiplier;
if (newCount > maxNeeded) {
newCount = maxNeeded;
} else if (newCount < 0) {
newCount = 0;
}

String str = StringUtil.getLeftPaddedStr(Integer.toString(++current), '0', 3);
String str = StringUtil.getLeftPaddedStr(Integer.toString(newCount), '0', 3);
progress.put(id, str);
//this.setUpdated();
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public class ServerConfig {

//Quest Configuration
public boolean USE_QUEST_RATE;
public int QUEST_MOB_COUNT_MODIFIER;

//Quest Points Configuration
public int QUEST_POINT_REPEATABLE_INTERVAL;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/provider/wz/WZFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ public enum WZFiles {
SOUND("Sound"),
UI("UI");

public static final String DIRECTORY = getWzDirectory();

private final String fileName;

WZFiles(String name) {
this.fileName = name + ".wz";
}

public Path getFile() {
return Path.of(DIRECTORY, fileName);
return Path.of(getWzDirectory(), fileName);
}

public String getFilePath() {
Expand Down
106 changes: 106 additions & 0 deletions src/test/java/client/QuestStatusTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package client;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import server.quest.Quest;
import tools.StringUtil;

import java.lang.reflect.Field;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

public class QuestStatusTest {
private QuestStatus questStatus;
private Quest mockQuest;
private static final int MOB_ID = 100;
private static final int MAX_MOB_AMOUNT = 10;

@BeforeEach
void setUp() throws Exception {
mockQuest = mock(Quest.class);
when(mockQuest.getId()).thenReturn((short) 1);
when(mockQuest.getMobAmountNeeded(MOB_ID)).thenReturn(MAX_MOB_AMOUNT);

questStatus = new QuestStatus(mockQuest, QuestStatus.Status.STARTED);
questStatus.setProgress(MOB_ID, "000"); // Set all tests to 0 to start

setQuestMobCountModifier(1); // Default multiplier
}

private void setQuestMobCountModifier(int value) throws Exception {
Field field = Class.forName("config.YamlConfig").getDeclaredField("config");
field.setAccessible(true);
Object config = field.get(null);
Field serverField = config.getClass().getDeclaredField("server");
serverField.setAccessible(true);
Object server = serverField.get(config);
Field modifierField = server.getClass().getDeclaredField("QUEST_MOB_COUNT_MODIFIER");
modifierField.setAccessible(true);
modifierField.set(server, value);
}

private void setQuestCount(int value) {
questStatus.setProgress(MOB_ID, StringUtil.getLeftPaddedStr(Integer.toString(value), '0', 3));
}

@Test
void testProgressDefaultIncrementSuccessfully() {
setQuestCount(5);
boolean result = questStatus.progress(MOB_ID);
assertTrue(result);
assertEquals("006", questStatus.getProgress(MOB_ID));
}

@Test
void testProgressReturnsFalseForUnknownMobId() {
boolean result = questStatus.progress(999);
assertFalse(result);
assertEquals("000", questStatus.getProgress(MOB_ID));
}

@Test
void testProgressDoesNotExceedMax() throws Exception {
questStatus.setProgress(MOB_ID, StringUtil.getLeftPaddedStr("8", '0', 3));
setQuestMobCountModifier(9999);

boolean result = questStatus.progress(MOB_ID);
assertTrue(result);

assertEquals("010", questStatus.getProgress(MOB_ID));
}

@Test
void testProgressWithZeroMultiplier() throws Exception {
setQuestCount(5);
setQuestMobCountModifier(0);

boolean result = questStatus.progress(MOB_ID);

assertTrue(result);
assertEquals("005", questStatus.getProgress(MOB_ID));
}

@Test
void testProgressWithNegativeMultiplier() throws Exception {
setQuestCount(0);
setQuestMobCountModifier(-1);

boolean result = questStatus.progress(MOB_ID);

assertTrue(result);
assertEquals("000", questStatus.getProgress(MOB_ID));
}

// Would be surprised if anyone ever does this but it's there
@Test
void testProgressedQuestWithNegativeMultiplier() throws Exception {
setQuestCount(5);
setQuestMobCountModifier(-1);

boolean result = questStatus.progress(MOB_ID);

assertTrue(result);
assertEquals("004", questStatus.getProgress(MOB_ID));
}
}
21 changes: 13 additions & 8 deletions src/test/java/server/life/MobSkillFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package server.life;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -18,16 +19,20 @@
class MobSkillFactoryTest {

@TempDir
private Path wzPath;
static Path wzPath;

@BeforeAll
static void setWzPath() {
System.setProperty("wz-path", "%s/wz".formatted(wzPath.toString()));
writeTestFileToTempDir();
}

@BeforeEach
void setWzPath() {
void setUp() {
MockitoAnnotations.openMocks(this);
writeTestFileToTempDir();
System.setProperty("wz-path", "%s/wz".formatted(wzPath.toString()));
}

private void writeTestFileToTempDir() {
private static void writeTestFileToTempDir() {
try {
String testFileContents = readTestFileContents();
writeTempDirFile(testFileContents);
Expand All @@ -36,15 +41,15 @@ private void writeTestFileToTempDir() {
}
}

private String readTestFileContents() throws IOException {
return new String(getClass()
private static String readTestFileContents() throws IOException {
return new String(MobSkillFactoryTest.class
.getClassLoader()
.getResourceAsStream("MobSkill-test.img.xml")
.readAllBytes()
);
}

private void writeTempDirFile(String fileContents) throws IOException {
private static void writeTempDirFile(String fileContents) throws IOException {
Path tempDirDirectory = wzPath.resolve("wz/Skill.wz");
Files.createDirectories(tempDirDirectory);
Path tempDirFile = Files.createFile(tempDirDirectory.resolve("MobSkill.img.xml"));
Expand Down