Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 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
4b8f184
added karte
Feluin Jun 20, 2025
f192728
added karte
Feluin Jun 20, 2025
7f9f5e1
Merge branch 'master' into fightsystem
holzmaster Sep 2, 2025
00157f1
Resolve linter issues
holzmaster Sep 2, 2025
ed64eec
Align file name
holzmaster Sep 2, 2025
562f3c0
Fix casing
holzmaster Sep 3, 2025
d1b9f46
Use author
holzmaster Sep 3, 2025
becc368
Backport map code
holzmaster Sep 3, 2025
764daea
Merge branch 'karte' into fightsystem
holzmaster Sep 3, 2025
ae3e9b9
Move migration
holzmaster Sep 3, 2025
7619cd5
Position -> location history
holzmaster Sep 3, 2025
66da09c
Align internal API
holzmaster Sep 3, 2025
6c63676
Add service
holzmaster Sep 3, 2025
e47e878
Use service
holzmaster Sep 3, 2025
25350cb
Simplify rows
holzmaster Sep 3, 2025
490c9de
Filter interactions
holzmaster Sep 3, 2025
d7edf94
Fix build
holzmaster Sep 3, 2025
c8500b8
Fix migration
holzmaster Sep 3, 2025
273c2c1
Merge branch 'karte' into fightsystem
holzmaster Sep 3, 2025
7e81953
Fix name
holzmaster Sep 3, 2025
2c449e9
Simplify loops
holzmaster Sep 3, 2025
632a774
buildMap -> drawMap
holzmaster Sep 3, 2025
fe1268d
Disable stay button
holzmaster Sep 3, 2025
4dfc2e9
Merge branch 'karte' into fightsystem
holzmaster Sep 3, 2025
10b28d1
Merge branch 'master' into fightsystem
holzmaster Sep 3, 2025
7f46204
Merge branch 'master' into fightsystem
holzmaster Sep 4, 2025
b0f95d4
poc for fighting
Feluin Oct 19, 2024
3208544
added rudamentary visualisation
Feluin Oct 19, 2024
f18a96f
added rudamentary visualisation
Feluin Oct 19, 2024
344c56e
added rudamentary visualisation
Feluin Oct 19, 2024
69b7d58
added rudamentary visualisation
Feluin Oct 19, 2024
876caea
added some item
Feluin Oct 22, 2024
d99150d
add command ausrüsten
Feluin Oct 23, 2024
e281358
add command ausrüsten
Feluin Nov 28, 2024
8b8a376
added kampfinventar
Feluin Dec 13, 2024
7c80c31
added fight with current inventory
Feluin Dec 15, 2024
164b2d3
added fight with current inventory
Feluin Dec 15, 2024
a3222fe
fixed multiselection
Feluin Dec 23, 2024
2635a2a
fixed multiselection
Feluin Dec 23, 2024
13ed34f
added history and stuff
Feluin Jan 2, 2025
3d752e6
added history and stuff
Feluin Jan 2, 2025
6e10f2e
fixed lint and reverted multiple drops
Feluin Jan 3, 2025
e56da7c
added karte
Feluin Jun 20, 2025
b6a4bfa
Fix casing of fightHistory + fightInventory
holzmaster Jan 23, 2025
29714bf
Move to service
holzmaster Jan 23, 2025
de331c0
Make random API more clear
holzmaster Jan 23, 2025
f04de57
Fix var casing
holzmaster Jan 23, 2025
ed71d9d
Copy function
holzmaster Jan 23, 2025
1843c3a
Fix var casing
holzmaster Jan 23, 2025
7724783
British english -> american english
holzmaster Jan 23, 2025
f52d0c6
Merge branch 'master' into fightsystem
holzmaster Sep 9, 2025
75e909c
Merge branch 'master' into fightsystem
holzmaster Oct 3, 2025
76a9753
Merge remote-tracking branch 'origin/fightsystem' into fightsystem
Feluin Oct 3, 2025
fcd7fd7
Fix
holzmaster Oct 4, 2025
00224ec
Merge branch 'master' into fightsystem
holzmaster Oct 13, 2025
10a133b
Merge branch 'master' into fightsystem
holzmaster Oct 20, 2025
43bbb16
Merge main
holzmaster Nov 15, 2025
52a88b8
Sort imports
holzmaster Nov 15, 2025
730a53d
Merge branch 'master' into fightsystem
holzmaster Nov 15, 2025
a5b0782
Merge branch 'master' into fightsystem
holzmaster Nov 15, 2025
e748691
Merge branch 'master' into fightsystem
holzmaster Nov 15, 2025
eaf9f4f
Fix imports
holzmaster Nov 15, 2025
227ed2b
Merge branch 'master' into fightsystem
holzmaster Feb 19, 2026
8f156d0
Remove empty file
holzmaster Feb 19, 2026
674efb9
add debug items command and fight simulator
Apr 25, 2026
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
Binary file added assets/maps/CSZ Karte V1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
202 changes: 202 additions & 0 deletions scripts/simulate-fight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* Fight simulator — run a boss fight N times and print statistics.
*
* Usage:
* node scripts/simulate-fight.ts --boss gudrun --n 1000
* node scripts/simulate-fight.ts --boss gudrun --n 5000 --weapon dildo --armor nachthemd --items ayran,oettinger
*
* Available bosses: gudrun, deinchef, schutzheiliger, rentner, barkeeper
* Available weapons: dildo, messerblock
* Available armors: nachthemd, eierwaermer
* Available items: ayran, oettinger, thunfischshake
*/

import {
baseStats,
bossMap,
Entity,
fightTemplates,
type BaseEntity,
type EquipableArmor,
type EquipableItem,
type EquipableWeapon,
type FightScene,
} from "../src/service/fightData.ts";

