Updated to new API

This commit is contained in:
wincent 2024-02-17 23:07:16 +01:00
parent 88e5f0e8fb
commit 685bd5d45b
5 changed files with 76 additions and 43 deletions

View File

@ -2175,8 +2175,8 @@ void Entity::ProcessPositionUpdate(PositionUpdate& update) {
update.velocity,
update.angularVelocity,
update.onGround,
update.velocity != NiPoint3::ZERO,
update.angularVelocity != NiPoint3::ZERO
update.velocity != NiPoint3Constant::ZERO,
update.angularVelocity != NiPoint3Constant::ZERO
));
}
}

View File

@ -538,13 +538,13 @@ void EntityManager::CheckGhosting(Entity* entity) {
const auto precondition = ServerPreconditions::CheckPreconditions(entity, player);
if (observed && (distance > ghostingDistanceMax || !precondition)) {
if (observed && (distance > m_GhostDistanceMaxSquared || !precondition)) {
ghostComponent->GhostEntity(id);
DestructEntity(entity, player->GetSystemAddress());
entity->SetObservers(entity->GetObservers() - 1);
} else if (!observed && (ghostingDistanceMin > distance && precondition)) {
} else if (!observed && (m_GhostDistanceMinSqaured > distance && precondition)) {
ghostComponent->ObserveEntity(id);
ConstructEntity(entity, player->GetSystemAddress());

View File

@ -1081,11 +1081,7 @@ Cinema::Recording::PlayEffectRecord::PlayEffectRecord(const std::string& effect)
}
void Cinema::Recording::PlayEffectRecord::Act(Entity* actor) {
int32_t effectID = 0;
if (!GeneralUtils::TryParse(effect, effectID)) {
return;
}
int32_t effectID = GeneralUtils::TryParse<int32_t>(effect).value_or(0);
GameMessages::SendPlayFXEffect(
actor->GetObjectID(),

View File

@ -1,6 +1,5 @@
#pragma once
#include "Player.h"
#include "Game.h"
#include "EntityManager.h"
#include "tinyxml2.h"

View File

@ -716,9 +716,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (chatCommand == "removemission" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
if (args.size() == 0) return;
uint32_t missionID;
uint32_t missionID = GeneralUtils::TryParse<uint32_t>(args.at(0)).value_or(0);
if (!GeneralUtils::TryParse(args[0], missionID)) {
if (missionID == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid mission id.");
return;
}
@ -914,9 +914,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
// If there is an argument, set the lot
if (args.size() > 0) {
if (!GeneralUtils::TryParse(args[0], info.lot)) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid lot.");
return;
const auto lotOptional = GeneralUtils::TryParse<LOT>(args[0]);
if (lotOptional) {
info.lot = lotOptional.value();
}
}
@ -998,9 +998,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
float scale = 1.0f;
if (args.size() >= 2) {
if (!GeneralUtils::TryParse(args[1], scale)) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid scale.");
return;
const auto scaleOptional = GeneralUtils::TryParse<float>(args[1]);
if (scaleOptional) {
scale = scaleOptional.value();
}
}
@ -1012,9 +1012,9 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
if (chatCommand == "prefab-destroy" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() == 1) {
size_t id;
size_t id = GeneralUtils::TryParse<size_t>(args[0]).value_or(0);
if (!GeneralUtils::TryParse(args[0], id)) {
if (id == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid prefab ID.");
return;
}
@ -2240,16 +2240,28 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
}
} else if (args[1] == "-rotate" && args.size() >= 4) {
const auto& rx = args[2];
const auto& ry = args[3];
const auto& rz = args[4];
float x, y, z;
if (!GeneralUtils::TryParse(rx, x) || !GeneralUtils::TryParse(ry, y) || !GeneralUtils::TryParse(rz, z)) {
const auto rx = GeneralUtils::TryParse<float>(args.at(2));
if (!rx) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid x.");
return;
}
const auto ry = GeneralUtils::TryParse<float>(args.at(3));
if (!ry) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid y.");
return;
}
const auto rz = GeneralUtils::TryParse<float>(args.at(4));
if (!rz) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid z.");
return;
}
float x = rx.value();
float y = ry.value();
float z = rz.value();
// Degrees to radia
x *= 0.0174533f;
y *= 0.0174533f;
@ -2261,41 +2273,67 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
Game::entityManager->SerializeEntity(closest);
} else if (args[1] == "-translate" && args.size() >= 4) {
const auto& tx = args[2];
const auto& ty = args[3];
const auto& tz = args[4];
float x, y, z;
if (!GeneralUtils::TryParse(tx, x) || !GeneralUtils::TryParse(ty, y) || !GeneralUtils::TryParse(tz, z)) {
const auto rx = GeneralUtils::TryParse<float>(args.at(2));
if (!rx) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid x.");
return;
}
const auto ry = GeneralUtils::TryParse<float>(args.at(3));
if (!ry) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid y.");
return;
}
const auto rz = GeneralUtils::TryParse<float>(args.at(4));
if (!rz) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid z.");
return;
}
float x = rx.value();
float y = ry.value();
float z = rz.value();
const auto translation = NiPoint3(x, y, z);
closest->SetPosition(closest->GetPosition() + translation);
Game::entityManager->SerializeEntity(closest);
} else if (args[1] == "-warp" && args.size() >= 4) {
const auto& tx = args[2];
const auto& ty = args[3];
const auto& tz = args[4];
float x, y, z;
if (!GeneralUtils::TryParse(tx, x) || !GeneralUtils::TryParse(ty, y) || !GeneralUtils::TryParse(tz, z)) {
const auto rx = GeneralUtils::TryParse<float>(args.at(2));
if (!rx) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid x.");
return;
}
const auto ry = GeneralUtils::TryParse<float>(args.at(3));
if (!ry) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid y.");
return;
}
const auto rz = GeneralUtils::TryParse<float>(args.at(4));
if (!rz) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid z.");
return;
}
float x = rx.value();
float y = ry.value();
float z = rz.value();
const auto translation = NiPoint3(x, y, z);
closest->SetPosition(translation);
Game::entityManager->SerializeEntity(closest);
} else if (args[1] == "-fx" && args.size() >= 4) {
int32_t effectID = 0;
int32_t effectID = GeneralUtils::TryParse<int32_t>(args[2]).value_or(-1);
if (!GeneralUtils::TryParse(args[2], effectID)) {
if (effectID == -1) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid effect ID.");
return;
}