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

Poc von einem Kampfsystem mit items #479

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5315a09
poc for fighting
Feluin Oct 19, 2024
f92dfaa
poc for fighting
Feluin Oct 19, 2024
7351905
Merge remote-tracking branch 'origin/fightsystem' into fightsystem
Feluin Oct 19, 2024
e5d5095
added rudamentary visualisation
Feluin Oct 19, 2024
9781695
added rudamentary visualisation
Feluin Oct 19, 2024
cc81c09
added rudamentary visualisation
Feluin Oct 19, 2024
134e4a0
added rudamentary visualisation
Feluin Oct 19, 2024
c1433ff
added some item
Feluin Oct 22, 2024
7f011fa
add command ausrüsten
Feluin Oct 23, 2024
7b197ed
add command ausrüsten
Feluin Nov 28, 2024
3d24dd0
added kampfinventar
Feluin Dec 13, 2024
ff39e52
added fight with current inventory
Feluin Dec 15, 2024
7423034
added fight with current inventory
Feluin Dec 15, 2024
e62142d
fixed multiselection
Feluin Dec 23, 2024
18e55c0
fixed multiselection
Feluin Dec 23, 2024
0bf4354
added history and stuff
Feluin Jan 2, 2025
dbab44a
added history and stuff
Feluin Jan 2, 2025
679b41b
fixed lint and reverted multiple drops
Feluin Jan 3, 2025
3e8a0d0
fixed copy paste error
Feluin Jan 3, 2025
78e6277
Merge branch 'master' into fightsystem
holzmaster Jan 23, 2025
8eafebe
Fix casing of fightHistory + fightInventory
holzmaster Jan 23, 2025
a89dbc3
Move to service
holzmaster Jan 23, 2025
6882cd7
Make random API more clear
holzmaster Jan 23, 2025
4fcc8ef
Merge branch 'master' into fightsystem
holzmaster Jan 23, 2025
853ce6a
Fix var casing
holzmaster Jan 23, 2025
d076d2a
Copy function
holzmaster Jan 23, 2025
404c2bd
Merge branch 'master' into fightsystem
holzmaster Jan 23, 2025
7178c35
Fix var casing
holzmaster Jan 23, 2025
b9cc22d
British english -> american english
holzmaster Jan 23, 2025
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
Prev Previous commit
Next Next commit
add command ausrüsten
Feluin committed Oct 23, 2024
commit 7f011fadf77b868a305af807d58f34af30b99de7
93 changes: 88 additions & 5 deletions src/commands/fight.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { ApplicationCommand } from "@/commands/command.js";
import {
APIEmbed,
APIEmbedField,
APIEmbedField, type BooleanCache, type CacheType,
type CommandInteraction,
ContextMenuCommandBuilder,
ContextMenuCommandBuilder, type InteractionResponse,
SlashCommandBuilder,
SlashCommandUserOption,
SlashCommandUserOption
} from "discord.js";
import type { BotContext } from "@/context.js";
import { fight, FightScene } from "@/service/fight.js";
import { JSONEncodable } from "@discordjs/util";
import { bossMap, Entity } from "@/service/fightData.js";
import {BaseEntity, bossMap, Entity} from "@/service/fightData.js";
import {setTimeout} from "node:timers/promises";

export default class FightCommand implements ApplicationCommand {
readonly description = "TBD";
@@ -49,3 +49,86 @@ export default class FightCommand implements ApplicationCommand {
await fight(playerstats, bossMap[boss], interactionResponse);
}
}


type result = "PLAYER" | "ENEMY" | undefined;

function checkWin(fightscene: FightScene): result {
if (fightscene.player.stats.health < 0) {
return "ENEMY";
}
if (fightscene.enemy.stats.health < 0) {
return "PLAYER";
}
}

export async function fight(
playerstats: BaseEntity,
enemystats: BaseEntity,
interactionResponse: InteractionResponse<BooleanCache<CacheType>>
) {
const enemy = new Entity(enemystats);
const player = new Entity(playerstats);

const scene: FightScene = {
player: player,
enemy: enemy
};
while (checkWin(scene) === undefined) {
player.itemtext = [];
enemy.itemtext = [];
//playerhit first
player.attack(enemy);
// then enemny hit
enemy.attack(player);
//special effects from items

player.stats.items.forEach(value => {
if (!value.afterFight) {
return;
}
value.afterFight(scene);
});
enemy.stats.items.forEach(value => {
if (!value.afterFight) {
return;
}
value.afterFight({player: enemy, enemy: player});
});
await interactionResponse.edit({embeds: [renderFightEmbedded(scene)]});
await setTimeout(200);
}
}

function renderStats(player: Entity) {
while (player.itemtext.length < 5) {
player.itemtext.push("-");
}

return {
name: player.stats.name,
value: `❤️HP${player.stats.health}/${player.maxhealth}
❤️${"=".repeat(Math.max(0, (player.stats.health / player.maxhealth) * 10))}
⚔️Waffe: ${player.stats.weapon?.name ?? "Schwengel"} ${player.lastattack}
🛡️Rüstung: ${player.stats.armor?.name ?? "Nackt"} ${player.lastdefence}
📚Items:
${player.itemtext.join("\n")}
`,
inline: true
};
}

function renderFightEmbedded(fightscene: FightScene): JSONEncodable<APIEmbed> | APIEmbed {
return {
title: `Kampf zwischen ${fightscene.player.stats.name} und ${fightscene.enemy.stats.name}`,
description: fightscene.enemy.stats.description,
fields: [
renderStats(fightscene.player),
renderStats(fightscene.enemy),
{
name: "Verlauf",
value: " "
}
]
};
}
Loading