Compare commits
2 Commits
3682497060
...
4c65b59b1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c65b59b1b | ||
|
|
719999b6aa |
@ -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,
|
||||
// },
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Entity } from "/Scripts/engine/entity/entity"
|
||||
import { Entity } from "/Scripts/types/host/entity/entity"
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* An entity
|
||||
*/
|
||||
export interface Entity {
|
||||
id: number,
|
||||
}
|
||||
|
||||
|
||||
16
assets/Scripts/types/host/entity/entity.ts
Normal file
16
assets/Scripts/types/host/entity/entity.ts
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An entity
|
||||
*/
|
||||
export interface Entity {
|
||||
|
||||
/**
|
||||
* Gets the id of the entity
|
||||
* @returns The id
|
||||
*/
|
||||
getId: () => number,
|
||||
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
import { Entity } from "/Scripts/types/host/entity/entity";
|
||||
import { TutorialUtils } from "/Scripts/types/host/renderer/ui/tutorial";
|
||||
import { Vector } from "/Scripts/types/spatial";
|
||||
|
||||
|
||||
/**
|
||||
@ -21,6 +23,11 @@ export interface StaticClasses {
|
||||
*/
|
||||
readonly tutorialUtils?: Class<TutorialUtils>,
|
||||
|
||||
/**
|
||||
* Utilities for performing actions on the server
|
||||
*/
|
||||
readonly serverUtils?: Class<ServerUtils>,
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -50,3 +57,31 @@ export interface SimulationClass {
|
||||
readonly setFramestep: (value: number) => void,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utilities for core functionality on the server
|
||||
*/
|
||||
export interface ServerUtils {
|
||||
|
||||
/**
|
||||
* Spawns a creature
|
||||
* @param creatureType The type of creature
|
||||
* @returns The entity created on the server
|
||||
*/
|
||||
readonly spawnCreature: (sceneInstanceId: number, creatureType: string, position: Vector) => Entity
|
||||
|
||||
/**
|
||||
* Gets the position of an entity
|
||||
* @param entity The entity
|
||||
* @returns The position
|
||||
*/
|
||||
readonly getPosition: (entity: Entity) => Vector
|
||||
|
||||
/**
|
||||
* Sets the position of an entity
|
||||
* @param entity The entity
|
||||
* @param position The position
|
||||
*/
|
||||
readonly setPosition: (entity: Entity, position: Vector) => void
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -2,6 +2,8 @@ package electrosphere.entity;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.graalvm.polyglot.HostAccess.Export;
|
||||
|
||||
|
||||
/**
|
||||
* An entity
|
||||
@ -29,6 +31,7 @@ public class Entity {
|
||||
* Gets the id of this entity
|
||||
* @return The id
|
||||
*/
|
||||
@Export
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -70,12 +70,6 @@ public class ServerEntityUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
// //if the server is also a client, update the drawcell manager to know to pull new chunks
|
||||
// if(Globals.RUN_CLIENT){
|
||||
// Globals.drawCellManager.invalidateAllCells();
|
||||
// Globals.drawCellManager.setCellX(Globals.clientPlayerData.getWorldPos().x);
|
||||
// Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPos().z);
|
||||
// }
|
||||
//reposition entity
|
||||
CollisionObjUtils.serverPositionCharacter(entity, position);
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.menu.tutorial.TutorialMenus;
|
||||
import electrosphere.script.translation.JSServerUtils;
|
||||
import electrosphere.util.FileUtils;
|
||||
import electrosphere.util.math.MathUtils;
|
||||
|
||||
@ -85,6 +86,7 @@ public class ScriptEngine {
|
||||
{"mathUtils",MathUtils.class},
|
||||
{"simulation",Main.class},
|
||||
{"tutorialUtils",TutorialMenus.class},
|
||||
{"serverUtils",JSServerUtils.class},
|
||||
};
|
||||
|
||||
//singletons from the host that are provided to the javascript context
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
package electrosphere.script.translation;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.ServerEntityUtils;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.script.access.Vector;
|
||||
import electrosphere.script.utils.AccessTransforms;
|
||||
|
||||
/**
|
||||
* Server utilities provided to the js context
|
||||
*/
|
||||
public class JSServerUtils {
|
||||
|
||||
/**
|
||||
* Spawns a creature
|
||||
* @param creatureType The creature
|
||||
*/
|
||||
public static void spawnCreature(int sceneInstanceId, String creatureType, Vector position){
|
||||
//TODO: find realm from scene id
|
||||
CreatureUtils.serverSpawnBasicCreature(null, AccessTransforms.getVector(position), creatureType, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of an entity
|
||||
* @param entity The entity
|
||||
* @return The position of the entity
|
||||
*/
|
||||
public static Vector getPosition(Entity entity){
|
||||
return AccessTransforms.getVector(EntityUtils.getPosition(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of an entity
|
||||
* @param entity The entity
|
||||
* @param vector THe new position of the entity
|
||||
*/
|
||||
public static void setPosition(Entity entity, Vector vector){
|
||||
ServerEntityUtils.repositionEntity(entity, AccessTransforms.getVector(vector));
|
||||
}
|
||||
|
||||
}
|
||||
@ -15,4 +15,13 @@ public class AccessTransforms {
|
||||
return new electrosphere.script.access.Vector(source.x, source.y, source.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an access vector into a JOML vector
|
||||
* @param source The access vectpr
|
||||
* @return The JOML vector
|
||||
*/
|
||||
public static org.joml.Vector3d getVector(electrosphere.script.access.Vector source){
|
||||
return new org.joml.Vector3d(source.x,source.y,source.z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user