Add some command handlers

This commit is contained in:
Aaron Kimbre 2023-08-12 00:40:48 -05:00
parent 2db8caadde
commit 84ba38bd1d
4 changed files with 122 additions and 51 deletions

View File

@ -20,7 +20,6 @@ enum class eWaypointCommandType : uint32_t {
CHANGE_WAYPOINT,
DELETE_SELF,
KILL_SELF,
REMOVE_SELF,
SPAWN_OBJECT,
PLAY_SOUND,
};
@ -45,7 +44,7 @@ public:
{"changeWP", eWaypointCommandType::CHANGE_WAYPOINT},
{"DeleteSelf", eWaypointCommandType::DELETE_SELF},
{"killself", eWaypointCommandType::KILL_SELF},
{"removeself", eWaypointCommandType::REMOVE_SELF},
{"removeself", eWaypointCommandType::DELETE_SELF},
{"spawnOBJ", eWaypointCommandType::SPAWN_OBJECT},
{"playSound", eWaypointCommandType::PLAY_SOUND},
};

View File

@ -195,7 +195,7 @@ public:
void ReversePath();
void HandleWaypointArrived();
void SetupPath(const std::string& pathname);
/**
@ -223,6 +223,21 @@ public:
*/
static float GetBaseSpeed(LOT lot);
void SetCurrentPathWaypointIndex(uint32_t value) { m_CurrentPathWaypointIndex = value; };
void SetNextPathWaypointIndex(uint32_t value) { m_NextPathWaypointIndex = value; };
void HandleWaypointCommandGroupEmote(std::string data);
void HandleWaypointCommandSetVariable(std::string data);
void HandleWaypointCommandCastSkill(std::string data);
void HandleWaypointCommandEquipInventory(std::string data);
void HandleWaypointCommandUnequipInventory(std::string data);
void HandleWaypointCommandDelay(std::string data);
void HandleWaypointCommandEmote(std::string data);
void HandleWaypointCommandTeleport(std::string data);
void HandleWaypointCommandPathSpeed(std::string data);
void HandleWaypointCommandRemoveNPC(std::string data);
void HandleWaypointCommandChangeWaypoint(std::string data);
void HandleWaypointCommandSpawnObject(std::string data);
private:
/**
@ -334,12 +349,12 @@ private:
int32_t m_CurrentPathWaypointIndex;
/**
* The index of the current waypoint in the path
* The index of the next waypoint in the path
*/
int32_t m_NextPathWaypointIndex;
/**
* Whether or not the path is being read in reverse
* Whether or not the path is being read in reverse
*/
bool m_IsInReverse;

View File

