Wire attack and combo execution (mobile step 3b)

Port the ActorInstanceBattle combo state machine, CRaceMotionData attack
data, player motion/combo tables, NEW_Attack + OnAttack/OnHit packets and
remote FUNC_ATTACK/FUNC_COMBO playback so keyboard and touch attacks swing
and hit on the real-server path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 20:30:57 +09:00
co-authored by Claude Opus 5.5
parent 5597842d90
commit 260d421bde
14 changed files with 1130 additions and 47 deletions
+2 -2
View File
@@ -1450,8 +1450,8 @@ void initchr() {
PyModule_AddIntConstant(module, "MOTION_MODE_HORSE_FAN", 14);
PyModule_AddIntConstant(module, "MOTION_MODE_HORSE_BELL", 15);
PyModule_AddIntConstant(module, "MOTION_MODE_WEDDING_DRESS", 16);
PyModule_AddIntConstant(module, "MOTION_MODE_CLAW", 17);
PyModule_AddIntConstant(module, "MOTION_MODE_BOW_SPECIAL", 18);
// AVA2 builds without ENABLE_WOLFMAN_CHARACTER: no MODE_CLAW, MODE_BOW_SPECIAL follows WEDDING_DRESS.
PyModule_AddIntConstant(module, "MOTION_MODE_BOW_SPECIAL", 17);
PyModule_AddIntConstant(module, "DIR_NORTH", 0);
PyModule_AddIntConstant(module, "DIR_NORTHEAST", 1);
PyModule_AddIntConstant(module, "DIR_EAST", 2);
+97
View File
@@ -984,6 +984,102 @@ bool GetPlayerMovementYaw(float cameraYaw, float& movementYaw) {
movementYaw = std::fmod(movementYaw + 720.0f, 360.0f);
return true;
}
// CPythonPlayer::SetTarget(dwVID, FALSE) as CPythonPlayerEventHandler::OnHit calls it: a different
// victim replaces the target only once the 1 s target hold has run out. CanChangeTarget and
// IsTargetableInstance are not checked.
static uint32_t s_targetEndTime = 0;
static void SetPlayerHitTarget(uint32_t vid) {
const uint32_t now = GetServerMSec();
if (s_targetVID == vid) {
s_targetEndTime = now + 1000;
return;
}
if (s_targetEndTime > now) return;
s_targetEndTime = now + 1000;
s_targetVID = vid;
PythonNetworkStream::Instance().SendTargetPacket(vid);
}
static float s_attackCameraYaw = 0.0f;
// CPythonPlayer::NEW_Attack + CInstanceBase::NEW_Attack(fDirRot). Not ported from __CanAttack:
// emotion / private shop / observer / new-mount skill checks. Bow mode needs a live target (the
// clickable-distance reserve and arrow flight are not ported).
static bool PlayerNewAttack() {
auto& manager = NetworkActorManager::Instance();
auto* main = manager.GetMainInstance();
if (!main || !main->m_pActorInstance) return false;
auto& inst = *main->m_pActorInstance;
if (!inst.CanAct() || inst.IsUsingSkill()) return false;
float dirYaw = inst.GetYaw();
if (inst.IsBowMode()) {
const auto* target = s_targetVID ? manager.GetActorData(s_targetVID) : nullptr;
if (!target || !target->m_pActorInstance || target->m_pActorInstance->IsDead()) {
player_window_call("OnCannotUseSkill", Py_BuildValue("(is)", PythonNetworkStream::Instance().GetMainActorVID(), "NEED_TARGET"));
return false;
}
if (!HasEnoughArrow()) return false;
const float dx = target->m_pActorInstance->GetX() - inst.GetX();
const float dz = target->m_pActorInstance->GetZ() - inst.GetZ();
dirYaw = std::fmod(std::atan2(dx, dz) * 180.0f / 3.14159265f + 360.0f, 360.0f);
} else if (!GetPlayerMovementYaw(s_attackCameraYaw, dirYaw)) {
// No hand attacks while mounted without a direction.
if (inst.IsMountingHorse() && inst.IsHandMode()) return false;
dirYaw = inst.GetYaw();
}
// EndWalking / m_isGoing = FALSE.
inst.ClearMoveTarget();
inst.StopMoving();
if (inst.IsPolymorph() || main->m_bType == 7) return inst.InputNormalAttackCommand(dirYaw);
return inst.InputComboAttackCommand(dirYaw);
}
bool IsPlayerAttacking() {
auto* main = NetworkActorManager::Instance().GetMainInstance();
return main && main->m_pActorInstance && main->m_pActorInstance->IsAttacking();
}
bool ProcessPlayerAttack(float cameraYaw, float frameDt, bool wasMoving) {
s_attackCameraYaw = cameraYaw;
auto& manager = NetworkActorManager::Instance();
auto* main = manager.GetMainInstance();
if (!main || !main->m_pActorInstance) return false;
auto& inst = *main->m_pActorInstance;
inst.SetReportAttacks(true);
// CInstanceBase::Update: ComboProcess, then CPythonPlayer input (m_isAtkKey -> NEW_Attack).
inst.ComboProcess();
if (s_isAtkKey) PlayerNewAttack();
// CPythonPlayerEventHandler::OnAttack: SendCharacterStatePacket(pos, rot, FUNC_COMBO, motion).
uint16_t motion;
bool stopSent = false;
while (inst.PopAttackMotion(&motion)) {
// EndWalking reports the stop (FUNC_WAIT) before the attack state.
if (wasMoving && !stopSent) {
PythonNetworkStream::Instance().SendCharacterMovePacket(0, 0,
uint8_t(std::fmod(inst.GetYaw() + 360.0f, 360.0f) / 5.0f),
int32_t(inst.GetX()), int32_t(inst.GetZ()), GetServerMSec());
stopSent = true;
}
PythonNetworkStream::Instance().SendCharacterMovePacket(3, uint8_t(motion),
uint8_t(std::fmod(inst.GetYaw() + 360.0f, 360.0f) / 5.0f),
int32_t(inst.GetX()), int32_t(inst.GetZ()), GetServerMSec());
}
// CInstanceBase::AttackProcess: hit-test every attackable instance (enemies and stones; PvP
// rules are not ported). Each hit is OnHit: SetTarget + SendAttackPacket(0, vid).
if (!inst.CanCheckAttacking()) return stopSent;
for (const auto& [vid, victim] : manager.GetActorDict()) {
if (vid == main->m_dwVID || !victim.m_pActorInstance) continue;
if (victim.m_bType != 0 && victim.m_bType != 2) continue; // TYPE_ENEMY / TYPE_STONE
const auto& v = *victim.m_pActorInstance;
if (v.IsDead()) continue;
if (inst.TestAttackHit(vid, v.GetX(), v.GetZ(), v.GetDefendingRadius(), frameDt, IsBossRace(victim.m_dwRace))) {
SetPlayerHitTarget(vid);
PythonNetworkStream::Instance().SendAttackPacket(0, vid);
}
}
return stopSent;
}
static float s_fCmrRotSpd = 0.0f;
static uint32_t s_inGuildAreaID = 0xffffffff;
@@ -2594,6 +2690,7 @@ static PyObject* player_ClearTarget(PyObject*, PyObject*) {
}
static PyObject* player_ComboAttack(PyObject*, PyObject*) {
PlayerNewAttack();
return Py_BuildNone();
}
+6
View File
@@ -93,6 +93,12 @@ void CancelPlayerMovement();
void SetPlayerJoystick(bool active, float x, float y);
// player.SetAttackKeyState for native input (touch attack button).
void SetPlayerAttackKey(bool pressed);
// Per frame, before movement: combo pre-input, held attack key (CPythonPlayer::NEW_Attack), FUNC_COMBO
// state packets for started attack motions, and the attack hit test (SendAttackPacket). wasMoving:
// a walk is in progress on the server; its stop packet is sent first. Returns true when it sent it.
bool ProcessPlayerAttack(float cameraYaw, float frameDt, bool wasMoving);
// The main actor is playing an attack motion (movement input is ignored meanwhile).
bool IsPlayerAttacking();
// True when handler is the window passed to player.SetGameWindow (game.GameWindow).
bool IsPlayerGameWindow(const void* handler);
void SetWeaponPower(uint32_t dwMinPower, uint32_t dwMaxPower, uint32_t dwMinMagicPower, uint32_t dwMaxMagicPower, uint32_t dwAddPower);