Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPG Saga #13

Open
wants to merge 7 commits into
base: Kiselev_Artem_Andreevich
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
9,236 changes: 2,128 additions & 7,108 deletions rpgsaga/saga/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion rpgsaga/saga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
},
"author": "",
"license": "ISC",
"dependencies": {},
"dependencies": {
"colorts": "^0.1.63",
"is-whole-number": "^1.1.0"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.0",
Expand Down
167 changes: 167 additions & 0 deletions rpgsaga/saga/src/character.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import color from 'colorts';

import { MathHelper } from './mathHelper';
import { fireDamage, names } from './constants';
import { Logger } from './logger';

export class Character {
className = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это зачем,

private isBurn = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а если завтра появится отравление, заморозка? в принципе любой флаг - это звоночек, что может быть стоит переделать

get isBurnValue(): boolean {
return this.isBurn;
}

protected isStunned = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

аналогично вот тут

private health: number;
get healthValue(): number {
return this.health;
}
protected minHealth = 5;
protected maxHealth = 10;

private strength: number;
get strengthValue(): number {
return this.strength;
}
protected minStrength = 5;
protected maxStrength = 10;

private characterName: string;
get characterNameValue(): string {
return this.characterName;
}

private dexterity: number;
get dexterityValue(): number {
return this.dexterity;
}
protected minDexterity = 5;
protected maxDexterity = 10;

protected mana = 0;
get manaValue(): number {
return this.mana;
}

private manaRegeneration: number;
get manaRegenerationValue(): number {
return this.manaRegeneration;
}
protected minManaRegeneration = 8;
protected maxManaRegeneration = 10;

private classSkillCost = 0;
get classSkillCostValue(): number {
return this.classSkillCost;
}
protected minClassSkillCost = 15;
protected maxClassSkillCost = 20;

constructor() {
this.generateStats();
}

public stun() {
this.isStunned = true;
}

private generateStats() {
this.health = MathHelper.genrateRandomNumber(this.minHealth, this.maxHealth);
this.strength = MathHelper.genrateRandomNumber(this.minStrength, this.maxStrength);
this.dexterity = MathHelper.genrateRandomNumber(this.minDexterity, this.maxDexterity);
this.characterName = this.selectColorName(names[MathHelper.genrateRandomNumber(0, names.length - 1)]);
this.manaRegeneration = MathHelper.genrateRandomNumber(this.minManaRegeneration, this.maxManaRegeneration);
this.classSkillCost = MathHelper.genrateRandomNumber(this.minClassSkillCost, this.maxClassSkillCost);
Comment on lines +69 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот это лучше бы передавать извне, иначе тесты будет сложно написать

}

public checkInitiative() {
return MathHelper.genrateRandomNumber(1, this.dexterity * 10);
}

public checkDexterity() {
return MathHelper.genrateRandomNumber(1, this.dexterity * 10);
}

public checkHit() {
return MathHelper.genrateRandomNumber(1, this.strengthValue * 10);
}

public takeDamage(damage: number) {
this.health -= damage;
}

private selectColorName(name: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на это тесты точно надо (может и есть уже)

let result = '';
switch (MathHelper.genrateRandomNumber(0, 6)) {
case 0:
result = color(name).red.toString();
break;
case 1:
result = color(name).green.toString();
break;
case 2:
result = color(name).yellow.toString();
break;
case 3:
result = color(name).blue.toString();
break;
case 4:
result = color(name).magenta.toString();
break;
case 5:
result = color(name).cyan.toString();
break;
default:
result = name;
break;
}
return result;
}

startBurn() {
this.isBurn = true;
}

endBurn() {
this.isBurn = false;
}

characterTurn(enemy: Character) {
this.attack(enemy);
this.processEffects();
}

protected attack(enemy: Character) {
if (!this.isStunned) {
Logger.startAttackMessage(this);

const hitStrength = this.checkDexterity();
const dodgeStrength = enemy.checkDexterity();

if (hitStrength > dodgeStrength) {
const damage = this.checkHit();
enemy.takeDamage(damage);
Logger.successAttackMessage(this, hitStrength, enemy, dodgeStrength, damage);
} else {
Logger.failedAttackMessage(this, hitStrength, enemy, dodgeStrength);
}
}
}

hillHP() {
this.health += 100;
}

protected processEffects() {
if (this.isBurn) {
this.health -= fireDamage;
Logger.characterBurn(this, fireDamage);
}

if (this.isStunned) {
this.isStunned = false;
}

this.mana += this.manaRegeneration;
}
}
35 changes: 35 additions & 0 deletions rpgsaga/saga/src/classes/archer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Character } from '../character';
import { Logger } from '../logger';

