koishi-plugin-xxck-1 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +17 -0
- package/lib/index.js +161 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -111,6 +111,23 @@ declare module 'koishi' {
|
|
|
111
111
|
got6: boolean;
|
|
112
112
|
got7: boolean;
|
|
113
113
|
};
|
|
114
|
+
gacha_battle_user: {
|
|
115
|
+
qq: string;
|
|
116
|
+
win: number;
|
|
117
|
+
lose: number;
|
|
118
|
+
streak: number;
|
|
119
|
+
max_streak: number;
|
|
120
|
+
day_count: number;
|
|
121
|
+
day_date: string;
|
|
122
|
+
};
|
|
123
|
+
gacha_battle_log: {
|
|
124
|
+
id: number;
|
|
125
|
+
qq1: string;
|
|
126
|
+
qq2: string;
|
|
127
|
+
star: number;
|
|
128
|
+
win_qq: string;
|
|
129
|
+
time: number;
|
|
130
|
+
};
|
|
114
131
|
}
|
|
115
132
|
interface Context {
|
|
116
133
|
canvas: {
|
package/lib/index.js
CHANGED
|
@@ -1736,6 +1736,118 @@ async function _do_broadcast(ctx, session, msg, masterQQ) {
|
|
|
1736
1736
|
await session.send(build_msg(session, session.text("tip.broadcast.success")));
|
|
1737
1737
|
}
|
|
1738
1738
|
__name(_do_broadcast, "_do_broadcast");
|
|
1739
|
+
function getBattleDay() {
|
|
1740
|
+
const d = /* @__PURE__ */ new Date();
|
|
1741
|
+
return `${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, "0")}${String(d.getDate()).padStart(2, "0")}`;
|
|
1742
|
+
}
|
|
1743
|
+
__name(getBattleDay, "getBattleDay");
|
|
1744
|
+
async function getTopStar(ctx, qq) {
|
|
1745
|
+
const cards = await ctx.database.get("gacha_user_card", { qq });
|
|
1746
|
+
const pool = await ctx.database.get("gacha_card_pool", {});
|
|
1747
|
+
const event = await ctx.database.get("gacha_event_pool", {});
|
|
1748
|
+
const all = [...pool, ...event];
|
|
1749
|
+
let max = 0;
|
|
1750
|
+
for (const uc of cards) {
|
|
1751
|
+
const c = all.find((x) => x.card_id === uc.card_id);
|
|
1752
|
+
if (!c) continue;
|
|
1753
|
+
const s = c.card_star;
|
|
1754
|
+
if (s === 6 || s === 7) {
|
|
1755
|
+
if (s > max) max = s;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return max;
|
|
1759
|
+
}
|
|
1760
|
+
__name(getTopStar, "getTopStar");
|
|
1761
|
+
var battlePending = /* @__PURE__ */ new Map();
|
|
1762
|
+
async function doBattleChallenge(ctx, session, tqq) {
|
|
1763
|
+
const qq = session.userId;
|
|
1764
|
+
if (!qq || !tqq) return;
|
|
1765
|
+
if (qq === tqq) return await session.send("不能挑战自己~");
|
|
1766
|
+
const today = getBattleDay();
|
|
1767
|
+
const me = await ctx.database.get("gacha_battle_user", { qq });
|
|
1768
|
+
const m = me[0] || { qq, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: today };
|
|
1769
|
+
if (m.day_date !== today) m.day_count = 0;
|
|
1770
|
+
if (m.day_count >= 10) return await session.send("今日对战次数已用完(每日10场)");
|
|
1771
|
+
const starMe = await getTopStar(ctx, qq);
|
|
1772
|
+
const starYou = await getTopStar(ctx, tqq);
|
|
1773
|
+
if (starMe < 6 || starYou < 6) return await session.send("双方必须拥有6星或7星卡才能对战");
|
|
1774
|
+
if (starMe !== starYou) return await session.send(`必须同星级对战!你的最高:${starMe}星,对方最高:${starYou}星`);
|
|
1775
|
+
battlePending.set(tqq, { from: qq, to: tqq, star: starMe, time: Date.now() });
|
|
1776
|
+
await session.send(`✅ 已向【${tqq}】发起挑战,请对方回复:同意 / 拒绝`);
|
|
1777
|
+
}
|
|
1778
|
+
__name(doBattleChallenge, "doBattleChallenge");
|
|
1779
|
+
async function doBattleAgree(ctx, session) {
|
|
1780
|
+
const qq = session.userId;
|
|
1781
|
+
if (!qq || !battlePending.has(qq)) return;
|
|
1782
|
+
const pen = battlePending.get(qq);
|
|
1783
|
+
battlePending.delete(qq);
|
|
1784
|
+
const star = pen.star;
|
|
1785
|
+
const p1 = pen.from;
|
|
1786
|
+
const p2 = qq;
|
|
1787
|
+
const power1 = star * 100 + Math.floor(Math.random() * 51);
|
|
1788
|
+
const power2 = star * 100 + Math.floor(Math.random() * 51);
|
|
1789
|
+
const win = power1 >= power2 ? p1 : p2;
|
|
1790
|
+
const lose = win === p1 ? p2 : p1;
|
|
1791
|
+
const wd = await ctx.database.get("gacha_battle_user", { qq: win });
|
|
1792
|
+
const w = wd[0] || { qq: win, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: getBattleDay() };
|
|
1793
|
+
w.win++;
|
|
1794
|
+
w.streak++;
|
|
1795
|
+
if (w.streak > w.max_streak) w.max_streak = w.streak;
|
|
1796
|
+
const x = Math.min(w.streak, 10);
|
|
1797
|
+
const reward = Math.floor(50 * (1 + 0.1 * x));
|
|
1798
|
+
const ld = await ctx.database.get("gacha_battle_user", { qq: lose });
|
|
1799
|
+
const l = ld[0] || { qq: lose, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: getBattleDay() };
|
|
1800
|
+
l.lose++;
|
|
1801
|
+
l.streak = 0;
|
|
1802
|
+
const today = getBattleDay();
|
|
1803
|
+
const p1data = await ctx.database.get("gacha_battle_user", { qq: p1 });
|
|
1804
|
+
const p1d = p1data[0] || { qq: p1, day_count: 0, day_date: today };
|
|
1805
|
+
if (p1d.day_date !== today) p1d.day_count = 0;
|
|
1806
|
+
p1d.day_count++;
|
|
1807
|
+
await ctx.database.upsert("gacha_battle_user", [w, l, p1d]);
|
|
1808
|
+
await ctx.database.create("gacha_battle_log", {
|
|
1809
|
+
qq1: p1,
|
|
1810
|
+
qq2: p2,
|
|
1811
|
+
star,
|
|
1812
|
+
win_qq: win,
|
|
1813
|
+
time: Date.now()
|
|
1814
|
+
});
|
|
1815
|
+
const asset = await ctx.database.get("gacha_user_draw_count", { qq: win });
|
|
1816
|
+
const v = asset[0]?.water_vapor || 0;
|
|
1817
|
+
await ctx.database.upsert("gacha_user_draw_count", [{
|
|
1818
|
+
qq: win,
|
|
1819
|
+
water_vapor: v + reward
|
|
1820
|
+
}]);
|
|
1821
|
+
await session.send(`
|
|
1822
|
+
⚔️ 对战结果
|
|
1823
|
+
【${p1}】${star}星 战力:${power1}
|
|
1824
|
+
【${p2}】${star}星 战力:${power2}
|
|
1825
|
+
🎉 胜利:${win}(奖励水汽 +${reward})`);
|
|
1826
|
+
}
|
|
1827
|
+
__name(doBattleAgree, "doBattleAgree");
|
|
1828
|
+
async function doBattleRecord(ctx, session) {
|
|
1829
|
+
const qq = session.userId;
|
|
1830
|
+
if (!qq) return;
|
|
1831
|
+
const d = await ctx.database.get("gacha_battle_user", { qq });
|
|
1832
|
+
const u = d[0] || { qq, win: 0, lose: 0, streak: 0, max_streak: 0 };
|
|
1833
|
+
const total = u.win + u.lose;
|
|
1834
|
+
const rate = total > 0 ? (u.win / total * 100).toFixed(1) : "0.0";
|
|
1835
|
+
const logs = await ctx.database.get("gacha_battle_log", {
|
|
1836
|
+
$or: [{ qq1: qq }, { qq2: qq }]
|
|
1837
|
+
}, { sort: { time: "desc" }, limit: 5 });
|
|
1838
|
+
let msg = `📊 对战数据
|
|
1839
|
+
胜场:${u.win} | 负场:${u.lose} | 胜率:${rate}%
|
|
1840
|
+
当前连胜:${u.streak} | 最大连胜:${u.max_streak}
|
|
1841
|
+
|
|
1842
|
+
最近5场:`;
|
|
1843
|
+
for (const log of logs) {
|
|
1844
|
+
const res = log.win_qq === qq ? "胜" : "负";
|
|
1845
|
+
msg += `
|
|
1846
|
+
${res} ${log.qq1} vs ${log.qq2}`;
|
|
1847
|
+
}
|
|
1848
|
+
await session.send(msg);
|
|
1849
|
+
}
|
|
1850
|
+
__name(doBattleRecord, "doBattleRecord");
|
|
1739
1851
|
async function _do_help(ctx, session) {
|
|
1740
1852
|
const helpMsg = session.text("command.wwc.help.title") + "\n" + session.text("command.wwc.help.register") + "\n" + session.text("command.wwc.help.sign") + "\n" + session.text("command.wwc.help.draw") + "\n" + session.text("command.wwc.help.warehouse") + "\n" + session.text("command.wwc.help.shop") + "\n" + session.text("command.wwc.help.upgrade") + "\n" + session.text("command.wwc.help.exchange") + "\n" + session.text("command.wwc.help.collection") + "\n" + session.text("command.wwc.help.ranking") + "\n" + session.text("command.wwc.help.eventStatus") + "\n" + session.text("command.wwc.help.eventDraw") + "\n" + session.text("command.wwc.help.eventExchange") + "\n" + session.text("command.wwc.help.tip");
|
|
1741
1853
|
await session.send(build_msg(session, helpMsg));
|
|
@@ -1837,6 +1949,24 @@ async function apply(ctx, config) {
|
|
|
1837
1949
|
got6: { type: "boolean" },
|
|
1838
1950
|
got7: { type: "boolean" }
|
|
1839
1951
|
}, { primary: ["qq", "event_code"] });
|
|
1952
|
+
ctx.model.extend("gacha_battle_user", {
|
|
1953
|
+
qq: { type: "string" },
|
|
1954
|
+
win: { type: "integer" },
|
|
1955
|
+
lose: { type: "integer" },
|
|
1956
|
+
streak: { type: "integer" },
|
|
1957
|
+
max_streak: { type: "integer" },
|
|
1958
|
+
day_count: { type: "integer" },
|
|
1959
|
+
day_date: { type: "string" }
|
|
1960
|
+
}, { primary: ["qq"] });
|
|
1961
|
+
ctx.model.extend("gacha_battle_log", {
|
|
1962
|
+
id: { type: "integer" },
|
|
1963
|
+
qq1: { type: "string" },
|
|
1964
|
+
qq2: { type: "string" },
|
|
1965
|
+
star: { type: "integer" },
|
|
1966
|
+
win_qq: { type: "string" },
|
|
1967
|
+
time: { type: "integer" }
|
|
1968
|
+
}, { primary: ["id"] });
|
|
1969
|
+
const battlePending2 = /* @__PURE__ */ new Map();
|
|
1840
1970
|
await ctx.database.upsert("gacha_global_switch", [{ id: 1, status: 0 }]);
|
|
1841
1971
|
await ctx.database.upsert("gacha_sign_config", [{ id: 1, reset_hour: config.signResetHour, reset_minute: config.signResetMinute }]);
|
|
1842
1972
|
await ctx.database.get("gacha_user_sign", { qq: "init" }).catch(() => {
|
|
@@ -1963,6 +2093,37 @@ async function apply(ctx, config) {
|
|
|
1963
2093
|
const msg = content.join(" ").trim();
|
|
1964
2094
|
await _do_broadcast(ctx, session, msg, config.masterQQ);
|
|
1965
2095
|
});
|
|
2096
|
+
ctx.command("WWC对战", "挑战他人对战(必须@)").action(async (argv) => {
|
|
2097
|
+
const session = argv.session;
|
|
2098
|
+
if (!session) return;
|
|
2099
|
+
let targetQQ = null;
|
|
2100
|
+
const content = session.content ?? "";
|
|
2101
|
+
const atMatch = content.match(/\[CQ:at,qq=(\d+)\]/);
|
|
2102
|
+
if (atMatch) {
|
|
2103
|
+
targetQQ = atMatch[1];
|
|
2104
|
+
}
|
|
2105
|
+
if (!targetQQ) {
|
|
2106
|
+
return await session.send(build_msg(session, "请@你要挑战的人,例如:WWC对战@XXX"));
|
|
2107
|
+
}
|
|
2108
|
+
await doBattleChallenge(ctx, session, targetQQ);
|
|
2109
|
+
});
|
|
2110
|
+
ctx.command("同意", "同意对战").action(async (argv) => {
|
|
2111
|
+
const session = argv.session;
|
|
2112
|
+
if (session) await doBattleAgree(ctx, session);
|
|
2113
|
+
});
|
|
2114
|
+
ctx.command("拒绝", "拒绝对战").action(async (argv) => {
|
|
2115
|
+
const session = argv.session;
|
|
2116
|
+
if (!session) return;
|
|
2117
|
+
const qq = session.userId;
|
|
2118
|
+
if (battlePending2.has(qq)) {
|
|
2119
|
+
battlePending2.delete(qq);
|
|
2120
|
+
await session.send("已拒绝对战");
|
|
2121
|
+
}
|
|
2122
|
+
});
|
|
2123
|
+
ctx.command("WWC对战记录", "查看对战数据、胜率、连胜、最近5场").action(async (argv) => {
|
|
2124
|
+
const session = argv.session;
|
|
2125
|
+
if (session) await doBattleRecord(ctx, session);
|
|
2126
|
+
});
|
|
1966
2127
|
ctx.command("WWChelp", "查看所有WWC指令的完整用法、示例和权限说明").alias("wwchelp").alias("WWC帮助").action(async (argv) => {
|
|
1967
2128
|
if (!argv.session) return;
|
|
1968
2129
|
const session = argv.session;
|