with one click
battle-system
处理战斗系统、血量显示、battle_status API接口等相关功能
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
处理战斗系统、血量显示、battle_status API接口等相关功能
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
This skill should be used when the user reports "白屏" after switching between old and new UI, mentions "新老界面切换", or discusses blank screen issues when switching between JSP (old) and Vue (new) interfaces.
处理装备按钮重复累积问题和相关游戏优化
| name | battle-system |
| description | 处理战斗系统、血量显示、battle_status API接口等相关功能 |
| version | 1.0.0 |
这个技能涵盖了 Pike9 MUD 游戏中的战斗系统相关功能,包括战斗状态 API、NPC 血量显示、战斗属性获取等。
/api/battle_status 接口获取当前战斗状态,包括玩家和敌人的信息。
请求参数:
txd: TXD 认证字符串返回数据结构:
{
"in_battle": true,
"player": {
"userid": "xd01jinghaha",
"name_cn": "无心法师",
"hp": 38,
"hp_max": 70,
"level": 1,
"exp": 60,
"exp_need": 800,
"energy": 64,
"mana": 0,
"profe": "剑仙",
"race": "人类"
},
"enemy": {
"name": "tulou1",
"name_cn": "土蝼",
"is_npc": 1,
"level": 1,
"hp": 60,
"hp_max": 100,
"is_dead": 0,
"profe": "野兽",
"race": "野兽",
"attack": 10,
"defend": 5
}
}
NPC 的血量使用以下函数获取:
// 获取当前血量
int get_cur_life()
// 获取最大血量
int query_life_max()
重要: NPC 使用 life/life_max 变量,而不是玩家的 jing/jing_max。
// 检查函数是否存在
if(functionp(enemy_obj->get_cur_life)) {
e_hp = enemy_obj->get_cur_life();
}
if(functionp(enemy_obj->query_life_max)) {
e_hp_max = enemy_obj->query_life_max();
}
// -1 表示死亡,转为 0
if(e_hp < 0) {
e_hp = 0;
}
enemy_state["hp"] = e_hp;
enemy_state["hp_max"] = e_hp_max;
enemy_state["is_dead"] = (e_hp <= 0);
| 属性 | 说明 | 获取方法 |
|---|---|---|
| hp | 当前血量 | get_cur_life() |
| hp_max | 最大血量 | query_life_max() |
| level | 等级 | query_level() |
| exp | 经验值 | query_exp() |
| exp_need | 升级所需经验 | query_levelUp_need_exp() |
| energy | 精力 | query_jingli() |
| mana | 法力 | get_cur_mofa() |
| mana_max | 最大法力 | query_mofa_max() |
| profe | 职业 | query_profe_cn() |
| race | 种族 | query_race_cn() |
| 属性 | 说明 | 获取方法 |
|---|---|---|
| name | 内部名称 | query_name() |
| name_cn | 显示名称 | query_name_cn() |
| is_npc | 是否为NPC | is_npc() |
| level | 等级 | query_level() |
| hp | 当前血量 | get_cur_life() |
| hp_max | 最大血量 | query_life_max() |
| profe | 职业/种类 | query_profe_cn() |
| race | 种族 | query_race_cn() |
| attack | 攻击力 | query_attack_power() |
| defend | 防御力 | query_defend_power() |
gamelib/single/daemons/http_api_daemon.pike - HTTP API 主文件
handle_api_battle_status() - 战斗状态接口lowlib/wapmud2/inherit/feature/fight.pike - 战斗系统核心
lowlib/wapmud2/inherit/npc.pike - NPC 基类
life / life_max 变量lowlib/mudlib/inherit/feature/char.pike - 角色属性
get_cur_life() - 获取当前血量query_life_max() - 获取最大血量lowlib/wapmud2/cmds/kill_quick.pike - 快速战斗命令通过 HTTP API (新界面/Vue前端) 登录的玩家自动获得 50% 经验加成,鼓励玩家使用新界面。
文件: lowlib/wapmud2/inherit/user.pike
// HTTP API 用户标记 - 用于经验加成等特殊功能
int is_http_api_user;
文件: lowlib/system/cmds/login_check.pike
HTTP API 登录时设置标记:
// HTTP API 模式检测:检查全局标记
int is_http_api = is_http_api_login(user_name);
if(is_http_api) {
// 标记玩家为 HTTP API 用户(用于经验加成等)
me->is_http_api_user = 1;
// 不调用 exec(),更新虚拟连接池
http_api_daemon->set_virtual_connection(user_name, ({0, time(), me}));
}
Socket (老界面) 登录时重置标记:
} else {
// Socket 模式:重置 HTTP API 标记,正常调用 exec()
me->is_http_api_user = 0;
exec(me,previous_object());
destruct(previous_object());
}
文件: lowlib/mudlib/inherit/feature/level.pike
/**
* 添加经验值(HTTP API 用户自动获得 50% 加成)
* @param base_exp 基础经验值
* @return 实际获得的经验值(含加成)
*/
int add_exp_with_bonus(int base_exp)
{
object me = this_object();
int final_exp = base_exp;
// HTTP API 用户获得 50% 经验加成
if(me->is_http_api_user && base_exp > 0) {
final_exp = base_exp * 3 / 2; // 1.5倍 = 原始 + 50%加成
}
me->exp += final_exp;
me->current_exp += final_exp;
return final_exp;
}
| 位置 | 文件 | 说明 |
|---|---|---|
| 战斗经验 | gamelib/inherit/npc.pike | 击杀怪物获得经验 |
| 任务奖励 | gamelib/single/daemons/taskd.pike | 完成任务获得经验 |
| 自动修炼 | gamelib/single/daemons/autolearnd.pike | 挂机修炼获得经验 |
// 构建 HTTP API 加成提示
string api_tip = "";
if(first->is_http_api_user && actual_exp > exp_gain) {
int bonus = actual_exp - exp_gain;
api_tip = "<font style=\"color:GOLD\">【新界面加成+"+bonus+"】</font> ";
}
t += api_tip + "你得到了 "+actual_exp+" 点经验。\n";
显示效果: 【新界面加成+30】你得到了 90 点经验。
if(player->is_http_api_user && actual_exp > get_exp) {
int bonus = actual_exp - get_exp;
s_rtn = "【新界面加成+"+bonus+"】得到了"+actual_exp+"点经验。\n";
} else {
s_rtn = "得到了"+actual_exp+"点经验。\n";
}
string api_bonus_tip = "";
if(user->is_http_api_user && actual_exp > speed) {
api_bonus_tip = "(含新界面加成)";
}
resultDesc = "你已经修炼了"+ time +"分钟,获得"+ exp +"点经验"+api_bonus_tip+"。";
1. 前端发送 /api 请求(含 txd)
2. http_api_daemon 解码 txd 获取用户名密码
3. 设置 http_api_login_pending[userid] = 1
4. 调用 login_check.pike 进行登录
5. login_check 检测到 http_api_login_pending 标记
6. 设置 me->is_http_api_user = 1
7. 将玩家加入虚拟连接池(不调用 exec())
8. 清除 http_api_login_pending 标记
1. Socket 连接建立
2. 调用 login_check.pike 进行登录
3. http_api_login_pending 标记不存在(值为 0)
4. 设置 me->is_http_api_user = 0
5. 调用 exec() 切换连接
状态切换安全:每次登录时都会重新设置 is_http_api_user 标记
只对正经验加成:base_exp > 0 检查确保损失经验时不触发加成
函数调用检查:所有属性获取都使用 functionp() 检查函数存在性
| 文件 | 作用 |
|---|---|
lowlib/wapmud2/inherit/user.pike | 玩家类,定义 is_http_api_user 标记 |
lowlib/system/cmds/login_check.pike | 登录检测,设置/重置标记 |
lowlib/mudlib/inherit/feature/level.pike | 经验系统,提供 add_exp_with_bonus() |
gamelib/inherit/npc.pike | 战斗经验,应用加成 |
gamelib/single/daemons/taskd.pike | 任务经验,应用加成 |
gamelib/single/daemons/autolearnd.pike | 修炼经验,应用加成 |
gamelib/single/daemons/http_api_daemon.pike | HTTP API,管理虚拟连接 |
原因: 代码使用了错误的变量名 jing/jing_max(玩家的变量),而 NPC 使用的是 life/life_max。
解决: 使用 get_cur_life() 和 query_life_max() 函数。
int is_dead = (e_hp <= 0);
// 或者
int is_dead = (enemy_obj->get_cur_life() <= 0);
// 方法1: 通过 query_attack_target()
if(functionp(enemy_obj->query_attack_target)) {
if(enemy_obj->query_attack_target() == player) {
// 这是敌人的敌人
}
}
// 方法2: 遍历房间生物
array inv = all_inventory(room);
foreach(inv, object ob) {
if(functionp(ob->query_in_combat) && ob->query_in_combat()) {
// 在战斗中
}
}
当用户提到以下问题时,触发此技能: