diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt index 919f6e7af..91edde126 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/EngineModules.kt @@ -40,33 +40,28 @@ val engineModule = module { single { SaveQueue(get(), SafeStorage(File(Settings["storage.players.errors"]))) } - single { - val homeTile = Tile( - x = Settings["world.home.x", 0], - y = Settings["world.home.y", 0], - level = Settings["world.home.level", 0] - ) - AccountManager(get(), get(), get(), get(), get(), get(), homeTile, get(), get(), get(), get(), Settings["world.experienceRate", 1.0]) - } + single { AccountManager(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } // IO single { Yaml(YamlReaderConfiguration(2, 8, VERY_FAST_LOAD_FACTOR)) } - single { if (Settings["storage.type", "files"] == "database") { - DatabaseStorage.connect( - Settings["storage.database.username"], - Settings["storage.database.password"], - Settings["storage.database.driver"], - Settings["storage.database.jdbcUrl"], - Settings["storage.database.poolSize", 2], - ) - DatabaseStorage() - } else { - val saves = File(Settings["storage.players.path"]) - if (!saves.exists()) { - saves.mkdir() + single { + if (Settings["storage.type", "files"] == "database") { + DatabaseStorage.connect( + Settings["storage.database.username"], + Settings["storage.database.password"], + Settings["storage.database.driver"], + Settings["storage.database.jdbcUrl"], + Settings["storage.database.poolSize", 2], + ) + DatabaseStorage() + } else { + val saves = File(Settings["storage.players.path"]) + if (!saves.exists()) { + saves.mkdir() + } + FileStorage(get(), saves) } - FileStorage(get(), saves, get(), Settings["world.experienceRate", 1.0]) - } } - single { PlayerAccountLoader(get(), get(), get(), get(), get(), Contexts.Game, Settings["world.experienceRate", 1.0]) } + } + single { PlayerAccountLoader(get(), get(), get(), get(), get(), Contexts.Game) } // Map single { ZoneBatchUpdates() } single { DynamicZones(get(), get(), get()) } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt index 3b205e878..20fcd72c2 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoader.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.withContext import world.gregs.voidps.engine.data.AccountManager import world.gregs.voidps.engine.data.AccountStorage import world.gregs.voidps.engine.data.SaveQueue +import world.gregs.voidps.engine.data.Settings import world.gregs.voidps.engine.data.definition.AccountDefinitions import world.gregs.voidps.engine.entity.World import world.gregs.voidps.engine.entity.character.player.Player @@ -29,8 +30,7 @@ class PlayerAccountLoader( private val accounts: AccountManager, private val saveQueue: SaveQueue, private val accountDefinitions: AccountDefinitions, - private val gameContext: CoroutineDispatcher, - private val experienceRate: Double + private val gameContext: CoroutineDispatcher ) : AccountLoader { private val logger = InlineLogger() @@ -52,7 +52,7 @@ class PlayerAccountLoader( client.disconnect(Response.ACCOUNT_ONLINE) return null } - val player = storage.load(username)?.toPlayer(experienceRate) ?: accounts.create(username, passwordHash) + val player = storage.load(username)?.toPlayer(Settings["world.experienceRate", 1.0]) ?: accounts.create(username, passwordHash) logger.info { "Player $username loaded and queued for login." } connect(player, client, displayMode) return player.instructions diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/AccountManager.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/AccountManager.kt index 7ac39d773..29801e376 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/AccountManager.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/AccountManager.kt @@ -35,17 +35,17 @@ class AccountManager( private val accountDefinitions: AccountDefinitions, private val collisionStrategyProvider: CollisionStrategyProvider, private val variableDefinitions: VariableDefinitions, - private val homeTile: Tile, private val saveQueue: SaveQueue, private val connectionQueue: ConnectionQueue, private val players: Players, - private val areaDefinitions: AreaDefinitions, - private val experienceRate: Double + private val areaDefinitions: AreaDefinitions ) { private val validItems = ValidItemRestriction(itemDefinitions) + private val homeTile: Tile + get() = Tile(Settings["world.home.x", 0], Settings["world.home.y", 0], Settings["world.home.level", 0]) fun create(name: String, passwordHash: String): Player { - return Player(tile = homeTile, accountName = name, passwordHash = passwordHash, experience = Experience(rate = experienceRate)).apply { + return Player(tile = homeTile, accountName = name, passwordHash = passwordHash, experience = Experience(rate = Settings["world.experienceRate", 1.0])).apply { this["creation"] = System.currentTimeMillis() this["new_player"] = true } diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/json/FileStorage.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/json/FileStorage.kt index 9680819bb..fe4698e06 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/json/FileStorage.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/json/FileStorage.kt @@ -4,7 +4,6 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import world.gregs.voidps.engine.data.AccountStorage import world.gregs.voidps.engine.data.PlayerSave import world.gregs.voidps.engine.data.config.AccountDefinition -import world.gregs.voidps.engine.data.definition.ItemDefinitions import world.gregs.voidps.engine.data.yaml.PlayerYamlReaderConfig import world.gregs.voidps.engine.data.yaml.PlayerYamlWriterConfig import world.gregs.voidps.engine.entity.character.player.chat.clan.Clan @@ -20,9 +19,7 @@ import java.io.File @Suppress("UNCHECKED_CAST") class FileStorage( private val yaml: Yaml, - private val directory: File, - itemDefinitions: ItemDefinitions, - experienceRate: Double + private val directory: File ) : AccountStorage { private val config = object : YamlReaderConfiguration() { override fun set(map: MutableMap, key: String, value: Any, indent: Int, parentMap: String?) { @@ -82,7 +79,7 @@ class FileStorage( } private val writeConfig = PlayerYamlWriterConfig() - private val readerConfig = PlayerYamlReaderConfig(itemDefinitions, experienceRate) + private val readerConfig = PlayerYamlReaderConfig() override fun save(accounts: List) { for (account in accounts) { diff --git a/engine/src/main/kotlin/world/gregs/voidps/engine/data/yaml/PlayerYamlReaderConfig.kt b/engine/src/main/kotlin/world/gregs/voidps/engine/data/yaml/PlayerYamlReaderConfig.kt index 4683b0f47..998f77f25 100644 --- a/engine/src/main/kotlin/world/gregs/voidps/engine/data/yaml/PlayerYamlReaderConfig.kt +++ b/engine/src/main/kotlin/world/gregs/voidps/engine/data/yaml/PlayerYamlReaderConfig.kt @@ -1,6 +1,6 @@ package world.gregs.voidps.engine.data.yaml -import world.gregs.voidps.engine.data.definition.ItemDefinitions +import world.gregs.voidps.engine.data.Settings import world.gregs.voidps.engine.entity.character.player.chat.clan.ClanRank import world.gregs.voidps.engine.entity.character.player.skill.Skill import world.gregs.voidps.engine.entity.character.player.skill.exp.Experience @@ -9,10 +9,7 @@ import world.gregs.voidps.engine.entity.item.Item import world.gregs.voidps.type.Tile import world.gregs.yaml.read.YamlReaderConfiguration -internal class PlayerYamlReaderConfig( - private val itemDefinitions: ItemDefinitions, - private val experienceRate: Double -) : YamlReaderConfiguration() { +internal class PlayerYamlReaderConfig : YamlReaderConfiguration() { override fun add(list: MutableList, value: Any, parentMap: String?) { if (value is Map<*, *> && value.containsKey("id")) { val id = value["id"] as String @@ -37,7 +34,7 @@ internal class PlayerYamlReaderConfig( val exp = Experience( experience = (value["experience"] as List).toDoubleArray(), blocked = (value["blocked"] as List).toMutableSet(), - rate = experienceRate + rate = Settings["world.experienceRate", 1.0] ) super.set(map, key, exp, indent, parentMap) } else if (key == "levels") { diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt index dbb52f8a8..1e076b541 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/client/PlayerAccountLoaderTest.kt @@ -56,7 +56,7 @@ internal class PlayerAccountLoaderTest : KoinMock() { saveQueue = SaveQueue(storage, scope = TestScope()) definitions = AccountDefinitions(mutableMapOf("name" to AccountDefinition("name", "oldName", "", "hash"))) accounts = mockk(relaxed = true) - loader = PlayerAccountLoader(queue, storage, accounts, saveQueue, definitions, UnconfinedTestDispatcher(), 1.0) + loader = PlayerAccountLoader(queue, storage, accounts, saveQueue, definitions, UnconfinedTestDispatcher()) } @Test diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/data/AccountManagerTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/data/AccountManagerTest.kt index 503be9187..ed8cb8f16 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/data/AccountManagerTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/data/AccountManagerTest.kt @@ -3,6 +3,7 @@ package world.gregs.voidps.engine.data import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.verify +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -53,6 +54,7 @@ class AccountManagerTest : KoinMock() { override fun load(accountName: String): PlayerSave? = null } + Settings.load(mapOf("world.home.x" to "1234", "world.home.y" to "5432", "world.experienceRate" to "1.0")) manager = AccountManager( interfaceDefinitions = get(), inventoryDefinitions = inventoryDefinitions, @@ -60,12 +62,10 @@ class AccountManagerTest : KoinMock() { accountDefinitions = AccountDefinitions(), collisionStrategyProvider = CollisionStrategyProvider(), variableDefinitions = VariableDefinitions(), - homeTile = Tile(1234, 5432), saveQueue = SaveQueue(storage), connectionQueue = connectionQueue, areaDefinitions = get(), - players = Players(), - experienceRate = 1.0 + players = Players() ) } @@ -120,4 +120,9 @@ class AccountManagerTest : KoinMock() { client.disconnect() } } + + @AfterEach + fun teardown() { + Settings.clear() + } } \ No newline at end of file diff --git a/engine/src/test/kotlin/world/gregs/voidps/engine/data/json/FileStorageTest.kt b/engine/src/test/kotlin/world/gregs/voidps/engine/data/json/FileStorageTest.kt index 8a3ed0df3..7ad1968cb 100644 --- a/engine/src/test/kotlin/world/gregs/voidps/engine/data/json/FileStorageTest.kt +++ b/engine/src/test/kotlin/world/gregs/voidps/engine/data/json/FileStorageTest.kt @@ -19,24 +19,20 @@ class FileStorageTest : AccountStorageTest() { override lateinit var storage: AccountStorage - private val itemDefinitions = ItemDefinitions(Array(30000) { ItemDefinition.EMPTY }).apply { - ids = emptyMap() - } - @BeforeEach fun setup() { - storage = FileStorage(Yaml(), directory, itemDefinitions, 1.0) + storage = FileStorage(Yaml(), directory) } @Test fun `Invalid directory returns no names`() { - val storage = FileStorage(Yaml(), directory.resolve("invalid"), itemDefinitions, 1.0) + val storage = FileStorage(Yaml(), directory.resolve("invalid")) assertTrue(storage.names().isEmpty()) } @Test fun `Invalid directory returns no clans`() { - val storage = FileStorage(Yaml(), directory.resolve("invalid"), itemDefinitions, 1.0) + val storage = FileStorage(Yaml(), directory.resolve("invalid")) assertTrue(storage.clans().isEmpty()) } diff --git a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts index add8610c5..a3281b6b2 100644 --- a/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts +++ b/game/src/main/kotlin/world/gregs/voidps/world/interact/entity/death/PlayerDeath.kts @@ -46,7 +46,7 @@ val Character.damageDealers: MutableMap get() = getOrPut("damage_dealers") { mutableMapOf() } val respawnTile: Tile - get() = Tile(Settings["world.home.x", 0], Settings["world.home.y", 0], Settings["world.home.level", 0]) + get() = Tile(Settings["world.home.x", 0], Settings["world.home.y", 0], Settings["world.home.level", 0]) playerDeath { player -> player.dead = true