@ -2,6 +2,8 @@
#include "MovementAIComponent.h"
#endif
#include "eWaypointCommandType.h"
#include "RenderComponent.h"
#include "SkillComponent.h"
void MovementAIComponent::HandleWaypointArrived() {
if (!m_Path) return;
@ -9,76 +11,138 @@ void MovementAIComponent::HandleWaypointArrived() {
for(auto [command, data] : m_Path->pathWaypoints[m_CurrentPathWaypointIndex].commands){
switch(command){
case eWaypointCommandType::STOP:
// call stop
Stop();
break;
case eWaypointCommandType::GROUP_EMOTE:
// get group
// make them all emote
HandleWaypointCommandGroupEmote(data);
break;
case eWaypointCommandType::SET_VARIABLE:
// set network variable???
HandleWaypointCommandSetVariable(data);
break;
case eWaypointCommandType::CAST_SKILL:
// just call cast skill lol
HandleWaypointCommandCastSkill(data);
break;
case eWaypointCommandType::EQUIP_INVENTORY:
// equip item via ID (not lot???)
HandleWaypointCommandEquipInventory(data);
break;
case eWaypointCommandType::UNEQUIP_INVENTORY:
// unequip item via ID (not lot??)
HandleWaypointCommandUnequipInventory(data);
break;
case eWaypointCommandType::DELAY:
// number
HandleWaypointCommandDelay(data);
break;
case eWaypointCommandType::EMOTE:
// emote name
HandleWaypointCommandEmote(data);
break;
case eWaypointCommandType::TELEPORT:
// x,y,z
HandleWaypointCommandTeleport(data);
break;
case eWaypointCommandType::PATH_SPEED:
// set speed?
HandleWaypointCommandPathSpeed(data);
break;
case eWaypointCommandType::REMOVE_NPC:
// get objects in proximity
// KillOBJS ???
HandleWaypointCommandRemoveNPC(data);
break;
case eWaypointCommandType::CHANGE_WAYPOINT:
// std::string path_string = "";
// sometimes there's a path and what waypoint to start, which are comma separated
// if (intermed.find(",") != std::string::npos){
// auto datas = GeneralUtils::SplitString(intermed, ',');
// path_string = datas[0];
// m_PathIndex = stoi(datas[1]) - 1;
// } else {
// path_string = intermed;
// m_PathIndex = 0;
// }
// if (path_string != "") {
// SetMovementPath(const_cast<Path*>(dZoneManager::Instance()->GetZone()->GetPath(path_string)));
// } else m_MovementPath = nullptr;
HandleWaypointCommandChangeWaypoint(data);
break;
case eWaypointCommandType::KILL_SELF:
// Kill Silent
m_Parent->Smash(LWOOBJID_EMPTY, eKillType::SILENT);
break;
case eWaypointCommandType::DELETE_SELF:
case eWaypointCommandType::REMOVE_SELF:
// Delete Object
m_Parent->Kill();
break;
case eWaypointCommandType::SPAWN_OBJECT:
// just make a new object
HandleWaypointCommandSpawnObject(data);
break;
case eWaypointCommandType::PLAY_SOUND:
// msgPlayNDAudioEmitter
GameMessages::SendPlayNDAudioEmitter(m_Parent, UNASSIGNED_SYSTEM_ADDRESS, data);
break;
case eWaypointCommandType::BOUNCE:
Game::logger->Log("MovementAIComponentAronwk", "Unusable Command %i", command);
Game::logger->LogDebug("MovementAIComponent", "Unusable Command %i", command);
break;
case eWaypointCommandType::INVALID:
default:
Game::logger->LogDebug("MovementAIComponentAronwk", "Got invalid waypoint command %i", command);
Game::logger->LogDebug("MovementAIComponent", "Got invalid waypoint command %i", command);
break;
}
}
}
void MovementAIComponent::HandleWaypointCommandGroupEmote(std::string data) {
const auto& split = GeneralUtils::SplitString(data, ';');
if (split.size() != 2) return;
const auto& entities = Game::entityManager->GetEntitiesInGroup(split[0]);
for (auto& entity: entities){
RenderComponent::PlayAnimation(entity, split[1]);
}
// delay for animation time
}
void MovementAIComponent::HandleWaypointCommandSetVariable(std::string data) {
const auto& split = GeneralUtils::SplitString(data, '=');
m_Parent->SetNetworkVar(GeneralUtils::ASCIIToUTF16(split[0]), split[1]);
}
void MovementAIComponent::HandleWaypointCommandCastSkill(std::string data) {
if (data.empty()) return;
auto* skillComponent = m_Parent->GetComponent<SkillComponent>();
if (!skillComponent) {
Game::logger->LogDebug("MovementAIComponent::HandleWaypointArrived", "Skill component not found!");
return;
}
uint32_t skillId = 0;
GeneralUtils::TryParse<uint32_t>(data, skillId);
if (skillId != 0) skillComponent->CastSkill(skillId);
// add some delay??
}
void MovementAIComponent::HandleWaypointCommandEquipInventory(std::string data) {
// equip item via ID (not lot???)
}
void MovementAIComponent::HandleWaypointCommandUnequipInventory(std::string data) {
// unequip item via ID (not lot??)
}
void MovementAIComponent::HandleWaypointCommandDelay(std::string data) {
Pause();
std::remove_if(data.begin(), data.end(), isspace);
// delay for time
}
void MovementAIComponent::HandleWaypointCommandEmote(std::string data) {
// pause fore animation time
auto delay = RenderComponent::PlayAnimation(m_Parent, data);
}
void MovementAIComponent::HandleWaypointCommandTeleport(std::string data) {
auto posString = GeneralUtils::SplitString(data, ',');
if (posString.size() == 0) return;
auto newPos = NiPoint3();
if (posString.size() == 1) GeneralUtils::TryParse<float>(posString[0], newPos.x);
if (posString.size() == 2) GeneralUtils::TryParse<float>(posString[1], newPos.y);
if (posString.size() == 3) GeneralUtils::TryParse<float>(posString[2], newPos.z);
GameMessages::SendTeleport(m_Parent->GetObjectID(), newPos, NiQuaternion::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS);
}
void MovementAIComponent::HandleWaypointCommandPathSpeed(std::string data) {
float speed = 0.0;
GeneralUtils::TryParse<float>(data, speed);
SetMaxSpeed(speed);
}
void MovementAIComponent::HandleWaypointCommandRemoveNPC(std::string data) {
// get objects in proximity
// KillOBJS ???
}
void MovementAIComponent::HandleWaypointCommandChangeWaypoint(std::string data) {
std::string path_string = "";
int32_t index = 0;
// sometimes there's a path and what waypoint to start, which are comma separated
if (data.find(",") != std::string::npos){
auto datas = GeneralUtils::SplitString(data, ',');
path_string = datas[0];
index = stoi(datas[1]);
} else path_string = data;
if (path_string != "") {
SetupPath(path_string);
SetCurrentPathWaypointIndex(index);
SetNextPathWaypointIndex(index);
}
}
void MovementAIComponent::HandleWaypointCommandSpawnObject(std::string data) {
// just do it
}

View File

@ -317,8 +317,8 @@ void GameMessages::SendPlayNDAudioEmitter(Entity* entity, const SystemAddress& s
bitStream.Write(entity->GetObjectID());
bitStream.Write((uint16_t)eGameMessageType::PLAY_ND_AUDIO_EMITTER);
bitStream.Write0();
bitStream.Write0();
bitStream.Write0(); // callback message data {lwoobjid}
bitStream.Write0(); // audio emmitterid {uint32_t}}
uint32_t length = audioGUID.size();
bitStream.Write(length);
@ -326,16 +326,9 @@ void GameMessages::SendPlayNDAudioEmitter(Entity* entity, const SystemAddress& s
bitStream.Write(static_cast<char>(audioGUID[k]));
}
//PacketUtils::WriteString(bitStream, audioGUID, audioGUID.size());
//bitStream.Write(uint32_t(audioGUID.size()));
//for (char character : audioGUID) {
// bitStream.Write(character);
//}
bitStream.Write(uint32_t(0));
bitStream.Write0();
bitStream.Write0();
bitStream.Write(uint32_t(0)); // size of NDAudioMetaEventName (then print he string like the guid)
bitStream.Write0(); //result {bool}
bitStream.Write0(); // m_TargetObjectIDForNDAudioCallbackMessages {lwoobjid}
SEND_PACKET_BROADCAST;
}