fix bugs to 2.7.1

This commit is contained in:
Sahik committed 2026-11-01 17:42:51 +08:00
1 parent 6747dbacb8
commit 7716f8c297
22 files changed
+639 -1018

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
# key: (名稱, 達成條件, 獎勵說明)
# 獎勵的實際發放寫在各遊戲邏輯裡(例如 lottery.GACHA_SETS)
ACHIEVEMENTS = {
"entangled": ("三顆糾纏之緣", "簽到時獲得三顆糾纏之緣", ""),
"gambler": ("賭狗", "幸運礦工累計 1000 次", ""),
"yaju": ("壓力馬斯內", "幸運礦工挖到 114514 exp", ""),
"win_all": ("贏下所有", "幸運礦工挖到 300000 exp", ""),
"pc_gamer": ("桌機玩家", "集齊扭蛋「主機」系列", "+480 exp"),
"shark_family": ("彩色鯊魚家族", "集齊扭蛋「鯊魚家族」系列", "+600 exp"),
"oshi": ("單推sthkm3", "集齊扭蛋「作者」系列", "+150 代幣"),
"lazy": ("懶人", "集齊扭蛋「配置」系列", "+600 exp"),
"crossdress": ("這就是...開發者的末路嗎...", "集齊扭蛋「女裝」系列", "+600 exp"),
"shut_up": ("閉嘴", "扭蛋稀有掉落", ""),
"bottom": ("到底", "扭蛋稀有掉落", ""),
}
def announce(keys) -> str:
lines = []
for k in keys:
name, _, reward = ACHIEVEMENTS[k]
lines.append(f"# 🏆 達成成就《{name}》 {reward}".rstrip())
return "\n".join(lines)
+25
View File
@@ -0,0 +1,25 @@
import random
import discord
text = [
"你輸了",
"加把勁,下次一定行",
"失誤啦,再來一次",
"唉,可惜了",
"再接再厲",
]
rare_text = [
"菜,就多練",
"可以剪精華了",
"這操作要上抖音了",
"你是不是閉著眼睛玩?",
"請問你有開螢幕嗎?"
]
def lose_message(lose_user: discord.User) -> str:
if random.random() < 0.05:
msg = random.choice(rare_text)
else:
msg = random.choice(text)
return f"{lose_user.mention} {msg}"
+132
View File
@@ -0,0 +1,132 @@
"""抽獎邏輯;代幣不足時丟出 db.NotEnoughCoins,整筆交易不會生效"""
import random
from collections import Counter
import db
# ===== 御神籤 =====
OMIKUJI_COST = 10
OMIKUJI = [ # (名稱, exp, 權重%)
("大吉", 130, 10),
("吉", 110, 20),
("中吉", 105, 15),
("小吉", 100, 15),
("末吉", 95, 15),
("凶", 85, 15),
("大凶", 70, 10),
]
def omikuji(user_id: int) -> tuple[str, int]:
with db.conn:
db.spend(user_id, OMIKUJI_COST)
name, exp, _ = random.choices(OMIKUJI, weights=[c[2] for c in OMIKUJI])[0]
db.add(user_id, exp=exp)
return name, exp
# ===== 幸運礦工 =====
MINER_MAX_TIMES = 500
MINER_POOLS = { # (獎勵, 權重)
"small": ([7, 22], [80, 20]),
"large": ([8, 350], [99, 1]),
"risk": ([9, 114514, 300000], [99997, 2, 1]),
}
MINER_ACHIEVEMENTS = {114514: "yaju", 300000: "win_all"}
GAMBLER_THRESHOLD = 1000
def miner(user_id: int, pool: str, times: int) -> tuple[int, Counter, list[str]]:
rewards, weights = MINER_POOLS[pool]
new_achievements = []
with db.conn:
db.spend(user_id, times)
log = random.choices(rewards, weights=weights, k=times)
total = sum(log)
db.add(user_id, exp=total)
db.conn.execute(
"UPDATE users SET miner_count = miner_count + ? WHERE id = ?", (times, user_id)
)
for reward, key in MINER_ACHIEVEMENTS.items():
if reward in log and db.grant_achievement(user_id, key):
new_achievements.append(key)
if db.get_user(user_id)["miner_count"] >= GAMBLER_THRESHOLD and db.grant_achievement(user_id, "gambler"):
new_achievements.append("gambler")
return total, Counter(log), new_achievements
# ===== 刮刮樂 =====
SCRATCH_COST = 5
# 對中幾個號碼 → exp;期望值約 46 exp/張 ≈ 9.2 exp/代幣
SCRATCH_REWARD = {0: 10, 1: 77, 2: 231, 3: 693}
def scratch(user_id: int) -> tuple[list[int], list[int], int, int]:
with db.conn:
db.spend(user_id, SCRATCH_COST)
opponent = random.sample(range(1, 61), 3)
player = random.sample(range(1, 61), 9)
hits = len(set(opponent) & set(player))
exp = SCRATCH_REWARD[hits]
db.add(user_id, exp=exp)
return opponent, player, hits, exp
# ===== 扭蛋 =====
GACHA_COST = 3
GACHA_SETS = { # 成就 key: (系列物品, 集齊獎勵)
"pc_gamer": (
["主機殼", "處理器", "主機板", "記憶體", "顯示卡", "塔扇", "電源供應器", "硬碟"],
{"exp": 480},
),
"shark_family": (
["白色鯊魚", "紅色鯊魚", "橘色鯊魚", "黃色鯊魚", "綠色鯊魚",
"藍色鯊魚", "紫色鯊魚", "灰色鯊魚", "黑色鯊魚", "彩色鯊魚"],
{"exp": 600},
),
"oshi": (
["作者的左手模型", "作者的右手模型", "作者的頭髮模型", "作者的左腳模型",
"作者的右腳模型", "作者的身體模型", "作者的頭模型"],
{"coin": 150},
),
"lazy": (
["床", "枕頭", "棉被", "冷氣", "椅子", "電腦桌", "筆電", "螢幕", "手機", "插座"],
{"exp": 600},
),
"crossdress": (
["假髮", "小褲褲", "上衣", "小裙子", "袖套", "絲襪", "褲襪", "蝴蝶結", "髮飾", "化妝品"],
{"exp": 600},
),
}
GACHA_SIDE = [30, 30, 25, 35] # 旁池 exp
GACHA_RARE = ["shut_up", "bottom"]
GACHA_RARE_RATE = 0.03
GACHA_POOL = [item for items, _ in GACHA_SETS.values() for item in items] + GACHA_SIDE
def gacha(user_id: int, draws: int) -> tuple[list[str], list[str]]:
lines = []
new_achievements = []
with db.conn:
db.spend(user_id, GACHA_COST * draws)
for _ in range(draws):
result = random.choice(GACHA_POOL)
if isinstance(result, int):
db.add(user_id, exp=result)
lines.append(f"{result} exp")
else:
count = db.add_item(user_id, result)
lines.append(f"{result}(持有 {count})")
if random.random() < GACHA_RARE_RATE:
key = random.choice(GACHA_RARE)
if db.grant_achievement(user_id, key):
new_achievements.append(key)
backpack = db.get_backpack(user_id)
for key, (items, reward) in GACHA_SETS.items():
if all(backpack.get(i, 0) > 0 for i in items) and db.grant_achievement(user_id, key):
db.add(user_id, **reward)
new_achievements.append(key)
return lines, new_achievements
+29
View File
@@ -0,0 +1,29 @@
import random
from datetime import datetime
import db
from config import TZ
SIGNIN_COIN = 10
JACKPOT_RATE = 0.0015
JACKPOT_COIN = 480 # 含當日簽到的 10 枚
def try_signin(user_id: int) -> tuple[bool, bool]:
"""回傳 (是否簽到成功, 是否中三顆糾纏之緣)"""
today = datetime.now(TZ).date().isoformat()
with db.conn:
db.ensure_user(user_id)
cur = db.conn.execute(
"UPDATE users SET coin = coin + ?, total_signin = total_signin + 1, last_signin = ? "
"WHERE id = ? AND (last_signin IS NULL OR last_signin <> ?)",
(SIGNIN_COIN, today, user_id, today),
)
if cur.rowcount == 0:
return False, False
jackpot = random.random() < JACKPOT_RATE
if jackpot:
db.add(user_id, coin=JACKPOT_COIN - SIGNIN_COIN)
db.grant_achievement(user_id, "entangled")
return True, jackpot