Renderer/src/test/java/electrosphere/entity/state/equip/ServerEquipStateTests.java
austin b5405081e7
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
fix testing bugs, leverage extensions
2024-08-24 14:35:55 -04:00

97 lines
4.0 KiB
Java

package electrosphere.entity.state.equip;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.joml.Vector3d;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.creature.CreatureTemplate;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import template.EntityTestTemplate;
import testutils.TestEngineUtils;
/**
* Server equip state tests
*/
public class ServerEquipStateTests extends EntityTestTemplate {
/**
* Try equipping an item
*/
@IntegrationTest
public void testEquipItem(){
TestEngineUtils.simulateFrames(1);
//spawn entities
CreatureTemplate creatureTemplate = CreatureTemplate.createDefault("human");
Entity creature = CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(0,0,0), "human", creatureTemplate);
Entity katana = ItemUtils.serverSpawnBasicItem(Globals.realmManager.first(), new Vector3d(0,0,0), "Katana2H");
//equip
Entity inInventoryItem = InventoryUtils.serverAttemptStoreItem(creature, katana);
ServerEquipState serverEquipState = ServerEquipState.getServerEquipState(creature);
serverEquipState.commandAttemptEquip(inInventoryItem, serverEquipState.getEquipPoint("handsCombined"));
//propagate to client
TestEngineUtils.simulateFrames(2);
//
//verify was equipped
assertNotNull(serverEquipState.getEquippedItemAtPoint("handsCombined"));
List<Entity> children = AttachUtils.getChildrenList(creature);
assertNotNull(children);
assertEquals(1, children.size());
Entity child = children.get(0);
assertTrue(ItemUtils.isItem(child));
assertTrue(ItemUtils.isWeapon(child));
assertNotNull(AttachUtils.getParent(child));
assertEquals(AttachUtils.getParent(child), creature);
}
/**
* Try equipping two items to the same slot
*/
@IntegrationTest
public void testFailEquipToOccupied(){
TestEngineUtils.simulateFrames(1);
//spawn entities
CreatureTemplate creatureTemplate = CreatureTemplate.createDefault("human");
Entity creature = CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(0,0,0), "human", creatureTemplate);
Entity katana = ItemUtils.serverSpawnBasicItem(Globals.realmManager.first(), new Vector3d(0,0,0), "Katana2H");
Entity katana2 = ItemUtils.serverSpawnBasicItem(Globals.realmManager.first(), new Vector3d(0,0,0), "Katana2H");
//equip
Entity inInventoryItem = InventoryUtils.serverAttemptStoreItem(creature, katana);
ServerEquipState serverEquipState = ServerEquipState.getServerEquipState(creature);
serverEquipState.commandAttemptEquip(inInventoryItem, serverEquipState.getEquipPoint("handsCombined"));
//attempt to equip second katana
Entity inInventoryItem2 = InventoryUtils.serverAttemptStoreItem(creature, katana2);
serverEquipState.commandAttemptEquip(inInventoryItem2, serverEquipState.getEquipPoint("handsCombined"));
//propagate to client
TestEngineUtils.simulateFrames(2);
//
//verify that only one item was equipped
assertNotNull(serverEquipState.getEquippedItemAtPoint("handsCombined"));
List<Entity> children = AttachUtils.getChildrenList(creature);
assertNotNull(children);
assertEquals(1, children.size());
Entity child = children.get(0);
assertTrue(ItemUtils.isItem(child));
assertTrue(ItemUtils.isWeapon(child));
assertNotNull(AttachUtils.getParent(child));
assertEquals(AttachUtils.getParent(child), creature);
}
}