This commit is contained in:
2025-10-26 21:24:02 +08:00
parent e73c08abf7
commit 95b2146b6a
3 changed files with 78 additions and 30 deletions

View File

@@ -64,15 +64,23 @@ bool BattleRoom::handleAction(const std::string& username,
const std::string& targetName) {
std::lock_guard<std::mutex> lock(m_mutex);
std::cout << "[DEBUG] handleAction called: user=" << username
<< " skillIndex=" << skillIndex
<< " target=" << targetName << std::endl;
if (!m_isRunning) {
std::cout << "[DEBUG] Battle not running!" << std::endl;
return false;
}
// 检查是否轮到该玩家
if (!isPlayerTurn(username)) {
std::cout << "[DEBUG] Not player's turn! Current turn: " << m_currentTurn << std::endl;
return false;
}
std::cout << "[DEBUG] Executing action..." << std::endl;
// 确定攻击者和防守者
ICharacter* attacker = (m_currentTurn == 0) ? m_char1.get() : m_char2.get();
ICharacter* defender = (m_currentTurn == 0) ? m_char2.get() : m_char1.get();
@@ -89,7 +97,19 @@ bool BattleRoom::handleAction(const std::string& username,
}
if (!skill) {
skill = attacker->getSkill("NormalAttack"); // fallback
std::cerr << "[ERROR] Skill not found for skillIndex " << skillIndex
<< " for character " << attacker->getName()
<< ". Falling back to NormalAttack." << std::endl;
skill = attacker->getSkill("NormalAttack");
}
// 最终检查,如果连普通攻击都没有,就无法继续
if (!skill) {
std::cerr << "[FATAL] Critical error: NormalAttack skill is missing for character "
<< attacker->getName() << ". Cannot proceed with action." << std::endl;
// 在这种严重错误下,也许应该结束战斗或通知玩家
broadcastToBoth(Protocol::buildBattleLog("错误:攻击失败,找不到技能!"));
return false; // 提前退出,防止崩溃
}
// 执行技能