|
| 1 | +package uuspaceagent; |
| 2 | + |
| 3 | +import eu.iv4xr.framework.mainConcepts.WorldEntity; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import spaceEngineers.controller.useobject.UseObjectExtensions; |
| 6 | +import spaceEngineers.model.*; |
| 7 | + |
| 8 | +import static uuspaceagent.TestUtils.loadSE; |
| 9 | + |
| 10 | +/** |
| 11 | + * For trying out use-block primitive from SE. |
| 12 | + */ |
| 13 | +public class Coba_UseObject { |
| 14 | + |
| 15 | + @Test |
| 16 | + public void test() throws InterruptedException { |
| 17 | + |
| 18 | + var state = loadSE("myworld-3 with open door X").snd; |
| 19 | + |
| 20 | + state.useSystemTimeForTimeStamping = true ; |
| 21 | + |
| 22 | + state.updateState(state.agentId); |
| 23 | + |
| 24 | + WorldEntity agentInfo = state.worldmodel.elements.get(state.agentId) ; |
| 25 | + System.out.println("** Agent's info: " + PrintInfos.showWorldEntity(agentInfo)); |
| 26 | + WorldEntity target = SEBlockFunctions.findClosestBlock(state.worldmodel, "SurvivalKitLarge", 10) ; |
| 27 | + System.out.println("** target: " + PrintInfos.showWorldEntity(target)); |
| 28 | + |
| 29 | + // Using a survival-kit to heal the agent. Making use of the |
| 30 | + // admin-feature-shortcut: |
| 31 | + for (int k=0; k<100; k++) { |
| 32 | + // run a loop to heal |
| 33 | + state.env().getController().getAdmin().getCharacter().use(target.id, 0, |
| 34 | + UseObject.Companion.getManipulate()); |
| 35 | + //Thread.sleep(20); |
| 36 | + state.updateState(state.agentId); |
| 37 | + float h = (Float) state.val("health") ; |
| 38 | + float h0 = (Float) state.before("health") ; |
| 39 | + agentInfo = state.get(state.agentId) ; |
| 40 | + long t = agentInfo.timestamp ; |
| 41 | + long t0 = agentInfo.getPreviousState().timestamp ; |
| 42 | + System.out.println(">>> healing: " + (h - h0) + "/" + (t - t0)); |
| 43 | + } |
| 44 | + |
| 45 | + Thread.sleep(2000); |
| 46 | + |
| 47 | + // for closing the Terminal-screen, if you experiment with |
| 48 | + // an action that open a terminal (above) |
| 49 | + /* |
| 50 | + try { |
| 51 | +
|
| 52 | + state.env().getController().getScreens().getTerminal().close(); |
| 53 | + } |
| 54 | + catch(Exception e) { |
| 55 | + // the terminal was not open |
| 56 | + } |
| 57 | + */ |
| 58 | + |
| 59 | + state.updateState(state.agentId); |
| 60 | + agentInfo = state.worldmodel.elements.get(state.agentId) ; |
| 61 | + System.out.println("** Agent's info: " + PrintInfos.showWorldEntity(agentInfo)); |
| 62 | + |
| 63 | + } |
| 64 | +} |
0 commit comments