test client ability to attack
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-09-02 12:15:21 -04:00
parent 058960727f
commit 67a90d1e02
5 changed files with 97 additions and 6 deletions

View File

@ -350,7 +350,7 @@ public class ClientAttackTree implements BehaviorTree {
* Gets the current attack type * Gets the current attack type
* @return The current attack type * @return The current attack type
*/ */
String getAttackType(){ protected String getAttackType(){
String rVal = null; String rVal = null;
if(ClientEquipState.hasEquipState(parent)){ if(ClientEquipState.hasEquipState(parent)){
ClientEquipState equipState = ClientEquipState.getEquipState(parent); ClientEquipState equipState = ClientEquipState.getEquipState(parent);
@ -381,7 +381,7 @@ public class ClientAttackTree implements BehaviorTree {
* @param attackType The attack type * @param attackType The attack type
* @return true if can attack, false otherwise * @return true if can attack, false otherwise
*/ */
private boolean canAttack(String attackType){ protected boolean canAttack(String attackType){
if(attackType == null){ if(attackType == null){
return false; return false;
} }

View File

@ -403,7 +403,7 @@ public class ServerAttackTree implements BehaviorTree {
* Gets the current attack type * Gets the current attack type
* @return The current attack type * @return The current attack type
*/ */
String getAttackType(){ protected String getAttackType(){
String rVal = null; String rVal = null;
if(ServerEquipState.hasEquipState(parent)){ if(ServerEquipState.hasEquipState(parent)){
ServerEquipState equipState = ServerEquipState.getEquipState(parent); ServerEquipState equipState = ServerEquipState.getEquipState(parent);
@ -434,7 +434,7 @@ public class ServerAttackTree implements BehaviorTree {
* @param attackType The attack type * @param attackType The attack type
* @return true if can attack, false otherwise * @return true if can attack, false otherwise
*/ */
private boolean canAttack(String attackType){ protected boolean canAttack(String attackType){
if(attackType == null){ if(attackType == null){
return false; return false;
} }

View File

@ -165,6 +165,17 @@ public class Server implements Runnable {
this.connectListLock.release(); this.connectListLock.release();
} }
/**
* Gets the first connection
* @return The first connection
*/
public ServerConnectionHandler getFirstConnection(){
connectListLock.acquireUninterruptibly();
ServerConnectionHandler firstCon = this.activeConnections.get(0);
connectListLock.release();
return firstCon;
}
/** /**
* Cleans up dead connections on the server * Cleans up dead connections on the server
*/ */

View File

@ -0,0 +1,56 @@
package electrosphere.entity.state.attack;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import annotations.IntegrationTest;
import electrosphere.controls.ControlHandler;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState;
import electrosphere.server.datacell.utils.EntityLookupUtils;
import template.EntityTestTemplate;
import testutils.InputAPI;
import testutils.TestEngineUtils;
/**
* Testing the client's attacking trees
*/
public class ClientAttackTreeTests extends EntityTestTemplate {
/**
* Make sure can attack in default scene
*/
@IntegrationTest
public void testClientAttack(){
//warm up engine
TestEngineUtils.simulateFrames(1);
//spy on the client-side player's attack state
ClientAttackTree clientAttackTree = ClientAttackTree.getClientAttackTree(Globals.playerEntity);
//spy on the server-side player's attack tree
int serverIdForClientEntity = Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId());
Entity serverPlayerEntity = EntityLookupUtils.getEntityById(serverIdForClientEntity);
ServerAttackTree serverAttackTree = ServerAttackTree.getServerAttackTree(serverPlayerEntity);
//verify can attack
assertEquals(true, clientAttackTree.canAttack(clientAttackTree.getAttackType()));
assertEquals(true, serverAttackTree.canAttack(serverAttackTree.getAttackType()));
//try attacking
InputAPI.simulatePress(ControlHandler.DATA_STRING_INPUT_CODE_ATTACK_PRIMARY);
InputAPI.simulateRelease(ControlHandler.DATA_STRING_INPUT_CODE_ATTACK_PRIMARY);
//wait for the attack to propagate back to the client
TestEngineUtils.simulateFrames(10);
//verify it was started on server
assertNotEquals(serverAttackTree.getState(), AttackTreeState.IDLE);
//verify state transition was triggered on client
assertNotEquals(clientAttackTree.getState(), AttackTreeState.IDLE);
}
}

View File

@ -1,10 +1,34 @@
package testutils; package testutils;
import electrosphere.engine.Globals;
/** /**
* Used to programmatically send input signals as if a user had * Used to programmatically send input signals as if a user had
*/ */
public class InputAPI { public class InputAPI {
/**
* Simulates clicking a control
* @param controlName The name of the control
*/
public static void simulateClick(String controlName){
Globals.controlHandler.getControl(controlName).onClick();
}
/**
* Simulates pressing a control
* @param controlName The name of the control
*/
public static void simulatePress(String controlName){
Globals.controlHandler.getControl(controlName).onPress();
}
/**
* Simulates releasing a control
* @param controlName The name of the control
*/
public static void simulateRelease(String controlName){
Globals.controlHandler.getControl(controlName).onRelease();
}
} }