-
Notifications
You must be signed in to change notification settings - Fork 24
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
Feluin
wants to merge
29
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
29 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 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
This file contains 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,228 @@ | ||
import type { ApplicationCommand } from "@/commands/command.js"; | ||
import { | ||
type APIEmbed, | ||
APIEmbedField, | ||
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) { | ||
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 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 anlegen
oder so verständlicher ist als/gegenstand ausrüsten
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.
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