diff --git a/assets/Scripts/client/client.ts b/assets/Scripts/client/client.ts index f8528595..4532122f 100644 --- a/assets/Scripts/client/client.ts +++ b/assets/Scripts/client/client.ts @@ -1,4 +1,3 @@ -import { ClientInventory, onEquipItem, onMoveItemContainer, onUnequipItem } from "/Scripts/client/entity/inventory"; import { Namespace } from "/Scripts/types/namespace"; @@ -6,17 +5,17 @@ import { Namespace } from "/Scripts/types/namespace"; * The client namespace type */ export interface NamespaceClient extends Namespace { - inventory: ClientInventory, + // inventory: ClientInventory, } /** * The client namespace (should contain all client callbacks, data, etc) */ export const Client: NamespaceClient = { - inventory: { - onMoveItemContainer: onMoveItemContainer, - onEquipItem: onEquipItem, - onUnequipItem: onUnequipItem, - }, + // inventory: { + // onMoveItemContainer: onMoveItemContainer, + // onEquipItem: onEquipItem, + // onUnequipItem: onUnequipItem, + // }, } diff --git a/assets/Scripts/client/entity/inventory.ts b/assets/Scripts/client/entity/inventory.ts index 90610277..3ab708fd 100644 --- a/assets/Scripts/client/entity/inventory.ts +++ b/assets/Scripts/client/entity/inventory.ts @@ -1,4 +1,4 @@ -import { Entity } from "/Scripts/engine/entity/entity" +import { Entity } from "/Scripts/types/host/entity/entity" /** diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 3da8833e..e805c43c 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -631,6 +631,10 @@ Return to main menu from ingame Tagging threads in manager Quitting to main menu +(08/25/2024) +Server utilities provided to scripting engine +Spawn player character with weapon when testing levels + # TODO diff --git a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java index ac086213..7243e382 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java +++ b/src/main/java/electrosphere/engine/loadingthreads/LoadingUtils.java @@ -11,6 +11,7 @@ import org.joml.Vector3i; import electrosphere.auth.AuthenticationManager; import electrosphere.engine.Globals; import electrosphere.engine.threads.LabeledThread.ThreadLabel; +import electrosphere.entity.types.creature.CreatureEquipData.EquippedItem; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; @@ -166,6 +167,7 @@ public class LoadingUtils { template.putAttributeValue(attribute.getAttributeId(), attribute.getVariants().get(0).getId()); } } + template.getCreatureEquipData().setSlotItem("handsCombined",new EquippedItem(71, "Katana2H")); //set player character template serverPlayerConnection.setCreatureTemplate(template); Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage()); diff --git a/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java b/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java index 92a98a4b..f386a844 100644 --- a/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java +++ b/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java @@ -5,13 +5,19 @@ import org.joml.Vector3i; import electrosphere.engine.Globals; import electrosphere.entity.Entity; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.state.equip.ServerEquipState; +import electrosphere.entity.state.inventory.InventoryUtils; import electrosphere.entity.state.server.ServerPlayerViewDirTree; +import electrosphere.entity.types.creature.CreatureEquipData.EquippedItem; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.entity.types.item.ItemUtils; import electrosphere.logger.LoggerInterface; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.server.player.Player; import electrosphere.server.datacell.Realm; +import electrosphere.server.datacell.utils.EntityLookupUtils; /** * Deals with spawning player characters @@ -36,6 +42,24 @@ public class PlayerCharacterCreation { Vector3d spawnPoint = realm.getSpawnPoint(); Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template); + // + //now that creature has been spawned, need to create all attached items + if(template != null && template.getCreatureEquipData() != null && template.getCreatureEquipData().getSlots() != null){ + for(String equipSlotId : template.getCreatureEquipData().getSlots()){ + + //spawn the item in the world + EquippedItem itemDefinition = template.getCreatureEquipData().getSlotItem(equipSlotId); + Entity itemInWorld = ItemUtils.serverSpawnBasicItem(realm, EntityUtils.getPosition(newPlayerEntity), itemDefinition.getItemType()); + + //add the item to the creature's inventory + Entity itemInInventory = InventoryUtils.serverAttemptStoreItem(newPlayerEntity, EntityLookupUtils.getEntityById(itemInWorld.getId())); + + //equip the item to the slot defined in the template + ServerEquipState serverEquipState = ServerEquipState.getEquipState(newPlayerEntity); + serverEquipState.commandAttemptEquip(itemInInventory,serverEquipState.getEquipPoint(equipSlotId)); + } + } + // //attach entity to player object LoggerInterface.loggerEngine.INFO("Spawned entity for player. Entity id: " + newPlayerEntity.getId() + " Player id: " + playerObject.getId());