-
Notifications
You must be signed in to change notification settings - Fork 24
Poc von einem Kampfsystem mit items #479
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
Open
Feluin
wants to merge
85
commits into
NullDev:master
Choose a base branch
from
Feluin:fightsystem
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
5315a09
poc for fighting
Feluin f92dfaa
poc for fighting
Feluin 7351905
Merge remote-tracking branch 'origin/fightsystem' into fightsystem
Feluin e5d5095
added rudamentary visualisation
Feluin 9781695
added rudamentary visualisation
Feluin cc81c09
added rudamentary visualisation
Feluin 134e4a0
added rudamentary visualisation
Feluin c1433ff
added some item
Feluin 7f011fa
add command ausrüsten
Feluin 7b197ed
add command ausrüsten
Feluin 3d24dd0
added kampfinventar
Feluin ff39e52
added fight with current inventory
Feluin 7423034
added fight with current inventory
Feluin e62142d
fixed multiselection
Feluin 18e55c0
fixed multiselection
Feluin 0bf4354
added history and stuff
Feluin dbab44a
added history and stuff
Feluin 679b41b
fixed lint and reverted multiple drops
Feluin 3e8a0d0
fixed copy paste error
Feluin 78e6277
Merge branch 'master' into fightsystem
holzmaster 8eafebe
Fix casing of fightHistory + fightInventory
holzmaster a89dbc3
Move to service
holzmaster 6882cd7
Make random API more clear
holzmaster 4fcc8ef
Merge branch 'master' into fightsystem
holzmaster 853ce6a
Fix var casing
holzmaster d076d2a
Copy function
holzmaster 404c2bd
Merge branch 'master' into fightsystem
holzmaster 7178c35
Fix var casing
holzmaster b9cc22d
British english -> american english
holzmaster 4b8f184
added karte
Feluin f192728
added karte
Feluin 7f9f5e1
Merge branch 'master' into fightsystem
holzmaster 00157f1
Resolve linter issues
holzmaster ed64eec
Align file name
holzmaster 562f3c0
Fix casing
holzmaster d1b9f46
Use author
holzmaster becc368
Backport map code
holzmaster 764daea
Merge branch 'karte' into fightsystem
holzmaster ae3e9b9
Move migration
holzmaster 7619cd5
Position -> location history
holzmaster 66da09c
Align internal API
holzmaster 6c63676
Add service
holzmaster e47e878
Use service
holzmaster 25350cb
Simplify rows
holzmaster 490c9de
Filter interactions
holzmaster d7edf94
Fix build
holzmaster c8500b8
Fix migration
holzmaster 273c2c1
Merge branch 'karte' into fightsystem
holzmaster 7e81953
Fix name
holzmaster 2c449e9
Simplify loops
holzmaster 632a774
buildMap -> drawMap
holzmaster fe1268d
Disable stay button
holzmaster 4dfc2e9
Merge branch 'karte' into fightsystem
holzmaster 10b28d1
Merge branch 'master' into fightsystem
holzmaster 7f46204
Merge branch 'master' into fightsystem
holzmaster b0f95d4
poc for fighting
Feluin 3208544
added rudamentary visualisation
Feluin f18a96f
added rudamentary visualisation
Feluin 344c56e
added rudamentary visualisation
Feluin 69b7d58
added rudamentary visualisation
Feluin 876caea
added some item
Feluin d99150d
add command ausrüsten
Feluin e281358
add command ausrüsten
Feluin 8b8a376
added kampfinventar
Feluin 7c80c31
added fight with current inventory
Feluin 164b2d3
added fight with current inventory
Feluin a3222fe
fixed multiselection
Feluin 2635a2a
fixed multiselection
Feluin 13ed34f
added history and stuff
Feluin 3d752e6
added history and stuff
Feluin 6e10f2e
fixed lint and reverted multiple drops
Feluin e56da7c
added karte
Feluin b6a4bfa
Fix casing of fightHistory + fightInventory
holzmaster 29714bf
Move to service
holzmaster de331c0
Make random API more clear
holzmaster f04de57
Fix var casing
holzmaster ed71d9d
Copy function
holzmaster 1843c3a
Fix var casing
holzmaster 7724783
British english -> american english
holzmaster f52d0c6
Merge branch 'master' into fightsystem
holzmaster 75e909c
Merge branch 'master' into fightsystem
holzmaster 76a9753
Merge remote-tracking branch 'origin/fightsystem' into fightsystem
Feluin fcd7fd7
Fix
holzmaster 00224ec
Merge branch 'master' into fightsystem
holzmaster 10a133b
Merge branch 'master' into fightsystem
holzmaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| import type { ApplicationCommand } from "@/commands/command.js"; | ||
| import { | ||
| type APIEmbed, | ||
| type BooleanCache, | ||
| type CacheType, | ||
| type CommandInteraction, | ||
| type InteractionResponse, | ||
| SlashCommandBuilder, | ||
| type User, | ||
| } from "discord.js"; | ||
| import type { BotContext } from "@/context.js"; | ||
| import type { JSONEncodable } from "@discordjs/util"; | ||
| import { | ||
| type BaseEntity, | ||
| baseStats, | ||
| bossMap, | ||
| Entity, | ||
| type EquipableArmor, | ||
| type EquipableItem, | ||
| type EquipableWeapon, | ||
| type FightScene, | ||
| } from "@/service/fightData.js"; | ||
| import { setTimeout } from "node:timers/promises"; | ||
| import { getFightInventoryEnriched, removeItemsAfterFight } from "@/storage/fightInventory.js"; | ||
| import { getLastFight, insertResult } from "@/storage/fightHistory.js"; | ||
|
|
||
| async function getFighter(user: User): Promise<BaseEntity> { | ||
| const userInventory = await getFightInventoryEnriched(user.id); | ||
|
|
||
| return { | ||
| ...baseStats, | ||
| name: user.displayName, | ||
| weapon: { | ||
| name: userInventory.weapon?.itemInfo?.displayName ?? "Nichts", | ||
| ...(userInventory.weapon?.gameTemplate as EquipableWeapon), | ||
| }, | ||
| armor: { | ||
| name: userInventory.armor?.itemInfo?.displayName ?? "Nichts", | ||
| ...(userInventory.armor?.gameTemplate as EquipableArmor), | ||
| }, | ||
| items: userInventory.items.map(value => { | ||
| return { | ||
| name: value.itemInfo?.displayName ?? "Error", | ||
| ...(value.gameTemplate as EquipableItem), | ||
| }; | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| export default class FightCommand implements ApplicationCommand { | ||
| readonly description = "TBD"; | ||
| readonly name = "fight"; | ||
| readonly applicationCommand = new SlashCommandBuilder() | ||
| .setName(this.name) | ||
| .setDescription(this.description) | ||
| .addStringOption(builder => | ||
| builder | ||
| .setRequired(true) | ||
| .setName("boss") | ||
| .setDescription("Boss") | ||
| //switch to autocomplete when we reach 25 | ||
| .addChoices( | ||
| Object.entries(bossMap) | ||
| .filter(boss => boss[1].enabled) | ||
| .map(boss => { | ||
| return { | ||
| name: boss[1].name, | ||
| value: boss[0], | ||
| }; | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| async handleInteraction(command: CommandInteraction, _context: BotContext) { | ||
| if (!command.isChatInputCommand()) { | ||
| throw new Error("Invalid command type"); | ||
| } | ||
|
|
||
| const boss = command.options.get("boss", true).value as string; | ||
|
|
||
| const _lastFight = await getLastFight(command.user.id); | ||
|
|
||
| // if (lastFight !== undefined && (new Date(lastFight?.createdAt).getTime() > new Date().getTime() - 1000 * 60 * 60 * 24 * 5)) { | ||
| // await command.reply({ | ||
| // embeds: | ||
| // [{ | ||
| // title: "Du bist noch nicht bereit", | ||
| // color: 0xe74c3c, | ||
| // description: `Dein Letzter Kampf gegen ${bossMap[lastFight.bossName]?.name} ist noch keine 5 Tage her. Gegen ${bossMap[boss].name} hast du sowieso Chance, aber noch weniger, wenn nicht die vorgeschriebenen Pausenzeiten einhältst ` | ||
| // } | ||
| // ] | ||
| // , | ||
| // ephemeral: true | ||
| // } | ||
| // ); | ||
|
|
||
| // return; | ||
| // } | ||
|
|
||
| const interactionResponse = await command.deferReply(); | ||
|
|
||
| const playerstats = await getFighter(command.user); | ||
|
|
||
| await fight(command.user, playerstats, boss, { ...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"; | ||
| } | ||
| } | ||
|
|
||
| function renderEndScreen(fightscene: FightScene): APIEmbed | JSONEncodable<APIEmbed> { | ||
| const result = checkWin(fightscene); | ||
| const fields = [ | ||
| renderStats(fightscene.player), | ||
| renderStats(fightscene.enemy), | ||
| { | ||
| name: "Verlauf", | ||
| value: " ", | ||
| }, | ||
| { | ||
| name: " Die Items sind dir leider beim Kampf kaputt gegangen: ", | ||
| value: fightscene.player.stats.items.map(value => value.name).join(" \n"), | ||
| }, | ||
| ]; | ||
| if (result === "PLAYER") { | ||
| return { | ||
| title: `Mit viel Glück konnte ${fightscene.player.stats.name} ${fightscene.enemy.stats.name} besiegen `, | ||
| color: 0x57f287, | ||
| description: fightscene.enemy.stats.description, | ||
| fields: fields, | ||
| }; | ||
| } | ||
| if (result === "ENEMY") { | ||
| return { | ||
| title: `${fightscene.enemy.stats.name} hat ${fightscene.player.stats.name} gnadenlos vernichtet`, | ||
| color: 0xed4245, | ||
| description: fightscene.enemy.stats.description, | ||
| fields: fields, | ||
| }; | ||
| } | ||
| return { | ||
| title: `Kampf zwischen ${fightscene.player.stats.name} und ${fightscene.enemy.stats.name}`, | ||
| description: fightscene.enemy.stats.description, | ||
| fields: fields, | ||
| }; | ||
| } | ||
|
|
||
| export async function fight( | ||
| user: User, | ||
| playerstats: BaseEntity, | ||
| boss: string, | ||
| 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 | ||
| for (const value of player.stats.items) { | ||
| if (!value.afterFight) { | ||
| continue; | ||
| } | ||
| value.afterFight(scene); | ||
| } | ||
| for (const value of enemy.stats.items) { | ||
| if (!value.afterFight) { | ||
| continue; | ||
| } | ||
| value.afterFight({ player: enemy, enemy: player }); | ||
| } | ||
| await interactionResponse.edit({ embeds: [renderFightEmbedded(scene)] }); | ||
| await setTimeout(200); | ||
| } | ||
|
|
||
| await interactionResponse.edit({ embeds: [renderEndScreen(scene)] }); | ||
| //delete items | ||
| await removeItemsAfterFight(user.id); | ||
| // | ||
| await insertResult(user.id, boss, checkWin(scene) === "PLAYER"); | ||
| } | ||
|
|
||
| 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.lastDefense} | ||
| 📚 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: " ", | ||
| }, | ||
| ], | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Vielleicht passt hier "anlegen" oder "tragen" besser. Zumindest glaube ich, dass sich
/gegenstand anlegenoder so verständlicher ist als/gegenstand ausrüstenThere 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.
Oder kollidiert das mit "benutzen"?
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.
anlegen finde ich tatsächlich passender.
Meinst du das benutzen und anlegen eigenlich das selbe tut? noch könnte man beides in ein command machen, aber potentiell gibt es items die man im chat und im kampf nutzen kann, daher würd ich das getrennt lassen
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.
Benutzen ist etwas, was in dem moment eine Aktion ausführt. Also z.b. ein Geschenk in den Chat droppt