export class Archer extends Character {
minHealth = 5;
maxHealth = 8;

minStrength = 7;
maxStrength = 10;

minDexterity = 7;
maxDexterity = 10;

minManaRegeneration = 8;
maxManaRegeneration = 15;

minClassSkillCost = 10;
maxClassSkillCost = 20;

Comment on lines +5 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это же есть в базовом классе

className = 'Лучник';

attack(enemy: Character): void {
if (this.classSkillCostValue < this.manaValue && !enemy.isBurnValue) {
Logger.useArcherSkill(this, enemy);
enemy.startBurn();
this.mana -= this.classSkillCostValue;
} else {
super.attack(enemy);
}
}

constructor() {
super();
}
}
34 changes: 34 additions & 0 deletions rpgsaga/saga/src/classes/assasin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Character } from '../character';
import { Logger } from '../logger';

export class Assasin extends Character {
minHealth = 5;
maxHealth = 8;

minStrength = 7;
maxStrength = 10;

minDexterity = 8;
maxDexterity = 10;

minManaRegeneration = 8;
maxManaRegeneration = 10;

minClassSkillCost = 15;
maxClassSkillCost = 20;

className = 'Ассасин';

attack(enemy: Character): void {
super.attack(enemy);
if (this.classSkillCostValue < this.manaValue) {
enemy.stun();
Logger.useAssasinSkill(this, enemy);
this.mana -= this.classSkillCostValue;
}
}

constructor() {
super();
}
}
38 changes: 38 additions & 0 deletions rpgsaga/saga/src/classes/knight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Character } from '../character';
import { Logger } from '../logger';

export class Knight extends Character {
minHealth = 6;
maxHealth = 8;

minStrength = 7;
maxStrength = 10;

minDexterity = 3;
maxDexterity = 7;

minManaRegeneration = 4;
maxManaRegeneration = 10;

minClassSkillCost = 20;
maxClassSkillCost = 25;

className = 'Рыцарь';

attack(enemy: Character): void {
if (this.classSkillCostValue < this.manaValue) {
Logger.startAttackMessage(this);
let damage = this.checkHit();
damage += (damage / 100) * 10;
enemy.takeDamage(damage);
Logger.useKnightSkill(this, enemy, damage);
this.mana -= this.classSkillCostValue;
} else {
super.attack(enemy);
}
}

constructor() {
super();
}
}
89 changes: 89 additions & 0 deletions rpgsaga/saga/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export const names: string[] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вокруг этого можно создать get метод - который бы возвращал элемент по индексу и элемент случайный

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

иначе тесты не получится получить

'Верронн',
'Верллианн',
'Вильгельм',
'Вениамин',
'Вандон',
'Виктуар',
'Аэлмар',
'Алексий',
'Аэлнесс',
'Абархам',
'Афкиллар',
'Анвиль',
'Арравел ',
'Арнольд',
'Агмасс ',
'Арчибальд',
'Андерс',
'Арни',
'Алекс',
'Арчи',
'Антеон',
'Альбус',
'Айбер',
'Адам',
'Бесталл',
'Боркас',
'Баэлнесс',
'Брэндон',
'Боб',
'Брандон',
'Беон',
'Бобби',
'Бурбон',
'Берадот',
'Гилдримм',
'Гарри',
'Гэри',
'Гарольд',
'Гордон',
'Гаррисон',
'Гудвин',
'Жеан',
'Жан',
'Иладар',
'Иррадион',
'Иллирий',
'Ингард',
'Ивиникум',
'Наиселл',
'Натаниэль',
'Нокс',
'Нур',
'Ниа',
'Оливер',
'Пармис',
'Пер',
'Поль',
'Пауль',
'Пьер',
'Питер',
'Титаний',
'Тоберон',
'Тиберий',
'Тор',
'Тейлор',
'Улан',
'Ург',
'Уилл',
'Ферммар',
'Фаавел',
'Феофил',
'Фиделий',
'Феб',
'Харрин',
'Шон',
'Ялмир',
'Янви',
'Якоб',
'Якин'
];

export enum Classes {
KNIGHT = 'KNIGHT',
ASSASIN = 'ASSASIN',
ARCHER = 'ARCHER',
}

export const fireDamage = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а почему этот тут?

Loading
Loading