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));
    }

}
