yahtzee-server/models/server_chat.py

441 lines
20 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import random
CAT_NAMES = {
"DE": {
"1": "Einser", "2": "Zweier", "3": "Dreier", "4": "Vierer", "5": "Fünfer", "6": "Sechser",
"3K": "Dreierpasch", "4K": "Viererpasch", "FH": "Full House",
"SS": "Kleine Straße", "LS": "Große Straße", "Y": "Yahtzee", "C": "Chance"
},
"EN": {
"1": "Ones", "2": "Twos", "3": "Threes", "4": "Fours", "5": "Fives", "6": "Sixes",
"3K": "Three of a Kind", "4K": "Four of a Kind", "FH": "Full House",
"SS": "Small Straight", "LS": "Large Straight", "Y": "Yahtzee", "C": "Chance"
}
}
REACTIONS_DATA = {
"DE": {
"other_zero": [
"@{0} Autsch, das tut weh! ☠",
"@{0} Nullrunde! (T_T)",
"@{0} Das war wohl nichts... ✖",
"@{0} Die Würfel sind heute gnadenlos zu dir! ⚡",
"@{0} Ein Opfer für die Würfelgötter! ✞",
"@{0} Direkt in den Abgrund gestrichen. ▼",
"@{0} Mehr Glück in der nächsten Runde! ☘",
"@{0} RIP an diese Kategorie. ✞",
"@{0} Manchmal muss man Federn lassen. ¯\\_(ツ)_/¯",
"@{0} Das gibt mir ordentlich Vorsprung! >:)",
"@{0} Komplett verhext! ✦",
"@{0} Schmerzhaft anzusehen... >_<",
"@{0} Da wollten die Würfel einfach nicht. ⚀✖",
"@{0} Uff, eiskalt abserviert! ❄",
"@{0} Wenigstens hast du es hinter dir! ^^"
],
"self_zero": [
"(╯°□°)╯︵ ┻━┻", "☠ ✞ ☠", "(T_T) ✖", ">_< ⚡", "⚀ ✖ ☠",
"¯\\_(ツ)_/¯ ✖", "(✖╭╮✖)", "⚡ ☠ ⚡", "(-_-;) ...", "(>_<)",
"grrr... ☠", "Verfluchte Würfel! ☠", "Nicht mein Ernst... (T_T)",
"Uff... ✞", "Das gibt Rache! ⚔"
],
"other_early_ss": [
"@{0} Oha, eine Kleine Straße gleich am Anfang! O_O",
"@{0} Direkt zum Start eine Kleine Straße, stark! ⚡",
"@{0} Früh übt sich, wer Straßen baut! ⚀⚁⚂⚃",
"@{0} Schon so früh 30 Punkte gesichert, nicht schlecht! ★",
"@{0} Blitzstart mit der Kleinen Straße! ⚡",
"@{0} Kaum angefangen und schon steht die Straße! ✦",
"@{0} Solider Auftakt mit 30 Punkten! ✔",
"@{0} Das ging aber schnell mit der Kleinen Straße! >>"
],
"other_ss": [
"@{0} Saubere Kleine Straße! ⚀⚁⚂⚃",
"@{0} 30 Punkte nimmt man immer gern mit! ✔",
"@{0} Schön der Reihe nach aufgestellt! ✦",
"@{0} Kleine Straße sitzt! ✔",
"@{0} Solide 30 Punkte aufs Konto! ★",
"@{0} Gut gerettet mit der Kleinen Straße! o7",
"@{0} Vier in einer Reihe, sauber gespielt! ♦",
"@{0} Die 30 Punkte hast du dir verdient! ✦"
],
"other_ls": [
"@{0} Große Straße?! Nicht schlecht! ★",
"@{0} 40 Punkte am Stück, starkes Ding! ⚡",
"@{0} Wie am Schnürchen gezogen! ⚀⚁⚂⚃⚄",
"@{0} Eine Bilderbuch-Straße! ✦",
"@{0} 1-2-3-4-5 oder 2-3-4-5-6... egal, 40 Punkte! ♛",
"@{0} Große Straße sitzt perfekt! ✔",
"@{0} Da haben alle fünf Würfel perfekt mitgespielt! ✦",
"@{0} Respekt für die Große Straße! o7",
"@{0} 40 Punkte auf einen Schlag, langsam wirst du gefährlich! O_O",
"@{0} Makellose Reihe! ⚡"
],
"other_fh": [
"@{0} Sauberes Full House! ⌂",
"@{0} Volles Haus und 25 sichere Punkte! ★",
"@{0} Drei plus Zwei – perfekt kombiniert! ⚂⚂⚂⚁⚁",
"@{0} Da steht die Hütte! ⌂✦",
"@{0} 25 Punkte für das Full House, stark! ✔",
"@{0} Schönes Full House eingetütet! :D",
"@{0} Volles Haus, keine Wünsche offen! ✦",
"@{0} Klassisches Full House, sauber! ♦"
],
"other_4k": [
"@{0} Vier Gleiche und richtig gute Punkte! ⚡",
"@{0} Fast ein Yahtzee! Starker Viererpasch! ⚄⚄⚄⚄",
"@{0} Vier auf einen Streich, Respekt! ⚔",
"@{0} Das scheppert ordentlich im Viererpasch! ⚡",
"@{0} Nur einer hat zum Yahtzee gefehlt! Trotzdem top Punkte! O_O",
"@{0} Mächtiger Viererpasch! ★",
"@{0} Vierlinge! Das bringt ordentlich Zähler! ▲",
"@{0} Stark gewürfelt beim Viererpasch! o7"
],
"other_yahtzee": [
"@{0} WAHNSINN! Ein Yahtzee! ♛✦",
"@{0} Fünf Gleiche?! Hast du gezinkte Würfel?! ⚅⚅⚅⚅⚅",
"@{0} Unglaublich, das volle Yahtzee! ♛",
"@{0} Verneigt euch vor diesem Wurf! o7 ♛",
"@{0} 50 Punkte direkt aus der Dunkelheit! ♛",
"@{0} Ein echtes Meisterstück! ♦✦",
"@{0} Jackpot! Besser geht es nicht! ★⚡",
"@{0} Das nennt man wohl pures Würfelglück! ☘♛",
"@{0} Legendärer Wurf! ⚡♛",
"@{0} Jetzt wird es richtig schwer, dich noch einzuholen! O_O"
],
"other_good": [
"@{0} Das war gar nicht schlecht! ✔",
"@{0} Starker Zug, Respekt! o7",
"@{0} Ordentliche Ausbeute! ★",
"@{0} Du sammelst ganz schön fleißig Punkte! O_O",
"@{0} Wichtige Punkte für den Bonus! ▲",
"@{0} Sehr sauber eingetragen! ✔",
"@{0} Nicht übel, gar nicht übel! :)",
"@{0} Das bringt dich gut nach vorne! >>",
"@{0} Gute Entscheidung bei diesem Wurf! ✦",
"@{0} Starke Runde von dir! ★",
"@{0} Solches Würfelglück hätte ich auch gern! ;)",
"@{0} Präzise abgeliefert! ♦"
],
"other_small": [
"@{0} Kleinvieh macht auch Mist! ⚀⚁",
"@{0} Punkte sind Punkte. :)",
"@{0} Besser als eine Nullrunde! ✔",
"@{0} Sicher gespielt, kann man machen. :)",
"@{0} Mühsam ernährt sich das Eichhörnchen! ^^",
"@{0} Solider Lückenfüller! ✔",
"@{0} Nicht die Welt, aber immerhin auf dem Konto. ▲",
"@{0} Schadensbegrenzung erfolgreich! ⚔",
"@{0} Schritt für Schritt! >>",
"@{0} Ganz vernünftig gelöst. :)"
],
"self_taunt": [
"Schlag das erst mal! B)",
"Da staunt ihr, was? ⚡",
"So wird das gemacht! ♛",
"Zu einfach für mich! ✦",
"Nehmt euch ein Beispiel daran! ;)",
"Präzision wie ein Uhrwerk! ⚡",
"Die Würfel gehorchen mir! ♛",
"Wer will mich heute noch stoppen? >>",
"Ein Meisterwerk aus dem Handgelenk! ★",
"Schreibt euch das hinter die Ohren! >:)",
"Genau nach Plan! ✦",
"Der Sieg rückt immer näher! ♛",
"Da bleibt euch die Spucke weg! >:D",
"Maximaler Ertrag, null Mühe! ♦",
"Heute läuft es einfach bei mir! ⚡⚅"
],
"self_normal": [
"Punkte sind Punkte! B)",
"Nehm ich so mit! ✔",
"Ganz solide für zwischendurch. :)",
"Immer schön weitersammeln! ▲",
"Pflichtaufgabe erfüllt. ✔",
"Passt schon so! ^^",
"Kleiner Schritt Richtung Sieg! >>",
"Besser als nichts! ⚔",
"Sicher ist sicher. ✔",
"Das fügt sich gut ins Bild. ♦"
]
},
"EN": {
"other_zero": [
"@{0} Ouch, that hurts! ☠",
"@{0} Zero points! (T_T)",
"@{0} That didn't go as planned... ✖",
"@{0} The dice are merciless today! ⚡",
"@{0} A sacrifice to the dice gods! ✞",
"@{0} Straight into the abyss. ▼",
"@{0} Better luck next round! ☘",
"@{0} RIP to that category. ✞",
"@{0} Sometimes you have to take the hit. ¯\\_(ツ)_/¯",
"@{0} That gives me a nice lead! >:)",
"@{0} Totally cursed! ✦",
"@{0} Painful to watch... >_<",
"@{0} The dice just said no. ⚀✖",
"@{0} Cold-blooded scratch! ❄",
"@{0} At least you got that one out of the way! ^^"
],
"self_zero": [
"(╯°□°)╯︵ ┻━┻", "☠ ✞ ☠", "(T_T) ✖", ">_< ⚡", "⚀ ✖ ☠",
"¯\\_(ツ)_/¯ ✖", "(✖╭╮✖)", "⚡ ☠ ⚡", "(-_-;) ...", "(>_<)",
"grrr... ☠", "Cursed dice! ☠", "Are you kidding me... (T_T)",
"Ugh... ✞", "I will have my revenge! ⚔"
],
"other_early_ss": [
"@{0} Whoa, a Small Straight right at the start! O_O",
"@{0} Starting off hot with a Small Straight! ⚡",
"@{0} Building straights early on, nice! ⚀⚁⚂⚃",
"@{0} 30 points locked in already, not bad! ★",
"@{0} Lightning start with that Small Straight! ⚡",
"@{0} Barely started and already rolling straights! ✦",
"@{0} Solid opening with 30 points! ✔",
"@{0} That was fast for a Small Straight! >>"
],
"other_ss": [
"@{0} Clean Small Straight! ⚀⚁⚂⚃",
"@{0} 30 points are always welcome! ✔",
"@{0} Nicely lined up! ✦",
"@{0} Small Straight locked in! ✔",
"@{0} Solid 30 points in the bank! ★",
"@{0} Good save with that Small Straight! o7",
"@{0} Four in a row, well played! ♦",
"@{0} Well-deserved 30 points! ✦"
],
"other_ls": [
"@{0} Large Straight?! Impressive! ★",
"@{0} 40 points in one go, huge play! ⚡",
"@{0} Lined up like clockwork! ⚀⚁⚂⚃⚄",
"@{0} A textbook Large Straight! ✦",
"@{0} Five in a row for a clean 40 points! ♛",
"@{0} Large Straight nailed to perfection! ✔",
"@{0} All five dice cooperated beautifully! ✦",
"@{0} Respect for that Large Straight! o7",
"@{0} 40 points at once, you're getting dangerous! O_O",
"@{0} Flawless sequence! ⚡"
],
"other_fh": [
"@{0} Clean Full House! ⌂",
"@{0} Full House and 25 safe points! ★",
"@{0} Three plus two – perfectly combined! ⚂⚂⚂⚁⚁",
"@{0} The house is packed! ⌂✦",
"@{0} 25 points for the Full House, strong! ✔",
"@{0} Nice Full House in the bag! :D",
"@{0} Full House, nothing left to wish for! ✦",
"@{0} Classic Full House, well done! ♦"
],
"other_4k": [
"@{0} Four of a kind and great points! ⚡",
"@{0} Almost a Yahtzee! Strong Four of a Kind! ⚄⚄⚄⚄",
"@{0} Four at once, respect! ⚔",
"@{0} Big points on that Four of a Kind! ⚡",
"@{0} Just one shy of a Yahtzee! Still awesome points! O_O",
"@{0} Mighty Four of a Kind! ★",
"@{0} Quads! That racks up the score! ▲",
"@{0} Great roll on that Four of a Kind! o7"
],
"other_yahtzee": [
"@{0} INSANE! A Yahtzee! ♛✦",
"@{0} Five of a kind?! Are those loaded dice?! ⚅⚅⚅⚅⚅",
"@{0} Unbelievable, a full Yahtzee! ♛",
"@{0} Bow down to that roll! o7 ♛",
"@{0} 50 points straight from the shadows! ♛",
"@{0} An absolute masterpiece! ♦✦",
"@{0} Jackpot! It doesn't get better than that! ★⚡",
"@{0} Pure dice magic right there! ☘♛",
"@{0} Legendary roll! ⚡♛",
"@{0} Catching up to you just got a lot harder! O_O"
],
"other_good": [
"@{0} That wasn't bad at all! ✔",
"@{0} Solid move, respect! o7",
"@{0} Decent haul right there! ★",
"@{0} You're stacking up points fast! O_O",
"@{0} Crucial points toward the bonus! ▲",
"@{0} Very cleanly scored! ✔",
"@{0} Not bad, not bad at all! :)",
"@{0} That pushes you right ahead! >>",
"@{0} Smart choice on that roll! ✦",
"@{0} Strong turn from you! ★",
"@{0} Wish I had that kind of dice luck! ;)",
"@{0} Delivered with precision! ♦"
],
"other_small": [
"@{0} Every point counts! ⚀⚁",
"@{0} Points are points. :)",
"@{0} Better than a zero! ✔",
"@{0} Played it safe, fair enough. :)",
"@{0} Little by little fills the scorecard! ^^",
"@{0} Solid filler score! ✔",
"@{0} Not huge, but it's on the board. ▲",
"@{0} Damage control successful! ⚔",
"@{0} Step by step! >>",
"@{0} Sensible choice. :)"
],
"self_taunt": [
"Beat that! B)",
"Amazed, aren't you? ⚡",
"That's how it's done! ♛",
"Too easy for me! ✦",
"Take notes, everyone! ;)",
"Precision like clockwork! ⚡",
"The dice obey my command! ♛",
"Who's gonna stop me today? >>",
"A masterpiece of a roll! ★",
"Remember that move! >:)",
"All according to plan! ✦",
"Victory is getting closer! ♛",
"Left you speechless, huh? >:D",
"Maximum points, zero effort! ♦",
"I'm on fire today! ⚡⚅"
],
"self_normal": [
"Points are points! B)",
"I'll take it! ✔",
"Solid enough for now. :)",
"Keep stacking them up! ▲",
"Job done. ✔",
"Works for me! ^^",
"One small step toward victory! >>",
"Better than nothing! ⚔",
"Better safe than sorry. ✔",
"Fits right into the plan. ♦"
]
}
}
class ServerChatEngine:
"""Erzeugt zweisprachige Wurf-Protokolle und Bot-Reaktionen für alle Clients im Raum."""
DICE_FACES = {1: "⚀", 2: "⚁", 3: "⚂", 4: "⚃", 5: "⚄", 6: "⚅"}
@classmethod
def format_roll_log(cls, player_name: str, dice: list[int], cat_key: str, pts: int) -> dict:
dice_str = "[" + " ".join(cls.DICE_FACES.get(d, str(d)) for d in sorted(dice)) + "]"
cat_de = CAT_NAMES["DE"].get(cat_key, cat_key)
cat_en = CAT_NAMES["EN"].get(cat_key, cat_key)
return {
"event": "CHAT_MSG",
"sender": player_name,
"text_de": f"würfelt {dice_str} -> {pts} Pkt. bei '{cat_de}'",
"text_en": f"rolled {dice_str} -> {pts} pts in '{cat_en}'",
"is_taunt": False,
"is_roll_log": True
}
@classmethod
def generate_reaction_event(cls, actor, all_participants, cat_key: str, pts: int, turn_num: int, has_joker: bool = False):
bots = [p for p in all_participants if p.is_bot]
if not bots:
return None
target_name = actor.name
other_bots = [b for b in bots if b != actor]
if not actor.is_bot:
sender = random.choice(bots).name
bucket = cls._pick_other_bucket(cat_key, pts, turn_num, has_joker)
idx = random.randrange(len(REACTIONS_DATA["DE"][bucket]))
return {
"event": "CHAT_MSG",
"sender": sender,
"text_de": REACTIONS_DATA["DE"][bucket][idx].format(target_name),
"text_en": REACTIONS_DATA["EN"][bucket][idx].format(target_name),
"is_taunt": False,
"is_roll_log": False
}
if pts == 0:
if not other_bots or random.random() < 0.75:
idx = random.randrange(len(REACTIONS_DATA["DE"]["self_zero"]))
return {
"event": "CHAT_MSG",
"sender": actor.name,
"text_de": REACTIONS_DATA["DE"]["self_zero"][idx],
"text_en": REACTIONS_DATA["EN"]["self_zero"][idx],
"is_taunt": False,
"is_roll_log": False
}
else:
commenter = random.choice(other_bots).name
idx = random.randrange(len(REACTIONS_DATA["DE"]["other_zero"]))
return {
"event": "CHAT_MSG",
"sender": commenter,
"text_de": REACTIONS_DATA["DE"]["other_zero"][idx].format(target_name),
"text_en": REACTIONS_DATA["EN"]["other_zero"][idx].format(target_name),
"is_taunt": False,
"is_roll_log": False
}
is_big = (
has_joker
or (cat_key in ["FH", "SS", "LS", "Y"] and pts > 0)
or (cat_key in ["1", "2", "3", "4", "5", "6"] and pts >= int(cat_key) * 3)
or pts >= 20
)
if is_big:
if not other_bots or random.random() < 0.70:
idx = random.randrange(len(REACTIONS_DATA["DE"]["self_taunt"]))
return {
"event": "CHAT_MSG",
"sender": actor.name,
"text_de": REACTIONS_DATA["DE"]["self_taunt"][idx],
"text_en": REACTIONS_DATA["EN"]["self_taunt"][idx],
"is_taunt": True,
"is_roll_log": False
}
else:
commenter = random.choice(other_bots).name
bucket = cls._pick_other_bucket(cat_key, pts, turn_num, has_joker)
idx = random.randrange(len(REACTIONS_DATA["DE"][bucket]))
return {
"event": "CHAT_MSG",
"sender": commenter,
"text_de": REACTIONS_DATA["DE"][bucket][idx].format(target_name),
"text_en": REACTIONS_DATA["EN"][bucket][idx].format(target_name),
"is_taunt": False,
"is_roll_log": False
}
else:
if not other_bots or random.random() < 0.65:
idx = random.randrange(len(REACTIONS_DATA["DE"]["self_normal"]))
return {
"event": "CHAT_MSG",
"sender": actor.name,
"text_de": REACTIONS_DATA["DE"]["self_normal"][idx],
"text_en": REACTIONS_DATA["EN"]["self_normal"][idx],
"is_taunt": False,
"is_roll_log": False
}
else:
commenter = random.choice(other_bots).name
idx = random.randrange(len(REACTIONS_DATA["DE"]["other_small"]))
return {
"event": "CHAT_MSG",
"sender": commenter,
"text_de": REACTIONS_DATA["DE"]["other_small"][idx].format(target_name),
"text_en": REACTIONS_DATA["EN"]["other_small"][idx].format(target_name),
"is_taunt": False,
"is_roll_log": False
}
@staticmethod
def _pick_other_bucket(cat_key, pts, turn_num, has_joker):
if pts == 0:
return "other_zero"
if (cat_key == "Y" and pts == 50) or has_joker:
return "other_yahtzee"
if cat_key == "LS" and pts == 40:
return "other_ls"
if cat_key == "SS" and pts == 30:
return "other_early_ss" if turn_num <= 4 else "other_ss"
if cat_key == "FH" and pts == 25:
return "other_fh"
if cat_key == "4K" and pts >= 15:
return "other_4k"
if (cat_key in ["1", "2", "3", "4", "5", "6"] and pts >= int(cat_key) * 3) or pts >= 18:
return "other_good"
return "other_small"