koishi-plugin-game-mini 0.2.8 → 0.2.9
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 +0 -1
- package/lib/index.js +28 -65
- package/package.json +1 -1
- package/readme.md +0 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -241,7 +241,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
241
241
|
autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
|
|
242
242
|
maxRounds: koishi_1.Schema.number().min(0).default(10).description('最大接龙回合数(0为无限)'),
|
|
243
243
|
botParticipate: koishi_1.Schema.boolean().default(false).description('机器人是否参与接龙'),
|
|
244
|
-
rewardScore: koishi_1.Schema.number().min(0).default(1).description('接龙成功奖励分数'),
|
|
245
244
|
messages: koishi_1.Schema.object({
|
|
246
245
|
usage: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.usage).description('用法错误提示'),
|
|
247
246
|
start: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.start).description('游戏开始提示\n{0}-总回合数'),
|
|
@@ -677,33 +676,23 @@ async function apply(ctx, cfg) {
|
|
|
677
676
|
};
|
|
678
677
|
const scheduleAutoPlay = (session, key, st) => {
|
|
679
678
|
clearAllTimers(st);
|
|
680
|
-
if (
|
|
681
|
-
|
|
679
|
+
if (st.chengyuJielong.currentRound === 1 && st.chengyuJielong.jielongCount === 0) {
|
|
680
|
+
const delay = 100;
|
|
681
|
+
st.chengyuJielong.autoPlayTimer = setTimeout(() => {
|
|
682
|
+
doAutoPlay(session, key, st);
|
|
683
|
+
}, delay);
|
|
682
684
|
return;
|
|
683
685
|
}
|
|
684
|
-
if (
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
doAutoPlay(session, key, st);
|
|
691
|
-
}, delay);
|
|
686
|
+
if (cfg.chengyuJielong.botParticipate && st.chengyuJielong.botTurn) {
|
|
687
|
+
const delay = cfg.chengyuJielong.autoPlayDelay * 1000;
|
|
688
|
+
st.chengyuJielong.autoPlayTimer = setTimeout(() => {
|
|
689
|
+
doAutoPlay(session, key, st);
|
|
690
|
+
}, delay);
|
|
691
|
+
}
|
|
692
692
|
};
|
|
693
693
|
const doAutoPlay = async (session, key, st) => {
|
|
694
694
|
if (!st.chengyuJielong.started)
|
|
695
695
|
return;
|
|
696
|
-
if (st.chengyuJielong.hasTriggeredAutoPlay)
|
|
697
|
-
return;
|
|
698
|
-
if (st.chengyuJielong.autoPlayCount >= cfg.chengyuJielong.autoPlayMaxCount) {
|
|
699
|
-
st.chengyuJielong.hasTriggeredAutoPlay = true;
|
|
700
|
-
gameStates.set(key, st);
|
|
701
|
-
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
st.chengyuJielong.hasTriggeredAutoPlay = true;
|
|
705
|
-
st.chengyuJielong.autoPlayCount += 1;
|
|
706
|
-
gameStates.set(key, st);
|
|
707
696
|
try {
|
|
708
697
|
const intUserId = getIntUserId(session);
|
|
709
698
|
const r = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
|
|
@@ -723,14 +712,17 @@ async function apply(ctx, cfg) {
|
|
|
723
712
|
m = d.chengyuJielong.botTurn.replace('{0}', sys.idiom);
|
|
724
713
|
st.chengyuJielong.lastChar = dt.data.current_char || '';
|
|
725
714
|
st.chengyuJielong.jielongCount += 1;
|
|
715
|
+
st.chengyuJielong.botTurn = false;
|
|
716
|
+
await session.send(m);
|
|
726
717
|
}
|
|
727
718
|
else {
|
|
728
719
|
m = dt.msg || d.chengyuJielong.botWin;
|
|
729
720
|
st.chengyuJielong.currentRound += 1;
|
|
721
|
+
st.chengyuJielong.botTurn = true;
|
|
722
|
+
await session.send(m);
|
|
730
723
|
if (st.chengyuJielong.currentRound > st.chengyuJielong.totalRounds) {
|
|
731
724
|
st.chengyuJielong.started = false;
|
|
732
725
|
clearAllTimers(st);
|
|
733
|
-
await session.send(m);
|
|
734
726
|
await session.send(d.chengyuJielong.gameEnd);
|
|
735
727
|
if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
|
|
736
728
|
const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
@@ -741,13 +733,12 @@ async function apply(ctx, cfg) {
|
|
|
741
733
|
return;
|
|
742
734
|
}
|
|
743
735
|
else {
|
|
744
|
-
|
|
736
|
+
await session.send(d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString()));
|
|
745
737
|
}
|
|
746
738
|
}
|
|
747
739
|
if (cfg.chengyuJielong.maxRounds > 0 && st.chengyuJielong.jielongCount >= cfg.chengyuJielong.maxRounds) {
|
|
748
740
|
st.chengyuJielong.started = false;
|
|
749
741
|
clearAllTimers(st);
|
|
750
|
-
await session.send(m);
|
|
751
742
|
await session.send(d.chengyuJielong.gameEnd);
|
|
752
743
|
if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
|
|
753
744
|
const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
@@ -757,7 +748,6 @@ async function apply(ctx, cfg) {
|
|
|
757
748
|
gameStates.set(key, st);
|
|
758
749
|
return;
|
|
759
750
|
}
|
|
760
|
-
await session.send(m);
|
|
761
751
|
}
|
|
762
752
|
catch (error) {
|
|
763
753
|
await session.send(d.chengyuJielong.apiError);
|
|
@@ -796,10 +786,14 @@ async function apply(ctx, cfg) {
|
|
|
796
786
|
st.chengyuJielong.participants.push(playerKey);
|
|
797
787
|
await updatePlayerPlayCount(session);
|
|
798
788
|
}
|
|
789
|
+
if (st.chengyuJielong.botTurn) {
|
|
790
|
+
await session.send('现在是机器人的回合,请稍候...');
|
|
791
|
+
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
799
794
|
if (!isFourCharIdiom(content)) {
|
|
800
795
|
await session.send(d.chengyuJielong.notIdiom);
|
|
801
796
|
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
802
|
-
scheduleAutoPlay(session, key, st);
|
|
803
797
|
return;
|
|
804
798
|
}
|
|
805
799
|
try {
|
|
@@ -821,9 +815,7 @@ async function apply(ctx, cfg) {
|
|
|
821
815
|
if (dt.data?.user) {
|
|
822
816
|
m += d.chengyuJielong.correct + '\n';
|
|
823
817
|
m += `你的成语:${dt.data.user.idiom}\n`;
|
|
824
|
-
st.chengyuJielong.
|
|
825
|
-
st.chengyuJielong.players[playerKey].correctCount += 1;
|
|
826
|
-
await savePlayerData(session, st.chengyuJielong.players[playerKey]);
|
|
818
|
+
st.chengyuJielong.botTurn = true;
|
|
827
819
|
}
|
|
828
820
|
else {
|
|
829
821
|
m += d.chengyuJielong.wrong + '\n';
|
|
@@ -834,35 +826,8 @@ async function apply(ctx, cfg) {
|
|
|
834
826
|
st.chengyuJielong.jielongCount += 1;
|
|
835
827
|
}
|
|
836
828
|
st.chengyuJielong.currentRound += 1;
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
clearAllTimers(st);
|
|
840
|
-
await session.send(m);
|
|
841
|
-
await session.send(d.chengyuJielong.gameEnd);
|
|
842
|
-
if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
|
|
843
|
-
const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
844
|
-
await session.send(rankText);
|
|
845
|
-
}
|
|
846
|
-
clearGameData(st.chengyuJielong);
|
|
847
|
-
gameStates.set(key, st);
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
if (st.chengyuJielong.currentRound > st.chengyuJielong.totalRounds) {
|
|
851
|
-
st.chengyuJielong.started = false;
|
|
852
|
-
clearAllTimers(st);
|
|
853
|
-
await session.send(m);
|
|
854
|
-
await session.send(d.chengyuJielong.gameEnd);
|
|
855
|
-
if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
|
|
856
|
-
const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
857
|
-
await session.send(rankText);
|
|
858
|
-
}
|
|
859
|
-
clearGameData(st.chengyuJielong);
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
m += '\n' + d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString());
|
|
863
|
-
await session.send(m);
|
|
864
|
-
st.chengyuJielong.hasTriggeredAutoPlay = false;
|
|
865
|
-
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
829
|
+
await session.send(m);
|
|
830
|
+
if (cfg.chengyuJielong.botParticipate && st.chengyuJielong.botTurn) {
|
|
866
831
|
scheduleAutoPlay(session, key, st);
|
|
867
832
|
}
|
|
868
833
|
}
|
|
@@ -874,9 +839,8 @@ async function apply(ctx, cfg) {
|
|
|
874
839
|
}
|
|
875
840
|
catch (error) {
|
|
876
841
|
await session.send(d.chengyuJielong.apiError);
|
|
877
|
-
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
878
|
-
scheduleAutoPlay(session, key, st);
|
|
879
842
|
}
|
|
843
|
+
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
880
844
|
gameStates.set(key, st);
|
|
881
845
|
return;
|
|
882
846
|
}
|
|
@@ -1354,13 +1318,12 @@ async function apply(ctx, cfg) {
|
|
|
1354
1318
|
if (action === '开始') {
|
|
1355
1319
|
st.chengyuJielong.started = true;
|
|
1356
1320
|
st.chengyuJielong.currentRound = 1;
|
|
1357
|
-
st.chengyuJielong.hasTriggeredAutoPlay = false;
|
|
1358
1321
|
st.chengyuJielong.autoPlayCount = 0;
|
|
1359
1322
|
st.chengyuJielong.jielongCount = 0;
|
|
1323
|
+
st.chengyuJielong.botTurn = true;
|
|
1324
|
+
st.chengyuJielong.hasTriggeredAutoPlay = false;
|
|
1360
1325
|
await session.send(d.chengyuJielong.start.replace('{0}', st.chengyuJielong.totalRounds.toString()));
|
|
1361
|
-
|
|
1362
|
-
scheduleAutoPlay(session, key, st);
|
|
1363
|
-
}, 100);
|
|
1326
|
+
scheduleAutoPlay(session, key, st);
|
|
1364
1327
|
gameStates.set(key, st);
|
|
1365
1328
|
setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
|
|
1366
1329
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -118,7 +118,6 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
|
|
|
118
118
|
| `chengyuJielong.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
|
|
119
119
|
| `chengyuJielong.maxRounds` | 最大接龙回合数(0为无限) | 10 |
|
|
120
120
|
| `chengyuJielong.botParticipate` | 机器人是否参与接龙 | false |
|
|
121
|
-
| `chengyuJielong.rewardScore` | 接龙成功奖励分数 | 1 |
|
|
122
121
|
| **🧮 算24点配置** | | |
|
|
123
122
|
| `calc24.totalRounds` | 总回合数 | 5 |
|
|
124
123
|
| `calc24.showRank` | 游戏结束后显示本局排行榜 | true |
|
|
@@ -187,7 +186,6 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
|
|
|
187
186
|
| `chengyuJielong.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
|
|
188
187
|
| `chengyuJielong.maxRounds` | Maximum solitaire rounds (0 for unlimited) | 10 |
|
|
189
188
|
| `chengyuJielong.botParticipate` | Whether bot participates in solitaire | false |
|
|
190
|
-
| `chengyuJielong.rewardScore` | Reward score for successful solitaire | 1 |
|
|
191
189
|
| **🧮 24-Point Calculation Configuration** | | |
|
|
192
190
|
| `calc24.totalRounds` | Total rounds | 5 |
|
|
193
191
|
| `calc24.showRank` | Show rank after game ends | true |
|