mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
Nirgends benutzte Exporte: ETF_SYMBOLS, ONB_BY_ID (samt BY_ID), outlookWord, OUTLOOK_LABEL, storyFor, ART_NAMES, delistedLine, inboxFolders, showFormer, poolSvg, catOf, portraitOpen, splashOpen. Ungenutzte Importnamen in 10 Client-Modulen, CLASS_ORDER (trade.js), known (stage.js), TAU (wheat.js), p (mcp.js) und die lokale Bindung energyFeed (index.js, ctx.energyFeed bleibt). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
134 lines
7.2 KiB
JavaScript
134 lines
7.2 KiB
JavaScript
// Geführter Einstieg: eine Folge kleiner Aufgaben für neue Spieler in ihrer ersten Woche – erste Limit-Order,
|
||
// Stopp setzen, in drei Branchen streuen, Zeitung lesen, auf einer Hauptversammlung abstimmen, den Coach fragen.
|
||
// Jede Aufgabe hat einen kurzen Erklärtext und bringt ein paar Erfahrungspunkte; wer alles schafft, bekommt das
|
||
// Abzeichen „Gut gestartet“. Kein Spielgeld, nichts Spielentscheidendes.
|
||
//
|
||
// Nur für neue Konten: register() ruft start() auf. Bestehende Spieler (ohne p.onb) sehen nichts. Der Einstieg ist
|
||
// jederzeit überspringbar und endet nach onbDays Tagen von selbst.
|
||
// Fortschritt zählt über Ereignisse aus dem Spiel (Progress.event → event(), dazu „limit“, „paper“, „coach“) und den
|
||
// Zustand des Depots (Branchen). Angezeigt wird er in „Mein Tag“ (Bereich „onboarding“ in todo.js, Gruppe „Erste Schritte“).
|
||
import { registerTodo } from './todo.js';
|
||
import { SECTOR_OF } from './world.js';
|
||
|
||
const DAY = 86_400_000;
|
||
export const ONB_BONUS_XP = 50;
|
||
export const ONB_ACHIEVEMENT = 'onboarding';
|
||
|
||
/**
|
||
* Aufgaben in empfohlener Reihenfolge. kind: Ereignis, das die Aufgabe erledigt (state: aus dem Depot geprüft).
|
||
* target: Sprungziel wie in todo.js ({view, anchor} oder act).
|
||
*/
|
||
export const ONB_TASKS = [
|
||
{ id: 'buy', kind: 'trade', xp: 20, icon: 'cart', title: 'Kaufe deine ersten Aktien',
|
||
text: 'Wähle im Markt einen Wert, gib die Stückzahl ein und kaufe. Außerhalb der Handelszeit wird die Order für die nächste Auktion gesammelt.',
|
||
target: { view: 'handeln' }, btn: 'Zum Orderticket' },
|
||
{ id: 'limit', kind: 'limit', xp: 25, icon: 'target', title: 'Gib eine Limit-Order auf',
|
||
text: 'Mit einem Limit legst du fest, wie viel du höchstens zahlst (oder beim Verkauf mindestens bekommst). Die Order wartet im Orderbuch, bis jemand zu deinem Preis handelt – und kostet als Maker weniger Gebühr.',
|
||
target: { view: 'handeln', anchor: 'oType' }, btn: 'Limit setzen' },
|
||
{ id: 'stop', kind: 'stop', xp: 30, icon: 'shield-check', title: 'Sichere eine Position mit einem Stopp ab',
|
||
text: 'Ein Stop-Loss verkauft automatisch, wenn der Kurs unter deinen Auslöser fällt. Lege ihn nicht zu eng – sonst löst schon das normale Auf und Ab aus. Ordertyp „Stop-Loss“ oder „Trailing-Stop“ im Orderticket.',
|
||
target: { view: 'handeln', anchor: 'oType' }, btn: 'Stopp setzen' },
|
||
{ id: 'spread', state: true, n: 3, xp: 40, icon: 'pie', title: 'Streue über drei Branchen',
|
||
text: 'Halte gleichzeitig Aktien aus mindestens drei verschiedenen Branchen. Eine schlechte Meldung trifft dann nicht gleich dein ganzes Depot.',
|
||
target: { view: 'markt' }, btn: 'Zum Markt' },
|
||
{ id: 'paper', kind: 'paper', xp: 15, icon: 'news', title: 'Lies die Börsenzeitung',
|
||
text: 'Die Zeitung fasst nach jedem Handelsschluss zusammen, was die Kurse bewegt hat: Gewinner, Verlierer, Politik und Firmenmeldungen.',
|
||
target: { act: 'paper' }, btn: 'Zeitung öffnen' },
|
||
{ id: 'agm', kind: 'agm', xp: 30, icon: 'ballot', title: 'Stimme auf einer Hauptversammlung ab',
|
||
text: 'Als Aktionär darfst du mitreden: Lädt eine Firma aus deinem Depot zur Hauptversammlung, findest du sie unter „Termine“. Du stimmst über Dividende, Vorstand und Kapitalmaßnahmen ab.',
|
||
target: { view: 'termine', anchor: 'agmCard' }, btn: 'Zu den Terminen' },
|
||
{ id: 'coach', kind: 'coach', xp: 15, icon: 'chat', title: 'Frag den Börsencoach',
|
||
text: 'Der Coach kennt dein Depot und deine Aufträge. Frag ihn etwa, ob dein Depot gut verteilt ist – oder stell im Hilfe-Chat eine Frage zu den Regeln.',
|
||
target: { act: 'coach' }, btn: 'Coach fragen' },
|
||
];
|
||
export const ONB_XP_TOTAL = ONB_TASKS.reduce((a, t) => a + t.xp, 0) + ONB_BONUS_XP;
|
||
|
||
/** Zahl der Branchen, aus denen der Spieler gerade Aktien hält (long) */
|
||
export function sectorsHeld(p) {
|
||
return new Set(Object.entries(p.positions ?? {}).filter(([s, x]) => x?.qty > 0 && SECTOR_OF[s]).map(([s]) => SECTOR_OF[s])).size;
|
||
}
|
||
|
||
export class Onboarding {
|
||
constructor(g) { this.g = g; }
|
||
get cfg() { return this.g.cfg; }
|
||
#days() { return Math.max(1, Number(this.cfg.onbDays) || 7); }
|
||
|
||
/** neues Konto: Einstieg anlegen (nur wenn eingeschaltet) */
|
||
start(p) {
|
||
if (!p || p.rival || p.onb || this.cfg.onbEnabled === false) return;
|
||
p.onb = { at: Date.now(), done: {}, skipped: false, doneAt: null };
|
||
this.g.markDirty(p);
|
||
}
|
||
|
||
/** läuft der Einstieg für diesen Spieler gerade? */
|
||
active(p) {
|
||
const o = p?.onb;
|
||
return !!o && !p.rival && this.cfg.onbEnabled !== false && !o.skipped && !o.doneAt && Date.now() - o.at < this.#days() * DAY;
|
||
}
|
||
|
||
/** Ereignis aus dem Spiel (Progress.event und direkte Aufrufe): passende Aufgaben erledigen */
|
||
event(p, kind) {
|
||
if (!this.active(p)) return;
|
||
for (const t of ONB_TASKS) if (t.kind === kind && !p.onb.done[t.id]) this.#complete(p, t);
|
||
this.check(p);
|
||
}
|
||
|
||
/** zustandsabhängige Aufgaben prüfen (Branchen im Depot) */
|
||
check(p) {
|
||
if (!this.active(p)) return;
|
||
for (const t of ONB_TASKS) if (t.state && !p.onb.done[t.id] && t.id === 'spread' && sectorsHeld(p) >= t.n) this.#complete(p, t);
|
||
}
|
||
|
||
#complete(p, t) {
|
||
const g = this.g;
|
||
p.onb.done[t.id] = Date.now();
|
||
g.prog.addXp(p, t.xp);
|
||
const n = this.#count(p);
|
||
const finished = n >= ONB_TASKS.length;
|
||
if (finished) p.onb.doneAt = Date.now();
|
||
g.markDirty(p);
|
||
g.todo?.touch(p.id);
|
||
g.sendTo(p.id, { type: 'onb', task: { id: t.id, title: t.title, xp: t.xp }, n, total: ONB_TASKS.length, finished, bonusXp: finished ? ONB_BONUS_XP : 0 });
|
||
if (finished) {
|
||
g.prog.addXp(p, ONB_BONUS_XP);
|
||
g.unlock(p, ONB_ACHIEVEMENT);
|
||
}
|
||
}
|
||
|
||
#count(p) { return ONB_TASKS.filter((t) => p.onb?.done?.[t.id]).length; }
|
||
|
||
/** Einstieg überspringen (lässt sich nicht rückgängig machen) */
|
||
skip(p) {
|
||
if (!this.active(p)) throw new Error('Der geführte Einstieg ist schon beendet');
|
||
p.onb.skipped = true;
|
||
this.g.markDirty(p);
|
||
this.g.todo?.touch(p.id);
|
||
return this.view(p);
|
||
}
|
||
|
||
/** Stand für den Client */
|
||
view(p) {
|
||
const o = p?.onb;
|
||
if (!o) return { active: false };
|
||
const tasks = ONB_TASKS.map((t) => ({
|
||
id: t.id, title: t.title, text: t.text, xp: t.xp, icon: t.icon, target: t.target, btn: t.btn, done: !!o.done?.[t.id],
|
||
...(t.id === 'spread' ? { progress: Math.min(t.n, sectorsHeld(p)), n: t.n } : {}),
|
||
}));
|
||
const n = tasks.filter((t) => t.done).length;
|
||
return {
|
||
active: this.active(p), n, total: tasks.length, tasks, endsAt: o.at + this.#days() * DAY,
|
||
xp: tasks.filter((t) => t.done).reduce((a, t) => a + t.xp, 0) + (o.doneAt ? ONB_BONUS_XP : 0), xpTotal: ONB_XP_TOTAL, bonusXp: ONB_BONUS_XP,
|
||
finished: !!o.doneAt, skipped: !!o.skipped,
|
||
};
|
||
}
|
||
}
|
||
|
||
// „Mein Tag“: ein Eintrag unter „Erste Schritte“ mit dem ganzen Einstieg (der Client zeichnet daraus eine eigene Karte)
|
||
registerTodo('onboarding', (g, p) => {
|
||
if (!g.onb?.active(p)) return [];
|
||
const v = g.onb.view(p);
|
||
const next = v.tasks.find((t) => !t.done);
|
||
return [{ id: 'onboarding', group: 'start', icon: 'cap', title: `Einstieg: ${v.n} von ${v.total} Aufgaben erledigt`,
|
||
detail: next ? `Als Nächstes: ${next.title}` : 'Alles geschafft!', target: next?.target ?? { view: 'fortschritt' }, btn: next?.btn ?? 'Ansehen', onb: v }];
|
||
});
|