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
+6 -2
View File
@@ -2054,14 +2054,18 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
static bool wasMoving = false;
static uint32_t lastMoveSent = 0;
float moveYaw = 0.0f;
const bool keyboardMoving = actor.CanAct() && ava2::GetPlayerMovementYaw(orbit_camera.GetYaw(), moveYaw);
// Attack input first (NEW_Attack ends walking); no movement while an attack plays.
if (ava2::ProcessPlayerAttack(orbit_camera.GetYaw(), dt, wasMoving)) wasMoving = false;
const bool attacking = ava2::IsPlayerAttacking();
if (attacking) actor.ClearMoveTarget();
const bool keyboardMoving = actor.CanAct() && !attacking && ava2::GetPlayerMovementYaw(orbit_camera.GetYaw(), moveYaw);
actor.SetSpeed(340.0f * float(main->m_dwMovSpd) / 100.0f);
if (keyboardMoving) {
actor.ClearMoveTarget();
actor.MoveInDirection(moveYaw, dt, active_terrain, active_map_objects);
} else {
if (wasKeyboardMoving) actor.StopMoving();
if (actor.CanAct() && ava2::IsPlayerMouseMoving() && renderer3d && active_terrain) {
if (actor.CanAct() && !attacking && ava2::IsPlayerMouseMoving() && renderer3d && active_terrain) {
long mouseX=0, mouseY=0;
UI::CWindowManager::Instance().GetMousePosition(mouseX,mouseY);
float pickX=0,pickY=0,pickZ=0;
+88 -5
View File
@@ -15,6 +15,8 @@ namespace ava2 {
namespace {
void RefreshState(SNetworkActorData& actor, uint32_t motion, bool loop);
// AVA2 InstanceBase.cpp SHORSE::Create / __AttachHorseSaddle: mounts are
// separate actors, and the rider's main model follows their "saddle" bone.
void ConfigureMount(SNetworkActorData& data) {
@@ -32,9 +34,8 @@ void ConfigureMount(SNetworkActorData& data) {
data.m_pMountInstance=std::move(mount);
}
}
const uint16_t mode=data.m_pMountInstance ? 9 : 1;
rider.SetMotionMode(mode);
rider.PlayMotion(MotionType::Wait,true);
// MountHorse / DismountHorse end in RefreshState(NAME_WAIT): the weapon picks the horse mode.
RefreshState(data, RaceData::NAME_WAIT, true);
}
// InstanceBaseEffect.cpp g_akD3DXClrName / g_akD3DXClrTitle / g_TitleNameMap: zero (transparent
@@ -74,6 +75,69 @@ bool ArmorVnumToShape(uint32_t vnum, uint32_t* shape) {
constexpr uint8_t kTypePC = 6; // CActorInstance::TYPE_PC
bool IsPC(const SNetworkActorData& actor) { return actor.m_bType == kTypePC; }
// CRaceMotionData::EMode (ENABLE_WOLFMAN_CHARACTER off) and CItemData weapon / item types.
enum {
MODE_GENERAL = 1, MODE_ONEHAND_SWORD, MODE_TWOHAND_SWORD, MODE_DUALHAND_SWORD, MODE_BOW, MODE_FAN,
MODE_BELL, MODE_FISHING, MODE_HORSE, MODE_HORSE_ONEHAND_SWORD, MODE_HORSE_TWOHAND_SWORD,
MODE_HORSE_DUALHAND_SWORD, MODE_HORSE_BOW, MODE_HORSE_FAN, MODE_HORSE_BELL, MODE_WEDDING_DRESS,
MODE_BOW_SPECIAL,
};
enum { WEAPON_SWORD, WEAPON_DAGGER, WEAPON_BOW, WEAPON_TWO_HANDED, WEAPON_BELL, WEAPON_FAN, WEAPON_ARROW,
WEAPON_MOUNT_SPEAR, WEAPON_CLAW, WEAPON_QUIVER };
enum { ITEM_TYPE_ROD = 13, ITEM_TYPE_COSTUME = 28 };
// CInstanceBase::RefreshState: picks the motion mode from the polymorph / dress / weapon / horse
// state, then intercepts the motion. The actor's attack speed follows m_dwAtkSpd (SetAttackSpeed).
void RefreshState(SNetworkActorData& actor, uint32_t motion, bool loop) {
if (!actor.m_pActorInstance) return;
auto& inst = *actor.m_pActorInstance;
const bool mounting = actor.m_pMountInstance != nullptr;
const uint32_t weapon = inst.GetPartItemID(RaceData::PART_WEAPON);
int itemType = 0xff, subType = 0xff;
SItemModelData item;
if (GetItemData(weapon, &item)) {
itemType = item.type;
subType = int(GetWeaponType(item));
}
int mode = MODE_GENERAL;
const bool pickAxe = actor.m_awPart[RaceData::PART_WEAPON] >= 29101 && actor.m_awPart[RaceData::PART_WEAPON] <= 29110;
if (actor.m_bType == 7) { // IsPoly
mode = MODE_GENERAL;
} else if (actor.m_awPart[RaceData::PART_MAIN] == 201 || inst.GetShape() == 201) { // IsWearingDress
mode = MODE_WEDDING_DRESS;
} else if (pickAxe) {
mode = mounting ? MODE_HORSE : MODE_GENERAL;
} else if (itemType == ITEM_TYPE_ROD) {
mode = mounting ? MODE_HORSE : MODE_FISHING;
} else if (mounting) {
switch (subType) {
case WEAPON_SWORD: mode = MODE_HORSE_ONEHAND_SWORD; break;
case WEAPON_TWO_HANDED: mode = MODE_HORSE_TWOHAND_SWORD; break;
case WEAPON_DAGGER: mode = MODE_HORSE_DUALHAND_SWORD; break;
case WEAPON_FAN: mode = MODE_HORSE_FAN; break;
case WEAPON_BELL: mode = MODE_HORSE_BELL; break;
case WEAPON_BOW: mode = MODE_HORSE_BOW; break;
default: mode = MODE_HORSE; break;
}
} else {
switch (subType) {
case WEAPON_SWORD: mode = MODE_ONEHAND_SWORD; break;
case WEAPON_TWO_HANDED: mode = MODE_TWOHAND_SWORD; break;
case WEAPON_DAGGER: mode = MODE_DUALHAND_SWORD; break;
case WEAPON_BOW:
mode = actor.m_awPart[RaceData::PART_ARROW_TYPE] == WEAPON_QUIVER ? MODE_BOW_SPECIAL : MODE_BOW;
break;
case WEAPON_FAN: mode = MODE_FAN; break;
case WEAPON_BELL: mode = MODE_BELL; break;
default: mode = MODE_GENERAL; break;
}
}
inst.SetMotionMode(mode);
inst.SetMountingHorse(mounting);
inst.SetAttackSpeed(float(actor.m_dwAtkSpd > 0 ? actor.m_dwAtkSpd : 100) / 100.0f);
if (!inst.InterceptMotionIndex(motion, loop)) inst.PlayMotion(static_cast<MotionType>(motion), loop);
}
// InstanceBase.h RaceToJob / RaceToSex (ENABLE_WOLFMAN_CHARACTER off).
int RaceToJob(int race) { return race % 4; }
int RaceToSex(int race) {
@@ -330,12 +394,16 @@ bool NetworkActorManager::ChangeArmor(SNetworkActorData& actor, uint32_t armor)
return true;
}
// CInstanceBase::ChangeWeapon(eWeapon, eArrow). The bow motion-mode switch is not ported.
// CInstanceBase::ChangeWeapon(eWeapon, eArrow).
void NetworkActorManager::ChangeWeapon(SNetworkActorData& actor, uint32_t weapon, uint32_t arrow) {
actor.m_awPart[RaceData::PART_ARROW_TYPE] = arrow;
if (!actor.m_pActorInstance) return;
SItemModelData item;
if (!actor.m_pMountInstance && GetItemData(weapon, &item) &&
(item.subType == WEAPON_BOW || (item.type == ITEM_TYPE_COSTUME && item.values[3] == WEAPON_BOW)))
actor.m_pActorInstance->SetMotionMode(arrow == WEAPON_QUIVER ? MODE_BOW_SPECIAL : MODE_BOW);
if (weapon == actor.m_pActorInstance->GetPartItemID(RaceData::PART_WEAPON)) return;
if (SetWeapon(actor, weapon, arrow)) actor.m_pActorInstance->PlayMotion(MotionType::Wait, true);
if (SetWeapon(actor, weapon, arrow)) RefreshState(actor, RaceData::NAME_WAIT, true);
}
// CInstanceBase::ChangeHair.
@@ -503,6 +571,8 @@ void NetworkActorManager::AppendActor(const SNetworkActorData& data) {
}
actor->PlayMotion(MotionType::Wait, true);
ConfigureMount(actorData);
// CInstanceBase::Create ends in Refresh(NAME_WAIT, true).
RefreshState(actorData, RaceData::NAME_WAIT, true);
// AVA2 InstanceBase::SetAffect(AFFECT_STUN=5) controls the sleep action flag.
actor->SetSleep((data.m_affectFlags[0] & (1u<<5))!=0);
@@ -584,6 +654,8 @@ void NetworkActorManager::UpdateActor(const SNetworkUpdateActorData& data) {
actorData.m_dwMountVnum = data.m_dwMountVnum;
actorData.m_dwMovSpd = data.m_dwMovSpd;
actorData.m_dwAtkSpd = data.m_dwAtkSpd;
if (actorData.m_pActorInstance)
actorData.m_pActorInstance->SetAttackSpeed(float(data.m_dwAtkSpd > 0 ? data.m_dwAtkSpd : 100) / 100.0f);
ConfigureMount(actorData);
// CNetworkActorManager::UpdateActor: ChangeArmor, ChangeWeapon(weapon, arrow), ChangeHair, ChangeSash.
@@ -636,6 +708,17 @@ void NetworkActorManager::MoveActor(const SNetworkMoveActorData& data) {
if (data.m_dwFunc == 0) { // Stop
actorData.m_isMoving = false;
actorData.m_pActorInstance->PlayMotion(MotionType::Wait);
} else if (data.m_dwFunc == 2 || data.m_dwFunc == 3) {
// FUNC_ATTACK / FUNC_COMBO (CInstanceBase::PushTCPState): RunNormalAttack /
// RunComboAttack(rot, arg) at the packet position. The original walks there first when
// it is 50 or more away; the port snaps.
actorData.m_isMoving = false;
actorData.m_lCurX = data.m_lPosX;
actorData.m_lCurY = data.m_lPosY;
auto& inst = *actorData.m_pActorInstance;
inst.SetPosition(float(data.m_lPosX), inst.GetY(), float(data.m_lPosY));
if (data.m_dwFunc == 2) inst.RunNormalAttack(data.m_fRot);
else inst.RunComboAttack(data.m_fRot, uint16_t(data.m_dwArg));
} else { // Move
actorData.m_isMoving = true;
actorData.m_pActorInstance->PlayMotion(MotionType::Run);
+208 -16
View File
@@ -413,19 +413,210 @@ bool ActorInstance::PlayMotion(MotionType type, bool loop) {
m_model->SetAnimationLoop(loop, loop);
SyncLodMotion();
if (type == MotionType::Attack || type == MotionType::ComboAttack1 ||
type == MotionType::ComboAttack2 || type == MotionType::ComboAttack3 ||
type == MotionType::Skill1 || type == MotionType::Skill2 ||
type == MotionType::Skill3 || type == MotionType::Skill4 ||
type == MotionType::Skill5) {
m_isAttacking = true;
} else {
m_isAttacking = false;
}
const uint32_t index = uint32_t(type);
m_isAttacking = (index >= RaceData::NAME_NORMAL_ATTACK && index <= RaceData::NAME_COMBO_ATTACK_8) ||
(index >= RaceData::NAME_SKILL && index < RaceData::NAME_SKILL_END);
OnMotionBound(index);
return true;
}
void ActorInstance::OnMotionBound(uint32_t type) {
// ActorInstanceMotion.cpp __BindMotionData: the race motion data of the new motion.
m_curRaceMotion = nullptr;
uint16_t keyMode;
if (m_raceData && m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(type), &keyMode)) {
const auto* entries = m_raceData->GetMotions(keyMode, type);
if (entries && !entries->empty()) m_curRaceMotion = GetRaceMotionData(entries->front().fileName);
}
if (!m_curRaceMotion) {
m_comboIndex = 0;
m_motionSpeed = 1.0f;
return;
}
if (m_curRaceMotion->isAttackingMotion) m_hitDataMap.clear();
if (m_comboIndex != 0 && !m_curRaceMotion->isComboMotion) m_comboIndex = 0;
// InterceptOnceMotion(..., __GetAttackSpeed()) for normal and combo attacks.
const bool attackMotion = m_curRaceMotion->isAttackingMotion &&
(m_curRaceMotion->motionType == RaceMotionData::MOTION_TYPE_NORMAL ||
m_curRaceMotion->motionType == RaceMotionData::MOTION_TYPE_COMBO);
m_motionSpeed = attackMotion ? m_atkSpd : 1.0f;
}
bool ActorInstance::IsWaiting() const {
const uint32_t index = uint32_t(m_currentMotion);
return index == RaceData::NAME_WAIT || index == RaceData::NAME_INTRO_WAIT || index == RaceData::NAME_STOP;
}
bool ActorInstance::IsUsingSkill() const {
const uint32_t index = uint32_t(m_currentMotion);
return (index >= RaceData::NAME_SKILL && index < RaceData::NAME_SKILL_END) ||
(index >= RaceData::NAME_SPECIAL_1 && index <= RaceData::NAME_SPECIAL_6);
}
float ActorInstance::GetDefendingRadius() const {
return m_raceData ? m_raceData->GetDefendingRadius() * m_scale : 0.0f;
}
bool ActorInstance::CanCheckAttacking() const {
if (!m_curRaceMotion || !m_curRaceMotion->isAttackingMotion || IsMotionFinished()) return false;
return m_curRaceMotion->motionType == RaceMotionData::MOTION_TYPE_NORMAL ||
m_curRaceMotion->motionType == RaceMotionData::MOTION_TYPE_COMBO;
}
uint16_t ActorInstance::GetCurrentComboType() const {
// __GetCurrentComboType
if (IsBowMode() || IsHandMode() || m_isMountingHorse) return 0;
return m_wcurComboType;
}
void ActorInstance::RunNextCombo() {
++m_comboIndex;
if (!m_raceData) return;
const auto* combo = m_raceData->GetComboData(uint16_t(m_motionMode), GetCurrentComboType());
// The original TraceErrors these two cases on every input; the port stays quiet.
if (!combo) return;
const uint32_t arrayIndex = m_comboIndex - 1;
if (arrayIndex >= combo->size()) return;
const uint32_t comboSize = uint32_t(combo->size());
const uint16_t motion = uint16_t((*combo)[arrayIndex]);
RunComboAttack(m_atkDirYaw, motion);
if (m_comboIndex == comboSize) {
// __OnEndCombo: mounted combos wrap; on foot the index resets when Wait binds.
if (m_isMountingHorse) m_comboIndex = 1;
}
}
bool ActorInstance::InputComboAttackCommand(float dirYaw) {
m_atkDirYaw = dirYaw;
if (m_isPreInput) return false;
if (m_comboIndex == 0) {
RunNextCombo();
return true;
}
if (!m_curRaceMotion) return false;
const float elapsed = GetAttackingElapsedTime();
if (m_curRaceMotion->isComboMotion) {
if (elapsed > m_curRaceMotion->inputEndTime) {
if (IsBowMode()) m_isNextPreInput = true;
return false;
}
if (elapsed > m_curRaceMotion->nextComboTime) {
RunNextCombo();
return true;
}
if (elapsed > m_curRaceMotion->inputStartTime) m_isPreInput = true;
} else if (elapsed > m_curRaceMotion->motionDuration * 0.9f) {
RunNextCombo();
return true;
}
return false;
}
bool ActorInstance::InputNormalAttackCommand(float dirYaw) {
// __CanInputNormalAttackCommand + NormalAttack
bool canInput = IsWaiting();
if (!canInput && m_curRaceMotion && m_curRaceMotion->isAttackingMotion &&
m_curRaceMotion->motionType == RaceMotionData::MOTION_TYPE_NORMAL)
canInput = GetAttackingElapsedTime() > m_curRaceMotion->motionDuration * 0.9f;
if (!canInput) return false;
return RunNormalAttack(dirYaw);
}
bool ActorInstance::RunNormalAttack(float dirYaw) {
uint16_t motion;
if (!m_raceData || !m_raceData->GetNormalAttackIndex(uint16_t(m_motionMode), &motion)) return false;
m_yaw = dirYaw;
if (!InterceptMotionIndex(motion, false)) return false;
if (m_reportAttacks) m_attackMotions.push_back(motion); // __OnAttack
return true;
}
bool ActorInstance::RunComboAttack(float dirYaw, uint16_t motion) {
// ComboAttack: rotate, InterceptOnceMotion at the attack speed, __OnAttack. The combo index is
// kept across the bind (the original binds before it compares the new motion's combo data).
m_yaw = dirYaw;
if (!InterceptMotionIndex(motion, false)) return false;
if (m_reportAttacks) m_attackMotions.push_back(motion);
return true;
}
void ActorInstance::ComboProcess() {
if (m_comboIndex != 0) {
if (!m_curRaceMotion) {
m_comboIndex = 0; // __ClearCombo
m_isPreInput = false;
return;
}
if (m_isPreInput && GetAttackingElapsedTime() > m_curRaceMotion->nextComboTime) {
RunNextCombo();
m_isPreInput = false;
}
} else {
m_isPreInput = false;
if (!IsUsingSkill() && m_isNextPreInput) {
RunNextCombo();
m_isNextPreInput = false;
}
}
}
bool ActorInstance::PopAttackMotion(uint16_t* motion) {
if (m_attackMotions.empty()) return false;
*motion = m_attackMotions.front();
m_attackMotions.pop_front();
return true;
}
bool ActorInstance::TestAttackHit(uint32_t victimVID, float x, float z, float radius, float frameDt, bool huge) {
// __NormalAttackProcess. The original's distance vector is (dx, dz, dz); horizontal distance here.
const float distX = x - m_posX, distZ = z - m_posZ;
const float range = huge ? 500.0f : 300.0f;
if (distX * distX + distZ * distZ >= range * range) return false;
if (!CanCheckAttacking()) return false;
const float attackRadius = 20.0f;
const float victimRadius = radius > 0.0f ? radius : 50.0f;
const float limit = attackRadius + victimRadius;
const auto& pad = *m_curRaceMotion;
const float motionTime = GetAttackingElapsedTime();
const float c = std::cos(m_yaw * DEG_TO_RAD), s = std::sin(m_yaw * DEG_TO_RAD);
// Graphic space (x, y) -> port (X, Z = -y); the port yaw is the graphic rotation.
auto toWorld = [&](const float* local, float& outX, float& outZ) {
outX = m_posX + local[0] * c - local[1] * s;
outZ = m_posZ - (local[0] * s + local[1] * c);
};
for (size_t hitIndex = 0; hitIndex < pad.hitData.size(); ++hitIndex) {
const auto& hit = pad.hitData[hitIndex];
auto& hitted = m_hitDataMap[hitIndex];
const auto already = hitted.find(victimVID);
if (already != hitted.end() &&
(pad.motionType == RaceMotionData::MOTION_TYPE_COMBO || already->second > m_localTime))
continue;
auto it = hit.hitPositions.lower_bound(motionTime - frameDt);
const auto end = hit.hitPositions.upper_bound(motionTime);
for (; it != end; ++it) {
// __GetReachScale() is 1: v3Position itself.
float ax, az, bx, bz;
toWorld(it->second.last, ax, az);
toWorld(it->second.pos, bx, bz);
// Segment (a, b) against the static victim point.
const float sx = bx - ax, sz = bz - az;
const float lenSq = sx * sx + sz * sz;
float t = lenSq > 1e-6f ? ((x - ax) * sx + (z - az) * sz) / lenSq : 0.0f;
t = std::clamp(t, 0.0f, 1.0f);
const float px = ax + sx * t - x, pz = az + sz * t - z;
if (px * px + pz * pz > limit * limit) continue;
// insert keeps an existing entry, like std::map::insert in the original.
hitted.insert({victimVID, m_localTime + pad.invisibleTime});
const size_t count = hitted.size();
const bool normal = pad.motionType == RaceMotionData::MOTION_TYPE_COMBO ||
pad.motionType == RaceMotionData::MOTION_TYPE_NORMAL;
if (normal ? count > 16 : int(count) > pad.hitLimitCount) return false;
return true;
}
}
return false;
}
bool ActorInstance::PlayMotionIndex(uint32_t index, bool loop) {
uint16_t keyMode;
if (!m_raceData || !m_raceData->GetMotionKey(uint16_t(m_motionMode), uint16_t(index), &keyMode)) return false;
@@ -586,8 +777,9 @@ void ActorInstance::Update(float dt, const TerrainHeightSource* terrain, const M
}
}
// Advance animation time
m_animTime += dt;
// Advance animation time (attack motions run at the attack speed ratio).
m_animTime += dt * m_motionSpeed;
m_localTime += dt;
m_lodLocalTime += dt; // CGrannyModelInstance::UpdateLocalTime
if (!m_motionQueue.empty() && m_animTime >= m_motionDuration) {
// ReservingMotionProcess: the next pushed motion takes over when the current one ends.
@@ -616,17 +808,17 @@ bool ActorInstance::Attack() {
if (m_curHP <= 0) return false;
if (!m_isAttacking) {
m_comboIndex = 1;
m_previewComboIndex = 1;
if (!PlayMotion(MotionType::ComboAttack1, false)) {
PlayMotion(MotionType::Attack, false);
}
return true;
} else if (m_animTime > m_motionDuration * 0.35f) {
// Advance combo chain
m_comboIndex = (m_comboIndex % 3) + 1;
m_previewComboIndex = (m_previewComboIndex % 3) + 1;
MotionType next = MotionType::ComboAttack1;
if (m_comboIndex == 2) next = MotionType::ComboAttack2;
else if (m_comboIndex == 3) next = MotionType::ComboAttack3;
if (m_previewComboIndex == 2) next = MotionType::ComboAttack2;
else if (m_previewComboIndex == 3) next = MotionType::ComboAttack3;
if (!PlayMotion(next, false)) {
PlayMotion(MotionType::Attack, false);
+58 -1
View File
@@ -11,6 +11,7 @@
namespace ava2 {
class RaceData;
struct RaceMotionData;
// Metin2 standard motion types (aligned with 40250 CRaceMotionData::EName)
enum class MotionType {
@@ -25,6 +26,11 @@ enum class MotionType {
ComboAttack1 = 14,
ComboAttack2 = 15,
ComboAttack3 = 16,
ComboAttack4 = 17,
ComboAttack5 = 18,
ComboAttack6 = 19,
ComboAttack7 = 20,
ComboAttack8 = 21,
Skill1 = 101, // Samyeon (三连击)
Skill2 = 102, // Palbang (八方风雨)
Skill3 = 103, // Jeongwi (狂战士)
@@ -185,6 +191,45 @@ public:
void SetComboType(uint16_t comboType) { m_wcurComboType = comboType; }
uint16_t GetComboType() const { return m_wcurComboType; }
// GameLib ActorInstanceBattle.cpp combo state machine. Direction is a port yaw (degrees).
// InputComboAttackCommand / ComboProcess / __RunNextCombo / __OnEndCombo follow the original;
// each started attack motion is queued for the caller (CPythonPlayerEventHandler::OnAttack sends
// it as a FUNC_COMBO state packet) and read with PopAttackMotion.
bool InputComboAttackCommand(float dirYaw);
bool InputNormalAttackCommand(float dirYaw);
// NormalAttack (CInstanceBase::RunNormalAttack for remote FUNC_ATTACK) and ComboAttack
// (RunComboAttack for FUNC_COMBO): play the motion facing dirYaw without the input checks.
bool RunNormalAttack(float dirYaw);
bool RunComboAttack(float dirYaw, uint16_t motion);
// Only the main actor reports its attacks (CPythonPlayerEventHandler is the main actor's handler).
void SetReportAttacks(bool report) { m_reportAttacks = report; if (!report) m_attackMotions.clear(); }
void ComboProcess();
bool PopAttackMotion(uint16_t* motion);
uint32_t GetComboIndex() const { return m_comboIndex; }
// m_fAtkSpd (atkspd / 100): attack motions advance this much faster, like the original motion
// speed ratio passed to InterceptOnceMotion.
void SetAttackSpeed(float ratio) { m_atkSpd = ratio > 0.0f ? ratio : 1.0f; }
float GetAttackSpeed() const { return m_atkSpd; }
// GetAttackingElapsedTime: motion local time scaled by the attack speed.
float GetAttackingElapsedTime() const { return m_animTime; }
const RaceMotionData* GetCurrentRaceMotionData() const { return m_curRaceMotion; }
bool IsWaiting() const; // __IsWaitMotion: WAIT / INTRO_WAIT / STOP
bool IsUsingSkill() const; // NAME_SKILL..NAME_SKILL_END or SPECIAL_1..6
bool IsBowMode() const { return m_motionMode == 5 || m_motionMode == 13 || m_motionMode == 17; }
bool IsHandMode() const { return m_motionMode == 1 || m_motionMode == 9; }
bool IsMountingHorse() const { return m_isMountingHorse; }
void SetMountingHorse(bool mounted) { m_isMountingHorse = mounted; }
// CanCheckAttacking: the current motion is a NORMAL or COMBO attacking motion.
bool CanCheckAttacking() const;
// ActorInstanceCollisionDetection.cpp __NormalAttackProcess against one victim. The victim's
// defending spheres are approximated by an upright cylinder of `radius` around (x, z) (0 radius:
// 50); DetectCollisionDynamicZCylinderVSDynamicZCylinder ignores height anyway. frameDt is the
// real frame time (hit positions in [t - dt, t]). Returns true for a new hit; a victim is hit
// once per hit data in a combo motion, else again after the invisible time.
// The race's DEFENDING sphere radius (.msm AttachingData), 0 when unknown.
float GetDefendingRadius() const;
bool TestAttackHit(uint32_t victimVID, float x, float z, float radius, float frameDt, bool huge = false);
// Cast specific skill motion (stops movement, sets attack state, plays one-shot)
bool CastSkill(MotionType skillMotion);
@@ -292,7 +337,19 @@ private:
std::deque<std::pair<uint32_t, bool>> m_motionQueue; // m_MotionDeque (index, loop)
bool PlayMotionIndex(uint32_t index, bool loop);
bool m_isAttacking = false;
int m_comboIndex = 0;
uint32_t m_comboIndex = 0;
// Combo state (CActorInstance m_isPreInput / m_isNextPreInput / m_fAtkDirRot / m_HitDataMap).
const RaceMotionData* m_curRaceMotion = nullptr;
bool m_isPreInput = false, m_isNextPreInput = false, m_isMountingHorse = false, m_reportAttacks = false;
float m_atkDirYaw = 0.0f, m_atkSpd = 1.0f, m_motionSpeed = 1.0f;
std::deque<uint16_t> m_attackMotions;
// m_HitDataMap: hit data index -> (vid -> local time the victim may be hit again).
std::unordered_map<size_t, std::unordered_map<uint32_t, float>> m_hitDataMap;
float m_localTime = 0.0f;
int m_previewComboIndex = 0; // Attack() (offline preview) cycle, separate from the real combo
uint16_t GetCurrentComboType() const;
void RunNextCombo();
void OnMotionBound(uint32_t type);
uint16_t m_wcurComboType = 0;
std::unordered_map<std::string, float> m_buffs;
+347 -16
View File
@@ -2,6 +2,7 @@
#include "ava2_text_file.h"
#include "ava2_text_file_loader.h"
#include "src/eter_resource/ResourceManager.h"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -124,10 +125,132 @@ bool RaceData::LoadRaceData(const std::string& fileName) {
}
loader.setParent();
}
// AttachingData (collision spheres, attached effects) is not ported.
// AttachingData: only COLLISION_TYPE_DEFENDING sphere radii are kept (CActorInstance defending
// spheres, approximated by one cylinder for the attack hit test). Attached effects are not ported.
if (loader.setChildNode("attachingdata")) {
for (size_t i = 0; i < loader.childCount(); ++i) {
if (!loader.setChild(i)) continue;
int collisionType = 0;
if (loader.tokenInteger("collisiontype", &collisionType) && collisionType == 3) {
for (size_t j = 0; j < loader.childCount(); ++j) {
if (!loader.setChild(j)) continue;
std::string radius;
if (loader.tokenString("radius", &radius))
m_defendingRadius = std::max(m_defendingRadius, float(std::atof(radius.c_str())));
loader.setParent();
}
}
loader.setParent();
}
loader.setParent();
}
return true;
}
namespace {
bool TokenFloat(const TextFileLoader& loader, const char* key, float* value) {
std::string token;
if (!loader.tokenString(key, &token)) return false;
*value = float(std::atof(token.c_str()));
return true;
}
// NRaceData::THitData::Load.
bool LoadHitData(const TextFileLoader& loader, RaceMotionData::HitData* hit) {
if (!TokenFloat(loader, "attackingstarttime", &hit->attackStartTime)) return false;
if (!TokenFloat(loader, "attackingendtime", &hit->attackEndTime)) return false;
if (!loader.tokenString("attackingbone", &hit->boneName)) hit->boneName.clear();
if (!TokenFloat(loader, "weaponlength", &hit->weaponLength)) hit->weaponLength = 0.0f;
hit->hitPositions.clear();
if (const auto* tv = loader.tokenVector("hitposition")) {
// The original walks the list 7 tokens at a time without a bounds check; a short tail is dropped.
for (size_t i = 0; i + 7 <= tv->size(); i += 7) {
RaceMotionData::HitTimePosition hp;
const float time = float(std::atof((*tv)[i].c_str()));
for (int k = 0; k < 3; ++k) {
hp.last[k] = float(std::atof((*tv)[i + 1 + k].c_str()));
hp.pos[k] = float(std::atof((*tv)[i + 4 + k].c_str()));
}
hit->hitPositions[time] = hp;
}
}
return true;
}
// NRaceData::LoadAttackData + LoadMotionAttackData.
bool LoadMotionAttackData(TextFileLoader& loader, RaceMotionData* data) {
if (!loader.tokenInteger("attacktype", &data->attackType)) data->attackType = 2; // ATTACK_TYPE_SPLASH
if (!loader.tokenInteger("hittingtype", &data->hittingType)) return false;
if (!TokenFloat(loader, "stiffentime", &data->stiffenTime)) return false;
if (!TokenFloat(loader, "invisibletime", &data->invisibleTime)) return false;
if (!TokenFloat(loader, "externalforce", &data->externalForce)) return false;
if (!loader.tokenInteger("hitlimitcount", &data->hitLimitCount)) data->hitLimitCount = 0;
// AttackingType was renamed MotionType; old files still carry the former key.
if (!loader.tokenInteger("motiontype", &data->motionType) &&
!loader.tokenInteger("attackingtype", &data->motionType))
return false;
data->hitData.clear();
int count = 0;
if (!loader.tokenInteger("hitdatacount", &count)) {
data->hitData.emplace_back();
return LoadHitData(loader, &data->hitData.back());
}
for (int i = 0; i < count; ++i) {
if (!loader.setChild(size_t(i))) return false;
data->hitData.emplace_back();
if (!LoadHitData(loader, &data->hitData.back())) return false;
loader.setParent();
}
return true;
}
} // namespace
bool ParseRaceMotionData(const std::string& text, RaceMotionData* data) {
TextFileLoader loader;
if (!loader.load(text)) return false;
loader.setTop();
if (!loader.tokenString("motionfilename", &data->motionFileName)) return false;
if (!TokenFloat(loader, "motionduration", &data->motionDuration)) return false;
if (const auto* acc = loader.tokenVector("accumulation")) {
if (acc->size() != 3) {
TraceError("CRaceMotioNData::LoadMotionData : syntax error on accumulation, vector size " + std::to_string(acc->size()));
return false;
}
for (int k = 0; k < 3; ++k) data->accumulation[k] = float(std::atof((*acc)[k].c_str()));
}
for (size_t i = 0; i < loader.childCount(); ++i) {
loader.setChild(i); // CGotoChild
const std::string name = loader.nodeName();
bool ok = true;
if (name == "comboinputdata") {
data->isComboMotion = true;
ok = TokenFloat(loader, "preinputtime", &data->inputStartTime) &&
TokenFloat(loader, "directinputtime", &data->nextComboTime) &&
TokenFloat(loader, "inputlimittime", &data->inputEndTime);
} else if (name == "attackingdata") {
data->isAttackingMotion = true;
ok = LoadMotionAttackData(loader, data);
}
loader.setTop();
if (!ok) return false;
}
return true;
}
const RaceMotionData* GetRaceMotionData(const std::string& msaFileName) {
static std::map<std::string, std::unique_ptr<RaceMotionData>> cache;
const std::string key = CResourceManager::NormalizePath(msaFileName.c_str());
auto it = cache.find(key);
if (it != cache.end()) return it->second.get();
std::unique_ptr<RaceMotionData> data;
std::string text;
if (ReadRaceResourceFile(msaFileName, &text)) {
data = std::make_unique<RaceMotionData>();
if (!ParseRaceMotionData(text, data.get())) data.reset();
}
return cache.emplace(key, std::move(data)).first->second.get();
}
void RaceData::SetShapeModel(uint32_t index, const std::string& model) { m_shapes[index].model = model; }
void RaceData::AppendShapeSkin(uint32_t index, uint32_t, const std::string& src, const std::string& dst) {
@@ -425,6 +548,228 @@ bool RaceManager::LoadGameNPC(const std::string& fileName) {
return true;
}
namespace {
// CPythonPlayerSettingsModule (UserInterface/PythonPlayerSettingsModule.cpp) motion tables.
enum {
MODE_GENERAL = 1, MODE_ONEHAND_SWORD, MODE_TWOHAND_SWORD, MODE_DUALHAND_SWORD, MODE_BOW, MODE_FAN, MODE_BELL,
MODE_FISHING, MODE_HORSE, MODE_HORSE_ONEHAND_SWORD, MODE_HORSE_TWOHAND_SWORD, MODE_HORSE_DUALHAND_SWORD,
MODE_HORSE_BOW, MODE_HORSE_FAN, MODE_HORSE_BELL, MODE_WEDDING_DRESS, MODE_BOW_SPECIAL,
};
enum { JOB_WARRIOR, JOB_ASSASSIN, JOB_SURA, JOB_SHAMAN };
enum {
HORSE_SKILL_WILDATTACK = RaceData::NAME_SKILL + 121,
HORSE_SKILL_CHARGE = RaceData::NAME_SKILL + 122,
HORSE_SKILL_SPLASH = RaceData::NAME_SKILL + 123,
};
enum { COMBO_TYPE_1, COMBO_TYPE_2, COMBO_TYPE_3 };
struct PlayerMotionLoader {
RaceData& race;
std::string path; // CRaceManager::SetPathName
int job;
// __RegisterCacheMotionData: CRaceData::RegisterMotionData drops a motion whose .msa fails to load.
void Register(uint16_t mode, uint16_t name, const char* file, int percent = 100) const {
const std::string fileName = path + file;
if (!GetRaceMotionData(fileName)) {
TraceError("CRaceData::RegisterMotionData - LoadMotionData(c_szFileName=" + fileName + ") ERROR");
return;
}
race.RegisterMotion(mode, name, fileName, percent);
}
void Combo(uint16_t mode, uint16_t type, std::initializer_list<uint16_t> motions) const {
race.ReserveComboAttack(mode, type, uint32_t(motions.size()));
uint32_t index = 0;
for (uint16_t motion : motions) race.RegisterComboAttack(mode, type, index++, motion);
}
// __SetGeneralMotions.
void GeneralMotions(uint16_t mode) const {
race.RegisterMotionMode(mode);
Register(mode, RaceData::NAME_WAIT, "wait.msa");
Register(mode, RaceData::NAME_WALK, "walk.msa");
Register(mode, RaceData::NAME_RUN, "run.msa");
Register(mode, RaceData::NAME_DAMAGE, "damage.msa", 50);
Register(mode, RaceData::NAME_DAMAGE, "damage_1.msa", 50);
Register(mode, RaceData::NAME_DAMAGE_BACK, "damage_2.msa", 50);
Register(mode, RaceData::NAME_DAMAGE_BACK, "damage_3.msa", 50);
Register(mode, RaceData::NAME_DAMAGE_FLYING, "damage_flying.msa");
Register(mode, RaceData::NAME_STAND_UP, "falling_stand.msa");
Register(mode, RaceData::NAME_DAMAGE_FLYING_BACK, "back_damage_flying.msa");
Register(mode, RaceData::NAME_STAND_UP_BACK, "back_falling_stand.msa");
Register(mode, RaceData::NAME_DEAD, "dead.msa");
Register(mode, RaceData::NAME_DIG, "dig.msa");
}
// __LoadCombo. MODE_BOW_SPECIAL takes the sword branch like the original.
void LoadCombo(uint16_t mode) const {
using R = RaceData;
if (mode == MODE_BOW) {
Combo(MODE_BOW, COMBO_TYPE_1, {R::NAME_COMBO_ATTACK_1});
return;
}
Combo(mode, COMBO_TYPE_1, {R::NAME_COMBO_ATTACK_1, R::NAME_COMBO_ATTACK_2, R::NAME_COMBO_ATTACK_3, R::NAME_COMBO_ATTACK_4});
Combo(mode, COMBO_TYPE_2, {R::NAME_COMBO_ATTACK_1, R::NAME_COMBO_ATTACK_2, R::NAME_COMBO_ATTACK_3, R::NAME_COMBO_ATTACK_5,
R::NAME_COMBO_ATTACK_7});
Combo(mode, COMBO_TYPE_3, {R::NAME_COMBO_ATTACK_1, R::NAME_COMBO_ATTACK_2, R::NAME_COMBO_ATTACK_3, R::NAME_COMBO_ATTACK_5,
R::NAME_COMBO_ATTACK_6,
uint16_t(mode == MODE_DUALHAND_SWORD ? R::NAME_COMBO_ATTACK_8 : R::NAME_COMBO_ATTACK_4)});
}
// __LoadWeaponMotion.
void WeaponMotion(uint16_t mode, const std::string& folder) {
path = folder;
race.RegisterMotionMode(mode);
switch (job) {
case JOB_WARRIOR: {
const bool oneHand = mode == MODE_ONEHAND_SWORD;
Register(mode, RaceData::NAME_WAIT, "wait.msa", oneHand ? 50 : 70);
Register(mode, RaceData::NAME_WAIT, "wait_1.msa", oneHand ? 50 : 30);
break;
}
case JOB_ASSASSIN:
Register(mode, RaceData::NAME_WAIT, "wait.msa", 70);
Register(mode, RaceData::NAME_WAIT, "wait_1.msa", 30);
break;
case JOB_SURA:
Register(mode, RaceData::NAME_WAIT, "wait.msa");
Register(mode, RaceData::NAME_DAMAGE, "damage.msa");
break;
case JOB_SHAMAN:
Register(mode, RaceData::NAME_WAIT, "wait.msa");
break;
}
Register(mode, RaceData::NAME_WALK, "walk.msa");
Register(mode, RaceData::NAME_RUN, "run.msa");
Register(mode, RaceData::NAME_DAMAGE, "damage.msa", 50);
Register(mode, RaceData::NAME_DAMAGE, "damage_1.msa", 50);
Register(mode, RaceData::NAME_DAMAGE_BACK, "damage_2.msa", 50);
Register(mode, RaceData::NAME_DAMAGE_BACK, "damage_3.msa", 50);
if (mode == MODE_BOW) {
Register(mode, RaceData::NAME_COMBO_ATTACK_1, "attack.msa");
} else if (mode == MODE_BOW_SPECIAL) {
Register(mode, RaceData::NAME_COMBO_ATTACK_1, "attack_special.msa");
} else {
static const char* kCombo[] = {"combo_01.msa", "combo_02.msa", "combo_03.msa", "combo_04.msa",
"combo_05.msa", "combo_06.msa", "combo_07.msa"};
for (uint16_t k = 0; k < 7; ++k) Register(mode, uint16_t(RaceData::NAME_COMBO_ATTACK_1 + k), kCombo[k]);
if (job == JOB_ASSASSIN && mode == MODE_DUALHAND_SWORD)
Register(mode, RaceData::NAME_COMBO_ATTACK_8, "combo_08.msa");
}
LoadCombo(mode);
}
};
// GetHorsePathNameByMode is not in the reference sources; the folders are the pack's horse_* names.
const char* HorsePathName(uint16_t mode) {
switch (mode) {
case MODE_HORSE_ONEHAND_SWORD: return "horse_onehand_sword/";
case MODE_HORSE_TWOHAND_SWORD: return "horse_twohand_sword/";
case MODE_HORSE_DUALHAND_SWORD: return "horse_dualhand_sword/";
case MODE_HORSE_FAN: return "horse_fan/";
case MODE_HORSE_BELL: return "horse_bell/";
default: return "horse/";
}
}
void LoadPlayerMotions(RaceData& race, const std::string& folder) {
using R = RaceData;
PlayerMotionLoader l{race, folder + "intro/", int(race.GetRace() % 4)};
// __SetIntroMotions
race.RegisterMotionMode(MODE_GENERAL);
l.Register(MODE_GENERAL, R::NAME_INTRO_WAIT, "wait.msa");
l.Register(MODE_GENERAL, R::NAME_INTRO_SELECTED, "selected.msa");
l.Register(MODE_GENERAL, R::NAME_INTRO_NOT_SELECTED, "not_selected.msa");
// __LoadGameRace (emotions, guild skills and skills are not ported)
l.path = folder + "general/";
l.GeneralMotions(MODE_GENERAL);
if (l.job == JOB_WARRIOR || l.job == JOB_ASSASSIN) {
race.SetMotionRandomWeight(MODE_GENERAL, R::NAME_WAIT, 0, 70);
l.Register(MODE_GENERAL, R::NAME_WAIT, "wait_1.msa", 30);
}
l.Register(MODE_GENERAL, R::NAME_COMBO_ATTACK_1, "attack.msa", 50);
l.Register(MODE_GENERAL, R::NAME_COMBO_ATTACK_1, "attack_1.msa", 50);
l.Combo(MODE_GENERAL, COMBO_TYPE_1, {R::NAME_COMBO_ATTACK_1});
switch (l.job) {
case JOB_WARRIOR:
l.WeaponMotion(MODE_ONEHAND_SWORD, folder + "onehand_sword/");
l.WeaponMotion(MODE_TWOHAND_SWORD, folder + "twohand_sword/");
break;
case JOB_ASSASSIN:
l.WeaponMotion(MODE_ONEHAND_SWORD, folder + "onehand_sword/");
l.WeaponMotion(MODE_DUALHAND_SWORD, folder + "dualhand_sword/");
l.WeaponMotion(MODE_BOW, folder + "bow/");
l.WeaponMotion(MODE_BOW_SPECIAL, folder + "bow/");
break;
case JOB_SURA:
l.WeaponMotion(MODE_ONEHAND_SWORD, folder + "onehand_sword/");
break;
case JOB_SHAMAN:
l.WeaponMotion(MODE_FAN, folder + "fan/");
l.WeaponMotion(MODE_BELL, folder + "Bell/");
break;
}
// __LoadHorse
l.path = folder + "horse/";
race.RegisterMotionMode(MODE_HORSE);
l.Register(MODE_HORSE, R::NAME_WAIT, "wait.msa", 90);
l.Register(MODE_HORSE, R::NAME_WALK, "walk.msa");
l.Register(MODE_HORSE, R::NAME_RUN, "run.msa");
l.Register(MODE_HORSE, R::NAME_DEAD, "dead.msa");
l.Register(MODE_HORSE, HORSE_SKILL_CHARGE, "skill_charge.msa");
l.Register(MODE_HORSE, R::NAME_WAIT, "wait_1.msa", 9);
l.Register(MODE_HORSE, R::NAME_WAIT, "wait_2.msa", 1);
l.Register(MODE_HORSE, R::NAME_DAMAGE, "damage.msa");
l.Register(MODE_HORSE, R::NAME_DAMAGE_BACK, "damage.msa");
if (l.job == JOB_SHAMAN || l.job == JOB_SURA) l.Register(MODE_HORSE, HORSE_SKILL_SPLASH, "skill_splash.msa");
static const std::vector<uint16_t> kHorseModes[] = {
{MODE_HORSE_ONEHAND_SWORD, MODE_HORSE_TWOHAND_SWORD}, // m_vecHorse JOB_WARRIOR
{MODE_HORSE_ONEHAND_SWORD, MODE_HORSE_DUALHAND_SWORD}, // JOB_ASSASSIN
{MODE_HORSE_ONEHAND_SWORD}, // JOB_SURA
{MODE_HORSE_FAN, MODE_HORSE_BELL}, // JOB_SHAMAN
};
for (uint16_t mode : kHorseModes[l.job]) {
l.path = folder + HorsePathName(mode);
race.RegisterMotionMode(mode);
l.Register(mode, R::NAME_COMBO_ATTACK_1, "combo_01.msa");
l.Register(mode, R::NAME_COMBO_ATTACK_2, "combo_02.msa");
l.Register(mode, R::NAME_COMBO_ATTACK_3, "combo_03.msa");
l.Combo(mode, COMBO_TYPE_1, {R::NAME_COMBO_ATTACK_1, R::NAME_COMBO_ATTACK_2, R::NAME_COMBO_ATTACK_3});
l.Register(mode, HORSE_SKILL_WILDATTACK, "skill_wildattack.msa");
if (l.job == JOB_WARRIOR || l.job == JOB_ASSASSIN) l.Register(mode, HORSE_SKILL_SPLASH, "skill_splash.msa");
}
if (l.job == JOB_ASSASSIN) {
l.path = folder + "horse_bow/";
race.RegisterMotionMode(MODE_HORSE_BOW);
l.Register(MODE_HORSE_BOW, R::NAME_WAIT, "wait.msa", 90);
l.Register(MODE_HORSE_BOW, R::NAME_WAIT, "wait_1.msa", 9);
l.Register(MODE_HORSE_BOW, R::NAME_WAIT, "wait_2.msa", 1);
l.Register(MODE_HORSE_BOW, R::NAME_RUN, "run.msa");
l.Register(MODE_HORSE_BOW, R::NAME_DAMAGE, "damage.msa");
l.Register(MODE_HORSE_BOW, R::NAME_DEAD, "dead.msa");
l.Register(MODE_HORSE_BOW, R::NAME_COMBO_ATTACK_1, "attack.msa");
l.Register(MODE_HORSE_BOW, HORSE_SKILL_WILDATTACK, "skill_wildattack.msa");
l.Register(MODE_HORSE_BOW, HORSE_SKILL_SPLASH, "skill_splash.msa");
l.Combo(MODE_HORSE_BOW, COMBO_TYPE_1, {R::NAME_COMBO_ATTACK_1});
}
// __LoadFishing
l.path = folder + "fishing/";
race.RegisterMotionMode(MODE_FISHING);
l.Register(MODE_FISHING, R::NAME_WAIT, "wait.msa");
l.Register(MODE_FISHING, R::NAME_WALK, "walk.msa");
l.Register(MODE_FISHING, R::NAME_RUN, "run.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_THROW, "throw.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_WAIT, "fishing_wait.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_STOP, "fishing_cancel.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_REACT, "fishing_react.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_CATCH, "fishing_catch.msa");
l.Register(MODE_FISHING, R::NAME_FISHING_FAIL, "fishing_fail.msa");
}
} // namespace
void RaceManager::LoadPlayerRaces() {
// CPythonPlayerSettingsModule m_vecRaceData.
static const struct { const char* msm; const char* path; } kRaces[] = {
@@ -449,21 +794,7 @@ void RaceManager::LoadPlayerRaces() {
case 2: race->RegisterAttachingBoneName(RaceData::PART_WEAPON, "equip_right"); break;
}
race->RegisterAttachingBoneName(RaceData::PART_SASH, "Bip01 Spine2"); // ENABLE_SASH_SYSTEM
race->RegisterMotionData(RaceData::NAME_INTRO_WAIT, kRaces[i].path + std::string("intro/wait.msa"), 100);
race->RegisterMotionData(RaceData::NAME_INTRO_SELECTED, kRaces[i].path + std::string("intro/selected.msa"), 100);
race->RegisterMotionData(RaceData::NAME_INTRO_NOT_SELECTED, kRaces[i].path + std::string("intro/not_selected.msa"), 100);
race->RegisterMotionData(RaceData::NAME_WAIT, kRaces[i].path + std::string("general/wait.msa"), 100);
race->RegisterMotionData(RaceData::NAME_WALK, kRaces[i].path + std::string("general/walk.msa"), 100);
race->RegisterMotionData(RaceData::NAME_RUN, kRaces[i].path + std::string("general/run.msa"), 100);
race->RegisterMotionData(RaceData::NAME_DEAD, kRaces[i].path + std::string("general/dead.msa"), 100);
// CPythonPlayerSettingsModule::__LoadHorse: mounted riders use a distinct pose.
race->RegisterMotionMode(9);
for (const auto& motion : {std::pair{RaceData::NAME_WAIT, "wait.msa"},
std::pair{RaceData::NAME_WALK, "walk.msa"},
std::pair{RaceData::NAME_RUN, "run.msa"},
std::pair{RaceData::NAME_DEAD, "dead.msa"}})
race->RegisterMotion(9, motion.first, kRaces[i].path + std::string("horse/") + motion.second, 100);
LoadPlayerMotions(*race, kRaces[i].path);
}
}
+33 -2
View File
@@ -2,8 +2,10 @@
// Port of AVA2 GameLib CRaceData (RaceData.h/.cpp, RaceDataFile.cpp LoadRaceData) and CRaceManager
// (RaceManager.cpp): .msm shape/hair tables, attaching bone names, the npclist race-name registry,
// the per-race resource path search and the motlist.txt GENERAL motion list.
// Not ported: smoke effects, AttachingData (collision spheres / attached effects), the CRaceMotionData
// .msa event payload (only MotionFileName is read), motion modes other than GENERAL.
// Player weapon / horse / fishing motion modes and combo tables follow UserInterface
// PythonPlayerSettingsModule.cpp. Not ported: smoke effects, attached effects, the .msa motion
// events / loop data, emotion and skill motions. Of AttachingData only the DEFENDING sphere radius
// is kept (hit test approximation).
#include <cstdint>
#include <map>
#include <memory>
@@ -119,7 +121,11 @@ public:
void RegisterComboAttack(uint16_t mode, uint16_t comboType, uint32_t comboIndex, uint16_t motion);
const std::vector<uint32_t>* GetComboData(uint16_t mode, uint16_t comboType) const;
// Largest COLLISION_TYPE_DEFENDING sphere radius of the .msm AttachingData (0 when none).
float GetDefendingRadius() const { return m_defendingRadius; }
private:
float m_defendingRadius = 0.0f;
uint32_t m_race = 0;
std::string m_baseModelFileName, m_treeFileName, m_attributeFileName, m_smokeBoneName;
std::string m_motionListFileName = "motlist.txt";
@@ -175,6 +181,31 @@ bool ReadRaceResourceFile(const std::string& fileName, std::string* text);
// .msa "MotionFileName" (CRaceMotionData::LoadMotionData); returns the gr2 path or "" on failure.
std::string ReadMotionFileName(const std::string& msaFileName);
// CRaceMotionData::LoadMotionData combat payload (GameLib RaceMotionData.cpp, GameType.cpp
// NRaceData::LoadMotionAttackData / THitData::Load). Loop data, motion events and sound are not read.
struct RaceMotionData {
enum { MOTION_TYPE_NONE, MOTION_TYPE_NORMAL, MOTION_TYPE_COMBO, MOTION_TYPE_SKILL };
struct HitTimePosition { float last[3] = {}; float pos[3] = {}; }; // v3LastPosition / v3Position (local)
struct HitData {
float attackStartTime = 0.0f, attackEndTime = 0.0f, weaponLength = 0.0f;
std::string boneName;
std::map<float, HitTimePosition> hitPositions; // mapHitPosition, keyed by motion time
};
std::string motionFileName;
float motionDuration = 0.0f;
float accumulation[3] = {};
bool isComboMotion = false;
float inputStartTime = 0.0f, nextComboTime = 0.0f, inputEndTime = 0.0f; // pre / direct / limit
bool isAttackingMotion = false;
int attackType = 0, hittingType = 0, motionType = MOTION_TYPE_NONE, hitLimitCount = 0;
float stiffenTime = 0.0f, invisibleTime = 0.0f, externalForce = 0.0f;
std::vector<HitData> hitData;
};
// Parses an .msa text; false where CRaceMotionData::LoadMotionData fails.
bool ParseRaceMotionData(const std::string& text, RaceMotionData* data);
// Cached by .msa path (CResourceManager static cache); nullptr when the file is missing or invalid.
const RaceMotionData* GetRaceMotionData(const std::string& msaFileName);
struct CRaceMotionData {
using EName = RaceData::EMotion;
enum {
+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);