diff --git a/server/src/Rooms/GameRoom/BodyParts.ts b/server/src/Rooms/GameRoom/BodyParts.ts new file mode 100644 index 0000000..a662bdd --- /dev/null +++ b/server/src/Rooms/GameRoom/BodyParts.ts @@ -0,0 +1,19 @@ +import { Part } from './Part'; + +export enum BodyPart { + Head = 'Head', + Torso = 'Torso', + Legs = 'Legs', +} + +export class BodyParts { + public head: Part; + public torso: Part; + public legs: Part; + + constructor(public characterName: string) { + this.head = new Part(characterName, BodyPart.Head); + this.torso = new Part(characterName, BodyPart.Torso); + this.legs = new Part(characterName, BodyPart.Legs); + } +} diff --git a/server/src/Rooms/GameRoom/Essence.ts b/server/src/Rooms/GameRoom/Essence.ts new file mode 100644 index 0000000..534a6d5 --- /dev/null +++ b/server/src/Rooms/GameRoom/Essence.ts @@ -0,0 +1,7 @@ +import * as jsonData from '../../database/Essences.json'; + +export class Essence { + public static getEssence(key: string): number { + return (jsonData).Essence[key]; + } +} diff --git a/server/src/Rooms/GameRoom/Part.ts b/server/src/Rooms/GameRoom/Part.ts new file mode 100644 index 0000000..e74a69e --- /dev/null +++ b/server/src/Rooms/GameRoom/Part.ts @@ -0,0 +1,11 @@ +import { StatsAdditions } from './StatsAdditions'; +import { StatsConverter } from './StatsConverter'; +import { BodyPart } from './BodyParts'; + +export class Part{ + public stats: StatsAdditions; + + constructor(public characterName: string, public part: BodyPart) { + this.stats = StatsConverter.getStats(characterName, part); + } +} diff --git a/server/src/Rooms/GameRoom/Player.ts b/server/src/Rooms/GameRoom/Player.ts index 135c9ff..658d470 100644 --- a/server/src/Rooms/GameRoom/Player.ts +++ b/server/src/Rooms/GameRoom/Player.ts @@ -1,15 +1,37 @@ import { Position } from './Position'; +import { PlayerStats } from './PlayerStats'; +import { BodyParts } from './BodyParts'; +import { Essence } from './Essence'; export class Player { private static playerCounter: number; - public name: string; + public score : number; + public currentKarma: number; + public currentHealth: number; + public currentHealthRegeneration: number; + public currentDamage: number; + public currentMovementSpeed: number; + public currentArmor: number; + public essence: number; + public bodyParts: BodyParts; + public stats: PlayerStats; constructor( public position: Position = new Position(), public rotation = 0, - ) { - this.name = `player${Player.playerCounter}`; + public name: string = `player${Player.playerCounter}`, + public team: string = 'team ' + `player${Player.playerCounter}`) { Player.playerCounter += 1; + this.score = 0; + this.currentHealth = 100; + this.stats = new PlayerStats(); + this.bodyParts = new BodyParts('Lion'); + this.currentKarma = this.stats.basicKarma; + this.currentHealthRegeneration = this.stats.basicHealthRegeneration; + this.currentDamage = this.stats.basicDamage; + this.currentMovementSpeed = this.stats.basicMovementSpeed; + this.currentArmor = this.stats.basicArmor; + this.essence = Essence.getEssence('NEUTRAL'); } } diff --git a/server/src/Rooms/GameRoom/PlayerStats.ts b/server/src/Rooms/GameRoom/PlayerStats.ts new file mode 100644 index 0000000..800d4e5 --- /dev/null +++ b/server/src/Rooms/GameRoom/PlayerStats.ts @@ -0,0 +1,12 @@ +export class PlayerStats{ + constructor( + public basicKarma : number = 0, + public basicHealthRegeneration : number = 0.5, + public basicDamage : number = 10, + public basicMovementSpeed : number = 25, + public basicArmor : number = 0, + public maxMovementSpeed: number = 250, + public maxArmor: number = 100, + public maxKarma: number = 150, + ) {} +} diff --git a/server/src/Rooms/GameRoom/StatsAdditions.ts b/server/src/Rooms/GameRoom/StatsAdditions.ts new file mode 100644 index 0000000..1d611bf --- /dev/null +++ b/server/src/Rooms/GameRoom/StatsAdditions.ts @@ -0,0 +1,11 @@ +export class StatsAdditions { + constructor( + public health : number = 0, + public healthRegeneration: number = 0, + public armor : number = 0, + public baseDamage: number = 0, + public karma : number = 0, + public movementSpeed : number = 0, + ) { + } +} diff --git a/server/src/Rooms/GameRoom/StatsConverter.ts b/server/src/Rooms/GameRoom/StatsConverter.ts new file mode 100644 index 0000000..d3857c3 --- /dev/null +++ b/server/src/Rooms/GameRoom/StatsConverter.ts @@ -0,0 +1,19 @@ +import * as data from '../../database/Characters.json'; +import { StatsAdditions } from './StatsAdditions'; +import { BodyPart } from './BodyParts.js'; + +export class StatsConverter { + public static getStats(name: string = 'Human', part: BodyPart) : StatsAdditions { + const databasePart = (data)[name][part].Stats || {}; + const health = StatsConverter.filterState(databasePart.HP); + const healthRegeneration = StatsConverter.filterState(databasePart.HPR); + const armor = StatsConverter.filterState(databasePart.AR); + const baseDamage = StatsConverter.filterState(databasePart.BD); + const karma = StatsConverter.filterState(databasePart.CK); + const movementSpeed = StatsConverter.filterState(databasePart.MS); + return new StatsAdditions( + health, healthRegeneration, armor, baseDamage, karma, movementSpeed); + } + + private static filterState = (state: any): number => state || 0; +} diff --git a/server/src/database/BeastsDatabase.json b/server/src/database/Characters.json similarity index 92% rename from server/src/database/BeastsDatabase.json rename to server/src/database/Characters.json index 0820653..685af33 100644 --- a/server/src/database/BeastsDatabase.json +++ b/server/src/database/Characters.json @@ -92,7 +92,7 @@ "Name": "Elwyn's Heart", "Description": "You take the unicorn's heart and become a little bit unicorn yourself.", "Stats": { - "HPR": "2.5", + "HRP": "2.5", "HP": "50" }, "Active": { @@ -122,7 +122,7 @@ "Stats": { "AR": "10", "MS": "15", - "HPR": "2", + "HRP": "2", "BD": "10" } }, @@ -168,7 +168,7 @@ "Evil": { "AR": "20 + 0.15 * CK", "HP": "35 + 0.15 * CK", - "HPR": "1.5" + "HRP": "1.5" } } }, @@ -218,7 +218,7 @@ "Description": "You wear the lions mighty mane as if you were the king of the jungle.", "Stats": { "HP": "80", - "HPR": "2", + "HRP": "2", "AR": "5", "MS": "20", "BD": "10" @@ -251,7 +251,7 @@ "Stats": { "MS": "-30", "HP": "20", - "HPR": "2" + "HRP": "2" }, "Active": { "Effects": [ @@ -286,7 +286,7 @@ "Type": "Change stats", "Stats": { "MS": "25", - "HPR": "5", + "HRP": "5", "AR": "15" }, "Duration": "5" @@ -326,5 +326,22 @@ "Name": "Loxodon", "Title": "The elephant. Biggest of them all.", "Essence": "Good" + }, + "Human": { + "Head": { + "Name": "Human Eyes", + "Description": "Basic human eyes, nothing special with those" + }, + "Torso": { + "Name": "Human Torso", + "Description": "Basic human torso, nothing special with those" + }, + "Legs": { + "Name": "Human Legs", + "Description": "Basic human legs, nothing special with those" + }, + "Name": "Human", + "Title": "The basic of them all", + "Essence": "Neutral" } } diff --git a/server/src/database/Essences.json b/server/src/database/Essences.json new file mode 100644 index 0000000..d72292a --- /dev/null +++ b/server/src/database/Essences.json @@ -0,0 +1,13 @@ +{ + "Essence": { + "NEUTRAL": 0, + "GOOD": 1, + "BENEVOLENT": 2, + "RIGHTEOUS": 3, + "DIVINE": 4, + "EVIL": -1, + "MALICIOUS": -2, + "NEFARIOUS": -3, + "SINISTER": -4 + } +} \ No newline at end of file diff --git a/server/src/index.ts b/server/src/index.ts index 42ab95a..f8bbdfe 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -7,6 +7,7 @@ import { GameRoom } from './Rooms/GameRoom/GameRoom'; import { FreeForAllLobbyRoom, TeamLobbyRoom } from './Rooms/GameLobbyRoom'; import { ruvenDebug, debugErrors } from './loggers'; import { subscribeToGameStart } from './Rooms/GameLobbyRoom/LobbyRoom'; +import { Player } from './Rooms/GameRoom/Player'; const app: express.Application = express(); const port: number = Number(process.env.PORT) || 3000; @@ -39,6 +40,9 @@ async function main() { gameServer.listen(port, undefined, undefined, () => { ruvenDebug('Server is listening on port %d', port); }); + + const p = new Player(); + debugErrors('%O', p); } main().catch(e => debugErrors('Something went wrong: %O', e));