koishi-plugin-smmcat-gensokyo 0.0.4 → 0.0.5

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 CHANGED
@@ -82,6 +82,8 @@ export type BattleAttribute = {
82
82
  name: string;
83
83
  time: number;
84
84
  }[];
85
+ /** 持有技能 */
86
+ fn?: [];
85
87
  };
86
88
  /** 最后战斗状态 */
87
89
  type LastPlay = {
@@ -132,6 +134,8 @@ export declare const BattleData: {
132
134
  };
133
135
  /** 清理战场 */
134
136
  clearBattleData(session: Session): void;
135
- play(session: Session, atkType: "\u666E\u653B", select?: string): Promise<void>;
137
+ play(session: Session, atkType: string, select?: string): Promise<void>;
136
138
  };
139
+ /** 获取阵容角色名 */
140
+ export declare function getLineupName(agent: BattleAttribute): string;
137
141
  export {};
package/lib/damage.d.ts CHANGED
@@ -10,7 +10,7 @@ type DamageCallback = {
10
10
  interface Callback {
11
11
  (data: DamageConfig): void;
12
12
  }
13
- type DamageConfig = {
13
+ export type DamageConfig = {
14
14
  agent: {
15
15
  self: BattleAttribute;
16
16
  goal: BattleAttribute;
@@ -48,4 +48,6 @@ declare class Damage {
48
48
  }
49
49
  /** 给予目标伤害 */
50
50
  declare function giveDamage(self: BattleAttribute, goal: BattleAttribute, damage: DamageConfig): number;
51
+ /** 伤害额外信息 */
52
+ export declare function moreDamageInfo(damage: DamageConfig): string;
51
53
  export { Damage, giveDamage };
package/lib/index.js CHANGED
@@ -800,7 +800,7 @@ var Damage = class {
800
800
  this.config = {
801
801
  agent: { self: { ...agent.self }, goal: { ...agent.goal } },
802
802
  harm: 0,
803
- default_harm: agent.self.atk + agent.self.gain.atk,
803
+ default_harm: 0,
804
804
  isRealHarm: realHarm,
805
805
  isEvasion: false,
806
806
  isCsp: false,
@@ -809,13 +809,14 @@ var Damage = class {
809
809
  }
810
810
  /** 伤害判定前 */
811
811
  before(fn) {
812
+ this.config.default_harm = this.config.agent.self.atk + this.config.agent.self.gain.atk;
812
813
  fn && fn(this.config);
813
814
  return this;
814
815
  }
815
816
  /** 真实伤害判定 */
816
817
  beforRealHarm(fn) {
817
818
  fn && fn(this.config);
818
- if (this.config.isEvasion) {
819
+ if (this.config.isRealHarm) {
819
820
  this.config.harm = this.config.default_harm;
820
821
  }
821
822
  return this;
@@ -891,6 +892,65 @@ function giveDamage(self, goal, damage) {
891
892
  }
892
893
  }
893
894
  __name(giveDamage, "giveDamage");
895
+ function moreDamageInfo(damage) {
896
+ return (damage.isCsp ? `(暴击!)` : "") + (damage.isEvasion ? `(闪避成功!)` : "") + (damage.isBadDef ? `(未破防!)` : "");
897
+ }
898
+ __name(moreDamageInfo, "moreDamageInfo");
899
+
900
+ // src/skillFn.ts
901
+ var skillFn = {
902
+ "重砍": {
903
+ name: "重砍",
904
+ type: "伤害技" /* 伤害技 */,
905
+ info: "[伤害技]消耗10MP,对敌方一个单位造成基于攻击力1.2倍伤害。该次伤害无视敌方30%防御!(最低无视1防御)",
906
+ mp: 10,
907
+ fn: /* @__PURE__ */ __name(function(agent, agentList, fn) {
908
+ const damageData = new Damage(agent).result({
909
+ before: /* @__PURE__ */ __name((val) => {
910
+ val.default_harm += Math.floor(val.default_harm * 0.2);
911
+ val.agent.goal.def -= Math.floor(val.agent.goal.def * 0.3) || 1;
912
+ }, "before")
913
+ });
914
+ fn({
915
+ damage: damageData,
916
+ type: this.type,
917
+ target: [agent.goal],
918
+ isNext: false
919
+ });
920
+ return `${getLineupName(agent.self)} 释放重砍,对 ${getLineupName(agent.goal)} 造成 ${damageData.harm} 伤害。` + moreDamageInfo(damageData);
921
+ }, "fn")
922
+ },
923
+ "濒死一击": {
924
+ name: "濒死一击",
925
+ type: "伤害技" /* 伤害技 */,
926
+ info: "[伤害技]血量低于40%可释放,消耗20MP,对敌方一个单位造成基于攻击力2倍伤害。该次伤害暴击率提高20%",
927
+ mp: 20,
928
+ fn: /* @__PURE__ */ __name(function(agent, agentList, fn) {
929
+ if (agent.self.hp / (agent.self.maxHp + agent.self.gain.maxHp) < 0.4) {
930
+ const damageData = new Damage(agent).result({
931
+ before: /* @__PURE__ */ __name((val) => {
932
+ val.default_harm += val.default_harm;
933
+ val.agent.self.chr += 200;
934
+ }, "before")
935
+ });
936
+ fn({
937
+ damage: damageData,
938
+ type: this.type,
939
+ target: [agent.goal],
940
+ isNext: false
941
+ });
942
+ return `${getLineupName(agent.self)} 释放濒死一击,对 ${getLineupName(agent.goal)} 造成 ${damageData.harm} 伤害。` + moreDamageInfo(damageData);
943
+ } else {
944
+ fn({
945
+ type: "释放失败" /* 释放失败 */,
946
+ isNext: true,
947
+ err: "释放失败,未达成条件。"
948
+ });
949
+ return ``;
950
+ }
951
+ }, "fn")
952
+ }
953
+ };
894
954
 
895
955
  // src/battle.ts
896
956
  var BattleData = {
@@ -921,8 +981,12 @@ var BattleData = {
921
981
  // 返回队伍信息
922
982
  teamListByUser(userId) {
923
983
  const teamList = [];
984
+ if (!BattleData.teamTemp[userId]) {
985
+ return [];
986
+ }
987
+ const _userId = BattleData.teamTemp[userId].for;
924
988
  Object.keys(BattleData.teamTemp).forEach((item) => {
925
- if (BattleData.teamTemp[item].for == userId) {
989
+ if (BattleData.teamTemp[item].for == _userId) {
926
990
  teamList.push(User.getUserAttributeByUserId(item));
927
991
  }
928
992
  });
@@ -1024,7 +1088,8 @@ var BattleData = {
1024
1088
  team.self.forEach((item) => {
1025
1089
  if (item.hp > 0) {
1026
1090
  selfTemp.push(`lv.${item.lv}[${item.name}]:
1027
- ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${item.maxHp + item.gain.maxHp})`);
1091
+ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${item.maxHp + item.gain.maxHp})
1092
+ MP:${item.mp}/${item.maxMp + item.gain.maxMp}`);
1028
1093
  } else {
1029
1094
  selfTemp.push(`lv.${item.lv}[${item.name}]:已阵亡`);
1030
1095
  }
@@ -1032,7 +1097,8 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
1032
1097
  team.goal.forEach((item) => {
1033
1098
  if (item.hp > 0) {
1034
1099
  goalTemp.push(`lv.${item.lv}[${item.name}]:
1035
- ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${item.maxHp + item.gain.maxHp})`);
1100
+ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${item.maxHp + item.gain.maxHp})
1101
+ MP:${item.mp}/${item.maxMp + item.gain.maxMp}`);
1036
1102
  } else {
1037
1103
  goalTemp.push(`lv.${item.lv}[${item.name}]:已阵亡`);
1038
1104
  }
@@ -1053,9 +1119,9 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
1053
1119
  if (self && goal) {
1054
1120
  return { over: true, type: "平局" };
1055
1121
  } else if (self) {
1056
- return { over: true, type: team.isPK ? "敌方赢" : "防御方赢" };
1122
+ return { over: true, type: team.isPK ? "防御方赢" : "敌方赢" };
1057
1123
  } else if (goal) {
1058
- return { over: true, type: team.isPK ? "我方赢" : "攻击方赢" };
1124
+ return { over: true, type: team.isPK ? "攻击方赢" : "我方赢" };
1059
1125
  }
1060
1126
  return { over: false, type: "未结束" };
1061
1127
  },
@@ -1084,27 +1150,71 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
1084
1150
  for (const agent of allAgentList) {
1085
1151
  if (agent.hp <= 0) continue;
1086
1152
  let lifeGoalList = [];
1153
+ let lifeSelfList = [];
1087
1154
  if (agent.for == "self") {
1088
1155
  lifeGoalList = currentBattle.goal.filter((item) => item.for == "goal" && item.hp > 0);
1156
+ lifeSelfList = currentBattle.self.filter((item) => item.for == "self" && item.hp > 0);
1089
1157
  } else {
1090
1158
  lifeGoalList = currentBattle.self.filter((item) => item.for == "self" && item.hp > 0);
1159
+ lifeSelfList = currentBattle.goal.filter((item) => item.for == "goal" && item.hp > 0);
1091
1160
  }
1092
1161
  if (!lifeGoalList.length) continue;
1093
1162
  let selectGoal = {};
1094
1163
  let isMy = false;
1164
+ let funType = "普攻";
1095
1165
  if (agent.type == "玩家" && agent.userId == session.userId) {
1096
1166
  isMy = true;
1167
+ funType = atkType;
1097
1168
  selectGoal = lifeGoalList.find((item) => item.name == select) || lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
1098
1169
  } else if (agent.type == "玩家") {
1099
1170
  selectGoal = lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
1100
1171
  } else {
1101
1172
  selectGoal = lifeGoalList[Math.floor(Math.random() * lifeGoalList.length)];
1102
1173
  }
1103
- const damageInfo = new Damage({ self: agent, goal: selectGoal }).result();
1104
- giveDamage(agent, selectGoal, damageInfo);
1105
- msgList.push(
1106
- `[${agent.type}]${agent.name} 使用普攻攻击了 [${selectGoal.type}]${selectGoal.name},造成了${damageInfo.harm}伤害。` + (damageInfo.isCsp ? `(暴击!)` : "") + (damageInfo.isEvasion ? `(闪避成功!)` : "") + (damageInfo.isBadDef ? `(未破防!)` : "")
1107
- );
1174
+ const noralAtk = /* @__PURE__ */ __name(() => {
1175
+ const damageInfo = new Damage({ self: agent, goal: selectGoal }).result();
1176
+ giveDamage(agent, selectGoal, damageInfo);
1177
+ msgList.push(
1178
+ `${getLineupName(agent)} 使用普攻攻击了 ${getLineupName(selectGoal)},造成了${damageInfo.harm}伤害。` + moreDamageInfo(damageInfo)
1179
+ );
1180
+ }, "noralAtk");
1181
+ if (funType == "普攻") {
1182
+ noralAtk();
1183
+ } else {
1184
+ if (skillFn[atkType]) {
1185
+ const selectFn = skillFn[atkType];
1186
+ if (selectFn.mp == 0 || agent.mp - selectFn.mp >= 0) {
1187
+ agent.mp -= selectFn.mp;
1188
+ let isNext = false;
1189
+ const fnMsg = selectFn.fn(
1190
+ { self: agent, goal: selectGoal },
1191
+ { selfList: lifeSelfList, goalList: lifeGoalList },
1192
+ (val) => {
1193
+ switch (val.type) {
1194
+ case "伤害技" /* 伤害技 */:
1195
+ val.target.map((goal) => {
1196
+ giveDamage(agent, goal, val.damage);
1197
+ });
1198
+ break;
1199
+ case "释放失败" /* 释放失败 */:
1200
+ val.err && session.send(val.err);
1201
+ default:
1202
+ break;
1203
+ }
1204
+ isNext = val.isNext;
1205
+ }
1206
+ );
1207
+ fnMsg && msgList.push(fnMsg);
1208
+ isNext && noralAtk();
1209
+ } else {
1210
+ await session.send(`MP不足,释放失败!`);
1211
+ noralAtk();
1212
+ }
1213
+ } else {
1214
+ await session.send(`未持有该技能或者该技能不存在,释放失败!`);
1215
+ noralAtk();
1216
+ }
1217
+ }
1108
1218
  }
1109
1219
  await session.send(msgList.length ? `战斗记录:
1110
1220
  ` + msgList.join("\n") : "");
@@ -1116,6 +1226,10 @@ ${generateHealthDisplay(item.hp, item.maxHp + item.gain.maxHp)}(${item.hp}/${ite
1116
1226
  }
1117
1227
  }
1118
1228
  };
1229
+ function getLineupName(agent) {
1230
+ return `[${agent.type}]${agent.name}`;
1231
+ }
1232
+ __name(getLineupName, "getLineupName");
1119
1233
  function initBattleAttribute(data) {
1120
1234
  if ("playName" in data) {
1121
1235
  const userData = data;
@@ -1147,7 +1261,8 @@ function initBattleAttribute(data) {
1147
1261
  hit: 0,
1148
1262
  speed: 0
1149
1263
  },
1150
- buff: []
1264
+ buff: [],
1265
+ fn: []
1151
1266
  };
1152
1267
  return temp;
1153
1268
  } else {
@@ -1179,7 +1294,8 @@ function initBattleAttribute(data) {
1179
1294
  hit: 0,
1180
1295
  speed: 0
1181
1296
  },
1182
- buff: []
1297
+ buff: [],
1298
+ fn: []
1183
1299
  };
1184
1300
  return temp;
1185
1301
  }
@@ -1313,7 +1429,7 @@ function apply(ctx, config) {
1313
1429
  GensokyoMap.initUserPoistion(session, userData);
1314
1430
  const areaInfo = GensokyoMap.getUserCurrentArea(session.userId);
1315
1431
  if (goal) {
1316
- if (!areaInfo.monster.map((i) => i.name).includes(goal)) {
1432
+ if (!areaInfo.monster?.map((i) => i.name).includes(goal)) {
1317
1433
  return `没有在该区域找到该怪物。`;
1318
1434
  }
1319
1435
  const selectMonster = areaInfo.monster.find((i) => i.name == goal);
@@ -1328,6 +1444,11 @@ function apply(ctx, config) {
1328
1444
  if (!userData) return;
1329
1445
  BattleData.play(session, "普攻", goal);
1330
1446
  });
1447
+ ctx.command("幻想乡/打怪技能 <skill> <goal>").action(async ({ session }, skill, goal) => {
1448
+ const userData = await User.getUserAttribute(session);
1449
+ if (!userData) return;
1450
+ BattleData.play(session, skill, goal);
1451
+ });
1331
1452
  ctx.command("打怪pk <goal>").action(async ({ session }, goal) => {
1332
1453
  const userData = await User.getUserAttribute(session);
1333
1454
  if (!userData) return;
@@ -1351,6 +1472,12 @@ function apply(ctx, config) {
1351
1472
  await BattleData.createBattleByUser(session, [{ userId: exist.userId }]);
1352
1473
  }
1353
1474
  });
1475
+ ctx.command("技能查询 <goal>").action(async ({ session }, goal) => {
1476
+ if (!goal) return `请输入技能名,例如 /技能查询 重砍`;
1477
+ if (!skillFn[goal]) return `没有存在 ${goal} 技能!`;
1478
+ return `[${goal}]信息如下:
1479
+ ` + skillFn[goal].info;
1480
+ });
1354
1481
  }
1355
1482
  __name(apply, "apply");
1356
1483
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,74 @@
1
+ import { BattleAttribute } from "./battle";
2
+ import { DamageConfig } from "./damage";
3
+ export declare enum SkillType {
4
+ 释放失败 = "\u91CA\u653E\u5931\u8D25",
5
+ 伤害技 = "\u4F24\u5BB3\u6280",
6
+ 增益技 = "\u589E\u76CA\u6280",
7
+ 治疗技 = "\u6CBB\u7597\u6280",
8
+ 奥义 = "\u5965\u4E49"
9
+ }
10
+ interface DamageSkillParams {
11
+ /** 伤害类型 */
12
+ type: SkillType.伤害技;
13
+ /** 伤害信息 */
14
+ damage: DamageConfig;
15
+ /** 释放目标 */
16
+ target: BattleAttribute[];
17
+ /** 是否衔接普攻 */
18
+ isNext: boolean;
19
+ }
20
+ interface BuffSkillParams {
21
+ type: SkillType.增益技;
22
+ buffs: {
23
+ val: number;
24
+ time: number;
25
+ name: number;
26
+ }[];
27
+ target: BattleAttribute | BattleAttribute[];
28
+ /** 是否衔接普攻 */
29
+ isNext: boolean;
30
+ }
31
+ interface HealSkillParams {
32
+ type: SkillType.治疗技;
33
+ /** 是否衔接普攻 */
34
+ isNext: boolean;
35
+ }
36
+ interface UltimateSkillParams {
37
+ type: SkillType.奥义;
38
+ /** 是否衔接普攻 */
39
+ isNext: boolean;
40
+ }
41
+ interface ErrSkillParams {
42
+ type: SkillType.释放失败;
43
+ /** 是否衔接普攻 */
44
+ isNext: boolean;
45
+ /** 错误提示 */
46
+ err?: string;
47
+ }
48
+ type SkillParams = DamageSkillParams | BuffSkillParams | HealSkillParams | UltimateSkillParams | ErrSkillParams;
49
+ interface SkillConfig<T extends SkillType = SkillType> {
50
+ /** 技能名 */
51
+ name: string;
52
+ /** 技能类型 */
53
+ type: T;
54
+ /** 技能说明 */
55
+ info: string;
56
+ /** 消耗MP */
57
+ mp: number;
58
+ /** 技能函数 */
59
+ fn(agent: {
60
+ self: BattleAttribute;
61
+ goal: BattleAttribute;
62
+ }, agentList: {
63
+ selfList: BattleAttribute[];
64
+ goalList: BattleAttribute[];
65
+ }, cb?: (val: Extract<SkillParams, {
66
+ type: T;
67
+ }>) => void): string;
68
+ }
69
+ type SkillFn = {
70
+ [key: string]: SkillConfig;
71
+ };
72
+ export type UseAtkType = keyof typeof skillFn | '普攻';
73
+ export declare const skillFn: SkillFn;
74
+ export {};
package/lib/test.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare const nameList: {
2
+ 张三: {};
3
+ 李四: {};
4
+ };
5
+ declare const fn: (name: any) => any;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gensokyo",
3
3
  "description": "名为《幻想乡》的文字冒险游戏",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [