diff --git a/CucumberTester/src/main/kotlin/bdd/CharacterActions.kt b/CucumberTester/src/main/kotlin/bdd/CharacterActions.kt index f067b7969..11559f127 100644 --- a/CucumberTester/src/main/kotlin/bdd/CharacterActions.kt +++ b/CucumberTester/src/main/kotlin/bdd/CharacterActions.kt @@ -488,7 +488,6 @@ class CharacterActions(connectionManager: ConnectionManager) : AbstractMultiplay @When("Character turns on personal light.") fun character_turns_on_personal_light() = mainClient { character.setLight(true) - println(screens.gamePlay.data().hud.stats) } @When("Character suicides.") diff --git a/CucumberTester/src/main/kotlin/bdd/CharacterAsserts.kt b/CucumberTester/src/main/kotlin/bdd/CharacterAsserts.kt index 98cbc535c..5a30374c9 100644 --- a/CucumberTester/src/main/kotlin/bdd/CharacterAsserts.kt +++ b/CucumberTester/src/main/kotlin/bdd/CharacterAsserts.kt @@ -616,8 +616,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay @Then("Character stats are:") fun character_stats_are_changed_to(dt: DataTable) { val dataTable = dt.asMaps().first().map { it.key to it.value.toFloat() }.toMap() - val relativeTolerance = dataTable["relative_tolerance"] ?: 0.001f - println(dataTable) + val relativeTolerance = dataTable["relative_tolerance"] ?: 0.01f mainClient { val observation = observer.observe() as CharacterStats checkStats(dataTable, observation, relativeTolerance) @@ -639,7 +638,12 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay relativeTolerance: Float ) { dataTable[name]?.let { tableStat -> - assertEquals(tableStat / 100f, stat, absoluteTolerance = stat * relativeTolerance) + assertEquals( + tableStat / 100f, + stat, + absoluteTolerance = 1f * relativeTolerance, + message = "absoluteTolerance: ${1f * relativeTolerance}" + ) } } @@ -654,7 +658,9 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay @Then("health is less than maximum.") fun health_is_less_than_maximum() { mainClient { - assertLessThan(observer.observe().health, 1f) + repeatUntilSuccess { + assertLessThan(observer.observe().health, 1f) + } } } @@ -682,7 +688,6 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay @Then("Personal light is off.") fun personal_light_is_off() = mainClient { - println(screens.gamePlay.data().hud.stats) assertEquals(0f, observer.observe().currentLightPower) //assertFalse(observer.observe().lightEnabled, "light is supposed to be off!") //TODO: check on hud too @@ -690,15 +695,17 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay @Then("Character is dead.") fun character_is_dead() = mainClient { - with(observer.observe()) { - assertTrue(movement.isDead) - assertEquals(0f, health) + repeatUntilSuccess { + with(observer.observe()) { + assertTrue(movement.isDead, "Not dead based on CharacterMovement flag: $movement") + assertEquals(0f, health, "Not dead based on health: $health") + } } } @Then("Remote terminal for grid {string} is disabled.") fun remote_terminal_is_disabled(grid: String) = mainClient { - delay(200.milliseconds) + delay(500.milliseconds) input.startPlaying( listOf( FrameSnapshot( @@ -708,7 +715,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay ) ) ) - delay(200.milliseconds) + delay(500.milliseconds) val grids = screens.terminal.remoteAccess.data().grids assertTrue(grids.isNotEmpty(), "No grids to see!") assertFalse( @@ -720,7 +727,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay @Then("Remote terminal for grid {string} is enabled.") fun remote_terminal_is_enabled(grid: String) = mainClient { - delay(200.milliseconds) + delay(500.milliseconds) input.startPlaying( listOf( FrameSnapshot( @@ -730,7 +737,7 @@ class CharacterAsserts(connectionManager: ConnectionManager) : AbstractMultiplay ) ) ) - delay(200.milliseconds) + delay(500.milliseconds) val grids = screens.terminal.remoteAccess.data().grids assertTrue(grids.isNotEmpty(), "No grids to see!") assertTrue( diff --git a/CucumberTester/src/main/kotlin/bdd/setup/Extensions.kt b/CucumberTester/src/main/kotlin/bdd/setup/Extensions.kt index 1ea112539..7b80509fb 100644 --- a/CucumberTester/src/main/kotlin/bdd/setup/Extensions.kt +++ b/CucumberTester/src/main/kotlin/bdd/setup/Extensions.kt @@ -33,7 +33,7 @@ suspend fun SpaceEngineers.dieAndConfirm(delayMs: Long = 100L) { screens.messageBox.pressYes() } -suspend fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) { +fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) { val info = session.info() val cameraInfo = info?.camera ?: error("No camera info") when (cameraConfig) { @@ -54,11 +54,54 @@ suspend fun SpaceEngineers.ensureCamera(cameraConfig: CameraConfig) { suspend fun ConnectionManagerUser.handleScenarioParameter(key: String, value: String) { when (key) { "delay_after_spawn" -> delay((value.toFloat() * 1000f).toLong()) - "energy" -> admin { admin.character.updateEnergy(energy = value.toFloat() / 100f) } - "hydrogen" -> admin { admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f) } - "health" -> admin { admin.character.updateHealth(health = value.toFloat() / 100f) } - "oxygen" -> admin { admin.character.updateOxygen(oxygen = value.toFloat() / 100f) } - "camera" -> mainClient { ensureCamera(CameraConfig.fromText(value)) } + "energy" -> { + val id = mainClient { + admin.character.updateEnergy(energy = value.toFloat() / 100f) + admin.character.mainCharacterId() + } + admin { + admin.character.switch(id) + admin.character.updateEnergy(energy = value.toFloat() / 100f) + } + } + + "hydrogen" -> { + val id = mainClient { + admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f) + admin.character.mainCharacterId() + } + admin { + admin.character.switch(id) + admin.character.updateHydrogen(hydrogen = value.toFloat() / 100f) + } + } + + "health" -> { + val id = mainClient { + admin.character.updateHealth(health = value.toFloat() / 100f) + admin.character.mainCharacterId() + } + admin { + admin.character.switch(id) + admin.character.updateHealth(health = value.toFloat() / 100f) + } + } + + "oxygen" -> { + val id = mainClient { + admin.character.updateOxygen(oxygen = value.toFloat() / 100f) + admin.character.mainCharacterId() + } + admin { + admin.character.switch(id) + admin.character.updateOxygen(oxygen = value.toFloat() / 100f) + } + } + + "camera" -> { + mainClient { ensureCamera(CameraConfig.fromText(value)) } + } + else -> error("Warning, unknown settings: $key - $value") } } diff --git a/Source/Ivxr.SePlugin/Control/CharacterController.cs b/Source/Ivxr.SePlugin/Control/CharacterController.cs index 851187323..cf124700f 100644 --- a/Source/Ivxr.SePlugin/Control/CharacterController.cs +++ b/Source/Ivxr.SePlugin/Control/CharacterController.cs @@ -74,7 +74,7 @@ public void UpdateEnergy(float energy) public void UpdateHealth(float health) { - Character.StatComp.Health.Value = health * 100; + Character.StatComp.Health.CallMethod("SetValue", new object[] { health * 100, null }); } @@ -120,7 +120,8 @@ public void SetHelmet(bool enabled) return; } - Character.OxygenComponent.SwitchHelmet(); + IMyControllableEntity entity = (IMyControllableEntity) Character; + entity.SwitchHelmet(); } public void SetLight(bool enabled) @@ -292,12 +293,12 @@ private MyEntityController GetEntityController() private MyCharacter Character => m_session.Character; - private void EnsureCharacterLives(string message ="Cannot do this while dead") + private void EnsureCharacterLives(string message = "Cannot do this while dead") { if (Character.IsDead) { throw new InvalidOperationException(message); - } + } } } }