Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneWWolf committed Jan 10, 2024
1 parent 1379c33 commit a78a18e
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rpgsaga/saga/src/bina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Bina {

if (isSuccessful) {
console.log(
`${this._message.attackerInfo} has casted a spell ${this._message.spell.toString()} on ${
`${this._message.attackerInfo} has casted a spell ${this._message.spell.describe()} on ${
this._message.targetInfo
}!`,
);
Expand All @@ -46,7 +46,7 @@ export class Bina {
if (target.statusEffects.contains(statusEffect)) {
const node: DoublyLinkedListNode = target.statusEffects.head;
while (node !== null) {
if (node.value.toString() === statusEffect.toString()) {
if (node.value.describe() === statusEffect.describe()) {
node.value.refresh();
return;
}
Expand Down
6 changes: 5 additions & 1 deletion rpgsaga/saga/src/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export class Character {
}

set name(value: string) {
this._name = value;
if (value.length > 0) {
this._name = value;
} else {
throw Error('Name should be longer than 0 characters');
}
}

get class() {
Expand Down
4 changes: 2 additions & 2 deletions rpgsaga/saga/src/doublyLinkedList/doublyLinkedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DoublyLinkedList {

let tmp = this.head;
while (tmp !== null) {
if (tmp.value.toString() === value.toString()) {
if (tmp.value.describe() === value.describe()) {
return true;
}
tmp = tmp.next;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class DoublyLinkedList {
let tmp = this._head;

while (tmp !== null) {
if (tmp.value.toString() === value.toString()) {
if (tmp.value.describe() === value.describe()) {
if (tmp.prev !== null) {
tmp.prev.next = tmp.next;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Character } from '../../character';
export interface IActiveEffect {
cast(target: Character): boolean;
canCast(): boolean;
toString(): string;
describe(): string;
}
2 changes: 1 addition & 1 deletion rpgsaga/saga/src/spell_system/activeEffects/fireArrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FireArrow implements IActiveEffect {
return false;
}

public toString(): string {
public describe(): string {
return `${this._castsRemaining} casts remaining`;
}

Expand Down
6 changes: 4 additions & 2 deletions rpgsaga/saga/src/spell_system/activeEffects/knightAttack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import { IActiveEffect } from './IActiveEffect';
export class KnightAttack implements IActiveEffect {
private _castsRemaining: number;
private _damagePoints: number;
private _strengthModificator: number;

constructor(castsRemaining: number, damagePoints: number) {
this._castsRemaining = castsRemaining;
this._damagePoints = damagePoints;
this._strengthModificator = 2.0;
}

public cast(target: Character): boolean {
if (this.canCast()) {
target.receiveDamage(this._damagePoints * 2.0);
target.receiveDamage(this._damagePoints * this._strengthModificator);
this._castsRemaining -= 1;
return true;
}

return false;
}

public toString(): string {
public describe(): string {
return `${this._castsRemaining} casts remaining`;
}

Expand Down
2 changes: 1 addition & 1 deletion rpgsaga/saga/src/spell_system/activeEffects/stun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Stun implements IActiveEffect {
return false;
}

public toString(): string {
public describe(): string {
return `${this._castsRemaining} casts remaining`;
}

Expand Down
2 changes: 1 addition & 1 deletion rpgsaga/saga/src/spell_system/spell/ISpell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface ISpell {
execute(target: Character): boolean;
hasStatusEffect(): boolean;
getStatusEffect(): IStatusEffect;
toString(): string;
describe(): string;
}
4 changes: 2 additions & 2 deletions rpgsaga/saga/src/spell_system/spell/spell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class Spell implements ISpell {
return isCastedSuccessfully;
}

public toString(): string {
return `${this._name} (${this._activeEffect.toString()})`;
public describe(): string {
return `${this._name} (${this._activeEffect.describe()})`;
}

public hasStatusEffect(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface IStatusEffect {
remove(target: Character);
refresh();
canApply(): boolean;
toString(): string;
describe(): string;
}
7 changes: 5 additions & 2 deletions rpgsaga/saga/src/spell_system/statusEffect/fireArrowEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class FireArrowEffect implements IStatusEffect {
private _name: string;
private _initialUsesRemaining: number;
private _usesRemaining: number;
private _damageAmount: number;

get name() {
return this._name;
Expand All @@ -15,6 +16,8 @@ export class FireArrowEffect implements IStatusEffect {
this._name = name;
this._initialUsesRemaining = usesAvailable;
this._usesRemaining = this._initialUsesRemaining;

this._damageAmount = 2;
}

public apply(target: Character): boolean {
Expand All @@ -27,7 +30,7 @@ export class FireArrowEffect implements IStatusEffect {
} turns remaining)`,
);

target.receiveDamage(2);
target.receiveDamage(this._damageAmount);

return true;
}
Expand All @@ -52,7 +55,7 @@ export class FireArrowEffect implements IStatusEffect {
return false;
}

public toString() {
public describe() {
return this._name;
}
}
2 changes: 1 addition & 1 deletion rpgsaga/saga/src/spell_system/statusEffect/stunEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class StunEffect implements IStatusEffect {
return false;
}

public toString() {
public describe() {
return this._name;
}
}
12 changes: 12 additions & 0 deletions rpgsaga/saga/tests/character.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe('Testing Character class', () => {
expect(character.healthPoints).toBe(105);
expect(character.spell).toBeInstanceOf(Spell);
});
it('Setting new name which contains 0 characters should result in exception', () => {
const character = new Character(
'Linda',
CharacterClass.mage,
105,
new Spell('Freeze', new Stun(2, 0), new StunEffect('Stun', 1)),
);

expect(() => {
character.name = '';
}).toThrow(Error('Name should be longer than 0 characters'));
});
it('Testing receiveDamage method', () => {
const character = new Character(
'Linda',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ describe('Testing toString method', () => {
const usesRemaining = 2;
const activeEffect = new FireArrow(usesRemaining, 7);

expect(activeEffect.toString()).toBe(`${usesRemaining} casts remaining`);
expect(activeEffect.describe()).toBe(`${usesRemaining} casts remaining`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ describe('Testing toString method', () => {
const usesRemaining = 2;
const activeEffect = new KnightAttack(usesRemaining, 7);

expect(activeEffect.toString()).toBe(`${usesRemaining} casts remaining`);
expect(activeEffect.describe()).toBe(`${usesRemaining} casts remaining`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ describe('Testing toString method', () => {
const usesRemaining = 2;
const activeEffect = new Stun(usesRemaining, 7);

expect(activeEffect.toString()).toBe(`${usesRemaining} casts remaining`);
expect(activeEffect.describe()).toBe(`${usesRemaining} casts remaining`);
});
});

0 comments on commit a78a18e

Please sign in to comment.