melee ai targeting fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-09-05 00:48:43 -04:00
parent d2a8acf027
commit d39254968f
8 changed files with 100 additions and 6 deletions

View File

@ -14,6 +14,16 @@
"name" : "Blocker"
}
]
},
{
"id" : "humanSwordsman",
"creatureId" : "human",
"equipment" : [
{
"pointId" : "handsCombined",
"itemId" : "Katana2H"
}
]
}
]
}

View File

@ -20,7 +20,6 @@
+ bug fixes
Fix falling tree not always deactivating on server
Fix AI tracking deleted entity
Fix server ground movement tree playing animation over falling animation
Fix empty item slot not showing underneath dragged item
Fix grass rendering distance

View File

@ -690,6 +690,9 @@ Unit tests for above
Fix physics debug rendering pipeline
Update human collidable data
(09/05/2024)
Fix AI tracking deleted entity
# TODO

View File

@ -119,8 +119,10 @@ public class EntityUtils {
*/
public static void cleanUpEntity(Entity e){
//remove from client
Globals.clientSceneWrapper.getScene().deregisterEntity(e);
Globals.clientSceneWrapper.deregisterTranslationMapping(e);
if(Globals.clientSceneWrapper != null){
Globals.clientSceneWrapper.getScene().deregisterEntity(e);
Globals.clientSceneWrapper.deregisterTranslationMapping(e);
}
//remove from all server classes
if(Globals.realmManager != null){
Realm realm = Globals.realmManager.getEntityRealm(e);

View File

@ -117,7 +117,9 @@ public class ServerEntityUtils {
HitboxCollectionState.destroyHitboxState(entity);
Globals.realmManager.removeEntity(entity);
EntityLookupUtils.removeEntity(entity);
Globals.aiManager.removeAI(entity);
if(Globals.aiManager != null){
Globals.aiManager.removeAI(entity);
}
//
//deregister all behavior trees

View File

@ -34,7 +34,7 @@ public class MeleeTargetingNode implements AITreeNode {
@Override
public AITreeNodeResult evaluate(Entity entity, Blackboard blackboard){
if(MeleeTargetingNode.hasTarget(blackboard) && this.targetIsValid(entity)){
if(MeleeTargetingNode.hasTarget(blackboard) && this.targetIsValid(MeleeTargetingNode.getTarget(blackboard))){
return AITreeNodeResult.SUCCESS;
}
@ -71,7 +71,9 @@ public class MeleeTargetingNode implements AITreeNode {
* @return true if valid, false otherwise
*/
private boolean targetIsValid(Entity entity){
return Globals.realmManager.getEntityRealm(entity) != null;
return
Globals.realmManager.getEntityRealm(entity) != null
;
}
/**

View File

@ -0,0 +1,31 @@
package electrosphere.entity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.joml.Vector3d;
import annotations.UnitTest;
import electrosphere.engine.Globals;
import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.RealmManager;
/**
* Unit tests for the server entity utils
*/
public class ServerEntityUtilsUnitTests {
@UnitTest
public void destroyEntity_ValidEntity_NoRealm(){
//setup
Globals.realmManager = new RealmManager();
Realm realm = Globals.realmManager.createViewportRealm(new Vector3d(0,0,0), new Vector3d(1,1,1));
Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d());
//perform action
ServerEntityUtils.destroyEntity(entity);
//verify
assertEquals(null, Globals.realmManager.getEntityRealm(entity));
}
}

View File

@ -0,0 +1,45 @@
package electrosphere.server.ai.nodes.actions.combat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.joml.Vector3d;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.ServerEntityUtils;
import electrosphere.entity.types.creature.CreatureTemplate;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.server.ai.blackboard.Blackboard;
import electrosphere.server.ai.nodes.AITreeNode.AITreeNodeResult;
import electrosphere.server.content.unit.UnitUtils;
import template.EntityTestTemplate;
/**
* Tests for the melee targeting ai node
*/
public class MeleeTargetingNodeTests extends EntityTestTemplate {
@IntegrationTest
public void testStopTargetingDeadEntity(){
float aggroRange = 10;
//spawn test entities
Entity swordsman = UnitUtils.spawnUnit(Globals.realmManager.first(), new Vector3d(0,0,0), "humanSwordsman");
Entity target = CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(1,0,0), "human", CreatureTemplate.createDefault("human"));
//check if the swordsman can find a target
Blackboard blackboard = new Blackboard();
MeleeTargetingNode meleeTargetingNode = new MeleeTargetingNode(aggroRange);
AITreeNodeResult eval1 = meleeTargetingNode.evaluate(swordsman, blackboard);
assertEquals(AITreeNodeResult.SUCCESS, eval1);
//delete the target
ServerEntityUtils.destroyEntity(target);
//check that the swordsman no longer finds a target
AITreeNodeResult eval2 = meleeTargetingNode.evaluate(swordsman, blackboard);
assertEquals(AITreeNodeResult.FAILURE, eval2);
}
}