Port .msa motion events, .mss sounds and skill motions
ParseRaceMotionData now reads LoopData, MotionEventData and the per-motion .mss sound script. ActorInstance runs the events each 1/60 s frame: effects, sounds, splash attacks, fly shots, show/hide and warp. Player skill and guild-skill motions are registered. ClickSkillSlot and remote FUNC_SKILL states play the skill motions, and fly targets are synced with the server (audit P1 #4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
31c74cec28
commit
f6dfcfc337
@@ -2,6 +2,8 @@
|
||||
#include "ava2_text_file.h"
|
||||
#include "ava2_text_file_loader.h"
|
||||
#include "src/eter_resource/ResourceManager.h"
|
||||
#include "eter_effect/EffectManager.h"
|
||||
#include "eter_effect/FlyingManager.h"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -179,7 +181,7 @@ bool LoadHitData(const TextFileLoader& loader, RaceMotionData::HitData* hit) {
|
||||
|
||||
// NRaceData::LoadAttackData + LoadMotionAttackData.
|
||||
bool LoadMotionAttackData(TextFileLoader& loader, RaceMotionData* data) {
|
||||
if (!loader.tokenInteger("attacktype", &data->attackType)) data->attackType = 2; // ATTACK_TYPE_SPLASH
|
||||
if (!loader.tokenInteger("attacktype", &data->attackType)) data->attackType = 0; // 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;
|
||||
@@ -203,9 +205,112 @@ bool LoadMotionAttackData(TextFileLoader& loader, RaceMotionData* data) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// CTextFileLoader::GetTokenPosition (GetTokenVector3): exactly three values.
|
||||
bool TokenPosition(const TextFileLoader& loader, const char* key, float* out) {
|
||||
const auto* tv = loader.tokenVector(key);
|
||||
if (!tv || tv->size() != 3) return false;
|
||||
for (int k = 0; k < 3; ++k) out[k] = float(std::atof((*tv)[k].c_str()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// GetTokenBoolean: BOOL(atoi(first token)).
|
||||
bool TokenBool(const TextFileLoader& loader, const char* key, bool* out) {
|
||||
const auto* tv = loader.tokenVector(key);
|
||||
if (!tv || tv->empty()) return false;
|
||||
*out = std::atoi((*tv)[0].c_str()) != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// NRaceData::LoadCollisionData into a SPECIAL_ATTACKING event.
|
||||
bool LoadCollisionData(TextFileLoader& loader, RaceMotionData::MotionEvent* ev) {
|
||||
if (!loader.tokenInteger("collisiontype", &ev->collisionType)) return false;
|
||||
int count = 0;
|
||||
if (!loader.tokenInteger("spheredatacount", &count)) return false;
|
||||
ev->spheres.clear();
|
||||
ev->spheres.resize(uint32_t(count));
|
||||
for (uint32_t i = 0; i < ev->spheres.size(); ++i) {
|
||||
if (!loader.setChildNode("spheredata", i)) return false;
|
||||
if (!TokenFloat(loader, "radius", &ev->spheres[i].radius)) return false;
|
||||
if (!TokenPosition(loader, "position", ev->spheres[i].position)) return false;
|
||||
loader.setParent();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// The per-type SMotionEventData*::Load (RaceMotionDataEvent.h). The caller ignores the result.
|
||||
bool LoadMotionEvent(TextFileLoader& loader, RaceMotionData::MotionEvent* ev) {
|
||||
switch (ev->type) {
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SCREEN_WAVING:
|
||||
if (!TokenFloat(loader, "duringtime", &ev->durationTime)) return false;
|
||||
if (!loader.tokenInteger("power", &ev->power)) return false;
|
||||
if (!loader.tokenInteger("affectingrange", &ev->affectingRange)) ev->affectingRange = 0;
|
||||
return true;
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_EFFECT:
|
||||
if (!TokenBool(loader, "independentflag", &ev->isIndependent)) ev->isIndependent = false;
|
||||
if (!TokenBool(loader, "attachingenable", &ev->isAttaching)) return false;
|
||||
if (!loader.tokenString("attachingbonename", &ev->boneName)) return false;
|
||||
if (!loader.tokenString("effectfilename", &ev->fileName)) return false;
|
||||
if (!TokenPosition(loader, "effectposition", ev->position)) return false;
|
||||
if (!TokenBool(loader, "followingenable", &ev->isFollowing)) ev->isFollowing = false;
|
||||
EffectManager::Instance().RegisterEffect(ev->fileName, &ev->index);
|
||||
return true;
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_EFFECT_TO_TARGET:
|
||||
if (!loader.tokenString("effectfilename", &ev->fileName)) return false;
|
||||
if (!TokenPosition(loader, "effectposition", ev->position)) return false;
|
||||
if (!TokenBool(loader, "followingenable", &ev->isFollowing)) ev->isFollowing = false;
|
||||
if (!TokenBool(loader, "fishingeffectflag", &ev->isFishingEffect)) ev->isFishingEffect = false;
|
||||
EffectManager::Instance().RegisterEffect(ev->fileName, &ev->index);
|
||||
return true;
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_FLY:
|
||||
if (!TokenBool(loader, "attachingenable", &ev->isAttaching)) return false;
|
||||
if (!loader.tokenString("attachingbonename", &ev->boneName)) return false;
|
||||
if (!loader.tokenString("flyfilename", &ev->fileName)) return false;
|
||||
if (!TokenPosition(loader, "flyposition", ev->position)) return false;
|
||||
FlyingManager::Instance().RegisterFlyingData(ev->fileName, &ev->index);
|
||||
return true;
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SPECIAL_ATTACKING:
|
||||
if (!TokenFloat(loader, "duringtime", &ev->durationTime)) return false;
|
||||
if (!TokenBool(loader, "enablehitprocess", &ev->isEnableHitProcess)) ev->isEnableHitProcess = true;
|
||||
// NRaceData::LoadAttackData
|
||||
if (!loader.tokenInteger("attacktype", &ev->attackType)) ev->attackType = 0; // ATTACK_TYPE_SPLASH
|
||||
if (!loader.tokenInteger("hittingtype", &ev->hittingType)) return false;
|
||||
if (!TokenFloat(loader, "stiffentime", &ev->stiffenTime)) return false;
|
||||
if (!TokenFloat(loader, "invisibletime", &ev->invisibleTime)) return false;
|
||||
if (!TokenFloat(loader, "externalforce", &ev->externalForce)) return false;
|
||||
if (!loader.tokenInteger("hitlimitcount", &ev->hitLimitCount)) ev->hitLimitCount = 0;
|
||||
return LoadCollisionData(loader, ev);
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SOUND:
|
||||
return loader.tokenString("soundfilename", &ev->fileName);
|
||||
default: // CHARACTER_SHOW / CHARACTER_HIDE / WARP carry no data
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float kFrameTime = 1.0f / 60.0f; // c_fFrameTime (g_fGameFPS)
|
||||
} // namespace
|
||||
|
||||
bool ParseRaceMotionData(const std::string& text, RaceMotionData* data) {
|
||||
bool ParseSoundScriptData(const std::string& text, std::vector<RaceMotionData::SoundInstance>* sounds) {
|
||||
TextFileLoader loader;
|
||||
if (!loader.load(text)) return false;
|
||||
loader.setTop();
|
||||
int count = 0;
|
||||
if (!loader.tokenInteger("sounddatacount", &count)) return false;
|
||||
std::vector<RaceMotionData::SoundInstance> data(uint32_t(count < 0 ? 0 : count));
|
||||
for (uint32_t i = 0; i < data.size(); ++i) {
|
||||
char key[33];
|
||||
std::snprintf(key, sizeof(key), "sounddata%02u", i);
|
||||
const auto* tv = loader.tokenVector(key);
|
||||
if (!tv || tv->size() != 2) return false;
|
||||
data[i].time = float(std::atof((*tv)[0].c_str()));
|
||||
data[i].fileName = (*tv)[1];
|
||||
data[i].frame = uint32_t(data[i].time / kFrameTime); // NSound::DataToInstance
|
||||
}
|
||||
*sounds = std::move(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseRaceMotionData(const std::string& text, RaceMotionData* data, const std::string& msaFileName) {
|
||||
TextFileLoader loader;
|
||||
if (!loader.load(text)) return false;
|
||||
loader.setTop();
|
||||
@@ -230,10 +335,69 @@ bool ParseRaceMotionData(const std::string& text, RaceMotionData* data) {
|
||||
} else if (name == "attackingdata") {
|
||||
data->isAttackingMotion = true;
|
||||
ok = LoadMotionAttackData(loader, data);
|
||||
} else if (name == "loopdata") {
|
||||
data->isLoopMotion = true;
|
||||
if (!loader.tokenInteger("motionloopcount", &data->loopCount)) data->loopCount = -1;
|
||||
if (!loader.tokenInteger("loopcancelenable", &data->loopCancelEnable)) data->loopCancelEnable = 0;
|
||||
ok = TokenFloat(loader, "loopstarttime", &data->loopStartTime) &&
|
||||
TokenFloat(loader, "loopendtime", &data->loopEndTime);
|
||||
} else if (name == "motioneventdata") {
|
||||
int count = 0;
|
||||
if (loader.tokenInteger("motioneventdatacount", &count)) {
|
||||
data->events.clear();
|
||||
data->events.resize(uint32_t(count));
|
||||
for (uint32_t j = 0; ok && j < data->events.size(); ++j) {
|
||||
auto& ev = data->events[j];
|
||||
int type = 0;
|
||||
if (!loader.setChildNode("event", j) || !loader.tokenInteger("motioneventtype", &type)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
switch (type) {
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SPECIAL_ATTACKING:
|
||||
data->hasSplashEvent = true;
|
||||
[[fallthrough]];
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_FLY:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_EFFECT:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SCREEN_WAVING:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_SOUND:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_CHARACTER_SHOW:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_CHARACTER_HIDE:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_WARP:
|
||||
case RaceMotionData::MOTION_EVENT_TYPE_EFFECT_TO_TARGET:
|
||||
break;
|
||||
default: // "Strange Event Type" (SCREEN_FLASHING has no event class)
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
if (!ok) break;
|
||||
ev.type = type;
|
||||
LoadMotionEvent(loader, &ev); // the original ignores Load()'s result
|
||||
if (!TokenFloat(loader, "startingtime", &ev.startingTime)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
ev.frame = uint32_t(ev.startingTime / kFrameTime);
|
||||
loader.setParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
loader.setTop();
|
||||
if (!ok) return false;
|
||||
}
|
||||
// Sound script: NoExtension(msa) + ".mss", the 13-character "d:/ymir work/" head becomes "sound/".
|
||||
if (!msaFileName.empty()) {
|
||||
std::string mss = msaFileName;
|
||||
const size_t slash = mss.find_last_of("/\\");
|
||||
const size_t dot = mss.find_last_of('.');
|
||||
if (dot != std::string::npos && (slash == std::string::npos || dot > slash)) mss.erase(dot);
|
||||
mss += ".mss";
|
||||
if (mss.length() > 13) {
|
||||
data->soundScriptFileName = "sound/" + mss.substr(13);
|
||||
std::string mssText;
|
||||
if (ReadRaceResourceFile(data->soundScriptFileName, &mssText)) ParseSoundScriptData(mssText, &data->sounds);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -246,7 +410,7 @@ const RaceMotionData* GetRaceMotionData(const std::string& msaFileName) {
|
||||
std::string text;
|
||||
if (ReadRaceResourceFile(msaFileName, &text)) {
|
||||
data = std::make_unique<RaceMotionData>();
|
||||
if (!ParseRaceMotionData(text, data.get())) data.reset();
|
||||
if (!ParseRaceMotionData(text, data.get(), msaFileName)) data.reset();
|
||||
}
|
||||
return cache.emplace(key, std::move(data)).first->second.get();
|
||||
}
|
||||
@@ -681,7 +845,7 @@ void LoadPlayerMotions(RaceData& race, const std::string& folder) {
|
||||
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)
|
||||
// __LoadGameRace (emotions are not ported; guild skills and skills are loaded after fishing)
|
||||
l.path = folder + "general/";
|
||||
l.GeneralMotions(MODE_GENERAL);
|
||||
if (l.job == JOB_WARRIOR || l.job == JOB_ASSASSIN) {
|
||||
@@ -767,6 +931,63 @@ void LoadPlayerMotions(RaceData& race, const std::string& folder) {
|
||||
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");
|
||||
|
||||
// __LoadGuildSkill (GUILD_SKILL_* = NAME_SKILL + 101..106)
|
||||
l.path = folder + "skill/";
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 101, "guild_yongsinuipi.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 102, "guild_yongsinuichukbok.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 103, "guild_seonghwigap.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 104, "guild_gasokhwa.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 105, "guild_yongsinuibunno.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 106, "guild_jumunsul.msa");
|
||||
|
||||
// __LoadSkill (m_vecSkillFileName: {job, vecFileName, vecExtraFileName}). Rows skip 7..15;
|
||||
// grade g (SKILL_EFFECT_COUNT 4, SKILL_GRADEGAP 25) uses suffix _<g+1>; shamans take grade 0
|
||||
// from the extra (_target) names.
|
||||
struct SkillFiles { int job; std::vector<const char*> files, extra; };
|
||||
static const SkillFiles kSkillFiles[] = {
|
||||
{JOB_WARRIOR, {"samyeon", "palbang", "jeongwi", "geomgyeong", "tanhwan", "gihyeol", "gigongcham", "gyeoksan", "daejin", "cheongeun", "geompung", "noegeom"}, {}},
|
||||
{JOB_ASSASSIN, {"amseup", "gungsin", "charyun", "eunhyeong", "sangong", "seomjeon", "yeonsa", "gwangyeok", "hwajo", "gyeonggong", "dokgigung", "seomgwang"}, {}},
|
||||
{JOB_SHAMAN, {"bipabu", "yongpa", "paeryong", "hosin", "boho", "gicheon", "noejeon", "byeorak", "pokroe", "jeongeop", "kwaesok", "jeungryeok"},
|
||||
{"bipabu", "yongpa", "paeryong", "hosin_target", "boho_target", "gicheon_target", "noejeon", "byeorak", "pokroe", "jeongeop_target", "kwaesok_target", "jeungryeok_target"}},
|
||||
{JOB_SURA, {"swaeryeong", "yonggwon", "gwigeom", "gongpo", "jumagap", "pabeop", "maryeong", "hwayeom", "muyeong", "heuksin", "tusok", "mahwan"}, {}},
|
||||
};
|
||||
const int gradeStart = l.job == JOB_SHAMAN ? 1 : 0;
|
||||
auto suffix = [](int grade) { return grade ? "_" + std::to_string(grade + 1) : std::string(); };
|
||||
for (const auto& skill : kSkillFiles) {
|
||||
if (skill.job != l.job) continue;
|
||||
int row = 1;
|
||||
for (const char* name : skill.extra) {
|
||||
if (row == 7) row += 9;
|
||||
l.Register(MODE_GENERAL, uint16_t(R::NAME_SKILL + row), (std::string(name) + ".msa").c_str());
|
||||
++row;
|
||||
}
|
||||
for (int grade = gradeStart; grade < 4; ++grade) {
|
||||
row = 1;
|
||||
for (const char* name : skill.files) {
|
||||
if (row == 7) row += 9;
|
||||
l.Register(MODE_GENERAL, uint16_t(R::NAME_SKILL + grade * 25 + row), (name + suffix(grade) + ".msa").c_str());
|
||||
++row;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// __LoadNinethSkill (ENABLE_CONQUEROR_LEVEL on, wolfman off): rows 9 and 24.
|
||||
static const std::vector<const char*> kNinethSkills[] = {
|
||||
{"finish", "finish"}, {"ilgangpyo", "pungraepo"}, {"akgi", "akgi_dark"}, {"meteo", "chunwoon"},
|
||||
};
|
||||
if (l.job == JOB_SHAMAN) {
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 9, "meteo.msa");
|
||||
l.Register(MODE_GENERAL, R::NAME_SKILL + 24, "chunwoon.msa");
|
||||
}
|
||||
for (int grade = gradeStart; grade < 4; ++grade) {
|
||||
int row = 0;
|
||||
for (const char* name : kNinethSkills[l.job]) {
|
||||
l.Register(MODE_GENERAL, uint16_t(R::NAME_SKILL + grade * 25 + (!row ? 9 : 24)), (name + suffix(grade) + ".msa").c_str());
|
||||
++row;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user