// ---------------------------------------------------------------------------
// CLI argument parsing
// ---------------------------------------------------------------------------

function parseArgs(argv: string[]): Record<string, string> {
const args: Record<string, string> = {};
for (let i = 0; i < argv.length; i++) {
if (argv[i].startsWith("--")) {
const key = argv[i].slice(2);
args[key] = argv[i + 1] ?? "true";
i++;
}
}
return args;
}

const args = parseArgs(process.argv.slice(2));

const bossKey = args["boss"];
const iterations = Math.max(1, Number(args["n"] ?? 1000));
const weaponKey = args["weapon"];
const armorKey = args["armor"];
const itemKeys = args["items"] ? args["items"].split(",") : [];

if (!bossKey || !(bossKey in bossMap)) {
console.error(`Unknown boss "${bossKey}". Available: ${Object.keys(bossMap).join(", ")}`);
process.exit(1);
}

// ---------------------------------------------------------------------------
// Build player stats from CLI args
// ---------------------------------------------------------------------------

function buildPlayer(): BaseEntity {
const weapon =
weaponKey && weaponKey in fightTemplates && fightTemplates[weaponKey].type === "weapon"
? { name: weaponKey, ...(fightTemplates[weaponKey] as EquipableWeapon) }
: undefined;

const armor =
armorKey && armorKey in fightTemplates && fightTemplates[armorKey].type === "armor"
? { name: armorKey, ...(fightTemplates[armorKey] as EquipableArmor) }
: undefined;

const items = itemKeys
.filter(k => k in fightTemplates && fightTemplates[k].type === "item")
.map(k => ({ name: k, ...(fightTemplates[k] as EquipableItem) }));

return {
...baseStats,
name: "Player",
weapon,
armor,
items,
};
}

// ---------------------------------------------------------------------------
// Headless fight loop (no Discord, no delays)
// ---------------------------------------------------------------------------

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

interface FightResult {
winner: "PLAYER" | "ENEMY";
playerHp: number;
enemyHp: number;
rounds: number;
}

const noop = () => {};

function simulateFight(playerStats: BaseEntity, enemyStats: BaseEntity): FightResult {
const player = new Entity(structuredClone(playerStats));
const enemy = new Entity(structuredClone(enemyStats));
const scene: FightScene = { player, enemy };

// Suppress the per-hit console.log inside Entity.attack
const origLog = console.log;
console.log = noop;

let rounds = 0;
while (checkWin(scene) === undefined) {
player.attack(enemy);
enemy.attack(player);
for (const item of player.stats.items) item.afterFight?.(scene);
for (const item of enemy.stats.items) item.afterFight?.({ player: enemy, enemy: player });
rounds++;
}

console.log = origLog;

return {
winner: checkWin(scene)!,
playerHp: player.stats.health,
enemyHp: enemy.stats.health,
rounds,
};
}

// ---------------------------------------------------------------------------
// Run simulations
// ---------------------------------------------------------------------------

const playerStats = buildPlayer();
const enemyStats = { ...bossMap[bossKey] };

const results: FightResult[] = [];
for (let i = 0; i < iterations; i++) {
results.push(simulateFight(playerStats, enemyStats));
}

// ---------------------------------------------------------------------------
// Statistics
// ---------------------------------------------------------------------------

function stats(values: number[]) {
if (values.length === 0) return { avg: 0, min: 0, max: 0 };
const avg = values.reduce((a, b) => a + b, 0) / values.length;
return { avg, min: Math.min(...values), max: Math.max(...values) };
}

const wins = results.filter(r => r.winner === "PLAYER");
const losses = results.filter(r => r.winner === "ENEMY");

const winRate = (wins.length / iterations) * 100;

const playerHpOnWin = stats(wins.map(r => r.playerHp));
const enemyHpOnLoss = stats(losses.map(r => r.enemyHp));
const roundStats = stats(results.map(r => r.rounds));

// ---------------------------------------------------------------------------
// Output
// ---------------------------------------------------------------------------

const playerDesc = [
weaponKey ? `weapon=${weaponKey}` : "no weapon",
armorKey ? `armor=${armorKey}` : "no armor",
itemKeys.length ? `items=${itemKeys.join(",")}` : "no items",
].join(", ");

console.log(
`\nFight Simulation: Player vs ${bossMap[bossKey].name} (${iterations.toLocaleString()} runs)`,
);
console.log(`Player: ${playerDesc}`);
console.log(
`Player HP: ${playerStats.health + (playerStats.armor?.health ?? 0)} | Enemy HP: ${enemyStats.health + (enemyStats.armor?.health ?? 0)}`,
);

console.log("\n── Results ──────────────────────────────");
console.log(` Wins: ${wins.length.toLocaleString().padStart(6)} (${winRate.toFixed(1)}%)`);
console.log(
` Losses: ${losses.length.toLocaleString().padStart(6)} (${(100 - winRate).toFixed(1)}%)`,
);

console.log("\n── Rounds per fight ─────────────────────");
console.log(` Avg: ${roundStats.avg.toFixed(1)} Min: ${roundStats.min} Max: ${roundStats.max}`);

if (wins.length > 0) {
console.log("\n── Player HP remaining on WIN ───────────");
console.log(
` Avg: ${playerHpOnWin.avg.toFixed(1)} Min: ${playerHpOnWin.min} Max: ${playerHpOnWin.max}`,
);
}

if (losses.length > 0) {
console.log("\n── Enemy HP remaining on LOSS ───────────");
console.log(
` Avg: ${enemyHpOnLoss.avg.toFixed(1)} Min: ${enemyHpOnLoss.min} Max: ${enemyHpOnLoss.max}`,
);
}

console.log("");
Loading
Loading