koishi-plugin-xxck-1 0.2.5 → 0.2.7
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.js +65 -65
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -196,6 +196,7 @@ function splitAndPreserveNames(str) {
|
|
|
196
196
|
}
|
|
197
197
|
__name(splitAndPreserveNames, "splitAndPreserveNames");
|
|
198
198
|
var CARD_LEVEL_MAX = 5;
|
|
199
|
+
var battlePending = /* @__PURE__ */ new Map();
|
|
199
200
|
function build_msg(session, content) {
|
|
200
201
|
const userId = session.userId ?? "";
|
|
201
202
|
if (session.channelId?.startsWith("private")) {
|
|
@@ -1741,95 +1742,85 @@ function getBattleDay() {
|
|
|
1741
1742
|
return `${d.getFullYear()}${String(d.getMonth() + 1).padStart(2, "0")}${String(d.getDate()).padStart(2, "0")}`;
|
|
1742
1743
|
}
|
|
1743
1744
|
__name(getBattleDay, "getBattleDay");
|
|
1744
|
-
async function
|
|
1745
|
-
const
|
|
1745
|
+
async function getUserTopStar(ctx, qq) {
|
|
1746
|
+
const userCards = await ctx.database.get("gacha_user_card", { qq });
|
|
1746
1747
|
const pool = await ctx.database.get("gacha_card_pool", {});
|
|
1747
1748
|
const event = await ctx.database.get("gacha_event_pool", {});
|
|
1748
|
-
const
|
|
1749
|
-
let
|
|
1750
|
-
for (const uc of
|
|
1751
|
-
const
|
|
1752
|
-
if (!
|
|
1753
|
-
const s =
|
|
1749
|
+
const allCards = [...pool, ...event];
|
|
1750
|
+
let maxStar = 0;
|
|
1751
|
+
for (const uc of userCards) {
|
|
1752
|
+
const card = allCards.find((c) => c.card_id === uc.card_id);
|
|
1753
|
+
if (!card) continue;
|
|
1754
|
+
const s = card.card_star;
|
|
1754
1755
|
if (s === 6 || s === 7) {
|
|
1755
|
-
if (s >
|
|
1756
|
+
if (s > maxStar) maxStar = s;
|
|
1756
1757
|
}
|
|
1757
1758
|
}
|
|
1758
|
-
return
|
|
1759
|
+
return maxStar;
|
|
1759
1760
|
}
|
|
1760
|
-
__name(
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
if (
|
|
1765
|
-
if (qq === tqq) return await session.send("不能挑战自己~");
|
|
1761
|
+
__name(getUserTopStar, "getUserTopStar");
|
|
1762
|
+
async function doBattleChallenge(ctx, session, targetQQ) {
|
|
1763
|
+
const qq = session.userId?.toString();
|
|
1764
|
+
if (!qq || !targetQQ) return;
|
|
1765
|
+
if (qq === targetQQ) return await session.send(build_msg(session, "不能挑战自己!"));
|
|
1766
1766
|
const today = getBattleDay();
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
if (
|
|
1770
|
-
if (
|
|
1771
|
-
const starMe = await
|
|
1772
|
-
const starYou = await
|
|
1773
|
-
if (starMe < 6 || starYou < 6) return await session.send("双方必须拥有6星或7
|
|
1774
|
-
if (starMe !== starYou) return await session.send(
|
|
1775
|
-
battlePending.set(
|
|
1776
|
-
await session.send(`✅ 已向【${
|
|
1767
|
+
let me = await ctx.database.get("gacha_battle_user", { qq });
|
|
1768
|
+
let userData = me[0] || { qq, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: today };
|
|
1769
|
+
if (userData.day_date !== today) userData.day_count = 0;
|
|
1770
|
+
if (userData.day_count >= 10) return await session.send(build_msg(session, "今日对战次数已达上限(10场)"));
|
|
1771
|
+
const starMe = await getUserTopStar(ctx, qq);
|
|
1772
|
+
const starYou = await getUserTopStar(ctx, targetQQ);
|
|
1773
|
+
if (starMe < 6 || starYou < 6) return await session.send(build_msg(session, "双方必须拥有6星或7星卡"));
|
|
1774
|
+
if (starMe !== starYou) return await session.send(build_msg(session, `必须同星级对战!你:${starMe}星,对方:${starYou}星`));
|
|
1775
|
+
battlePending.set(targetQQ, { from: qq, to: targetQQ, star: starMe, time: Date.now() });
|
|
1776
|
+
await session.send(build_msg(session, `✅ 已向【${targetQQ}】发起挑战,请对方回复:同意`));
|
|
1777
1777
|
}
|
|
1778
1778
|
__name(doBattleChallenge, "doBattleChallenge");
|
|
1779
1779
|
async function doBattleAgree(ctx, session) {
|
|
1780
|
-
const qq = session.userId;
|
|
1780
|
+
const qq = session.userId?.toString();
|
|
1781
1781
|
if (!qq || !battlePending.has(qq)) return;
|
|
1782
1782
|
const pen = battlePending.get(qq);
|
|
1783
1783
|
battlePending.delete(qq);
|
|
1784
|
-
const star = pen.star;
|
|
1785
1784
|
const p1 = pen.from;
|
|
1786
1785
|
const p2 = qq;
|
|
1786
|
+
const star = pen.star;
|
|
1787
1787
|
const power1 = star * 100 + Math.floor(Math.random() * 51);
|
|
1788
1788
|
const power2 = star * 100 + Math.floor(Math.random() * 51);
|
|
1789
|
-
const
|
|
1790
|
-
const
|
|
1791
|
-
|
|
1792
|
-
|
|
1789
|
+
const winQQ = power1 >= power2 ? p1 : p2;
|
|
1790
|
+
const loseQQ = winQQ === p1 ? p2 : p1;
|
|
1791
|
+
let winData = await ctx.database.get("gacha_battle_user", { qq: winQQ });
|
|
1792
|
+
let w = winData[0] || { qq: winQQ, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: getBattleDay() };
|
|
1793
1793
|
w.win++;
|
|
1794
1794
|
w.streak++;
|
|
1795
1795
|
if (w.streak > w.max_streak) w.max_streak = w.streak;
|
|
1796
1796
|
const x = Math.min(w.streak, 10);
|
|
1797
1797
|
const reward = Math.floor(50 * (1 + 0.1 * x));
|
|
1798
|
-
|
|
1799
|
-
|
|
1798
|
+
let loseData = await ctx.database.get("gacha_battle_user", { qq: loseQQ });
|
|
1799
|
+
let l = loseData[0] || { qq: loseQQ, win: 0, lose: 0, streak: 0, max_streak: 0, day_count: 0, day_date: getBattleDay() };
|
|
1800
1800
|
l.lose++;
|
|
1801
1801
|
l.streak = 0;
|
|
1802
1802
|
const today = getBattleDay();
|
|
1803
|
-
|
|
1804
|
-
|
|
1803
|
+
let p1Data = await ctx.database.get("gacha_battle_user", { qq: p1 });
|
|
1804
|
+
let p1d = p1Data[0] || { qq: p1, day_count: 0, day_date: today };
|
|
1805
1805
|
if (p1d.day_date !== today) p1d.day_count = 0;
|
|
1806
1806
|
p1d.day_count++;
|
|
1807
1807
|
await ctx.database.upsert("gacha_battle_user", [w, l, p1d]);
|
|
1808
|
-
await ctx.database.create("gacha_battle_log", {
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
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(`
|
|
1808
|
+
await ctx.database.create("gacha_battle_log", { qq1: p1, qq2: p2, star, win_qq: winQQ, time: Date.now() });
|
|
1809
|
+
let asset = await ctx.database.get("gacha_user_draw_count", { qq: winQQ });
|
|
1810
|
+
let vapor = asset[0]?.water_vapor || 0;
|
|
1811
|
+
await ctx.database.upsert("gacha_user_draw_count", [{ qq: winQQ, water_vapor: vapor + reward }]);
|
|
1812
|
+
await session.send(build_msg(session, `
|
|
1822
1813
|
⚔️ 对战结果
|
|
1823
1814
|
【${p1}】${star}星 战力:${power1}
|
|
1824
1815
|
【${p2}】${star}星 战力:${power2}
|
|
1825
|
-
🎉 胜利:${
|
|
1816
|
+
🎉 胜利:${winQQ}(水汽 +${reward})`));
|
|
1826
1817
|
}
|
|
1827
1818
|
__name(doBattleAgree, "doBattleAgree");
|
|
1828
1819
|
async function doBattleRecord(ctx, session) {
|
|
1829
|
-
const qq = session.userId;
|
|
1820
|
+
const qq = session.userId?.toString();
|
|
1830
1821
|
if (!qq) return;
|
|
1831
|
-
|
|
1832
|
-
|
|
1822
|
+
let data = await ctx.database.get("gacha_battle_user", { qq });
|
|
1823
|
+
let u = data[0] || { qq, win: 0, lose: 0, streak: 0, max_streak: 0 };
|
|
1833
1824
|
const total = u.win + u.lose;
|
|
1834
1825
|
const rate = total > 0 ? (u.win / total * 100).toFixed(1) : "0.0";
|
|
1835
1826
|
const logs = await ctx.database.get("gacha_battle_log", {
|
|
@@ -1838,14 +1829,13 @@ async function doBattleRecord(ctx, session) {
|
|
|
1838
1829
|
let msg = `📊 对战数据
|
|
1839
1830
|
胜场:${u.win} | 负场:${u.lose} | 胜率:${rate}%
|
|
1840
1831
|
当前连胜:${u.streak} | 最大连胜:${u.max_streak}
|
|
1841
|
-
|
|
1842
1832
|
最近5场:`;
|
|
1843
1833
|
for (const log of logs) {
|
|
1844
1834
|
const res = log.win_qq === qq ? "胜" : "负";
|
|
1845
1835
|
msg += `
|
|
1846
1836
|
${res} ${log.qq1} vs ${log.qq2}`;
|
|
1847
1837
|
}
|
|
1848
|
-
await session.send(msg);
|
|
1838
|
+
await session.send(build_msg(session, msg));
|
|
1849
1839
|
}
|
|
1850
1840
|
__name(doBattleRecord, "doBattleRecord");
|
|
1851
1841
|
async function _do_help(ctx, session) {
|
|
@@ -2093,36 +2083,46 @@ async function apply(ctx, config) {
|
|
|
2093
2083
|
const msg = content.join(" ").trim();
|
|
2094
2084
|
await _do_broadcast(ctx, session, msg, config.masterQQ);
|
|
2095
2085
|
});
|
|
2096
|
-
ctx.command("WWC对战", "
|
|
2086
|
+
ctx.command("WWC对战", "挑战他人对战").action(async (argv) => {
|
|
2097
2087
|
const session = argv.session;
|
|
2098
2088
|
if (!session) return;
|
|
2089
|
+
const content = session.content || "";
|
|
2099
2090
|
let targetQQ = null;
|
|
2100
|
-
|
|
2101
|
-
|
|
2091
|
+
const cqMatch = content.match(/\[CQ:at,qq=(\d+)\]/i);
|
|
2092
|
+
if (cqMatch) {
|
|
2093
|
+
targetQQ = cqMatch[1];
|
|
2102
2094
|
} else {
|
|
2103
|
-
const
|
|
2104
|
-
if (
|
|
2095
|
+
const atMatch = content.match(/@(\d+)/);
|
|
2096
|
+
if (atMatch) {
|
|
2097
|
+
targetQQ = atMatch[1];
|
|
2098
|
+
}
|
|
2105
2099
|
}
|
|
2106
2100
|
if (!targetQQ) {
|
|
2107
|
-
return await session.send(build_msg(session, "请@你要挑战的人,如:WWC对战@
|
|
2101
|
+
return await session.send(build_msg(session, "请@你要挑战的人,如:WWC对战@123456"));
|
|
2108
2102
|
}
|
|
2109
2103
|
await doBattleChallenge(ctx, session, targetQQ);
|
|
2110
2104
|
});
|
|
2111
2105
|
ctx.command("同意", "同意对战").action(async (argv) => {
|
|
2112
2106
|
const session = argv.session;
|
|
2113
2107
|
if (!session) return;
|
|
2108
|
+
const qq = session.userId?.toString();
|
|
2109
|
+
if (!qq || !battlePending2.has(qq)) {
|
|
2110
|
+
return await session.send(build_msg(session, "没有待处理的对战请求"));
|
|
2111
|
+
}
|
|
2114
2112
|
await doBattleAgree(ctx, session);
|
|
2115
2113
|
});
|
|
2116
2114
|
ctx.command("拒绝", "拒绝对战").action(async (argv) => {
|
|
2117
2115
|
const session = argv.session;
|
|
2118
2116
|
if (!session) return;
|
|
2119
|
-
const qq = session.userId;
|
|
2120
|
-
if (battlePending2.has(qq)) {
|
|
2117
|
+
const qq = session.userId?.toString();
|
|
2118
|
+
if (qq && battlePending2.has(qq)) {
|
|
2121
2119
|
battlePending2.delete(qq);
|
|
2122
2120
|
await session.send(build_msg(session, "已拒绝对战"));
|
|
2121
|
+
} else {
|
|
2122
|
+
await session.send(build_msg(session, "没有待处理的对战请求"));
|
|
2123
2123
|
}
|
|
2124
2124
|
});
|
|
2125
|
-
ctx.command("WWC对战记录", "
|
|
2125
|
+
ctx.command("WWC对战记录", "查看对战记录").action(async (argv) => {
|
|
2126
2126
|
const session = argv.session;
|
|
2127
2127
|
if (session) await doBattleRecord(ctx, session);
|
|
2128
2128
|
});
|