Skip to content

joonipea/byteCrawler-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ByteCrawler Server

A server for the ByteCrawler project. The server is built with Node.js and SurrealDB.

Installation

  1. Clone the repository: git clone https://github.com/joonipea/byteCrawler.git
  2. Install the dependencies: npm install
  3. Install SurrealDB

Usage

  1. Start SurrealDB: npm run surreal
  2. Start the server: npm run start
  3. Access the server at http://localhost:7001

API Routes

/api/v1/generateWorld

Generates a new world with 50 items, 50 mobs, 50 chars, and 1 map and returns a message about the success of the operation.

Usage

const name: string = "worldName";

const url: string = "http://localhost:7001/api/v1/generateWorld";

const headers = {
    user: name
};

const response = await fetch(url, {
    method: "GET",
    headers: headers
});
console.log(await response.json());

Response:

"world generated"

/api/v1/get

Returns information on any requested record(s) within a world.

Usage

Example of getting all Records

function getRecord(name, record) {
    const url: string = "http://localhost:/api/v1/get";
    const headers = {
        user: name,
        record: record
    };
    return fetch(url, {
        method: "GET",
        headers: headers,
    });
}
let record = "chars";
let name = "worldName";
getRecord(name, record).then((response) => {
    console.log(response.json()); //return the first record
});

Response:

[
    {
        "alignment": 7,
        "description": "c HidaLAwTcNmiZwCQrI",
        "id": "chars:Ajani_Nalaar",
        "level": 1,
        "mood": 3,
        "name": "Ajani_Nalaar",
        "rarity": 3,
        "species": "iJWYcWVXyd",
        "stats": {
            "attack": 2,
            "defense": 3,
            "health": 11,
            "luck": 9,
            "maxHealth": 11
        }
    },
    {
        "alignment": 4,
        "description": "QhChxTb YgzltkGYZmGO",
        "id": "chars:Ajani_Revane",
        "level": 1,
        "mood": 8,
        "name": "Ajani_Revane",
        "rarity": 2,
        "species": "OzmsIRBZbS",
        "stats": {
            "attack": 8,
            "defense": 6,
            "health": 1,
            "luck": 4,
            "maxHealth": 1
        }
    },
    {
        "alignment": 9,
        "description": "dZPXlKaeIKSXCxbdPUYx",
        "id": "chars:Ajani_The_Unbowed",
        "level": 1,
        "mood": 9,
        "name": "Ajani_The_Unbowed",
        "rarity": 2,
        "species": " kPHfkCQPz",
        "stats": {
            "attack": 3,
            "defense": 6,
            "health": 7,
            "luck": 5,
            "maxHealth": 7
        }
    }
]

Example of getting a single record

function getRecord(name, record) {
    const url: string = "http://localhost:/api/v1/get";
    const headers = {
        user: name,
        record: record
    };
    return fetch(url, {
        method: "GET",
        headers: headers,
    });
}
let record = "chars:Ajani_Nalaar";
let name = "worldName";
getRecord(name, record).then((response) => {
    console.log(response.json());
});

Response (shortened for readability):

[
    {
        "alignment": 7,
        "description": "c HidaLAwTcNmiZwCQrI",
        "id": "chars:Ajani_Nalaar",
        "level": 1,
        "mood": 3,
        "name": "Ajani_Nalaar",
        "rarity": 3,
        "species": "iJWYcWVXyd",
        "stats": {
            "attack": 2,
            "defense": 3,
            "health": 11,
            "luck": 9,
            "maxHealth": 11
        }
    }
]

/api/v1/generateMap

Generates a new map and returns the map.

async function generateMap(name, floor) {
    const url: string = "http://localhost:7001/api/v1/generateMap";
    const headers = {
        user: name,
        floor: floor
    };
    return fetch(url, {
        method: "GET",
        headers: headers,
    });
}
let name = "worldName";
let floor = 2;
generateMap(name, floor).then((response) => {
    console.log(response.json());
});

Response (shortened for readability):

[
    {
        "floor": 2,
        "id": "maps:1",
        "map": [
            [
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall"
            ],
            [
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall",
                "wall"
            ]
        ],
        "name": "green_tomb"
    }
]

Object Types

Chars

Randomly generated player characters.

type char = {
    name: string;
    description: string;
    level: number;
    mood: number;
    rarity: number;
    stats: stats;
    alignment: number;
    taxonomy?: taxonomy;
    species: taxonomy["species"];
};

Items

Randomly generated items.

type item = {
    name: string;
    description: string;
    profeciencyStat?: skill["profeciencyStat"];
    skills?: skill;
    rarity: number;
    price: number;
    levelRequirement?: number;
};

Mobs

Randomly generated mobs.

type mob = {
    name: string;
    description: string;
    level: number;
    drops: item[];
    stats: stats;
    alignment: number;
    taxonomy?: taxonomy;
    species: taxonomy["species"];
};

Maps

Randomly generated maps.

type map = {
    name: string;
    floor: number;
    map: string[][];
};

Stats

type stats = {
    maxHealth: number;
    health: number;
    attack: number;
    defense: number;
    luck: number;
};

About

Server for a rougue-like dungeon crawler with procedural dungeons.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published