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

added monsters #2

Open
wants to merge 7 commits into
base: main
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
479 changes: 479 additions & 0 deletions install_nvm.sh

Large diffs are not rendered by default.

503 changes: 283 additions & 220 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

590 changes: 553 additions & 37 deletions src/bot.ts

Large diffs are not rendered by default.

54 changes: 42 additions & 12 deletions src/botAnswers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {Player} from "./types";
import { Player } from "./types";

export const botAnswers = {
alreadyStarted: "The game has already started. To end the game, type /endgame.",
gameStarted: "The D&D game has begun! Add players using the /join command.",
notStarted: "Please start the game first using the /startgame command.",
helpCommandDescription: `
Welcome to the D&D Telegram bot! Here is a list of available commands:

Expand All @@ -17,19 +14,52 @@ Welcome to the D&D Telegram bot! Here is a list of available commands:
/endgame - End the current game.

/narrate - Get a dynamic narration of the current game situation from the AI storyteller.

/inventory - View your current gold and items.
/shop - Visit the shop to buy items.
/buy <item_id> - Purchase an item using your gold.
/use <item_id> - Use an item from your inventory.
`,
alreadyStarted: "The game has already started. To end the game, type /endgame.",
gameStarted: "The D&D game has begun! Add players using the /join command.",
notStarted: "Please start the game first using the /startgame command.",
player: {
joined: (name: string, initiative: string | number) => `Player ${name} has joined the game with an initiative of ${initiative}.`,
joined: (name: string, initiative: number) => `Player ${name} has joined the game with an initiative of ${initiative}.`,
alreadyJoined: (name: string) => `Player ${name} is already part of the game.`,
getState: (player: Player) => `Player ${player.name}: ${player.person.toString()}, initiative: ${player.initiative.toString()}`,
getState: (player: Player) => `Player ${player.name}: ${player.person.toString()}, Initiative: ${player.initiative}, Gold: ${player.gold}`,
defeated: (name: string) => `${name} has been defeated and is out of the game.`,
},
endGame: {
success: "The game has ended.",
notStarted: "The game hasn't been started yet.",
},
turn: {
emptyPlayerOrder: "There are no players in the game.",
playerTurn: (name: string) => `It's ${name}'s turn.`,
anotherPlayerTurn: "It's not your turn!"
anotherPlayerTurn: "It's not your turn!",
},
endGame: {
success: "The game has ended.",
notStarted: "The game hasn't been started yet.",
}
}
inventory: {
header: (gold: number) => `You have ${gold} gold.\nYour items:`,
empty: "You have no items in your inventory.",
item: (item: { id: number, name: string, description: string }) => `ID: ${item.id} | ${item.name} - ${item.description}`,
},
shop: {
header: "Welcome to the shop! Here are the available items:",
item: (item: { id: number, name: string, description: string, value: number }) => `ID: ${item.id} | ${item.name} - ${item.description} | Price: ${item.value} gold`,
footer: "Use /buy <item_id> to purchase an item.",
notEnoughGold: "You don't have enough gold to buy this item.",
bought: (name: string) => `You have purchased ${name}.`,
},
useItem: {
success: (name: string) => `You have used ${name}.`,
notFound: "Item not found in your inventory.",
error: "Unable to use the item.",
},
treasure: {
gold: (amount: number) => `You found ${amount} gold!`,
item: (itemName: string) => `You found a ${itemName}!`,
},
playerAction: {
// Additional player-related messages
},
};
45 changes: 33 additions & 12 deletions src/dnd/classes/Mage.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
import {Person} from "./Person";
import { Person } from "./Person";

