-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: Kiselev_Artem_Andreevich
Are you sure you want to change the base?
RPG Saga #13
Changes from all commits
026fdaf
a573145
57d55ec
241812b
0ac214e
75c060a
b57735a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 = ''; | ||
private isBurn = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а если завтра появится отравление, заморозка? в принципе любой флаг - это звоночек, что может быть стоит переделать |
||
get isBurnValue(): boolean { | ||
return this.isBurn; | ||
} | ||
|
||
protected isStunned = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
export const names: string[] = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вокруг этого можно создать get метод - который бы возвращал элемент по индексу и элемент случайный There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а почему этот тут? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это зачем,