更新说明
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
xinian
2026-04-05 23:13:06 +08:00
committed by cnb
parent 24b463f0aa
commit d83cf365ac
39 changed files with 307 additions and 111 deletions

View File

@@ -12,27 +12,46 @@
## 2. JS 可调用的 Go 函数
1. `useSkill(skillId: number)`
- 作用指定本回合使用技能
- 示例`useSkill(5001)`
2. `switchPet(catchTime: number)`
- 作用指定本回合切换精灵
- 示例`switchPet(2)`
## 3. `hookaction` 参数字段
基础字段
1. `hookaction.hookaction: boolean`
- effect 链原始判定
2. `hookaction.round: number`
- 当前回合数
3. `hookaction.is_first: boolean`
- 是否先手
4. `hookaction.our: { pet_id, catch_time, hp, max_hp } | null`
- 我方当前精灵
5. `hookaction.opp: { pet_id, catch_time, hp, max_hp } | null`
- 对方当前精灵
6. `hookaction.skills: Array<{ skill_id, pp, can_use }>`
- 我方当前技能快照
AttackValue 映射字段重点
1. `hookaction.our_attack`
2. `hookaction.opp_attack`
结构
```ts
{
skill_id: number;
attack_time: number;
is_critical: number;
lost_hp: number;
gain_hp: number;
remain_hp: number;
max_hp: number;
state: number;
offensive: number;
status: number[]; // 对应 AttackValue.Status[20]
prop: number[]; // 对应 AttackValue.Prop[6]
}
```
其中
- `prop` 索引`[攻, 防, 特攻, 特防, 速度, 命中]`
- 对应值 `> 0` 代表强化`< 0` 代表下降`0` 代表无变化
返回值
@@ -42,50 +61,55 @@
## 4. 脚本示例
### 4.1 第3回合固定放技能
### 4.1 判断对方是否存在强化你问的这个
```js
function hookAction(hookaction) {
if (!hookaction.hookaction) return false;
if (hookaction.round === 3) {
useSkill(5001);
}
return true;
}
```
### 4.2 低血切宠
```js
function hookAction(hookaction) {
if (!hookaction.hookaction) return false;
if (!hookaction.our) return true;
var hpRate = hookaction.our.max_hp > 0 ? hookaction.our.hp / hookaction.our.max_hp : 1;
if (hpRate < 0.3) {
switchPet(2);
}
return true;
}
```
### 4.3 读取技能可用性后出招
```js
function hookAction(hookaction) {
if (!hookaction.hookaction) return false;
for (var i = 0; i < hookaction.skills.length; i++) {
var s = hookaction.skills[i];
if (s.can_use && s.skill_id === 5001) {
useSkill(s.skill_id);
break;
var oppAtk = hookaction.opp_attack;
var oppHasBuff = false;
if (oppAtk && oppAtk.prop) {
for (var i = 0; i < oppAtk.prop.length; i++) {
if (oppAtk.prop[i] > 0) {
oppHasBuff = true;
break;
}
}
}
if (oppHasBuff) {
// 对方有强化时,放一个针对技能
useSkill(5001);
return true;
}
return true;
}
```
### 4.2 判断对方是否有异常状态
```js
function hookAction(hookaction) {
if (!hookaction.hookaction) return false;
var oppAtk = hookaction.opp_attack;
var hasStatus = false;
if (oppAtk && oppAtk.status) {
for (var i = 0; i < oppAtk.status.length; i++) {
if (oppAtk.status[i] > 0) {
hasStatus = true;
break;
}
}
}
if (!hasStatus) {
// 没有异常时尝试上异常
useSkill(6002);
}
return true;
}
```
@@ -116,6 +140,20 @@ interface BossHookSkillContext {
can_use: boolean;
}
interface BossHookAttackContext {
skill_id: number;
attack_time: number;
is_critical: number;
lost_hp: number;
gain_hp: number;
remain_hp: number;
max_hp: number;
state: number;
offensive: number;
status: number[];
prop: number[];
}
interface BossHookActionContext {
hookaction: boolean;
round: number;
@@ -123,6 +161,8 @@ interface BossHookActionContext {
our: BossHookPetContext | null;
opp: BossHookPetContext | null;
skills: BossHookSkillContext[];
our_attack: BossHookAttackContext | null;
opp_attack: BossHookAttackContext | null;
}
declare function hookAction(hookaction: BossHookActionContext): boolean;
@@ -136,38 +176,8 @@ declare function switchPet(catchTime: number): void;
);
```
## 6. Monaco 补全可选
```ts
monaco.languages.registerCompletionItemProvider("javascript", {
provideCompletionItems() {
return {
suggestions: [
{
label: "boss hookAction",
kind: monaco.languages.CompletionItemKind.Snippet,
insertTextRules:
monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
insertText: [
"function hookAction(hookaction) {",
" if (!hookaction.hookaction) return false;",
" if (hookaction.round >= 3) useSkill(5001);",
" return true;",
"}",
].join("\\n"),
documentation: "Boss脚本模板可读取回合/血量并调用 useSkill/switchPet。",
},
],
};
},
});
```
## 7. 后端代码
## 6. 后端代码
- 脚本执行器与函数绑定`modules/config/model/boss_pet.go`
- AI 出手转发`logic/service/fight/input/ai.go`
- BOSS 脚本注入
- `logic/controller/fight_boss野怪和地图怪.go`
- `logic/controller/fight_塔.go`
- AI 出手转发与上下文构建`logic/service/fight/input/ai.go`