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

Commit 66ebdd2

Browse files
committed
Created a classes to save player's data on the server.
for #2
1 parent 92eec02 commit 66ebdd2

File tree

9 files changed

+134
-9
lines changed

9 files changed

+134
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Part } from './Part';
2+
3+
export class BodyParts {
4+
public head : Part;
5+
public torso : Part;
6+
public legs : Part;
7+
8+
constructor(public characterName: string) {
9+
this.head = new Part(characterName, 'Head');
10+
this.torso = new Part(characterName, 'Torso');
11+
this.legs = new Part(characterName, 'Legs');
12+
}
13+
}

server/src/Rooms/GameRoom/Essence.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as data from '../../database/Essences.json';
2+
3+
export class Essence {
4+
public static getEssence(key : string) : number {
5+
return data.Essence[key];
6+
}
7+
}

server/src/Rooms/GameRoom/Part.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { StatsAdditions } from './StatsAdditions';
2+
import { StatsConverter } from './StatsConverter';
3+
4+
export class Part{
5+
public stats: StatsAdditions;
6+
7+
constructor(public characterName: string, public part : string) {
8+
this.stats = StatsConverter.getStats(characterName, part);
9+
}
10+
}

server/src/Rooms/GameRoom/Player.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
import { Position } from './Position';
2+
import { PlayerCharactiristics } from './PlayerCharactiristics';
3+
import { BodyParts } from './BodyParts';
4+
import { Essence } from './Essence';
25

36
export class Player {
47
private static playerCounter: number;
58

6-
public name: string;
9+
public score : number;
10+
public currentKarma: number;
11+
public currentHealth: number;
12+
public currentHealthRegeneration: number;
13+
public currentDamage: number;
14+
public currentMovementSpeed: number;
15+
public currentArmor: number;
16+
public essence: number;
17+
public bodyParts: BodyParts;
18+
public charactirisrics: PlayerCharactiristics;
719

820
constructor(
921
public position: Position = new Position(),
1022
public rotation = 0,
11-
) {
12-
this.name = `player${Player.playerCounter}`;
23+
public name: string = `player${Player.playerCounter}`,
24+
public team: string = 'team ' + `player${Player.playerCounter}`) {
1325
Player.playerCounter += 1;
26+
this.score = 0;
27+
this.currentHealth = 100;
28+
this.charactirisrics = new PlayerCharactiristics();
29+
this.bodyParts = new BodyParts('Human');
30+
this.currentKarma = this.charactirisrics.basicKarma;
31+
this.currentHealthRegeneration = this.charactirisrics.basicHealthRegeneration;
32+
this.currentDamage = this.charactirisrics.basicDamage;
33+
this.currentMovementSpeed = this.charactirisrics.basicMovementSpeed;
34+
this.currentArmor = this.charactirisrics.basicArmor;
35+
this.essence = Essence.getEssence('NEAUTRAL');
1436
}
1537
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class PlayerCharactiristics{
2+
constructor(public basicKarma : number = 0,
3+
public basicHealthRegeneration : number = 0.5,
4+
public basicDamage : number = 10,
5+
public basicMovementSpeed : number = 25,
6+
public basicArmor : number = 0,
7+
public maxMovementSpeed: number = 250,
8+
public maxArmor: number = 100,
9+
public maxKarma: number = 150) {}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Essence } from './Essence';
2+
3+
export class StatsAdditions {
4+
constructor(public health : number = 0,
5+
public healthRegeneration: number = 0,
6+
public armor : number = 0,
7+
public baseDamage: number = 0,
8+
public karma : number = 0,
9+
public movementSpeed : number = 0) {}
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as data from '../../database/Characters.json';
2+
import { StatsAdditions } from './StatsAdditions';
3+
4+
export class StatsConverter {
5+
public static getStats (name : string = 'Human', part : string) : StatsAdditions {
6+
const databasePart = data[name][part];
7+
const health = StatsConverter.filterState(databasePart['HP']);
8+
const healthRegeneration = StatsConverter.filterState(databasePart['HRP']);
9+
const armor = StatsConverter.filterState(databasePart['AR']);
10+
const baseDamage = StatsConverter.filterState(databasePart['BD']);
11+
const karma = StatsConverter.filterState(databasePart['CK']);
12+
const movementSpeed = StatsConverter.filterState(databasePart['MS']);
13+
return new StatsAdditions(health, healthRegeneration, armor,
14+
baseDamage, karma, movementSpeed);
15+
}
16+
17+
private static filterState(state : any) : number {
18+
if (state === 'undefined') {
19+
return 0;
20+
}
21+
return state;
22+
}
23+
}

server/src/database/BeastsDatabase.json renamed to server/src/database/Characters.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"Name": "Elwyn's Heart",
9393
"Description": "You take the unicorn's heart and become a little bit unicorn yourself.",
9494
"Stats": {
95-
"HPR": "2.5",
95+
"HRP": "2.5",
9696
"HP": "50"
9797
},
9898
"Active": {
@@ -122,7 +122,7 @@
122122
"Stats": {
123123
"AR": "10",
124124
"MS": "15",
125-
"HPR": "2",
125+
"HRP": "2",
126126
"BD": "10"
127127
}
128128
},
@@ -168,7 +168,7 @@
168168
"Evil": {
169169
"AR": "20 + 0.15 * CK",
170170
"HP": "35 + 0.15 * CK",
171-
"HPR": "1.5"
171+
"HRP": "1.5"
172172
}
173173
}
174174
},
@@ -218,7 +218,7 @@
218218
"Description": "You wear the lions mighty mane as if you were the king of the jungle.",
219219
"Stats": {
220220
"HP": "80",
221-
"HPR": "2",
221+
"HRP": "2",
222222
"AR": "5",
223223
"MS": "20",
224224
"BD": "10"
@@ -251,7 +251,7 @@
251251
"Stats": {
252252
"MS": "-30",
253253
"HP": "20",
254-
"HPR": "2"
254+
"HRP": "2"
255255
},
256256
"Active": {
257257
"Effects": [
@@ -286,7 +286,7 @@
286286
"Type": "Change stats",
287287
"Stats": {
288288
"MS": "25",
289-
"HPR": "5",
289+
"HRP": "5",
290290
"AR": "15"
291291
},
292292
"Duration": "5"
@@ -326,5 +326,22 @@
326326
"Name": "Loxodon",
327327
"Title": "The elephant. Biggest of them all.",
328328
"Essence": "Good"
329+
},
330+
"Hunman": {
331+
"Head": {
332+
"Name": "Human Eyes",
333+
"Description": "Basic human eyes, nothing special with those"
334+
},
335+
"Torso": {
336+
"Name": "Human Torso",
337+
"Description": "Basic human torso, nothing special with those"
338+
},
339+
"Legs": {
340+
"Name": "Human Legs",
341+
"Description": "Basic human legs, nothing special with those"
342+
},
343+
"Name": "Human",
344+
"Title": "The basic of them all",
345+
"Essence": "Neutral"
329346
}
330347
}

server/src/database/Essences.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Essence": {
3+
"NEUTRAL": 0,
4+
"GOOD": 1,
5+
"BENEVOLENT": 2,
6+
"RIGHTEOUS": 3,
7+
"DIVINE": 4,
8+
"EVIL": -1,
9+
"MALICIOUS": -2,
10+
"NEFARIOUS": -3,
11+
"SINISTER": -4
12+
}
13+
}

0 commit comments

Comments
 (0)