Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Created a classes to save player's data on the server. #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions server/src/Rooms/GameRoom/BodyParts.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 7 additions & 0 deletions server/src/Rooms/GameRoom/Essence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as jsonData from '../../database/Essences.json';

export class Essence {
public static getEssence(key: string): number {
return (<any>jsonData).Essence[key];
}
}
11 changes: 11 additions & 0 deletions server/src/Rooms/GameRoom/Part.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
28 changes: 25 additions & 3 deletions server/src/Rooms/GameRoom/Player.ts
Original file line number Diff line number Diff line change
@@ -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');
}
}
12 changes: 12 additions & 0 deletions server/src/Rooms/GameRoom/PlayerStats.ts
Original file line number Diff line number Diff line change
@@ -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,
) {}
}
11 changes: 11 additions & 0 deletions server/src/Rooms/GameRoom/StatsAdditions.ts
Original file line number Diff line number Diff line change
@@ -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,
) {
}
}
19 changes: 19 additions & 0 deletions server/src/Rooms/GameRoom/StatsConverter.ts
Original file line number Diff line number Diff line change
@@ -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 = (<any>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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -122,7 +122,7 @@
"Stats": {
"AR": "10",
"MS": "15",
"HPR": "2",
"HRP": "2",
"BD": "10"
}
},
Expand Down Expand Up @@ -168,7 +168,7 @@
"Evil": {
"AR": "20 + 0.15 * CK",
"HP": "35 + 0.15 * CK",
"HPR": "1.5"
"HRP": "1.5"
}
}
},
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -251,7 +251,7 @@
"Stats": {
"MS": "-30",
"HP": "20",
"HPR": "2"
"HRP": "2"
},
"Active": {
"Effects": [
Expand Down Expand Up @@ -286,7 +286,7 @@
"Type": "Change stats",
"Stats": {
"MS": "25",
"HPR": "5",
"HRP": "5",
"AR": "15"
},
"Duration": "5"
Expand Down Expand Up @@ -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"
}
}
13 changes: 13 additions & 0 deletions server/src/database/Essences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Essence": {
"NEUTRAL": 0,
"GOOD": 1,
"BENEVOLENT": 2,
"RIGHTEOUS": 3,
"DIVINE": 4,
"EVIL": -1,
"MALICIOUS": -2,
"NEFARIOUS": -3,
"SINISTER": -4
}
}
4 changes: 4 additions & 0 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));