test client ability to attack
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
058960727f
commit
67a90d1e02
@ -350,7 +350,7 @@ public class ClientAttackTree implements BehaviorTree {
|
||||
* Gets the current attack type
|
||||
* @return The current attack type
|
||||
*/
|
||||
String getAttackType(){
|
||||
protected String getAttackType(){
|
||||
String rVal = null;
|
||||
if(ClientEquipState.hasEquipState(parent)){
|
||||
ClientEquipState equipState = ClientEquipState.getEquipState(parent);
|
||||
@ -381,7 +381,7 @@ public class ClientAttackTree implements BehaviorTree {
|
||||
* @param attackType The attack type
|
||||
* @return true if can attack, false otherwise
|
||||
*/
|
||||
private boolean canAttack(String attackType){
|
||||
protected boolean canAttack(String attackType){
|
||||
if(attackType == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ public class ServerAttackTree implements BehaviorTree {
|
||||
* Gets the current attack type
|
||||
* @return The current attack type
|
||||
*/
|
||||
String getAttackType(){
|
||||
protected String getAttackType(){
|
||||
String rVal = null;
|
||||
if(ServerEquipState.hasEquipState(parent)){
|
||||
ServerEquipState equipState = ServerEquipState.getEquipState(parent);
|
||||
@ -434,7 +434,7 @@ public class ServerAttackTree implements BehaviorTree {
|
||||
* @param attackType The attack type
|
||||
* @return true if can attack, false otherwise
|
||||
*/
|
||||
private boolean canAttack(String attackType){
|
||||
protected boolean canAttack(String attackType){
|
||||
if(attackType == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -165,6 +165,17 @@ public class Server implements Runnable {
|
||||
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
|
||||
*/
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +1,34 @@
|
||||
package testutils;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
|
||||
/**
|
||||
* Used to programmatically send input signals as if a user had
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user