koishi-plugin-smmcat-gensokyo 0.0.3 → 0.0.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/battle.d.ts +12 -0
- package/lib/index.js +128 -11
- package/lib/map.d.ts +5 -0
- package/package.json +1 -1
package/lib/battle.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context, Session } from "koishi";
|
|
2
2
|
import { Config } from ".";
|
|
3
|
+
import { UserBaseAttribute } from "./users";
|
|
3
4
|
declare module 'koishi' {
|
|
4
5
|
interface Tables {
|
|
5
6
|
smm_gensokyo_battle_history: BattleHistory;
|
|
@@ -87,6 +88,7 @@ type LastPlay = {
|
|
|
87
88
|
[keys: string]: {
|
|
88
89
|
self: BattleAttribute[];
|
|
89
90
|
goal: BattleAttribute[];
|
|
91
|
+
isPK?: boolean;
|
|
90
92
|
};
|
|
91
93
|
};
|
|
92
94
|
export declare const BattleData: {
|
|
@@ -98,22 +100,32 @@ export declare const BattleData: {
|
|
|
98
100
|
init(config: Config, ctx: Context): void;
|
|
99
101
|
/** 玩家是否正在战斗 */
|
|
100
102
|
isBattle(session: Session): boolean;
|
|
103
|
+
/** 玩家是否正在战斗 */
|
|
104
|
+
isBattleByUserId(userId: string): boolean;
|
|
101
105
|
/** 玩家是否在队伍中 */
|
|
102
106
|
isTeam(session: Session): boolean;
|
|
107
|
+
isTeamByUserId(userId: string): boolean;
|
|
108
|
+
teamListByUser(userId: string): UserBaseAttribute[];
|
|
103
109
|
/** 创建战斗-与怪物 */
|
|
104
110
|
createBattleByMonster(session: Session, goal: {
|
|
105
111
|
name: string;
|
|
106
112
|
lv: number;
|
|
107
113
|
}[]): Promise<void>;
|
|
114
|
+
/** 创建战斗-与玩家 */
|
|
115
|
+
createBattleByUser(session: Session, goal: {
|
|
116
|
+
userId: string;
|
|
117
|
+
}[]): Promise<void>;
|
|
108
118
|
/** 文本化当前战况 */
|
|
109
119
|
battleSituationTextFormat(team: {
|
|
110
120
|
self: BattleAttribute[];
|
|
111
121
|
goal: BattleAttribute[];
|
|
122
|
+
isPK?: boolean;
|
|
112
123
|
}): string;
|
|
113
124
|
/** 判断输赢 */
|
|
114
125
|
playOver(team: {
|
|
115
126
|
self: BattleAttribute[];
|
|
116
127
|
goal: BattleAttribute[];
|
|
128
|
+
isPK?: boolean;
|
|
117
129
|
}): {
|
|
118
130
|
over: boolean;
|
|
119
131
|
type: string;
|
package/lib/index.js
CHANGED
|
@@ -308,10 +308,24 @@ var GensokyoMap = {
|
|
|
308
308
|
};
|
|
309
309
|
fn && await fn(areaInfo);
|
|
310
310
|
await delay(3e3);
|
|
311
|
-
GensokyoMap.setLocalStoragePoistionData(session.userId);
|
|
312
311
|
userCurrentArea.moveing = false;
|
|
312
|
+
GensokyoMap.setLocalStoragePoistionData(session.userId);
|
|
313
313
|
return;
|
|
314
314
|
},
|
|
315
|
+
/** 查询附近玩家 */
|
|
316
|
+
nearbyPlayersByUserId(userId) {
|
|
317
|
+
const areaData = GensokyoMap.getUserCurrentArea(userId);
|
|
318
|
+
const liveUser = [];
|
|
319
|
+
Object.keys(GensokyoMap.userCurrentLoal).forEach((_userId) => {
|
|
320
|
+
const userItem = GensokyoMap.userCurrentLoal[_userId];
|
|
321
|
+
if (userItem.areaName == areaData.areaName && userItem.floor == areaData.floor) {
|
|
322
|
+
if (userId !== userItem.userId) {
|
|
323
|
+
liveUser.push({ userId: userItem.userId, playName: userItem.playName });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
return liveUser;
|
|
328
|
+
},
|
|
315
329
|
/** 区域信息格式化 */
|
|
316
330
|
userAreaTextFormat(gameName, data) {
|
|
317
331
|
const liveUser = [];
|
|
@@ -893,10 +907,27 @@ var BattleData = {
|
|
|
893
907
|
isBattle(session) {
|
|
894
908
|
return !!BattleData.lastPlay[session.userId];
|
|
895
909
|
},
|
|
910
|
+
/** 玩家是否正在战斗 */
|
|
911
|
+
isBattleByUserId(userId) {
|
|
912
|
+
return !!BattleData.lastPlay[userId];
|
|
913
|
+
},
|
|
896
914
|
/** 玩家是否在队伍中 */
|
|
897
915
|
isTeam(session) {
|
|
898
916
|
return !!BattleData.teamTemp[session.userId];
|
|
899
917
|
},
|
|
918
|
+
isTeamByUserId(userId) {
|
|
919
|
+
return !!BattleData.teamTemp[userId];
|
|
920
|
+
},
|
|
921
|
+
// 返回队伍信息
|
|
922
|
+
teamListByUser(userId) {
|
|
923
|
+
const teamList = [];
|
|
924
|
+
Object.keys(BattleData.teamTemp).forEach((item) => {
|
|
925
|
+
if (BattleData.teamTemp[item].for == userId) {
|
|
926
|
+
teamList.push(User.getUserAttributeByUserId(item));
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
return teamList;
|
|
930
|
+
},
|
|
900
931
|
/** 创建战斗-与怪物 */
|
|
901
932
|
async createBattleByMonster(session, goal) {
|
|
902
933
|
if (BattleData.isBattle(session)) {
|
|
@@ -923,14 +954,69 @@ var BattleData = {
|
|
|
923
954
|
goal.forEach((item) => {
|
|
924
955
|
battle_monsterList.push(initBattleAttribute(Monster.getMonsterAttributeData(item.name, item.lv)));
|
|
925
956
|
});
|
|
957
|
+
const temp = {
|
|
958
|
+
self: battle_user.map((i) => ({ ...i, for: "self" })),
|
|
959
|
+
goal: battle_monsterList.map((i) => ({ ...i, for: "goal" }))
|
|
960
|
+
};
|
|
926
961
|
playUser.forEach((userId) => {
|
|
927
|
-
BattleData.lastPlay[userId] =
|
|
928
|
-
self: battle_user.map((i) => ({ ...i, for: "self" })),
|
|
929
|
-
goal: battle_monsterList.map((i) => ({ ...i, for: "goal" }))
|
|
930
|
-
};
|
|
962
|
+
BattleData.lastPlay[userId] = temp;
|
|
931
963
|
});
|
|
932
964
|
await session.send(`开始与 ${goal.map((i) => i.name).join("、")} 进行战斗`);
|
|
933
965
|
},
|
|
966
|
+
/** 创建战斗-与玩家 */
|
|
967
|
+
async createBattleByUser(session, goal) {
|
|
968
|
+
if (BattleData.isBattle(session)) {
|
|
969
|
+
await session.send("当前正在战斗,还不能逃脱!");
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const battle_self = [];
|
|
973
|
+
const battle_goal = [];
|
|
974
|
+
const playUser = [];
|
|
975
|
+
const lostMsg = [];
|
|
976
|
+
goal = goal.filter((item) => {
|
|
977
|
+
const isBattle = BattleData.isBattleByUserId(item.userId);
|
|
978
|
+
const pyUser = User.userTempData[item.userId];
|
|
979
|
+
if (isBattle) {
|
|
980
|
+
lostMsg.push(`${pyUser.playName}正在参与着一场战斗,无法被PK选中。`);
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
return true;
|
|
984
|
+
});
|
|
985
|
+
if (lostMsg.length) {
|
|
986
|
+
await session.send(lostMsg.join("\n"));
|
|
987
|
+
}
|
|
988
|
+
if (!goal.length) {
|
|
989
|
+
lostMsg.push(`PK失败,无任何目标进行PK`);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (BattleData.isTeam(session) && BattleData.teamTemp[session.userId].identity == "队员") {
|
|
993
|
+
await session.send("你不是队伍的队长,无法主动操作战斗!");
|
|
994
|
+
return;
|
|
995
|
+
} else if (BattleData.isTeam(session)) {
|
|
996
|
+
Object.keys(BattleData.teamTemp).forEach((item) => {
|
|
997
|
+
if (BattleData.teamTemp[item].for == session.userId) {
|
|
998
|
+
playUser.push(item);
|
|
999
|
+
battle_self.push(initBattleAttribute(User.getUserAttributeByUserId(item)));
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
} else {
|
|
1003
|
+
playUser.push(session.userId);
|
|
1004
|
+
battle_self.push(initBattleAttribute(User.getUserAttributeByUserId(session.userId)));
|
|
1005
|
+
}
|
|
1006
|
+
goal.forEach((item) => {
|
|
1007
|
+
playUser.push(item.userId);
|
|
1008
|
+
battle_goal.push(initBattleAttribute(User.getUserAttributeByUserId(item.userId)));
|
|
1009
|
+
});
|
|
1010
|
+
const pkTemp = {
|
|
1011
|
+
self: battle_self.map((i) => ({ ...i, for: "self" })),
|
|
1012
|
+
goal: battle_goal.map((i) => ({ ...i, for: "goal" })),
|
|
1013
|
+
isPK: true
|
|
1014
|
+
};
|
|
1015
|
+
playUser.forEach((userId) => {
|
|
1016
|
+
BattleData.lastPlay[userId] = pkTemp;
|
|
1017
|
+
});
|
|
1018
|
+
await session.send(`开始与玩家 ${battle_goal.map((i) => i.name).join("、")} 进行PK战斗`);
|
|
1019
|
+
},
|
|
934
1020
|
/** 文本化当前战况 */
|
|
935
1021
|
battleSituationTextFormat(team) {
|
|
936
1022
|
const selfTemp = [];
|
|
@@ -951,6 +1037,11 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
|
|
|
951
1037
|
goalTemp.push(`lv.${item.lv}[${item.name}]:已阵亡`);
|
|
952
1038
|
}
|
|
953
1039
|
});
|
|
1040
|
+
if (team.isPK) {
|
|
1041
|
+
return `[当前战况]
|
|
1042
|
+
攻击方:
|
|
1043
|
+
` + selfTemp.join("\n") + "\n\n防御方:\n" + goalTemp.join("\n");
|
|
1044
|
+
}
|
|
954
1045
|
return `[当前战况]
|
|
955
1046
|
我方阵容:
|
|
956
1047
|
` + selfTemp.join("\n") + "\n\n敌方阵容:\n" + goalTemp.join("\n");
|
|
@@ -962,19 +1053,20 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
|
|
|
962
1053
|
if (self && goal) {
|
|
963
1054
|
return { over: true, type: "平局" };
|
|
964
1055
|
} else if (self) {
|
|
965
|
-
return { over: true, type: "敌方赢" };
|
|
1056
|
+
return { over: true, type: team.isPK ? "敌方赢" : "防御方赢" };
|
|
966
1057
|
} else if (goal) {
|
|
967
|
-
return { over: true, type: "我方赢" };
|
|
1058
|
+
return { over: true, type: team.isPK ? "我方赢" : "攻击方赢" };
|
|
968
1059
|
}
|
|
969
1060
|
return { over: false, type: "未结束" };
|
|
970
1061
|
},
|
|
971
1062
|
/** 清理战场 */
|
|
972
1063
|
clearBattleData(session) {
|
|
973
1064
|
if (BattleData.isTeam(session)) {
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1065
|
+
const currentBattle = BattleData.lastPlay[session.userId];
|
|
1066
|
+
const allAgentList = [...currentBattle.goal, ...currentBattle.self].sort((a, b) => b.speed - a.speed);
|
|
1067
|
+
allAgentList.forEach((item) => {
|
|
1068
|
+
if (item.type == "玩家") {
|
|
1069
|
+
delete BattleData.lastPlay[item.userId];
|
|
978
1070
|
}
|
|
979
1071
|
});
|
|
980
1072
|
} else {
|
|
@@ -1003,6 +1095,8 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
|
|
|
1003
1095
|
if (agent.type == "玩家" && agent.userId == session.userId) {
|
|
1004
1096
|
isMy = true;
|
|
1005
1097
|
selectGoal = lifeGoalList.find((item) => item.name == select) || lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
|
|
1098
|
+
} else if (agent.type == "玩家") {
|
|
1099
|
+
selectGoal = lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
|
|
1006
1100
|
} else {
|
|
1007
1101
|
selectGoal = lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
|
|
1008
1102
|
}
|
|
@@ -1234,6 +1328,29 @@ function apply(ctx, config) {
|
|
|
1234
1328
|
if (!userData) return;
|
|
1235
1329
|
BattleData.play(session, "普攻", goal);
|
|
1236
1330
|
});
|
|
1331
|
+
ctx.command("打怪pk <goal>").action(async ({ session }, goal) => {
|
|
1332
|
+
const userData = await User.getUserAttribute(session);
|
|
1333
|
+
if (!userData) return;
|
|
1334
|
+
GensokyoMap.initUserPoistion(session, userData);
|
|
1335
|
+
if (!goal) {
|
|
1336
|
+
await session.send("请选择PK目标!");
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
const nearUserItem = GensokyoMap.nearbyPlayersByUserId(session.userId);
|
|
1340
|
+
const exist = nearUserItem.find((item) => item.playName == goal.trim());
|
|
1341
|
+
if (!exist) {
|
|
1342
|
+
await session.send(`PK失败,当前区域未存在【${goal}】玩家`);
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (BattleData.isTeamByUserId(exist.userId)) {
|
|
1346
|
+
const teamItem = BattleData.teamListByUser(exist.userId);
|
|
1347
|
+
await session.send(`对方有组队,您将扮演攻击方与对方队伍进行战斗。`);
|
|
1348
|
+
await BattleData.createBattleByUser(session, teamItem.map((item) => ({ userId: item.userId })));
|
|
1349
|
+
} else {
|
|
1350
|
+
await session.send(`您将扮演攻击方与对方进行战斗。`);
|
|
1351
|
+
await BattleData.createBattleByUser(session, [{ userId: exist.userId }]);
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1237
1354
|
}
|
|
1238
1355
|
__name(apply, "apply");
|
|
1239
1356
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/map.d.ts
CHANGED
|
@@ -98,6 +98,11 @@ export declare const GensokyoMap: {
|
|
|
98
98
|
setLocalStoragePoistionData(userId: string): Promise<void>;
|
|
99
99
|
/** 用户移动 */
|
|
100
100
|
move(session: Session, type: MoveType, fn?: (area: AreaCallbackData) => Promise<void>): Promise<void>;
|
|
101
|
+
/** 查询附近玩家 */
|
|
102
|
+
nearbyPlayersByUserId(userId: string): {
|
|
103
|
+
userId: string;
|
|
104
|
+
playName: string;
|
|
105
|
+
}[];
|
|
101
106
|
/** 区域信息格式化 */
|
|
102
107
|
userAreaTextFormat(gameName: string, data: AreaCallbackData): string;
|
|
103
108
|
};
|