export class Mage extends Person {
private mana: number;
private readonly maxMana: number;
private maxMana: number;

constructor(hp: number, mana: number, strength: number, agility: number, intelligence: number, initiative: number) {
super(hp, strength, agility, intelligence, initiative);
this.maxMana = mana;
constructor(
maxHp: number,
hp: number,
mana: number,
strength: number,
agility: number,
intelligence: number,
initiative: number
) {
super(maxHp, hp, strength, agility, intelligence, initiative);
this.mana = mana;
this.maxMana = mana;
}

public getMana(): number {
return this.mana;
}

public castSpell(cost: number) {
if (this.mana >= cost) {
this.mana -= cost;
console.log("Заклинание успешно применено.");
public useMana(amount: number): boolean {
if (this.mana >= amount) {
this.mana -= amount;
console.log(`Used ${amount} mana. Remaining mana: ${this.mana}`);
return true;
} else {
console.log("Недостаточно маны для заклинания.");
console.log(`Not enough mana. Required: ${amount}, Available: ${this.mana}`);
return false;
}
}

public regenerateMana(amount: number) {
public regenerateMana(amount: number): void {
this.mana = Math.min(this.mana + amount, this.maxMana);
console.log(`Regenerated ${amount} mana. Current mana: ${this.mana}`);
}

// Add the missing method
public increaseIntelligence(amount: number): void {
super.increaseArmor(amount);
}

public toString() {
// Override toString to include mana
public toString(): string {
return `Mage: ${super.toString()}, Mana: ${this.mana}/${this.maxMana}`;
}
}
142 changes: 118 additions & 24 deletions src/dnd/classes/Person.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,151 @@
import { Item } from "../../types";

export class Person {
private readonly maxHp: number;
protected hp: number;
protected strength: number; // Сила
protected agility: number; // Ловкость
protected intelligence: number; // Интеллект
protected initiative: number;

constructor(hp: number, strength: number, agility: number, intelligence: number, initiative: number) {
this.maxHp = hp;
private maxHp: number;
private hp: number;
private strength: number;
private agility: number;
private intelligence: number;
private initiative: number;
private isblocking: boolean = false;
private gold: number;
private inventory: Item[];
private armor: number;

constructor(
maxHp: number,
hp: number,
strength: number,
agility: number,
intelligence: number,
initiative: number
) {
this.maxHp = maxHp;
this.hp = hp;
this.strength = strength;
this.agility = agility;
this.intelligence = intelligence;
this.initiative = initiative;
this.gold = 0;
this.inventory = [];
this.armor = 0;
}

public heal(hp: number) {
this.hp = Math.min(this.hp + hp, this.maxHp);
// Gold Management
public addGold(amount: number): void {
this.gold += amount;
console.log(`Gained ${amount} gold. Total gold: ${this.gold}`);
}

public damage(hp: number) {
if (this.hp - hp < 0) {
this.dead();
public subtractGold(amount: number): boolean {
if (this.gold >= amount) {
this.gold -= amount;
console.log(`Spent ${amount} gold. Remaining gold: ${this.gold}`);
return true;
} else {
this.hp -= hp;
console.log(`Not enough gold. Required: ${amount}, Available: ${this.gold}`);
return false;
}
}

public dead() {
console.log("Персонаж мертв.");
public getGold(): number {
return this.gold;
}

// Inventory Management
public addItem(item: Item): void {
this.inventory.push(item);
console.log(`Added ${item.name} to inventory.`);
}

public getHp() {
public setBlocking(status: boolean): void {
this.isblocking = status;
}

public isBlocking(): boolean {
return this.isblocking;
}

public useItem(itemId: number): void {
const itemIndex = this.inventory.findIndex(item => item.id === itemId);
if (itemIndex !== -1) {
const item = this.inventory[itemIndex];
item.effect(this); // Apply the item's effect to this person
this.inventory.splice(itemIndex, 1); // Remove the item after use
console.log(`Used ${item.name}.`);
} else {
console.log(`Item with ID ${itemId} not found in inventory.`);
}
}

public getInventory(): Item[] {
return this.inventory;
}

// Stat Adjustments
public restoreHpBy(amount: number): void {
this.hp = Math.min(this.hp + amount, this.maxHp);
console.log(`Restored ${amount} HP. Current HP: ${this.hp}`);
}

public increaseStrength(amount: number): void {
this.strength += amount;
console.log(`Strength increased by ${amount}. New strength: ${this.strength}`);
}

public increaseArmor(amount: number): void {
this.armor += amount;
console.log(`Armor increased by ${amount}. New armor: ${this.armor}`);
}

// Damage Calculation
public damage(amount: number): void {
const actualDamage = Math.max(0, amount - this.armor);
this.hp -= actualDamage;
if (this.hp < 0) this.hp = 0;
console.log(`Person takes ${actualDamage} damage (original: ${amount}, armor: ${this.armor}). Remaining HP: ${this.hp}`);
}

public restoreHp(): void {
this.hp = this.maxHp;
console.log(`Person restores to full HP: ${this.hp}`);
}

public getHp(): number {
return this.hp;
}

public getStrength() {
public getMaxHp(): number {
return this.maxHp;
}

public getStrength(): number {
return this.strength;
}

public getAgility() {
public getAgility(): number {
return this.agility;
}

public getIntelligence() {
public getIntelligence(): number {
return this.intelligence;
}

public getInitiative() {
public getInitiative(): number {
return this.initiative;
}

public toString() {
return `HP: ${this.hp}/${this.maxHp}, Strength: ${this.strength}, Agility: ${this.agility}, Intelligence: ${this.intelligence}, Initiative: ${this.initiative}`;
public getArmor(): number {
return this.armor;
}

public increaseIntelligence(amount: number): void {
this.intelligence += amount;
console.log(`Intelligence increased by ${amount}. New intelligence: ${this.intelligence}`);
}


public toString(): string {
return `HP: ${this.hp}/${this.maxHp}, Gold: ${this.gold}, Strength: ${this.strength}, Armor: ${this.armor}`;
}
}
28 changes: 18 additions & 10 deletions src/dnd/classes/Rouge.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import {Person} from "./Person";

import { Person } from "./Person";

export class Rogue extends Person {
private stealth: number;

constructor(hp: number, stealth: number, strength: number, agility: number, intelligence: number, initiative: number) {
super(hp, strength, agility, intelligence, initiative);
this.stealth = stealth;
constructor(
maxHp: number,
hp: number,
strength: number,
agility: number,
intelligence: number,
initiative: number
) {
super(maxHp, hp, strength, agility, intelligence, initiative);
this.stealth = agility; // Stealth is based on agility
}

public sneakAttack() {
console.log("Наносит удар из тени!");
public getStealth(): number {
return this.stealth;
}

public increaseStealth(amount: number) {
public increaseStealth(amount: number): void {
this.stealth += amount;
console.log("Скрытность увеличена.");
console.log(`Stealth increased by ${amount}. New stealth: ${this.stealth}`);
}

public toString() {
return `Rouge: ${super.toString()}, Stealth: ${this.stealth}`;
public toString(): string {
return `Rogue: ${super.toString()}, Stealth: ${this.stealth}`;
}
}
35 changes: 17 additions & 18 deletions src/dnd/classes/Warrior.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import {Person} from "./Person";
import { Person } from "./Person";

export class Warrior extends Person {
private armor: number;

constructor(hp: number, armor: number, strength: number, agility: number, intelligence: number, initiative: number) {
super(hp, strength, agility, intelligence, initiative);
this.armor = armor;
}

public defend(damage: number) {
const effectiveDamage = Math.max(damage - this.armor, 0);
this.damage(effectiveDamage);
console.log(`Получен урон: ${effectiveDamage}.`);
constructor(
maxHp: number,
hp: number,
strength: number,
agility: number,
intelligence: number,
initiative: number
) {
super(maxHp, hp, strength, agility, intelligence, initiative);
// Warriors start with base armor
this.increaseArmor(5);
}

public increaseArmor(amount: number) {
this.armor += amount;
console.log("Броня увеличена.");
public hasArmor(): boolean {
return this.getArmor() > 0;
}

public toString() {
return `Warrior: ${super.toString()}, Armor: ${this.armor}`;
public toString(): string {
return `Warrior: ${super.toString()}`;
}
}
}
Loading