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

Commit

Permalink
Created a classes to save player's data on the server.
Browse files Browse the repository at this point in the history
for #2
  • Loading branch information
jlevertov committed Nov 16, 2018
1 parent 92eec02 commit 66ebdd2
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 9 deletions.
13 changes: 13 additions & 0 deletions server/src/Rooms/GameRoom/BodyParts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Part } from './Part';

export class BodyParts {
public head : Part;
public torso : Part;
public legs : Part;

constructor(public characterName: string) {
this.head = new Part(characterName, 'Head');
this.torso = new Part(characterName, 'Torso');
this.legs = new Part(characterName, '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 data from '../../database/Essences.json';

export class Essence {
public static getEssence(key : string) : number {
return data.Essence[key];
}
}
10 changes: 10 additions & 0 deletions server/src/Rooms/GameRoom/Part.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StatsAdditions } from './StatsAdditions';
import { StatsConverter } from './StatsConverter';

export class Part{
public stats: StatsAdditions;

constructor(public characterName: string, public part : string) {
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 { PlayerCharactiristics } from './PlayerCharactiristics';
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 charactirisrics: PlayerCharactiristics;

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.charactirisrics = new PlayerCharactiristics();
this.bodyParts = new BodyParts('Human');
this.currentKarma = this.charactirisrics.basicKarma;
this.currentHealthRegeneration = this.charactirisrics.basicHealthRegeneration;
this.currentDamage = this.charactirisrics.basicDamage;
this.currentMovementSpeed = this.charactirisrics.basicMovementSpeed;
this.currentArmor = this.charactirisrics.basicArmor;
this.essence = Essence.getEssence('NEAUTRAL');
}
}
10 changes: 10 additions & 0 deletions server/src/Rooms/GameRoom/PlayerCharactiristics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class PlayerCharactiristics{
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) {}
}
10 changes: 10 additions & 0 deletions server/src/Rooms/GameRoom/StatsAdditions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Essence } from './Essence';

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) {}
}
23 changes: 23 additions & 0 deletions server/src/Rooms/GameRoom/StatsConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as data from '../../database/Characters.json';
import { StatsAdditions } from './StatsAdditions';

export class StatsConverter {
public static getStats (name : string = 'Human', part : string) : StatsAdditions {
const databasePart = data[name][part];

This comment has been minimized.

Copy link
@jlevertov

jlevertov Nov 17, 2018

Author Contributor

data[name][part]["Stats"]

const health = StatsConverter.filterState(databasePart['HP']);
const healthRegeneration = StatsConverter.filterState(databasePart['HRP']);
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 {
if (state === 'undefined') {
return 0;
}
return state;
}
}
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"
},
"Hunman": {
"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
}
}

0 comments on commit 66ebdd2

Please sign in to comment.