mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-17 20:14:31 -06:00
Compare commits
52 Commits
fix-jitter
...
naming-of-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f6ee6327e | ||
|
|
d572ce1f1c | ||
|
|
85cd609168 | ||
|
|
d4e6939dbd | ||
|
|
f8d5110290 | ||
|
|
f0960d48b2 | ||
|
|
dc430d9758 | ||
|
|
dea10c6d56 | ||
|
|
ed00551982 | ||
|
|
d6cac65a8d | ||
|
|
a153d0a78c | ||
|
|
bfeb10c972 | ||
|
|
82507e642a | ||
|
|
abd978c348 | ||
|
|
10f8d40b69 | ||
|
|
37c2c5db5d | ||
|
|
693a2fef35 | ||
|
|
787237c930 | ||
|
|
0464f37fab | ||
|
|
78ae8bc6b6 | ||
|
|
d8f079cb1b | ||
|
|
c8e0bb0db0 | ||
|
|
d9d262d3f1 | ||
|
|
d0a5678290 | ||
|
|
35321b22d9 | ||
|
|
8837b110ab | ||
|
|
09a8c99f3e | ||
|
|
e3b108e00e | ||
|
|
9f382aca42 | ||
|
|
4d1395e522 | ||
| 9e36510c6b | |||
|
|
2ca61c3e57 | ||
| 07cb19cc30 | |||
|
|
794b254fe7 | ||
|
|
ab7f6f0b57 | ||
|
|
58cc569c75 | ||
|
|
35c463656d | ||
| 3801a97722 | |||
|
|
0367c67c85 | ||
|
|
8fdc212cda | ||
| 99e7349f6c | |||
|
|
fafe2aefad | ||
|
|
5049f215ba | ||
|
|
3a6123fe36 | ||
|
|
b8b2b687e2 | ||
| d067a8d12f | |||
|
|
1ee45639af | ||
|
|
db192d2cde | ||
|
|
28ce8ac54d | ||
|
|
be0a2f6f14 | ||
|
|
3260a063cb | ||
| feeac2e041 |
@@ -1,5 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
project(Darkflame)
|
||||
|
||||
# check if the path to the source directory contains a space
|
||||
if("${CMAKE_SOURCE_DIR}" MATCHES " ")
|
||||
message(FATAL_ERROR "The server cannot build in the path (" ${CMAKE_SOURCE_DIR} ") because it contains a space. Please move the server to a path without spaces.")
|
||||
endif()
|
||||
|
||||
include(CTest)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
PROJECT_VERSION_MAJOR=1
|
||||
PROJECT_VERSION_MINOR=1
|
||||
PROJECT_VERSION_PATCH=1
|
||||
PROJECT_VERSION_MAJOR=2
|
||||
PROJECT_VERSION_MINOR=3
|
||||
PROJECT_VERSION_PATCH=0
|
||||
|
||||
# Debugging
|
||||
# Set DYNAMIC to 1 to enable the -rdynamic flag for the linker, yielding some symbols in crashlogs.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "eGameMessageType.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "ChatPackets.h"
|
||||
|
||||
void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
//Get from the packet which player we want to do something with:
|
||||
@@ -354,6 +355,67 @@ void ChatPacketHandler::HandleGMLevelUpdate(Packet* packet) {
|
||||
inStream.Read(player.gmLevel);
|
||||
}
|
||||
|
||||
|
||||
void ChatPacketHandler::HandleWho(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
FindPlayerRequest request;
|
||||
request.Deserialize(inStream);
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(request.requestor);
|
||||
if (!sender) return;
|
||||
|
||||
const auto& player = Game::playerContainer.GetPlayerData(request.playerName.GetAsString());
|
||||
bool online = player;
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET);
|
||||
bitStream.Write(request.requestor);
|
||||
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::WHO_RESPONSE);
|
||||
bitStream.Write<uint8_t>(online);
|
||||
bitStream.Write(player.zoneID.GetMapID());
|
||||
bitStream.Write(player.zoneID.GetInstanceID());
|
||||
bitStream.Write(player.zoneID.GetCloneID());
|
||||
bitStream.Write(request.playerName);
|
||||
|
||||
SystemAddress sysAddr = sender.sysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleShowAll(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ShowAllRequest request;
|
||||
request.Deserialize(inStream);
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(request.requestor);
|
||||
if (!sender) return;
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WORLD_ROUTE_PACKET);
|
||||
bitStream.Write(request.requestor);
|
||||
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::SHOW_ALL_RESPONSE);
|
||||
bitStream.Write<uint8_t>(!request.displayZoneData && !request.displayIndividualPlayers);
|
||||
bitStream.Write(Game::playerContainer.GetPlayerCount());
|
||||
bitStream.Write(Game::playerContainer.GetSimCount());
|
||||
bitStream.Write<uint8_t>(request.displayIndividualPlayers);
|
||||
bitStream.Write<uint8_t>(request.displayZoneData);
|
||||
if (request.displayZoneData || request.displayIndividualPlayers){
|
||||
for (auto& [playerID, playerData ]: Game::playerContainer.GetAllPlayers()){
|
||||
if (!playerData) continue;
|
||||
bitStream.Write<uint8_t>(0); // structure packing
|
||||
if (request.displayIndividualPlayers) bitStream.Write(LUWString(playerData.playerName));
|
||||
if (request.displayZoneData) {
|
||||
bitStream.Write(playerData.zoneID.GetMapID());
|
||||
bitStream.Write(playerData.zoneID.GetInstanceID());
|
||||
bitStream.Write(playerData.zoneID.GetCloneID());
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemAddress sysAddr = sender.sysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
// the structure the client uses to send this packet is shared in many chat messages
|
||||
// that are sent to the server. Because of this, there are large gaps of unused data in chat messages
|
||||
void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
|
||||
@@ -50,6 +50,8 @@ namespace ChatPacketHandler {
|
||||
void HandleFriendResponse(Packet* packet);
|
||||
void HandleRemoveFriend(Packet* packet);
|
||||
void HandleGMLevelUpdate(Packet* packet);
|
||||
void HandleWho(Packet* packet);
|
||||
void HandleShowAll(Packet* packet);
|
||||
|
||||
void HandleChatMessage(Packet* packet);
|
||||
void HandlePrivateChatMessage(Packet* packet);
|
||||
|
||||
@@ -289,7 +289,11 @@ void HandlePacket(Packet* packet) {
|
||||
Game::playerContainer.RemovePlayer(packet);
|
||||
break;
|
||||
case eChatMessageType::WHO:
|
||||
ChatPacketHandler::HandleWho(packet);
|
||||
break;
|
||||
case eChatMessageType::SHOW_ALL:
|
||||
ChatPacketHandler::HandleShowAll(packet);
|
||||
break;
|
||||
case eChatMessageType::USER_CHANNEL_CHAT_MESSAGE:
|
||||
case eChatMessageType::WORLD_DISCONNECT_REQUEST:
|
||||
case eChatMessageType::WORLD_PROXIMITY_RESPONSE:
|
||||
|
||||
@@ -49,6 +49,7 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
data.sysAddr = packet->systemAddress;
|
||||
|
||||
m_Names[data.playerID] = GeneralUtils::UTF8ToUTF16(data.playerName);
|
||||
m_PlayerCount++;
|
||||
|
||||
LOG("Added user: %s (%llu), zone: %i", data.playerName.c_str(), data.playerID, data.zoneID.GetMapID());
|
||||
|
||||
@@ -87,6 +88,7 @@ void PlayerContainer::RemovePlayer(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
m_PlayerCount--;
|
||||
LOG("Removed user: %llu", playerID);
|
||||
m_Players.erase(playerID);
|
||||
|
||||
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
const PlayerData& GetPlayerData(const std::string& playerName);
|
||||
PlayerData& GetPlayerDataMutable(const LWOOBJID& playerID);
|
||||
PlayerData& GetPlayerDataMutable(const std::string& playerName);
|
||||
uint32_t GetPlayerCount() { return m_PlayerCount; };
|
||||
uint32_t GetSimCount() { return m_SimCount; };
|
||||
const std::map<LWOOBJID, PlayerData>& GetAllPlayers() { return m_Players; };
|
||||
|
||||
TeamData* CreateLocalTeam(std::vector<LWOOBJID> members);
|
||||
TeamData* CreateTeam(LWOOBJID leader, bool local = false);
|
||||
@@ -93,5 +96,7 @@ private:
|
||||
std::unordered_map<LWOOBJID, std::u16string> m_Names;
|
||||
uint32_t m_MaxNumberOfBestFriends = 5;
|
||||
uint32_t m_MaxNumberOfFriends = 50;
|
||||
uint32_t m_PlayerCount = 0;
|
||||
uint32_t m_SimCount = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ void CatchUnhandled(int sig) {
|
||||
if (eptr) std::rethrow_exception(eptr);
|
||||
} catch(const std::exception& e) {
|
||||
LOG("Caught exception: '%s'", e.what());
|
||||
} catch (...) {
|
||||
LOG("Caught unknown exception.");
|
||||
}
|
||||
|
||||
#ifndef INCLUDE_BACKTRACE
|
||||
|
||||
@@ -8,23 +8,23 @@
|
||||
#include <map>
|
||||
|
||||
template <typename T>
|
||||
inline size_t MinSize(size_t size, const std::basic_string_view<T>& string) {
|
||||
if (size == size_t(-1) || size > string.size()) {
|
||||
static inline size_t MinSize(const size_t size, const std::basic_string_view<T> string) {
|
||||
if (size == SIZE_MAX || size > string.size()) {
|
||||
return string.size();
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsLeadSurrogate(char16_t c) {
|
||||
inline bool IsLeadSurrogate(const char16_t c) {
|
||||
return (0xD800 <= c) && (c <= 0xDBFF);
|
||||
}
|
||||
|
||||
inline bool IsTrailSurrogate(char16_t c) {
|
||||
inline bool IsTrailSurrogate(const char16_t c) {
|
||||
return (0xDC00 <= c) && (c <= 0xDFFF);
|
||||
}
|
||||
|
||||
inline void PushUTF8CodePoint(std::string& ret, char32_t cp) {
|
||||
inline void PushUTF8CodePoint(std::string& ret, const char32_t cp) {
|
||||
if (cp <= 0x007F) {
|
||||
ret.push_back(static_cast<uint8_t>(cp));
|
||||
} else if (cp <= 0x07FF) {
|
||||
@@ -46,16 +46,16 @@ inline void PushUTF8CodePoint(std::string& ret, char32_t cp) {
|
||||
|
||||
constexpr const char16_t REPLACEMENT_CHARACTER = 0xFFFD;
|
||||
|
||||
bool _IsSuffixChar(uint8_t c) {
|
||||
bool static _IsSuffixChar(const uint8_t c) {
|
||||
return (c & 0xC0) == 0x80;
|
||||
}
|
||||
|
||||
bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
size_t rem = slice.length();
|
||||
bool GeneralUtils::details::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
const size_t rem = slice.length();
|
||||
if (slice.empty()) return false;
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&slice.front());
|
||||
if (rem > 0) {
|
||||
uint8_t first = bytes[0];
|
||||
const uint8_t first = bytes[0];
|
||||
if (first < 0x80) { // 1 byte character
|
||||
out = static_cast<uint32_t>(first & 0x7F);
|
||||
slice.remove_prefix(1);
|
||||
@@ -64,7 +64,7 @@ bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
// middle byte, not valid at start, fall through
|
||||
} else if (first < 0xE0) { // two byte character
|
||||
if (rem > 1) {
|
||||
uint8_t second = bytes[1];
|
||||
const uint8_t second = bytes[1];
|
||||
if (_IsSuffixChar(second)) {
|
||||
out = (static_cast<uint32_t>(first & 0x1F) << 6)
|
||||
+ static_cast<uint32_t>(second & 0x3F);
|
||||
@@ -74,8 +74,8 @@ bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
}
|
||||
} else if (first < 0xF0) { // three byte character
|
||||
if (rem > 2) {
|
||||
uint8_t second = bytes[1];
|
||||
uint8_t third = bytes[2];
|
||||
const uint8_t second = bytes[1];
|
||||
const uint8_t third = bytes[2];
|
||||
if (_IsSuffixChar(second) && _IsSuffixChar(third)) {
|
||||
out = (static_cast<uint32_t>(first & 0x0F) << 12)
|
||||
+ (static_cast<uint32_t>(second & 0x3F) << 6)
|
||||
@@ -86,9 +86,9 @@ bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
}
|
||||
} else if (first < 0xF8) { // four byte character
|
||||
if (rem > 3) {
|
||||
uint8_t second = bytes[1];
|
||||
uint8_t third = bytes[2];
|
||||
uint8_t fourth = bytes[3];
|
||||
const uint8_t second = bytes[1];
|
||||
const uint8_t third = bytes[2];
|
||||
const uint8_t fourth = bytes[3];
|
||||
if (_IsSuffixChar(second) && _IsSuffixChar(third) && _IsSuffixChar(fourth)) {
|
||||
out = (static_cast<uint32_t>(first & 0x07) << 18)
|
||||
+ (static_cast<uint32_t>(second & 0x3F) << 12)
|
||||
@@ -107,7 +107,7 @@ bool GeneralUtils::_NextUTF8Char(std::string_view& slice, uint32_t& out) {
|
||||
}
|
||||
|
||||
/// See <https://www.ietf.org/rfc/rfc2781.html#section-2.1>
|
||||
bool PushUTF16CodePoint(std::u16string& output, uint32_t U, size_t size) {
|
||||
bool PushUTF16CodePoint(std::u16string& output, const uint32_t U, const size_t size) {
|
||||
if (output.length() >= size) return false;
|
||||
if (U < 0x10000) {
|
||||
// If U < 0x10000, encode U as a 16-bit unsigned integer and terminate.
|
||||
@@ -120,7 +120,7 @@ bool PushUTF16CodePoint(std::u16string& output, uint32_t U, size_t size) {
|
||||
// Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
|
||||
// U' must be less than or equal to 0xFFFFF. That is, U' can be
|
||||
// represented in 20 bits.
|
||||
uint32_t Ut = U - 0x10000;
|
||||
const uint32_t Ut = U - 0x10000;
|
||||
|
||||
// Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
|
||||
// 0xDC00, respectively. These integers each have 10 bits free to
|
||||
@@ -141,25 +141,25 @@ bool PushUTF16CodePoint(std::u16string& output, uint32_t U, size_t size) {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
std::u16string GeneralUtils::UTF8ToUTF16(const std::string_view& string, size_t size) {
|
||||
size_t newSize = MinSize(size, string);
|
||||
std::u16string GeneralUtils::UTF8ToUTF16(const std::string_view string, const size_t size) {
|
||||
const size_t newSize = MinSize(size, string);
|
||||
std::u16string output;
|
||||
output.reserve(newSize);
|
||||
std::string_view iterator = string;
|
||||
|
||||
uint32_t c;
|
||||
while (_NextUTF8Char(iterator, c) && PushUTF16CodePoint(output, c, size)) {}
|
||||
while (details::_NextUTF8Char(iterator, c) && PushUTF16CodePoint(output, c, size)) {}
|
||||
return output;
|
||||
}
|
||||
|
||||
//! Converts an std::string (ASCII) to UCS-2 / UTF-16
|
||||
std::u16string GeneralUtils::ASCIIToUTF16(const std::string_view& string, size_t size) {
|
||||
size_t newSize = MinSize(size, string);
|
||||
std::u16string GeneralUtils::ASCIIToUTF16(const std::string_view string, const size_t size) {
|
||||
const size_t newSize = MinSize(size, string);
|
||||
std::u16string ret;
|
||||
ret.reserve(newSize);
|
||||
|
||||
for (size_t i = 0; i < newSize; i++) {
|
||||
char c = string[i];
|
||||
for (size_t i = 0; i < newSize; ++i) {
|
||||
const char c = string[i];
|
||||
// Note: both 7-bit ascii characters and REPLACEMENT_CHARACTER fit in one char16_t
|
||||
ret.push_back((c > 0 && c <= 127) ? static_cast<char16_t>(c) : REPLACEMENT_CHARACTER);
|
||||
}
|
||||
@@ -169,18 +169,18 @@ std::u16string GeneralUtils::ASCIIToUTF16(const std::string_view& string, size_t
|
||||
|
||||
//! Converts a (potentially-ill-formed) UTF-16 string to UTF-8
|
||||
//! See: <http://simonsapin.github.io/wtf-8/#decoding-ill-formed-utf-16>
|
||||
std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view& string, size_t size) {
|
||||
size_t newSize = MinSize(size, string);
|
||||
std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const size_t size) {
|
||||
const size_t newSize = MinSize(size, string);
|
||||
std::string ret;
|
||||
ret.reserve(newSize);
|
||||
|
||||
for (size_t i = 0; i < newSize; i++) {
|
||||
char16_t u = string[i];
|
||||
for (size_t i = 0; i < newSize; ++i) {
|
||||
const char16_t u = string[i];
|
||||
if (IsLeadSurrogate(u) && (i + 1) < newSize) {
|
||||
char16_t next = string[i + 1];
|
||||
const char16_t next = string[i + 1];
|
||||
if (IsTrailSurrogate(next)) {
|
||||
i += 1;
|
||||
char32_t cp = 0x10000
|
||||
const char32_t cp = 0x10000
|
||||
+ ((static_cast<char32_t>(u) - 0xD800) << 10)
|
||||
+ (static_cast<char32_t>(next) - 0xDC00);
|
||||
PushUTF8CodePoint(ret, cp);
|
||||
@@ -195,40 +195,40 @@ std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view& string, size_t
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool GeneralUtils::CaseInsensitiveStringCompare(const std::string& a, const std::string& b) {
|
||||
bool GeneralUtils::CaseInsensitiveStringCompare(const std::string_view a, const std::string_view b) {
|
||||
return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == tolower(b); });
|
||||
}
|
||||
|
||||
// MARK: Bits
|
||||
|
||||
//! Sets a specific bit in a signed 64-bit integer
|
||||
int64_t GeneralUtils::SetBit(int64_t value, uint32_t index) {
|
||||
int64_t GeneralUtils::SetBit(int64_t value, const uint32_t index) {
|
||||
return value |= 1ULL << index;
|
||||
}
|
||||
|
||||
//! Clears a specific bit in a signed 64-bit integer
|
||||
int64_t GeneralUtils::ClearBit(int64_t value, uint32_t index) {
|
||||
int64_t GeneralUtils::ClearBit(int64_t value, const uint32_t index) {
|
||||
return value &= ~(1ULL << index);
|
||||
}
|
||||
|
||||
//! Checks a specific bit in a signed 64-bit integer
|
||||
bool GeneralUtils::CheckBit(int64_t value, uint32_t index) {
|
||||
bool GeneralUtils::CheckBit(int64_t value, const uint32_t index) {
|
||||
return value & (1ULL << index);
|
||||
}
|
||||
|
||||
bool GeneralUtils::ReplaceInString(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = str.find(from);
|
||||
bool GeneralUtils::ReplaceInString(std::string& str, const std::string_view from, const std::string_view to) {
|
||||
const size_t start_pos = str.find(from);
|
||||
if (start_pos == std::string::npos)
|
||||
return false;
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GeneralUtils::SplitString(std::wstring& str, wchar_t delimiter) {
|
||||
std::vector<std::wstring> GeneralUtils::SplitString(const std::wstring_view str, const wchar_t delimiter) {
|
||||
std::vector<std::wstring> vector = std::vector<std::wstring>();
|
||||
std::wstring current;
|
||||
|
||||
for (const auto& c : str) {
|
||||
for (const wchar_t c : str) {
|
||||
if (c == delimiter) {
|
||||
vector.push_back(current);
|
||||
current = L"";
|
||||
@@ -237,15 +237,15 @@ std::vector<std::wstring> GeneralUtils::SplitString(std::wstring& str, wchar_t d
|
||||
}
|
||||
}
|
||||
|
||||
vector.push_back(current);
|
||||
vector.push_back(std::move(current));
|
||||
return vector;
|
||||
}
|
||||
|
||||
std::vector<std::u16string> GeneralUtils::SplitString(const std::u16string& str, char16_t delimiter) {
|
||||
std::vector<std::u16string> GeneralUtils::SplitString(const std::u16string_view str, const char16_t delimiter) {
|
||||
std::vector<std::u16string> vector = std::vector<std::u16string>();
|
||||
std::u16string current;
|
||||
|
||||
for (const auto& c : str) {
|
||||
for (const char16_t c : str) {
|
||||
if (c == delimiter) {
|
||||
vector.push_back(current);
|
||||
current = u"";
|
||||
@@ -254,17 +254,15 @@ std::vector<std::u16string> GeneralUtils::SplitString(const std::u16string& str,
|
||||
}
|
||||
}
|
||||
|
||||
vector.push_back(current);
|
||||
vector.push_back(std::move(current));
|
||||
return vector;
|
||||
}
|
||||
|
||||
std::vector<std::string> GeneralUtils::SplitString(const std::string& str, char delimiter) {
|
||||
std::vector<std::string> GeneralUtils::SplitString(const std::string_view str, const char delimiter) {
|
||||
std::vector<std::string> vector = std::vector<std::string>();
|
||||
std::string current = "";
|
||||
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
char c = str[i];
|
||||
|
||||
for (const char c : str) {
|
||||
if (c == delimiter) {
|
||||
vector.push_back(current);
|
||||
current = "";
|
||||
@@ -273,8 +271,7 @@ std::vector<std::string> GeneralUtils::SplitString(const std::string& str, char
|
||||
}
|
||||
}
|
||||
|
||||
vector.push_back(current);
|
||||
|
||||
vector.push_back(std::move(current));
|
||||
return vector;
|
||||
}
|
||||
|
||||
@@ -283,7 +280,7 @@ std::u16string GeneralUtils::ReadWString(RakNet::BitStream& inStream) {
|
||||
inStream.Read<uint32_t>(length);
|
||||
|
||||
std::u16string string;
|
||||
for (auto i = 0; i < length; i++) {
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
uint16_t c;
|
||||
inStream.Read(c);
|
||||
string.push_back(c);
|
||||
@@ -292,29 +289,29 @@ std::u16string GeneralUtils::ReadWString(RakNet::BitStream& inStream) {
|
||||
return string;
|
||||
}
|
||||
|
||||
std::vector<std::string> GeneralUtils::GetSqlFileNamesFromFolder(const std::string& folder) {
|
||||
std::vector<std::string> GeneralUtils::GetSqlFileNamesFromFolder(const std::string_view folder) {
|
||||
// Because we dont know how large the initial number before the first _ is we need to make it a map like so.
|
||||
std::map<uint32_t, std::string> filenames{};
|
||||
for (auto& t : std::filesystem::directory_iterator(folder)) {
|
||||
auto filename = t.path().filename().string();
|
||||
auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
||||
filenames.insert(std::make_pair(index, filename));
|
||||
std::map<uint32_t, std::string> filenames{};
|
||||
for (const auto& t : std::filesystem::directory_iterator(folder)) {
|
||||
auto filename = t.path().filename().string();
|
||||
const auto index = std::stoi(GeneralUtils::SplitString(filename, '_').at(0));
|
||||
filenames.emplace(index, std::move(filename));
|
||||
}
|
||||
|
||||
// Now sort the map by the oldest migration.
|
||||
std::vector<std::string> sortedFiles{};
|
||||
auto fileIterator = filenames.begin();
|
||||
std::map<uint32_t, std::string>::iterator oldest = filenames.begin();
|
||||
auto fileIterator = filenames.cbegin();
|
||||
auto oldest = filenames.cbegin();
|
||||
while (!filenames.empty()) {
|
||||
if (fileIterator == filenames.end()) {
|
||||
if (fileIterator == filenames.cend()) {
|
||||
sortedFiles.push_back(oldest->second);
|
||||
filenames.erase(oldest);
|
||||
fileIterator = filenames.begin();
|
||||
oldest = filenames.begin();
|
||||
fileIterator = filenames.cbegin();
|
||||
oldest = filenames.cbegin();
|
||||
continue;
|
||||
}
|
||||
if (oldest->first > fileIterator->first) oldest = fileIterator;
|
||||
fileIterator++;
|
||||
++fileIterator;
|
||||
}
|
||||
|
||||
return sortedFiles;
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
// C++
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "NiPoint3.h"
|
||||
|
||||
#include "dPlatforms.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
@@ -32,29 +33,31 @@ namespace GeneralUtils {
|
||||
//! Converts a plain ASCII string to a UTF-16 string
|
||||
/*!
|
||||
\param string The string to convert
|
||||
\param size A size to trim the string to. Default is -1 (No trimming)
|
||||
\param size A size to trim the string to. Default is SIZE_MAX (No trimming)
|
||||
\return An UTF-16 representation of the string
|
||||
*/
|
||||
std::u16string ASCIIToUTF16(const std::string_view& string, size_t size = -1);
|
||||
std::u16string ASCIIToUTF16(const std::string_view string, const size_t size = SIZE_MAX);
|
||||
|
||||
//! Converts a UTF-8 String to a UTF-16 string
|
||||
/*!
|
||||
\param string The string to convert
|
||||
\param size A size to trim the string to. Default is -1 (No trimming)
|
||||
\param size A size to trim the string to. Default is SIZE_MAX (No trimming)
|
||||
\return An UTF-16 representation of the string
|
||||
*/
|
||||
std::u16string UTF8ToUTF16(const std::string_view& string, size_t size = -1);
|
||||
std::u16string UTF8ToUTF16(const std::string_view string, const size_t size = SIZE_MAX);
|
||||
|
||||
//! Internal, do not use
|
||||
bool _NextUTF8Char(std::string_view& slice, uint32_t& out);
|
||||
namespace details {
|
||||
//! Internal, do not use
|
||||
bool _NextUTF8Char(std::string_view& slice, uint32_t& out);
|
||||
}
|
||||
|
||||
//! Converts a UTF-16 string to a UTF-8 string
|
||||
/*!
|
||||
\param string The string to convert
|
||||
\param size A size to trim the string to. Default is -1 (No trimming)
|
||||
\param size A size to trim the string to. Default is SIZE_MAX (No trimming)
|
||||
\return An UTF-8 representation of the string
|
||||
*/
|
||||
std::string UTF16ToWTF8(const std::u16string_view& string, size_t size = -1);
|
||||
std::string UTF16ToWTF8(const std::u16string_view string, const size_t size = SIZE_MAX);
|
||||
|
||||
/**
|
||||
* Compares two basic strings but does so ignoring case sensitivity
|
||||
@@ -62,7 +65,7 @@ namespace GeneralUtils {
|
||||
* \param b the second string to compare against the first string
|
||||
* @return if the two strings are equal
|
||||
*/
|
||||
bool CaseInsensitiveStringCompare(const std::string& a, const std::string& b);
|
||||
bool CaseInsensitiveStringCompare(const std::string_view a, const std::string_view b);
|
||||
|
||||
// MARK: Bits
|
||||
|
||||
@@ -70,9 +73,9 @@ namespace GeneralUtils {
|
||||
|
||||
//! Sets a bit on a numerical value
|
||||
template <typename T>
|
||||
inline void SetBit(T& value, eObjectBits bits) {
|
||||
inline void SetBit(T& value, const eObjectBits bits) {
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
auto index = static_cast<size_t>(bits);
|
||||
const auto index = static_cast<size_t>(bits);
|
||||
if (index > (sizeof(T) * 8) - 1) {
|
||||
return;
|
||||
}
|
||||
@@ -82,9 +85,9 @@ namespace GeneralUtils {
|
||||
|
||||
//! Clears a bit on a numerical value
|
||||
template <typename T>
|
||||
inline void ClearBit(T& value, eObjectBits bits) {
|
||||
inline void ClearBit(T& value, const eObjectBits bits) {
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
auto index = static_cast<size_t>(bits);
|
||||
const auto index = static_cast<size_t>(bits);
|
||||
if (index > (sizeof(T) * 8 - 1)) {
|
||||
return;
|
||||
}
|
||||
@@ -97,14 +100,14 @@ namespace GeneralUtils {
|
||||
\param value The value to set the bit for
|
||||
\param index The index of the bit
|
||||
*/
|
||||
int64_t SetBit(int64_t value, uint32_t index);
|
||||
int64_t SetBit(int64_t value, const uint32_t index);
|
||||
|
||||
//! Clears a specific bit in a signed 64-bit integer
|
||||
/*!
|
||||
\param value The value to clear the bit from
|
||||
\param index The index of the bit
|
||||
*/
|
||||
int64_t ClearBit(int64_t value, uint32_t index);
|
||||
int64_t ClearBit(int64_t value, const uint32_t index);
|
||||
|
||||
//! Checks a specific bit in a signed 64-bit integer
|
||||
/*!
|
||||
@@ -112,19 +115,19 @@ namespace GeneralUtils {
|
||||
\param index The index of the bit
|
||||
\return Whether or not the bit is set
|
||||
*/
|
||||
bool CheckBit(int64_t value, uint32_t index);
|
||||
bool CheckBit(int64_t value, const uint32_t index);
|
||||
|
||||
bool ReplaceInString(std::string& str, const std::string& from, const std::string& to);
|
||||
bool ReplaceInString(std::string& str, const std::string_view from, const std::string_view to);
|
||||
|
||||
std::u16string ReadWString(RakNet::BitStream& inStream);
|
||||
|
||||
std::vector<std::wstring> SplitString(std::wstring& str, wchar_t delimiter);
|
||||
std::vector<std::wstring> SplitString(const std::wstring_view str, const wchar_t delimiter);
|
||||
|
||||
std::vector<std::u16string> SplitString(const std::u16string& str, char16_t delimiter);
|
||||
std::vector<std::u16string> SplitString(const std::u16string_view str, const char16_t delimiter);
|
||||
|
||||
std::vector<std::string> SplitString(const std::string& str, char delimiter);
|
||||
std::vector<std::string> SplitString(const std::string_view str, const char delimiter);
|
||||
|
||||
std::vector<std::string> GetSqlFileNamesFromFolder(const std::string& folder);
|
||||
std::vector<std::string> GetSqlFileNamesFromFolder(const std::string_view folder);
|
||||
|
||||
// Concept constraining to enum types
|
||||
template <typename T>
|
||||
@@ -144,7 +147,7 @@ namespace GeneralUtils {
|
||||
|
||||
// If a boolean, present an alias to an intermediate integral type for parsing
|
||||
template <Numeric T> requires std::same_as<T, bool>
|
||||
struct numeric_parse<T> { using type = uint32_t; };
|
||||
struct numeric_parse<T> { using type = uint8_t; };
|
||||
|
||||
// Shorthand type alias
|
||||
template <Numeric T>
|
||||
@@ -156,8 +159,9 @@ namespace GeneralUtils {
|
||||
* @returns An std::optional containing the desired value if it is equivalent to the string
|
||||
*/
|
||||
template <Numeric T>
|
||||
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) {
|
||||
[[nodiscard]] std::optional<T> TryParse(std::string_view str) {
|
||||
numeric_parse_t<T> result;
|
||||
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);
|
||||
|
||||
const char* const strEnd = str.data() + str.size();
|
||||
const auto [parseEnd, ec] = std::from_chars(str.data(), strEnd, result);
|
||||
@@ -181,8 +185,10 @@ namespace GeneralUtils {
|
||||
* @returns An std::optional containing the desired value if it is equivalent to the string
|
||||
*/
|
||||
template <std::floating_point T>
|
||||
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) noexcept
|
||||
[[nodiscard]] std::optional<T> TryParse(std::string_view str) noexcept
|
||||
try {
|
||||
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);
|
||||
|
||||
size_t parseNum;
|
||||
const T result = details::_parse<T>(str, parseNum);
|
||||
const bool isParsed = str.length() == parseNum;
|
||||
@@ -202,7 +208,7 @@ namespace GeneralUtils {
|
||||
* @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::optional<NiPoint3> TryParse(const std::string& strX, const std::string& strY, const std::string& strZ) {
|
||||
[[nodiscard]] std::optional<NiPoint3> TryParse(const std::string_view strX, const std::string_view strY, const std::string_view strZ) {
|
||||
const auto x = TryParse<float>(strX);
|
||||
if (!x) return std::nullopt;
|
||||
|
||||
@@ -214,17 +220,17 @@ namespace GeneralUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* The TryParse overload for handling NiPoint3 by passingn a reference to a vector of three strings
|
||||
* @param str The string vector representing the X, Y, and Xcoordinates
|
||||
* The TryParse overload for handling NiPoint3 by passing a span of three strings
|
||||
* @param str The string vector representing the X, Y, and Z coordinates
|
||||
* @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters
|
||||
*/
|
||||
template <typename T>
|
||||
[[nodiscard]] std::optional<NiPoint3> TryParse(const std::vector<std::string>& str) {
|
||||
[[nodiscard]] std::optional<NiPoint3> TryParse(const std::span<const std::string> str) {
|
||||
return (str.size() == 3) ? TryParse<NiPoint3>(str[0], str[1], str[2]) : std::nullopt;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::u16string to_u16string(T value) {
|
||||
std::u16string to_u16string(const T value) {
|
||||
return GeneralUtils::ASCIIToUTF16(std::to_string(value));
|
||||
}
|
||||
|
||||
@@ -243,7 +249,7 @@ namespace GeneralUtils {
|
||||
\param max The maximum to generate to
|
||||
*/
|
||||
template <typename T>
|
||||
inline T GenerateRandomNumber(std::size_t min, std::size_t max) {
|
||||
inline T GenerateRandomNumber(const std::size_t min, const std::size_t max) {
|
||||
// Make sure it is a numeric type
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
|
||||
@@ -270,10 +276,10 @@ namespace GeneralUtils {
|
||||
|
||||
// on Windows we need to undef these or else they conflict with our numeric limits calls
|
||||
// DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS
|
||||
#ifdef _WIN32
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline T GenerateRandomNumber() {
|
||||
|
||||
@@ -31,22 +31,22 @@ public:
|
||||
|
||||
virtual ~LDFBaseData() {}
|
||||
|
||||
virtual void WriteToPacket(RakNet::BitStream& packet) = 0;
|
||||
virtual void WriteToPacket(RakNet::BitStream& packet) const = 0;
|
||||
|
||||
virtual const std::u16string& GetKey() = 0;
|
||||
virtual const std::u16string& GetKey() const = 0;
|
||||
|
||||
virtual eLDFType GetValueType() = 0;
|
||||
virtual eLDFType GetValueType() const = 0;
|
||||
|
||||
/** Gets a string from the key/value pair
|
||||
* @param includeKey Whether or not to include the key in the data
|
||||
* @param includeTypeId Whether or not to include the type id in the data
|
||||
* @return The string representation of the data
|
||||
*/
|
||||
virtual std::string GetString(bool includeKey = true, bool includeTypeId = true) = 0;
|
||||
virtual std::string GetString(bool includeKey = true, bool includeTypeId = true) const = 0;
|
||||
|
||||
virtual std::string GetValueAsString() = 0;
|
||||
virtual std::string GetValueAsString() const = 0;
|
||||
|
||||
virtual LDFBaseData* Copy() = 0;
|
||||
virtual LDFBaseData* Copy() const = 0;
|
||||
|
||||
/**
|
||||
* Given an input string, return the data as a LDF key.
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
T value;
|
||||
|
||||
//! Writes the key to the packet
|
||||
void WriteKey(RakNet::BitStream& packet) {
|
||||
void WriteKey(RakNet::BitStream& packet) const {
|
||||
packet.Write<uint8_t>(this->key.length() * sizeof(uint16_t));
|
||||
for (uint32_t i = 0; i < this->key.length(); ++i) {
|
||||
packet.Write<uint16_t>(this->key[i]);
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
}
|
||||
|
||||
//! Writes the value to the packet
|
||||
void WriteValue(RakNet::BitStream& packet) {
|
||||
void WriteValue(RakNet::BitStream& packet) const {
|
||||
packet.Write<uint8_t>(this->GetValueType());
|
||||
packet.Write(this->value);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
/*!
|
||||
\return The value
|
||||
*/
|
||||
const T& GetValue(void) { return this->value; }
|
||||
const T& GetValue(void) const { return this->value; }
|
||||
|
||||
//! Sets the value
|
||||
/*!
|
||||
@@ -102,13 +102,13 @@ public:
|
||||
/*!
|
||||
\return The value string
|
||||
*/
|
||||
std::string GetValueString(void) { return ""; }
|
||||
std::string GetValueString(void) const { return ""; }
|
||||
|
||||
//! Writes the data to a packet
|
||||
/*!
|
||||
\param packet The packet
|
||||
*/
|
||||
void WriteToPacket(RakNet::BitStream& packet) override {
|
||||
void WriteToPacket(RakNet::BitStream& packet) const override {
|
||||
this->WriteKey(packet);
|
||||
this->WriteValue(packet);
|
||||
}
|
||||
@@ -117,13 +117,13 @@ public:
|
||||
/*!
|
||||
\return The key
|
||||
*/
|
||||
const std::u16string& GetKey(void) override { return this->key; }
|
||||
const std::u16string& GetKey(void) const override { return this->key; }
|
||||
|
||||
//! Gets the LDF Type
|
||||
/*!
|
||||
\return The LDF value type
|
||||
*/
|
||||
eLDFType GetValueType(void) override { return LDF_TYPE_UNKNOWN; }
|
||||
eLDFType GetValueType(void) const override { return LDF_TYPE_UNKNOWN; }
|
||||
|
||||
//! Gets the string data
|
||||
/*!
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
\param includeTypeId Whether or not to include the type id in the data
|
||||
\return The string representation of the data
|
||||
*/
|
||||
std::string GetString(const bool includeKey = true, const bool includeTypeId = true) override {
|
||||
std::string GetString(const bool includeKey = true, const bool includeTypeId = true) const override {
|
||||
if (GetValueType() == -1) {
|
||||
return GeneralUtils::UTF16ToWTF8(this->key) + "=-1:<server variable>";
|
||||
}
|
||||
@@ -154,11 +154,11 @@ public:
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string GetValueAsString() override {
|
||||
std::string GetValueAsString() const override {
|
||||
return this->GetValueString();
|
||||
}
|
||||
|
||||
LDFBaseData* Copy() override {
|
||||
LDFBaseData* Copy() const override {
|
||||
return new LDFData<T>(key, value);
|
||||
}
|
||||
|
||||
@@ -166,19 +166,19 @@ public:
|
||||
};
|
||||
|
||||
// LDF Types
|
||||
template<> inline eLDFType LDFData<std::u16string>::GetValueType(void) { return LDF_TYPE_UTF_16; };
|
||||
template<> inline eLDFType LDFData<int32_t>::GetValueType(void) { return LDF_TYPE_S32; };
|
||||
template<> inline eLDFType LDFData<float>::GetValueType(void) { return LDF_TYPE_FLOAT; };
|
||||
template<> inline eLDFType LDFData<double>::GetValueType(void) { return LDF_TYPE_DOUBLE; };
|
||||
template<> inline eLDFType LDFData<uint32_t>::GetValueType(void) { return LDF_TYPE_U32; };
|
||||
template<> inline eLDFType LDFData<bool>::GetValueType(void) { return LDF_TYPE_BOOLEAN; };
|
||||
template<> inline eLDFType LDFData<uint64_t>::GetValueType(void) { return LDF_TYPE_U64; };
|
||||
template<> inline eLDFType LDFData<LWOOBJID>::GetValueType(void) { return LDF_TYPE_OBJID; };
|
||||
template<> inline eLDFType LDFData<std::string>::GetValueType(void) { return LDF_TYPE_UTF_8; };
|
||||
template<> inline eLDFType LDFData<std::u16string>::GetValueType(void) const { return LDF_TYPE_UTF_16; };
|
||||
template<> inline eLDFType LDFData<int32_t>::GetValueType(void) const { return LDF_TYPE_S32; };
|
||||
template<> inline eLDFType LDFData<float>::GetValueType(void) const { return LDF_TYPE_FLOAT; };
|
||||
template<> inline eLDFType LDFData<double>::GetValueType(void) const { return LDF_TYPE_DOUBLE; };
|
||||
template<> inline eLDFType LDFData<uint32_t>::GetValueType(void) const { return LDF_TYPE_U32; };
|
||||
template<> inline eLDFType LDFData<bool>::GetValueType(void) const { return LDF_TYPE_BOOLEAN; };
|
||||
template<> inline eLDFType LDFData<uint64_t>::GetValueType(void) const { return LDF_TYPE_U64; };
|
||||
template<> inline eLDFType LDFData<LWOOBJID>::GetValueType(void) const { return LDF_TYPE_OBJID; };
|
||||
template<> inline eLDFType LDFData<std::string>::GetValueType(void) const { return LDF_TYPE_UTF_8; };
|
||||
|
||||
// The specialized version for std::u16string (UTF-16)
|
||||
template<>
|
||||
inline void LDFData<std::u16string>::WriteValue(RakNet::BitStream& packet) {
|
||||
inline void LDFData<std::u16string>::WriteValue(RakNet::BitStream& packet) const {
|
||||
packet.Write<uint8_t>(this->GetValueType());
|
||||
|
||||
packet.Write<uint32_t>(this->value.length());
|
||||
@@ -189,7 +189,7 @@ inline void LDFData<std::u16string>::WriteValue(RakNet::BitStream& packet) {
|
||||
|
||||
// The specialized version for bool
|
||||
template<>
|
||||
inline void LDFData<bool>::WriteValue(RakNet::BitStream& packet) {
|
||||
inline void LDFData<bool>::WriteValue(RakNet::BitStream& packet) const {
|
||||
packet.Write<uint8_t>(this->GetValueType());
|
||||
|
||||
packet.Write<uint8_t>(this->value);
|
||||
@@ -197,7 +197,7 @@ inline void LDFData<bool>::WriteValue(RakNet::BitStream& packet) {
|
||||
|
||||
// The specialized version for std::string (UTF-8)
|
||||
template<>
|
||||
inline void LDFData<std::string>::WriteValue(RakNet::BitStream& packet) {
|
||||
inline void LDFData<std::string>::WriteValue(RakNet::BitStream& packet) const {
|
||||
packet.Write<uint8_t>(this->GetValueType());
|
||||
|
||||
packet.Write<uint32_t>(this->value.length());
|
||||
@@ -206,18 +206,18 @@ inline void LDFData<std::string>::WriteValue(RakNet::BitStream& packet) {
|
||||
}
|
||||
}
|
||||
|
||||
template<> inline std::string LDFData<std::u16string>::GetValueString() {
|
||||
template<> inline std::string LDFData<std::u16string>::GetValueString() const {
|
||||
return GeneralUtils::UTF16ToWTF8(this->value, this->value.size());
|
||||
}
|
||||
|
||||
template<> inline std::string LDFData<int32_t>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<float>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<double>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<uint32_t>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<bool>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<uint64_t>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<LWOOBJID>::GetValueString() { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<int32_t>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<float>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<double>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<uint32_t>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<bool>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<uint64_t>::GetValueString() const { return std::to_string(this->value); }
|
||||
template<> inline std::string LDFData<LWOOBJID>::GetValueString() const { return std::to_string(this->value); }
|
||||
|
||||
template<> inline std::string LDFData<std::string>::GetValueString() { return this->value; }
|
||||
template<> inline std::string LDFData<std::string>::GetValueString() const { return this->value; }
|
||||
|
||||
#endif //!__LDFFORMAT__H__
|
||||
|
||||
@@ -790,9 +790,10 @@ enum class eGameMessageType : uint16_t {
|
||||
GET_MISSION_TYPE_STATES = 853,
|
||||
GET_TIME_PLAYED = 854,
|
||||
SET_MISSION_VIEWED = 855,
|
||||
SLASH_COMMAND_TEXT_FEEDBACK = 856,
|
||||
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 857,
|
||||
HKX_VEHICLE_LOADED = 856,
|
||||
SLASH_COMMAND_TEXT_FEEDBACK = 857,
|
||||
BROADCAST_TEXT_TO_CHATBOX = 858,
|
||||
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 859,
|
||||
OPEN_PROPERTY_MANAGEMENT = 860,
|
||||
OPEN_PROPERTY_VENDOR = 861,
|
||||
VOTE_ON_PROPERTY = 862,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "CDScriptComponentTable.h"
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "CDTamingBuildPuzzleTable.h"
|
||||
#include "CDVendorComponentTable.h"
|
||||
#include "CDActivitiesTable.h"
|
||||
#include "CDPackageComponentTable.h"
|
||||
@@ -41,8 +42,6 @@
|
||||
#include "CDRewardCodesTable.h"
|
||||
#include "CDPetComponentTable.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
#ifndef CDCLIENT_CACHE_ALL
|
||||
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
|
||||
// A vanilla CDClient takes about 46MB of memory + the regular world data.
|
||||
@@ -55,13 +54,6 @@
|
||||
#define CDCLIENT_DONT_CACHE_TABLE(x)
|
||||
#endif
|
||||
|
||||
class CDClientConnectionException : public std::exception {
|
||||
public:
|
||||
virtual const char* what() const throw() {
|
||||
return "CDClientDatabase is not connected!";
|
||||
}
|
||||
};
|
||||
|
||||
// Using a macro to reduce repetitive code and issues from copy and paste.
|
||||
// As a note, ## in a macro is used to concatenate two tokens together.
|
||||
|
||||
@@ -108,11 +100,14 @@ DEFINE_TABLE_STORAGE(CDRewardCodesTable);
|
||||
DEFINE_TABLE_STORAGE(CDRewardsTable);
|
||||
DEFINE_TABLE_STORAGE(CDScriptComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDSkillBehaviorTable);
|
||||
DEFINE_TABLE_STORAGE(CDTamingBuildPuzzleTable);
|
||||
DEFINE_TABLE_STORAGE(CDVendorComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDZoneTableTable);
|
||||
|
||||
void CDClientManager::LoadValuesFromDatabase() {
|
||||
if (!CDClientDatabase::isConnected) throw CDClientConnectionException();
|
||||
if (!CDClientDatabase::isConnected) {
|
||||
throw std::runtime_error{ "CDClientDatabase is not connected!" };
|
||||
}
|
||||
|
||||
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
|
||||
CDActivitiesTable::Instance().LoadValuesFromDatabase();
|
||||
@@ -152,6 +147,7 @@ void CDClientManager::LoadValuesFromDatabase() {
|
||||
CDRewardsTable::Instance().LoadValuesFromDatabase();
|
||||
CDScriptComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDSkillBehaviorTable::Instance().LoadValuesFromDatabase();
|
||||
CDTamingBuildPuzzleTable::Instance().LoadValuesFromDatabase();
|
||||
CDVendorComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDZoneTableTable::Instance().LoadValuesFromDatabase();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void CDPetComponentTable::LoadValuesFromDatabase() {
|
||||
}
|
||||
|
||||
void CDPetComponentTable::LoadValuesFromDefaults() {
|
||||
GetEntriesMutable().insert(std::make_pair(defaultEntry.id, defaultEntry));
|
||||
GetEntriesMutable().emplace(defaultEntry.id, defaultEntry);
|
||||
}
|
||||
|
||||
CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "CDTamingBuildPuzzleTable.h"
|
||||
|
||||
void CDTamingBuildPuzzleTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
uint32_t size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM TamingBuildPuzzles");
|
||||
while (!tableSize.eof()) {
|
||||
size = tableSize.getIntField(0, 0);
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
// Reserve the size
|
||||
auto& entries = GetEntriesMutable();
|
||||
entries.reserve(size);
|
||||
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM TamingBuildPuzzles");
|
||||
while (!tableData.eof()) {
|
||||
const auto lot = static_cast<LOT>(tableData.getIntField("NPCLot", LOT_NULL));
|
||||
entries.emplace(lot, CDTamingBuildPuzzle{
|
||||
.puzzleModelLot = lot,
|
||||
.validPieces{ tableData.getStringField("ValidPiecesLXF") },
|
||||
.timeLimit = static_cast<float>(tableData.getFloatField("Timelimit", 30.0f)),
|
||||
.numValidPieces = tableData.getIntField("NumValidPieces", 6),
|
||||
.imaginationCost = tableData.getIntField("imagCostPerBuild", 10)
|
||||
});
|
||||
tableData.nextRow();
|
||||
}
|
||||
}
|
||||
|
||||
const CDTamingBuildPuzzle* CDTamingBuildPuzzleTable::GetByLOT(const LOT lot) const {
|
||||
const auto& entries = GetEntries();
|
||||
const auto itr = entries.find(lot);
|
||||
return itr != entries.cend() ? &itr->second : nullptr;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "CDTable.h"
|
||||
|
||||
/**
|
||||
* Information for the minigame to be completed
|
||||
*/
|
||||
struct CDTamingBuildPuzzle {
|
||||
UNUSED_COLUMN(uint32_t id = 0;)
|
||||
|
||||
// The LOT of the object that is to be created
|
||||
LOT puzzleModelLot = LOT_NULL;
|
||||
|
||||
// The LOT of the NPC
|
||||
UNUSED_COLUMN(LOT npcLot = LOT_NULL;)
|
||||
|
||||
// The .lxfml file that contains the bricks required to build the model
|
||||
std::string validPieces{};
|
||||
|
||||
// The .lxfml file that contains the bricks NOT required to build the model
|
||||
UNUSED_COLUMN(std::string invalidPieces{};)
|
||||
|
||||
// Difficulty value
|
||||
UNUSED_COLUMN(int32_t difficulty = 1;)
|
||||
|
||||
// The time limit to complete the build
|
||||
float timeLimit = 30.0f;
|
||||
|
||||
// The number of pieces required to complete the minigame
|
||||
int32_t numValidPieces = 6;
|
||||
|
||||
// Number of valid pieces
|
||||
UNUSED_COLUMN(int32_t totalNumPieces = 16;)
|
||||
|
||||
// Model name
|
||||
UNUSED_COLUMN(std::string modelName{};)
|
||||
|
||||
// The .lxfml file that contains the full model
|
||||
UNUSED_COLUMN(std::string fullModel{};)
|
||||
|
||||
// The duration of the pet taming minigame
|
||||
UNUSED_COLUMN(float duration = 45.0f;)
|
||||
|
||||
// The imagination cost for the tamer to start the minigame
|
||||
int32_t imaginationCost = 10;
|
||||
};
|
||||
|
||||
class CDTamingBuildPuzzleTable : public CDTable<CDTamingBuildPuzzleTable, std::unordered_map<LOT, CDTamingBuildPuzzle>> {
|
||||
public:
|
||||
/**
|
||||
* Load values from the CD client database
|
||||
*/
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
/**
|
||||
* Gets the pet ability table corresponding to the pet LOT
|
||||
* @returns A pointer to the corresponding table, or nullptr if one cannot be found
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const CDTamingBuildPuzzle* GetByLOT(const LOT lot) const;
|
||||
};
|
||||
@@ -36,5 +36,6 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
|
||||
"CDRewardsTable.cpp"
|
||||
"CDScriptComponentTable.cpp"
|
||||
"CDSkillBehaviorTable.cpp"
|
||||
"CDTamingBuildPuzzleTable.cpp"
|
||||
"CDVendorComponentTable.cpp"
|
||||
"CDZoneTableTable.cpp" PARENT_SCOPE)
|
||||
|
||||
@@ -27,12 +27,9 @@ Character::Character(uint32_t id, User* parentUser) {
|
||||
m_ID = id;
|
||||
m_ParentUser = parentUser;
|
||||
m_OurEntity = nullptr;
|
||||
m_Doc = nullptr;
|
||||
}
|
||||
|
||||
Character::~Character() {
|
||||
if (m_Doc) delete m_Doc;
|
||||
m_Doc = nullptr;
|
||||
m_OurEntity = nullptr;
|
||||
m_ParentUser = nullptr;
|
||||
}
|
||||
@@ -55,8 +52,6 @@ void Character::UpdateInfoFromDatabase() {
|
||||
m_ZoneInstanceID = 0; //These values don't really matter, these are only used on the char select screen and seem unused.
|
||||
m_ZoneCloneID = 0;
|
||||
|
||||
m_Doc = nullptr;
|
||||
|
||||
//Quickly and dirtly parse the xmlData to get the info we need:
|
||||
DoQuickXMLDataParse();
|
||||
|
||||
@@ -70,18 +65,13 @@ void Character::UpdateInfoFromDatabase() {
|
||||
}
|
||||
|
||||
void Character::UpdateFromDatabase() {
|
||||
if (m_Doc) delete m_Doc;
|
||||
UpdateInfoFromDatabase();
|
||||
}
|
||||
|
||||
void Character::DoQuickXMLDataParse() {
|
||||
if (m_XMLData.size() == 0) return;
|
||||
|
||||
delete m_Doc;
|
||||
m_Doc = new tinyxml2::XMLDocument();
|
||||
if (!m_Doc) return;
|
||||
|
||||
if (m_Doc->Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
|
||||
if (m_Doc.Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
|
||||
LOG("Loaded xmlData for character %s (%i)!", m_Name.c_str(), m_ID);
|
||||
} else {
|
||||
LOG("Failed to load xmlData!");
|
||||
@@ -89,7 +79,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
return;
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement* mf = m_Doc->FirstChildElement("obj")->FirstChildElement("mf");
|
||||
tinyxml2::XMLElement* mf = m_Doc.FirstChildElement("obj")->FirstChildElement("mf");
|
||||
if (!mf) {
|
||||
LOG("Failed to find mf tag!");
|
||||
return;
|
||||
@@ -108,7 +98,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
mf->QueryAttribute("ess", &m_Eyes);
|
||||
mf->QueryAttribute("ms", &m_Mouth);
|
||||
|
||||
tinyxml2::XMLElement* inv = m_Doc->FirstChildElement("obj")->FirstChildElement("inv");
|
||||
tinyxml2::XMLElement* inv = m_Doc.FirstChildElement("obj")->FirstChildElement("inv");
|
||||
if (!inv) {
|
||||
LOG("Char has no inv!");
|
||||
return;
|
||||
@@ -141,7 +131,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
}
|
||||
|
||||
|
||||
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
tinyxml2::XMLElement* character = m_Doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (character) {
|
||||
character->QueryAttribute("cc", &m_Coins);
|
||||
int32_t gm_level = 0;
|
||||
@@ -205,7 +195,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
character->QueryAttribute("lzrw", &m_OriginalRotation.w);
|
||||
}
|
||||
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (flags) {
|
||||
auto* currentChild = flags->FirstChildElement();
|
||||
while (currentChild) {
|
||||
@@ -239,19 +229,17 @@ void Character::SetBuildMode(bool buildMode) {
|
||||
}
|
||||
|
||||
void Character::SaveXMLToDatabase() {
|
||||
if (!m_Doc) return;
|
||||
|
||||
//For metrics, we'll record the time it took to save:
|
||||
auto start = std::chrono::system_clock::now();
|
||||
|
||||
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
tinyxml2::XMLElement* character = m_Doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (character) {
|
||||
character->SetAttribute("gm", static_cast<uint32_t>(m_GMLevel));
|
||||
character->SetAttribute("cc", m_Coins);
|
||||
|
||||
auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID();
|
||||
// lzid garbage, binary concat of zoneID, zoneInstance and zoneClone
|
||||
if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) {
|
||||
// if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) {
|
||||
uint64_t lzidConcat = zoneInfo.GetCloneID();
|
||||
lzidConcat = (lzidConcat << 16) | uint16_t(zoneInfo.GetInstanceID());
|
||||
lzidConcat = (lzidConcat << 16) | uint16_t(zoneInfo.GetMapID());
|
||||
@@ -263,14 +251,14 @@ void Character::SaveXMLToDatabase() {
|
||||
|
||||
// Set the target scene, custom attribute
|
||||
character->SetAttribute("tscene", m_TargetScene.c_str());
|
||||
}
|
||||
// }
|
||||
|
||||
auto emotes = character->FirstChildElement("ue");
|
||||
if (!emotes) emotes = m_Doc->NewElement("ue");
|
||||
if (!emotes) emotes = m_Doc.NewElement("ue");
|
||||
|
||||
emotes->DeleteChildren();
|
||||
for (int emoteID : m_UnlockedEmotes) {
|
||||
auto emote = m_Doc->NewElement("e");
|
||||
auto emote = m_Doc.NewElement("e");
|
||||
emote->SetAttribute("id", emoteID);
|
||||
|
||||
emotes->LinkEndChild(emote);
|
||||
@@ -280,15 +268,15 @@ void Character::SaveXMLToDatabase() {
|
||||
}
|
||||
|
||||
//Export our flags:
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (!flags) {
|
||||
flags = m_Doc->NewElement("flag"); //Create a flags tag if we don't have one
|
||||
m_Doc->FirstChildElement("obj")->LinkEndChild(flags); //Link it to the obj tag so we can find next time
|
||||
flags = m_Doc.NewElement("flag"); //Create a flags tag if we don't have one
|
||||
m_Doc.FirstChildElement("obj")->LinkEndChild(flags); //Link it to the obj tag so we can find next time
|
||||
}
|
||||
|
||||
flags->DeleteChildren(); //Clear it if we have anything, so that we can fill it up again without dupes
|
||||
for (std::pair<uint32_t, uint64_t> flag : m_PlayerFlags) {
|
||||
auto* f = m_Doc->NewElement("f");
|
||||
auto* f = m_Doc.NewElement("f");
|
||||
f->SetAttribute("id", flag.first);
|
||||
|
||||
//Because of the joy that is tinyxml2, it doesn't offer a function to set a uint64 as an attribute.
|
||||
@@ -301,7 +289,7 @@ void Character::SaveXMLToDatabase() {
|
||||
|
||||
// Prevents the news feed from showing up on world transfers
|
||||
if (GetPlayerFlag(ePlayerFlag::IS_NEWS_SCREEN_VISIBLE)) {
|
||||
auto* s = m_Doc->NewElement("s");
|
||||
auto* s = m_Doc.NewElement("s");
|
||||
s->SetAttribute("si", ePlayerFlag::IS_NEWS_SCREEN_VISIBLE);
|
||||
flags->LinkEndChild(s);
|
||||
}
|
||||
@@ -326,7 +314,7 @@ void Character::SaveXMLToDatabase() {
|
||||
|
||||
void Character::SetIsNewLogin() {
|
||||
// If we dont have a flag element, then we cannot have a s element as a child of flag.
|
||||
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
|
||||
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
|
||||
if (!flags) return;
|
||||
|
||||
auto* currentChild = flags->FirstChildElement();
|
||||
@@ -344,7 +332,7 @@ void Character::SetIsNewLogin() {
|
||||
void Character::WriteToDatabase() {
|
||||
//Dump our xml into m_XMLData:
|
||||
tinyxml2::XMLPrinter printer(0, true, 0);
|
||||
m_Doc->Print(&printer);
|
||||
m_Doc.Print(&printer);
|
||||
|
||||
//Finally, save to db:
|
||||
Database::Get()->UpdateCharacterXml(m_ID, printer.CStr());
|
||||
@@ -421,15 +409,15 @@ void Character::SetRetroactiveFlags() {
|
||||
|
||||
void Character::SaveXmlRespawnCheckpoints() {
|
||||
//Export our respawn points:
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
auto* points = m_Doc.FirstChildElement("obj")->FirstChildElement("res");
|
||||
if (!points) {
|
||||
points = m_Doc->NewElement("res");
|
||||
m_Doc->FirstChildElement("obj")->LinkEndChild(points);
|
||||
points = m_Doc.NewElement("res");
|
||||
m_Doc.FirstChildElement("obj")->LinkEndChild(points);
|
||||
}
|
||||
|
||||
points->DeleteChildren();
|
||||
for (const auto& point : m_WorldRespawnCheckpoints) {
|
||||
auto* r = m_Doc->NewElement("r");
|
||||
auto* r = m_Doc.NewElement("r");
|
||||
r->SetAttribute("w", point.first);
|
||||
|
||||
r->SetAttribute("x", point.second.x);
|
||||
@@ -443,7 +431,7 @@ void Character::SaveXmlRespawnCheckpoints() {
|
||||
void Character::LoadXmlRespawnCheckpoints() {
|
||||
m_WorldRespawnCheckpoints.clear();
|
||||
|
||||
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
|
||||
auto* points = m_Doc.FirstChildElement("obj")->FirstChildElement("res");
|
||||
if (!points) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
void LoadXmlRespawnCheckpoints();
|
||||
|
||||
const std::string& GetXMLData() const { return m_XMLData; }
|
||||
tinyxml2::XMLDocument* GetXMLDoc() const { return m_Doc; }
|
||||
const tinyxml2::XMLDocument& GetXMLDoc() const { return m_Doc; }
|
||||
|
||||
/**
|
||||
* Out of abundance of safety and clarity of what this saves, this is its own function.
|
||||
@@ -623,7 +623,7 @@ private:
|
||||
/**
|
||||
* The character XML belonging to this character
|
||||
*/
|
||||
tinyxml2::XMLDocument* m_Doc;
|
||||
tinyxml2::XMLDocument m_Doc;
|
||||
|
||||
/**
|
||||
* Title of an announcement this character made (reserved for GMs)
|
||||
|
||||
@@ -476,8 +476,7 @@ void Entity::Initialize() {
|
||||
}
|
||||
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) {
|
||||
auto* xmlDoc = m_Character ? m_Character->GetXMLDoc() : nullptr;
|
||||
AddComponent<InventoryComponent>(xmlDoc);
|
||||
AddComponent<InventoryComponent>();
|
||||
}
|
||||
// if this component exists, then we initialize it. it's value is always 0
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MULTI_ZONE_ENTRANCE, -1) != -1) {
|
||||
@@ -661,7 +660,7 @@ void Entity::Initialize() {
|
||||
}
|
||||
|
||||
PetComponent* petComponent;
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) {
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0) {
|
||||
AddComponent<ItemComponent>();
|
||||
}
|
||||
|
||||
@@ -902,6 +901,14 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacke
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
outBitStream.Write<uint16_t>(name[i]);
|
||||
}
|
||||
} else if (HasVar(u"userModelName")) {
|
||||
const auto& name = GetVar<std::string>(u"userModelName");
|
||||
outBitStream.Write<uint8_t>(uint8_t(name.size()));
|
||||
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
outBitStream.Write<uint16_t>(name[i]);
|
||||
}
|
||||
|
||||
} else {
|
||||
const auto& name = GetVar<std::string>(u"npcName");
|
||||
outBitStream.Write<uint8_t>(uint8_t(name.size()));
|
||||
@@ -1244,7 +1251,7 @@ void Entity::WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType
|
||||
outBitStream.Write0();
|
||||
}
|
||||
|
||||
void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) {
|
||||
void Entity::UpdateXMLDoc(tinyxml2::XMLDocument& doc) {
|
||||
//This function should only ever be called from within Character, meaning doc should always exist when this is called.
|
||||
//Naturally, we don't include any non-player components in this update function.
|
||||
|
||||
@@ -1535,7 +1542,7 @@ void Entity::Kill(Entity* murderer, const eKillType killType) {
|
||||
bool waitForDeathAnimation = false;
|
||||
|
||||
if (destroyableComponent) {
|
||||
waitForDeathAnimation = destroyableComponent->GetDeathBehavior() == 0 && killType != eKillType::SILENT;
|
||||
waitForDeathAnimation = !destroyableComponent->GetIsSmashable() && destroyableComponent->GetDeathBehavior() == 0 && killType != eKillType::SILENT;
|
||||
}
|
||||
|
||||
// Live waited a hard coded 12 seconds for death animations of type 0 before networking destruction!
|
||||
@@ -1635,10 +1642,8 @@ void Entity::PickupItem(const LWOOBJID& objectID) {
|
||||
CDObjectSkillsTable* skillsTable = CDClientManager::GetTable<CDObjectSkillsTable>();
|
||||
std::vector<CDObjectSkills> skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == p.second.lot); });
|
||||
for (CDObjectSkills skill : skills) {
|
||||
CDSkillBehaviorTable* skillBehTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
|
||||
|
||||
auto* skillComponent = GetComponent<SkillComponent>();
|
||||
if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID());
|
||||
if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID(), skill.castOnType, NiQuaternion(0, 0, 0, 0));
|
||||
|
||||
auto* missionComponent = GetComponent<MissionComponent>();
|
||||
|
||||
@@ -1843,6 +1848,12 @@ const NiPoint3& Entity::GetPosition() const {
|
||||
return vehicel->GetPosition();
|
||||
}
|
||||
|
||||
auto* rigidBodyPhantomPhysicsComponent = GetComponent<RigidbodyPhantomPhysicsComponent>();
|
||||
|
||||
if (rigidBodyPhantomPhysicsComponent != nullptr) {
|
||||
return rigidBodyPhantomPhysicsComponent->GetPosition();
|
||||
}
|
||||
|
||||
return NiPoint3Constant::ZERO;
|
||||
}
|
||||
|
||||
@@ -1871,6 +1882,12 @@ const NiQuaternion& Entity::GetRotation() const {
|
||||
return vehicel->GetRotation();
|
||||
}
|
||||
|
||||
auto* rigidBodyPhantomPhysicsComponent = GetComponent<RigidbodyPhantomPhysicsComponent>();
|
||||
|
||||
if (rigidBodyPhantomPhysicsComponent != nullptr) {
|
||||
return rigidBodyPhantomPhysicsComponent->GetRotation();
|
||||
}
|
||||
|
||||
return NiQuaternionConstant::IDENTITY;
|
||||
}
|
||||
|
||||
@@ -1899,6 +1916,12 @@ void Entity::SetPosition(const NiPoint3& position) {
|
||||
vehicel->SetPosition(position);
|
||||
}
|
||||
|
||||
auto* rigidBodyPhantomPhysicsComponent = GetComponent<RigidbodyPhantomPhysicsComponent>();
|
||||
|
||||
if (rigidBodyPhantomPhysicsComponent != nullptr) {
|
||||
rigidBodyPhantomPhysicsComponent->SetPosition(position);
|
||||
}
|
||||
|
||||
Game::entityManager->SerializeEntity(this);
|
||||
}
|
||||
|
||||
@@ -1927,6 +1950,12 @@ void Entity::SetRotation(const NiQuaternion& rotation) {
|
||||
vehicel->SetRotation(rotation);
|
||||
}
|
||||
|
||||
auto* rigidBodyPhantomPhysicsComponent = GetComponent<RigidbodyPhantomPhysicsComponent>();
|
||||
|
||||
if (rigidBodyPhantomPhysicsComponent != nullptr) {
|
||||
rigidBodyPhantomPhysicsComponent->SetRotation(rotation);
|
||||
}
|
||||
|
||||
Game::entityManager->SerializeEntity(this);
|
||||
}
|
||||
|
||||
@@ -2137,3 +2166,12 @@ void Entity::SetRespawnRot(const NiQuaternion& rotation) {
|
||||
auto* characterComponent = GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SetRespawnRot(rotation);
|
||||
}
|
||||
|
||||
void Entity::EraseVar(const std::u16string& name) {
|
||||
for (auto it = m_Settings.begin(); it != m_Settings.end(); ++it) {
|
||||
if ((*it)->GetKey() == name) {
|
||||
m_Settings.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
|
||||
void WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
|
||||
void WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
|
||||
void UpdateXMLDoc(tinyxml2::XMLDocument* doc);
|
||||
void UpdateXMLDoc(tinyxml2::XMLDocument& doc);
|
||||
void Update(float deltaTime);
|
||||
|
||||
// Events
|
||||
@@ -299,6 +299,7 @@ public:
|
||||
// Scale will only be communicated to the client when the construction packet is sent
|
||||
void SetScale(const float scale) { m_Scale = scale; };
|
||||
|
||||
void EraseVar(const std::u16string& name);
|
||||
protected:
|
||||
LWOOBJID m_ObjectID;
|
||||
|
||||
|
||||
@@ -536,13 +536,13 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
|
||||
uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
||||
try {
|
||||
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ? AND icc.decal == ?"
|
||||
"select obj.id as objectId from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ? AND icc.decal == ?"
|
||||
);
|
||||
stmt.bind(1, "character create shirt");
|
||||
stmt.bind(2, static_cast<int>(shirtColor));
|
||||
stmt.bind(3, static_cast<int>(shirtStyle));
|
||||
auto tableData = stmt.execQuery();
|
||||
auto shirtLOT = tableData.getIntField(0, 4069);
|
||||
auto shirtLOT = tableData.getIntField("objectId", 4069);
|
||||
tableData.finalize();
|
||||
return shirtLOT;
|
||||
} catch (const std::exception& ex) {
|
||||
@@ -555,12 +555,12 @@ uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
||||
uint32_t FindCharPantsID(uint32_t pantsColor) {
|
||||
try {
|
||||
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ?"
|
||||
"select obj.id as objectId from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ?"
|
||||
);
|
||||
stmt.bind(1, "cc pants");
|
||||
stmt.bind(2, static_cast<int>(pantsColor));
|
||||
auto tableData = stmt.execQuery();
|
||||
auto pantsLOT = tableData.getIntField(0, 2508);
|
||||
auto pantsLOT = tableData.getIntField("objectId", 2508);
|
||||
tableData.finalize();
|
||||
return pantsLOT;
|
||||
} catch (const std::exception& ex) {
|
||||
|
||||
@@ -377,10 +377,10 @@ void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID
|
||||
return;
|
||||
}
|
||||
|
||||
const auto name = std::string(result.getStringField(0));
|
||||
const auto name = std::string(result.getStringField("effectName"));
|
||||
|
||||
if (type.empty()) {
|
||||
const auto typeResult = result.getStringField(1);
|
||||
const auto typeResult = result.getStringField("effectType");
|
||||
|
||||
type = GeneralUtils::ASCIIToUTF16(typeResult);
|
||||
|
||||
|
||||
@@ -224,6 +224,16 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime) {
|
||||
for (auto i = 0u; i < this->syncEntries.size(); ++i) {
|
||||
auto entry = this->syncEntries.at(i);
|
||||
|
||||
if (entry.behavior->m_templateId == BehaviorTemplate::ATTACK_DELAY) {
|
||||
auto* self = Game::entityManager->GetEntity(originator);
|
||||
if (self) {
|
||||
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
||||
if (destroyableComponent && destroyableComponent->GetHealth() <= 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.time > 0) {
|
||||
entry.time -= deltaTime;
|
||||
|
||||
@@ -333,7 +343,7 @@ void BehaviorContext::FilterTargets(std::vector<Entity*>& targets, std::forward_
|
||||
}
|
||||
|
||||
// handle targeting the caster
|
||||
if (candidate == caster){
|
||||
if (candidate == caster) {
|
||||
// if we aren't targeting self, erase, otherise increment and continue
|
||||
if (!targetSelf) index = targets.erase(index);
|
||||
else index++;
|
||||
@@ -356,24 +366,24 @@ void BehaviorContext::FilterTargets(std::vector<Entity*>& targets, std::forward_
|
||||
}
|
||||
|
||||
// if they are dead, then earse and continue
|
||||
if (candidateDestroyableComponent->GetIsDead()){
|
||||
if (candidateDestroyableComponent->GetIsDead()) {
|
||||
index = targets.erase(index);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if their faction is explicitly included, increment and continue
|
||||
auto candidateFactions = candidateDestroyableComponent->GetFactionIDs();
|
||||
if (CheckFactionList(includeFactionList, candidateFactions)){
|
||||
if (CheckFactionList(includeFactionList, candidateFactions)) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if they are a team member
|
||||
if (targetTeam){
|
||||
if (targetTeam) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(this->caster);
|
||||
if (team){
|
||||
if (team) {
|
||||
// if we find a team member keep it and continue to skip enemy checks
|
||||
if(std::find(team->members.begin(), team->members.end(), candidate->GetObjectID()) != team->members.end()){
|
||||
if (std::find(team->members.begin(), team->members.end(), candidate->GetObjectID()) != team->members.end()) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
@@ -419,8 +429,8 @@ bool BehaviorContext::CheckTargetingRequirements(const Entity* target) const {
|
||||
// returns true if any of the object factions are in the faction list
|
||||
bool BehaviorContext::CheckFactionList(std::forward_list<int32_t>& factionList, std::vector<int32_t>& objectsFactions) const {
|
||||
if (factionList.empty() || objectsFactions.empty()) return false;
|
||||
for (auto faction : factionList){
|
||||
if(std::find(objectsFactions.begin(), objectsFactions.end(), faction) != objectsFactions.end()) return true;
|
||||
for (auto faction : factionList) {
|
||||
if (std::find(objectsFactions.begin(), objectsFactions.end(), faction) != objectsFactions.end()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ void SwitchMultipleBehavior::Load() {
|
||||
auto result = query.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getFloatField(1));
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getFloatField("behavior"));
|
||||
|
||||
auto* behavior = CreateBehavior(behavior_id);
|
||||
|
||||
auto value = result.getFloatField(2);
|
||||
auto value = result.getFloatField("value");
|
||||
|
||||
this->m_behaviors.emplace_back(value, behavior);
|
||||
|
||||
|
||||
@@ -45,20 +45,20 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
|
||||
auto componentResult = componentQuery.execQuery();
|
||||
|
||||
if (!componentResult.eof()) {
|
||||
if (!componentResult.fieldIsNull(0))
|
||||
m_AggroRadius = componentResult.getFloatField(0);
|
||||
if (!componentResult.fieldIsNull("aggroRadius"))
|
||||
m_AggroRadius = componentResult.getFloatField("aggroRadius");
|
||||
|
||||
if (!componentResult.fieldIsNull(1))
|
||||
m_TetherSpeed = componentResult.getFloatField(1);
|
||||
if (!componentResult.fieldIsNull("tetherSpeed"))
|
||||
m_TetherSpeed = componentResult.getFloatField("tetherSpeed");
|
||||
|
||||
if (!componentResult.fieldIsNull(2))
|
||||
m_PursuitSpeed = componentResult.getFloatField(2);
|
||||
if (!componentResult.fieldIsNull("pursuitSpeed"))
|
||||
m_PursuitSpeed = componentResult.getFloatField("pursuitSpeed");
|
||||
|
||||
if (!componentResult.fieldIsNull(3))
|
||||
m_SoftTetherRadius = componentResult.getFloatField(3);
|
||||
if (!componentResult.fieldIsNull("softTetherRadius"))
|
||||
m_SoftTetherRadius = componentResult.getFloatField("softTetherRadius");
|
||||
|
||||
if (!componentResult.fieldIsNull(4))
|
||||
m_HardTetherRadius = componentResult.getFloatField(4);
|
||||
if (!componentResult.fieldIsNull("hardTetherRadius"))
|
||||
m_HardTetherRadius = componentResult.getFloatField("hardTetherRadius");
|
||||
}
|
||||
|
||||
componentResult.finalize();
|
||||
@@ -82,11 +82,11 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
|
||||
auto result = skillQuery.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto skillId = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto skillId = static_cast<uint32_t>(result.getIntField("skillID"));
|
||||
|
||||
const auto abilityCooldown = static_cast<float>(result.getFloatField(1));
|
||||
const auto abilityCooldown = static_cast<float>(result.getFloatField("cooldown"));
|
||||
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField(2));
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
|
||||
|
||||
@@ -326,9 +326,9 @@ Entity* BuffComponent::GetParent() const {
|
||||
return m_Parent;
|
||||
}
|
||||
|
||||
void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
void BuffComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
// Load buffs
|
||||
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
|
||||
|
||||
// Make sure we have a clean buff element.
|
||||
auto* buffElement = dest->FirstChildElement("buff");
|
||||
@@ -386,15 +386,15 @@ void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
}
|
||||
|
||||
void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
void BuffComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
// Save buffs
|
||||
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
|
||||
|
||||
// Make sure we have a clean buff element.
|
||||
auto* buffElement = dest->FirstChildElement("buff");
|
||||
|
||||
if (buffElement == nullptr) {
|
||||
buffElement = doc->NewElement("buff");
|
||||
buffElement = doc.NewElement("buff");
|
||||
|
||||
dest->LinkEndChild(buffElement);
|
||||
} else {
|
||||
@@ -402,7 +402,7 @@ void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
|
||||
for (const auto& [id, buff] : m_Buffs) {
|
||||
auto* buffEntry = doc->NewElement("b");
|
||||
auto* buffEntry = doc.NewElement("b");
|
||||
// TODO: change this if to if (buff.cancelOnZone || buff.cancelOnLogout) handling at some point. No current way to differentiate between zone transfer and logout.
|
||||
if (buff.cancelOnZone) continue;
|
||||
|
||||
@@ -450,7 +450,7 @@ const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffI
|
||||
param.value = result.getFloatField("NumberValue");
|
||||
param.effectId = result.getIntField("EffectID");
|
||||
|
||||
if (!result.fieldIsNull(3)) {
|
||||
if (!result.fieldIsNull("StringValue")) {
|
||||
std::istringstream stream(result.getStringField("StringValue"));
|
||||
std::string token;
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ public:
|
||||
|
||||
Entity* GetParent() const;
|
||||
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
|
||||
@@ -186,9 +186,9 @@ void CharacterComponent::SetGMLevel(eGameMasterLevel gmlevel) {
|
||||
m_GMLevel = gmlevel;
|
||||
}
|
||||
|
||||
void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
void CharacterComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
|
||||
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
auto* character = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (!character) {
|
||||
LOG("Failed to find char tag while loading XML!");
|
||||
return;
|
||||
@@ -299,8 +299,8 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* minifig = doc->FirstChildElement("obj")->FirstChildElement("mf");
|
||||
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
tinyxml2::XMLElement* minifig = doc.FirstChildElement("obj")->FirstChildElement("mf");
|
||||
if (!minifig) {
|
||||
LOG("Failed to find mf tag while updating XML!");
|
||||
return;
|
||||
@@ -320,7 +320,7 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
// done with minifig
|
||||
|
||||
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
tinyxml2::XMLElement* character = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (!character) {
|
||||
LOG("Failed to find char tag while updating XML!");
|
||||
return;
|
||||
@@ -338,11 +338,11 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
// Set the zone statistics of the form <zs><s/> ... <s/></zs>
|
||||
auto zoneStatistics = character->FirstChildElement("zs");
|
||||
if (!zoneStatistics) zoneStatistics = doc->NewElement("zs");
|
||||
if (!zoneStatistics) zoneStatistics = doc.NewElement("zs");
|
||||
zoneStatistics->DeleteChildren();
|
||||
|
||||
for (auto pair : m_ZoneStatistics) {
|
||||
auto zoneStatistic = doc->NewElement("s");
|
||||
auto zoneStatistic = doc.NewElement("s");
|
||||
|
||||
zoneStatistic->SetAttribute("map", pair.first);
|
||||
zoneStatistic->SetAttribute("ac", pair.second.m_AchievementsCollected);
|
||||
|
||||
@@ -70,8 +70,8 @@ public:
|
||||
CharacterComponent(Entity* parent, Character* character, const SystemAddress& systemAddress);
|
||||
~CharacterComponent() override;
|
||||
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ void Component::OnUse(Entity* originator) {
|
||||
|
||||
}
|
||||
|
||||
void Component::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
void Component::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
|
||||
}
|
||||
|
||||
void Component::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
void Component::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ public:
|
||||
* Save data from this componennt to character XML
|
||||
* @param doc the document to write data to
|
||||
*/
|
||||
virtual void UpdateXml(tinyxml2::XMLDocument* doc);
|
||||
virtual void UpdateXml(tinyxml2::XMLDocument& doc);
|
||||
|
||||
/**
|
||||
* Load base data for this component from character XML
|
||||
* @param doc the document to read data from
|
||||
*/
|
||||
virtual void LoadFromXml(tinyxml2::XMLDocument* doc);
|
||||
virtual void LoadFromXml(const tinyxml2::XMLDocument& doc);
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
}
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
void ControllablePhysicsComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
auto* character = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (!character) {
|
||||
LOG("Failed to find char tag!");
|
||||
return;
|
||||
@@ -178,8 +178,8 @@ void ControllablePhysicsComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
m_DirtyPosition = true;
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
tinyxml2::XMLElement* character = doc.FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (!character) {
|
||||
LOG("Failed to find char tag while updating XML!");
|
||||
return;
|
||||
@@ -187,7 +187,7 @@ void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) {
|
||||
// if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) {
|
||||
character->SetAttribute("lzx", m_Position.x);
|
||||
character->SetAttribute("lzy", m_Position.y);
|
||||
character->SetAttribute("lzz", m_Position.z);
|
||||
@@ -195,7 +195,7 @@ void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
character->SetAttribute("lzry", m_Rotation.y);
|
||||
character->SetAttribute("lzrz", m_Rotation.z);
|
||||
character->SetAttribute("lzrw", m_Rotation.w);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::SetPosition(const NiPoint3& pos) {
|
||||
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
/**
|
||||
* Sets the position of this entity, also ensures this update is serialized next tick.
|
||||
|
||||
@@ -185,8 +185,8 @@ void DestroyableComponent::Update(float deltaTime) {
|
||||
m_DamageCooldownTimer -= deltaTime;
|
||||
}
|
||||
|
||||
void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
void DestroyableComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
|
||||
if (!dest) {
|
||||
LOG("Failed to find dest tag!");
|
||||
return;
|
||||
@@ -207,8 +207,8 @@ void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
m_DirtyHealth = true;
|
||||
}
|
||||
|
||||
void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
|
||||
void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
tinyxml2::XMLElement* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
|
||||
if (!dest) {
|
||||
LOG("Failed to find dest tag!");
|
||||
return;
|
||||
@@ -389,9 +389,9 @@ void DestroyableComponent::AddFaction(const int32_t factionID, const bool ignore
|
||||
|
||||
if (result.eof()) return;
|
||||
|
||||
if (result.fieldIsNull(0)) return;
|
||||
if (result.fieldIsNull("enemyList")) return;
|
||||
|
||||
const auto* list_string = result.getStringField(0);
|
||||
const auto* list_string = result.getStringField("enemyList");
|
||||
|
||||
std::stringstream ss(list_string);
|
||||
std::string token;
|
||||
|
||||
@@ -26,8 +26,8 @@ public:
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
/**
|
||||
* Initializes the component using a different LOT
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "CDObjectSkillsTable.h"
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
|
||||
InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document) : Component(parent) {
|
||||
InventoryComponent::InventoryComponent(Entity* parent) : Component(parent) {
|
||||
this->m_Dirty = true;
|
||||
this->m_Equipped = {};
|
||||
this->m_Pushed = {};
|
||||
@@ -48,7 +48,8 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do
|
||||
const auto lot = parent->GetLOT();
|
||||
|
||||
if (lot == 1) {
|
||||
LoadXml(document);
|
||||
auto* character = m_Parent->GetCharacter();
|
||||
if (character) LoadXml(character->GetXMLDoc());
|
||||
|
||||
CheckProxyIntegrity();
|
||||
|
||||
@@ -472,10 +473,10 @@ bool InventoryComponent::HasSpaceForLoot(const std::unordered_map<LOT, int32_t>&
|
||||
return true;
|
||||
}
|
||||
|
||||
void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
void InventoryComponent::LoadXml(const tinyxml2::XMLDocument& document) {
|
||||
LoadPetXml(document);
|
||||
|
||||
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
|
||||
auto* inventoryElement = document.FirstChildElement("obj")->FirstChildElement("inv");
|
||||
|
||||
if (inventoryElement == nullptr) {
|
||||
LOG("Failed to find 'inv' xml element!");
|
||||
@@ -557,19 +558,9 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
itemElement->QueryAttribute("parent", &parent);
|
||||
// End custom xml
|
||||
|
||||
std::vector<LDFBaseData*> config;
|
||||
auto* item = new Item(id, lot, inventory, slot, count, bound, {}, parent, subKey);
|
||||
|
||||
auto* extraInfo = itemElement->FirstChildElement("x");
|
||||
|
||||
if (extraInfo) {
|
||||
std::string modInfo = extraInfo->Attribute("ma");
|
||||
|
||||
LDFBaseData* moduleAssembly = new LDFData<std::u16string>(u"assemblyPartLOTs", GeneralUtils::ASCIIToUTF16(modInfo.substr(2, modInfo.size() - 1)));
|
||||
|
||||
config.push_back(moduleAssembly);
|
||||
}
|
||||
|
||||
const auto* item = new Item(id, lot, inventory, slot, count, bound, config, parent, subKey);
|
||||
item->LoadConfigXml(*itemElement);
|
||||
|
||||
if (equipped) {
|
||||
const auto info = Inventory::FindItemComponent(lot);
|
||||
@@ -594,10 +585,10 @@ void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
|
||||
UpdatePetXml(document);
|
||||
|
||||
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
|
||||
auto* inventoryElement = document.FirstChildElement("obj")->FirstChildElement("inv");
|
||||
|
||||
if (inventoryElement == nullptr) {
|
||||
LOG("Failed to find 'inv' xml element!");
|
||||
@@ -631,7 +622,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
bags->DeleteChildren();
|
||||
|
||||
for (const auto* inventory : inventoriesToSave) {
|
||||
auto* bag = document->NewElement("b");
|
||||
auto* bag = document.NewElement("b");
|
||||
|
||||
bag->SetAttribute("t", inventory->GetType());
|
||||
bag->SetAttribute("m", static_cast<unsigned int>(inventory->GetSize()));
|
||||
@@ -654,14 +645,14 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* bagElement = document->NewElement("in");
|
||||
auto* bagElement = document.NewElement("in");
|
||||
|
||||
bagElement->SetAttribute("t", inventory->GetType());
|
||||
|
||||
for (const auto& pair : inventory->GetItems()) {
|
||||
auto* item = pair.second;
|
||||
|
||||
auto* itemElement = document->NewElement("i");
|
||||
auto* itemElement = document.NewElement("i");
|
||||
|
||||
itemElement->SetAttribute("l", item->GetLot());
|
||||
itemElement->SetAttribute("id", item->GetId());
|
||||
@@ -675,17 +666,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
itemElement->SetAttribute("parent", item->GetParent());
|
||||
// End custom xml
|
||||
|
||||
for (auto* data : item->GetConfig()) {
|
||||
if (data->GetKey() != u"assemblyPartLOTs") {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* extraInfo = document->NewElement("x");
|
||||
|
||||
extraInfo->SetAttribute("ma", data->GetString(false).c_str());
|
||||
|
||||
itemElement->LinkEndChild(extraInfo);
|
||||
}
|
||||
item->SaveConfigXml(*itemElement);
|
||||
|
||||
bagElement->LinkEndChild(itemElement);
|
||||
}
|
||||
@@ -1093,7 +1074,7 @@ void InventoryComponent::CheckItemSet(const LOT lot) {
|
||||
auto result = query.execQuery();
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto id = result.getIntField(0);
|
||||
const auto id = result.getIntField("setID");
|
||||
|
||||
bool found = false;
|
||||
|
||||
@@ -1542,8 +1523,8 @@ void InventoryComponent::PurgeProxies(Item* item) {
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document) {
|
||||
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
|
||||
void InventoryComponent::LoadPetXml(const tinyxml2::XMLDocument& document) {
|
||||
auto* petInventoryElement = document.FirstChildElement("obj")->FirstChildElement("pet");
|
||||
|
||||
if (petInventoryElement == nullptr) {
|
||||
m_Pets.clear();
|
||||
@@ -1574,19 +1555,19 @@ void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document) {
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document) {
|
||||
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
|
||||
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument& document) {
|
||||
auto* petInventoryElement = document.FirstChildElement("obj")->FirstChildElement("pet");
|
||||
|
||||
if (petInventoryElement == nullptr) {
|
||||
petInventoryElement = document->NewElement("pet");
|
||||
petInventoryElement = document.NewElement("pet");
|
||||
|
||||
document->FirstChildElement("obj")->LinkEndChild(petInventoryElement);
|
||||
document.FirstChildElement("obj")->LinkEndChild(petInventoryElement);
|
||||
}
|
||||
|
||||
petInventoryElement->DeleteChildren();
|
||||
|
||||
for (const auto& pet : m_Pets) {
|
||||
auto* petElement = document->NewElement("p");
|
||||
auto* petElement = document.NewElement("p");
|
||||
|
||||
petElement->SetAttribute("id", pet.first);
|
||||
petElement->SetAttribute("l", pet.second.lot);
|
||||
@@ -1599,18 +1580,18 @@ void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document) {
|
||||
}
|
||||
|
||||
|
||||
bool InventoryComponent::SetSkill(int32_t slot, uint32_t skillId){
|
||||
bool InventoryComponent::SetSkill(int32_t slot, uint32_t skillId) {
|
||||
BehaviorSlot behaviorSlot = BehaviorSlot::Invalid;
|
||||
if (slot == 1 ) behaviorSlot = BehaviorSlot::Primary;
|
||||
else if (slot == 2 ) behaviorSlot = BehaviorSlot::Offhand;
|
||||
else if (slot == 3 ) behaviorSlot = BehaviorSlot::Neck;
|
||||
else if (slot == 4 ) behaviorSlot = BehaviorSlot::Head;
|
||||
else if (slot == 5 ) behaviorSlot = BehaviorSlot::Consumable;
|
||||
if (slot == 1) behaviorSlot = BehaviorSlot::Primary;
|
||||
else if (slot == 2) behaviorSlot = BehaviorSlot::Offhand;
|
||||
else if (slot == 3) behaviorSlot = BehaviorSlot::Neck;
|
||||
else if (slot == 4) behaviorSlot = BehaviorSlot::Head;
|
||||
else if (slot == 5) behaviorSlot = BehaviorSlot::Consumable;
|
||||
else return false;
|
||||
return SetSkill(behaviorSlot, skillId);
|
||||
}
|
||||
|
||||
bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId){
|
||||
bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId) {
|
||||
if (skillId == 0) return false;
|
||||
const auto index = m_Skills.find(slot);
|
||||
if (index != m_Skills.end()) {
|
||||
@@ -1622,4 +1603,3 @@ bool InventoryComponent::SetSkill(BehaviorSlot slot, uint32_t skillId){
|
||||
m_Skills.insert_or_assign(slot, skillId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ enum class eItemType : int32_t;
|
||||
class InventoryComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::INVENTORY;
|
||||
explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr);
|
||||
InventoryComponent(Entity* parent);
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadXml(tinyxml2::XMLDocument* document);
|
||||
void UpdateXml(tinyxml2::XMLDocument* document) override;
|
||||
void LoadXml(const tinyxml2::XMLDocument& document);
|
||||
void UpdateXml(tinyxml2::XMLDocument& document) override;
|
||||
|
||||
/**
|
||||
* Returns an inventory of the specified type, if it exists
|
||||
@@ -470,13 +470,13 @@ private:
|
||||
* Saves all the pet information stored in inventory items to the database
|
||||
* @param document the xml doc to save to
|
||||
*/
|
||||
void LoadPetXml(tinyxml2::XMLDocument* document);
|
||||
void LoadPetXml(const tinyxml2::XMLDocument& document);
|
||||
|
||||
/**
|
||||
* Loads all the pet information from an xml doc into items
|
||||
* @param document the xml doc to load from
|
||||
*/
|
||||
void UpdatePetXml(tinyxml2::XMLDocument* document);
|
||||
void UpdatePetXml(tinyxml2::XMLDocument& document);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
#include "ItemComponent.h"
|
||||
|
||||
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
|
||||
outBitStream.Write0();
|
||||
ItemComponent::ItemComponent(Entity* entity) : Component(entity) {
|
||||
m_UgcId = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||
m_Description = GeneralUtils::ASCIIToUTF16(m_Parent->GetVar<std::string>(u"userModelDesc"));
|
||||
m_Dirty = false;
|
||||
m_ModerationStatus = 2;
|
||||
LOG("%s", m_Parent->GetVarAsString(u"userModelDesc").c_str());
|
||||
}
|
||||
|
||||
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
|
||||
outBitStream.Write(m_Dirty || isConstruction);
|
||||
if (m_Dirty || isConstruction) {
|
||||
outBitStream.Write(m_UgcId);
|
||||
outBitStream.Write(m_ModerationStatus);
|
||||
outBitStream.Write(!m_Description.empty());
|
||||
if (!m_Description.empty()) {
|
||||
outBitStream.Write<uint32_t>(m_Description.size());
|
||||
outBitStream.Write(m_Description);
|
||||
}
|
||||
if (!isConstruction) m_Dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemComponent::UpdateDescription(const std::u16string& description) {
|
||||
if (m_Description == description) return;
|
||||
m_Dirty = true;
|
||||
m_Description = description;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,16 @@ class ItemComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::ITEM;
|
||||
|
||||
ItemComponent(Entity* entity) : Component(entity) {}
|
||||
ItemComponent(Entity* entity);
|
||||
|
||||
void Serialize(RakNet::BitStream& bitStream, bool isConstruction) override;
|
||||
|
||||
void UpdateDescription(const std::u16string& description);
|
||||
private:
|
||||
std::u16string m_Description;
|
||||
bool m_Dirty = false;
|
||||
LWOOBJID m_UgcId = LWOOBJID_EMPTY;
|
||||
uint32_t m_ModerationStatus = 0;
|
||||
};
|
||||
|
||||
#endif //!__ITEMCOMPONENT__H__
|
||||
|
||||
@@ -13,8 +13,8 @@ LevelProgressionComponent::LevelProgressionComponent(Entity* parent) : Component
|
||||
m_CharacterVersion = eCharacterVersion::LIVE;
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
tinyxml2::XMLElement* level = doc.FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
LOG("Failed to find lvl tag while updating XML!");
|
||||
return;
|
||||
@@ -24,8 +24,8 @@ void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
level->SetAttribute("cv", static_cast<uint32_t>(m_CharacterVersion));
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
void LevelProgressionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
auto* level = doc.FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
LOG("Failed to find lvl tag while loading XML!");
|
||||
return;
|
||||
|
||||
@@ -27,13 +27,13 @@ public:
|
||||
* Save data from this componennt to character XML
|
||||
* @param doc the document to write data to
|
||||
*/
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
/**
|
||||
* Load base data for this component from character XML
|
||||
* @param doc the document to read data from
|
||||
*/
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
/**
|
||||
* Gets the current level of the entity
|
||||
|
||||
@@ -466,8 +466,8 @@ bool MissionComponent::RequiresItem(const LOT lot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!result.fieldIsNull(0)) {
|
||||
const auto type = std::string(result.getStringField(0));
|
||||
if (!result.fieldIsNull("type")) {
|
||||
const auto type = std::string(result.getStringField("type"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
@@ -504,10 +504,8 @@ bool MissionComponent::RequiresItem(const LOT lot) {
|
||||
}
|
||||
|
||||
|
||||
void MissionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
if (doc == nullptr) return;
|
||||
|
||||
auto* mis = doc->FirstChildElement("obj")->FirstChildElement("mis");
|
||||
void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
|
||||
auto* mis = doc.FirstChildElement("obj")->FirstChildElement("mis");
|
||||
|
||||
if (mis == nullptr) return;
|
||||
|
||||
@@ -523,7 +521,7 @@ void MissionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
auto* mission = new Mission(this, missionId);
|
||||
|
||||
mission->LoadFromXml(doneM);
|
||||
mission->LoadFromXml(*doneM);
|
||||
|
||||
doneM = doneM->NextSiblingElement();
|
||||
|
||||
@@ -540,7 +538,7 @@ void MissionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
auto* mission = new Mission(this, missionId);
|
||||
|
||||
mission->LoadFromXml(currentM);
|
||||
mission->LoadFromXml(*currentM);
|
||||
|
||||
if (currentM->QueryAttribute("o", &missionOrder) == tinyxml2::XML_SUCCESS && mission->IsMission()) {
|
||||
mission->SetUniqueMissionOrderID(missionOrder);
|
||||
@@ -554,25 +552,23 @@ void MissionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
|
||||
|
||||
void MissionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
if (doc == nullptr) return;
|
||||
|
||||
void MissionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
|
||||
auto shouldInsertMis = false;
|
||||
|
||||
auto* obj = doc->FirstChildElement("obj");
|
||||
auto* obj = doc.FirstChildElement("obj");
|
||||
|
||||
auto* mis = obj->FirstChildElement("mis");
|
||||
|
||||
if (mis == nullptr) {
|
||||
mis = doc->NewElement("mis");
|
||||
mis = doc.NewElement("mis");
|
||||
|
||||
shouldInsertMis = true;
|
||||
}
|
||||
|
||||
mis->DeleteChildren();
|
||||
|
||||
auto* done = doc->NewElement("done");
|
||||
auto* cur = doc->NewElement("cur");
|
||||
auto* done = doc.NewElement("done");
|
||||
auto* cur = doc.NewElement("cur");
|
||||
|
||||
for (const auto& pair : m_Missions) {
|
||||
auto* mission = pair.second;
|
||||
@@ -580,10 +576,10 @@ void MissionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
if (mission) {
|
||||
const auto complete = mission->IsComplete();
|
||||
|
||||
auto* m = doc->NewElement("m");
|
||||
auto* m = doc.NewElement("m");
|
||||
|
||||
if (complete) {
|
||||
mission->UpdateXml(m);
|
||||
mission->UpdateXml(*m);
|
||||
|
||||
done->LinkEndChild(m);
|
||||
|
||||
@@ -591,7 +587,7 @@ void MissionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
}
|
||||
if (mission->IsMission()) m->SetAttribute("o", mission->GetUniqueMissionOrderID());
|
||||
|
||||
mission->UpdateXml(m);
|
||||
mission->UpdateXml(*m);
|
||||
|
||||
cur->LinkEndChild(m);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ public:
|
||||
explicit MissionComponent(Entity* parent);
|
||||
~MissionComponent() override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument& doc) override;
|
||||
|
||||
/**
|
||||
* Returns all the missions for this entity, mapped by mission ID
|
||||
|
||||
@@ -10,19 +10,9 @@
|
||||
ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
|
||||
m_OriginalPosition = m_Parent->GetDefaultPosition();
|
||||
m_OriginalRotation = m_Parent->GetDefaultRotation();
|
||||
|
||||
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||
}
|
||||
|
||||
void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
// ItemComponent Serialization. Pets do not get this serialization.
|
||||
if (!m_Parent->HasComponent(eReplicaComponentType::PET)) {
|
||||
outBitStream.Write1();
|
||||
outBitStream.Write<LWOOBJID>(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID());
|
||||
outBitStream.Write<int>(0);
|
||||
outBitStream.Write0();
|
||||
}
|
||||
|
||||
//actual model component:
|
||||
outBitStream.Write1(); // Yes we are writing model info
|
||||
outBitStream.Write0(); // Is pickable
|
||||
|
||||
@@ -126,9 +126,4 @@ private:
|
||||
* The rotation original of the model
|
||||
*/
|
||||
NiQuaternion m_OriginalRotation;
|
||||
|
||||
/**
|
||||
* The ID of the user that made the model
|
||||
*/
|
||||
LWOOBJID m_userModelID;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "GameMessages.h"
|
||||
#include "BrickDatabase.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDTamingBuildPuzzleTable.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Character.h"
|
||||
@@ -31,8 +32,9 @@
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "eMissionState.h"
|
||||
#include "dNavMesh.h"
|
||||
#include "eGameActivity.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
std::unordered_map<LOT, PetComponent::PetPuzzleData> PetComponent::buildCache{};
|
||||
std::unordered_map<LWOOBJID, LWOOBJID> PetComponent::currentActivities{};
|
||||
std::unordered_map<LWOOBJID, LWOOBJID> PetComponent::activePets{};
|
||||
|
||||
@@ -40,7 +42,7 @@ std::unordered_map<LWOOBJID, LWOOBJID> PetComponent::activePets{};
|
||||
* Maps all the pet lots to a flag indicating that the player has caught it. All basic pets have been guessed by ObjID
|
||||
* while the faction ones could be checked using their respective missions.
|
||||
*/
|
||||
std::map<LOT, int32_t> PetComponent::petFlags = {
|
||||
const std::map<LOT, int32_t> PetComponent::petFlags{
|
||||
{ 3050, 801 }, // Elephant
|
||||
{ 3054, 803 }, // Cat
|
||||
{ 3195, 806 }, // Triceratops
|
||||
@@ -87,7 +89,6 @@ PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Compone
|
||||
m_StartPosition = NiPoint3Constant::ZERO;
|
||||
m_MovementAI = nullptr;
|
||||
m_TresureTime = 0;
|
||||
m_Preconditions = nullptr;
|
||||
|
||||
std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parentEntity->GetVar<std::u16string>(u"CheckPrecondition"));
|
||||
|
||||
@@ -152,96 +153,53 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
}
|
||||
|
||||
auto* inventoryComponent = originator->GetComponent<InventoryComponent>();
|
||||
|
||||
auto* const inventoryComponent = originator->GetComponent<InventoryComponent>();
|
||||
if (inventoryComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Preconditions != nullptr && !m_Preconditions->Check(originator, true)) {
|
||||
if (m_Preconditions.has_value() && !m_Preconditions->Check(originator, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* movementAIComponent = m_Parent->GetComponent<MovementAIComponent>();
|
||||
|
||||
auto* const movementAIComponent = m_Parent->GetComponent<MovementAIComponent>();
|
||||
if (movementAIComponent != nullptr) {
|
||||
movementAIComponent->Stop();
|
||||
}
|
||||
|
||||
inventoryComponent->DespawnPet();
|
||||
|
||||
const auto& cached = buildCache.find(m_Parent->GetLOT());
|
||||
int32_t imaginationCost = 0;
|
||||
|
||||
std::string buildFile;
|
||||
|
||||
if (cached == buildCache.end()) {
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT ValidPiecesLXF, PuzzleModelLot, Timelimit, NumValidPieces, imagCostPerBuild FROM TamingBuildPuzzles WHERE NPCLot = ?;");
|
||||
query.bind(1, static_cast<int>(m_Parent->GetLOT()));
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof()) {
|
||||
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to find the puzzle minigame for this pet.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.fieldIsNull(0)) {
|
||||
result.finalize();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
buildFile = std::string(result.getStringField(0));
|
||||
|
||||
PetPuzzleData data;
|
||||
data.buildFile = buildFile;
|
||||
data.puzzleModelLot = result.getIntField(1);
|
||||
data.timeLimit = result.getFloatField(2);
|
||||
data.numValidPieces = result.getIntField(3);
|
||||
data.imaginationCost = result.getIntField(4);
|
||||
if (data.timeLimit <= 0) data.timeLimit = 60;
|
||||
imaginationCost = data.imaginationCost;
|
||||
|
||||
buildCache[m_Parent->GetLOT()] = data;
|
||||
|
||||
result.finalize();
|
||||
} else {
|
||||
buildFile = cached->second.buildFile;
|
||||
imaginationCost = cached->second.imaginationCost;
|
||||
const auto* const entry = CDClientManager::GetTable<CDTamingBuildPuzzleTable>()->GetByLOT(m_Parent->GetLOT());
|
||||
if (!entry) {
|
||||
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to find the puzzle minigame for this pet.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* destroyableComponent = originator->GetComponent<DestroyableComponent>();
|
||||
|
||||
const auto* const destroyableComponent = originator->GetComponent<DestroyableComponent>();
|
||||
if (destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto imagination = destroyableComponent->GetImagination();
|
||||
|
||||
if (imagination < imaginationCost) {
|
||||
const auto imagination = destroyableComponent->GetImagination();
|
||||
if (imagination < entry->imaginationCost) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& bricks = BrickDatabase::GetBricks(buildFile);
|
||||
|
||||
const auto& bricks = BrickDatabase::GetBricks(entry->validPieces);
|
||||
if (bricks.empty()) {
|
||||
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to load the puzzle minigame for this pet.");
|
||||
LOG("Couldn't find %s for minigame!", buildFile.c_str());
|
||||
LOG("Couldn't find %s for minigame!", entry->validPieces.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto petPosition = m_Parent->GetPosition();
|
||||
const auto petPosition = m_Parent->GetPosition();
|
||||
|
||||
auto originatorPosition = originator->GetPosition();
|
||||
const auto originatorPosition = originator->GetPosition();
|
||||
|
||||
m_Parent->SetRotation(NiQuaternion::LookAt(petPosition, originatorPosition));
|
||||
|
||||
float interactionDistance = m_Parent->GetVar<float>(u"interaction_distance");
|
||||
|
||||
if (interactionDistance <= 0) {
|
||||
interactionDistance = 15;
|
||||
}
|
||||
@@ -254,24 +212,23 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
if (dpWorld::IsLoaded()) {
|
||||
NiPoint3 attempt = petPosition + forward * interactionDistance;
|
||||
|
||||
float y = dpWorld::GetNavMesh()->GetHeightAtPoint(attempt);
|
||||
NiPoint3 nearestPoint = dpWorld::GetNavMesh()->NearestPoint(attempt);
|
||||
|
||||
while (std::abs(y - petPosition.y) > 4 && interactionDistance > 10) {
|
||||
while (std::abs(nearestPoint.y - petPosition.y) > 4 && interactionDistance > 10) {
|
||||
const NiPoint3 forward = m_Parent->GetRotation().GetForwardVector();
|
||||
|
||||
attempt = originatorPosition + forward * interactionDistance;
|
||||
|
||||
y = dpWorld::GetNavMesh()->GetHeightAtPoint(attempt);
|
||||
nearestPoint = dpWorld::GetNavMesh()->NearestPoint(attempt);
|
||||
|
||||
interactionDistance -= 0.5f;
|
||||
}
|
||||
|
||||
position = attempt;
|
||||
position = nearestPoint;
|
||||
} else {
|
||||
position = petPosition + forward * interactionDistance;
|
||||
}
|
||||
|
||||
|
||||
auto rotation = NiQuaternion::LookAt(position, petPosition);
|
||||
|
||||
GameMessages::SendNotifyPetTamingMinigame(
|
||||
@@ -290,11 +247,11 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
m_Parent->GetObjectID(),
|
||||
LWOOBJID_EMPTY,
|
||||
originator->GetObjectID(),
|
||||
true,
|
||||
false,
|
||||
ePetTamingNotifyType::BEGIN,
|
||||
petPosition,
|
||||
position,
|
||||
rotation,
|
||||
NiPoint3Constant::ZERO,
|
||||
NiPoint3Constant::ZERO,
|
||||
NiQuaternion(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
UNASSIGNED_SYSTEM_ADDRESS
|
||||
);
|
||||
|
||||
@@ -302,11 +259,18 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
|
||||
m_Tamer = originator->GetObjectID();
|
||||
SetStatus(5);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
currentActivities.insert_or_assign(m_Tamer, m_Parent->GetObjectID());
|
||||
|
||||
// Notify the start of a pet taming minigame
|
||||
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, originator, ePetTamingNotifyType::BEGIN);
|
||||
|
||||
auto* characterComponent = originator->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->SetCurrentActivity(eGameActivity::PET_TAMING);
|
||||
Game::entityManager->SerializeEntity(originator);
|
||||
}
|
||||
}
|
||||
|
||||
void PetComponent::Update(float deltaTime) {
|
||||
@@ -477,9 +441,8 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& cached = buildCache.find(m_Parent->GetLOT());
|
||||
|
||||
if (cached == buildCache.end()) return;
|
||||
const auto* const entry = CDClientManager::GetTable<CDTamingBuildPuzzleTable>()->GetByLOT(m_Parent->GetLOT());
|
||||
if (!entry) return;
|
||||
|
||||
auto* destroyableComponent = tamer->GetComponent<DestroyableComponent>();
|
||||
|
||||
@@ -487,14 +450,14 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
|
||||
|
||||
auto imagination = destroyableComponent->GetImagination();
|
||||
|
||||
imagination -= cached->second.imaginationCost;
|
||||
imagination -= entry->imaginationCost;
|
||||
|
||||
destroyableComponent->SetImagination(imagination);
|
||||
|
||||
Game::entityManager->SerializeEntity(tamer);
|
||||
|
||||
if (clientFailed) {
|
||||
if (imagination < cached->second.imaginationCost) {
|
||||
if (imagination < entry->imaginationCost) {
|
||||
ClientFailTamingMinigame();
|
||||
}
|
||||
} else {
|
||||
@@ -517,17 +480,14 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& cached = buildCache.find(m_Parent->GetLOT());
|
||||
|
||||
if (cached == buildCache.end()) {
|
||||
return;
|
||||
}
|
||||
const auto* const entry = CDClientManager::GetTable<CDTamingBuildPuzzleTable>()->GetByLOT(m_Parent->GetLOT());
|
||||
if (!entry) return;
|
||||
|
||||
GameMessages::SendPlayFXEffect(tamer, -1, u"petceleb", "", LWOOBJID_EMPTY, 1, 1, true);
|
||||
RenderComponent::PlayAnimation(tamer, u"rebuild-celebrate");
|
||||
|
||||
EntityInfo info{};
|
||||
info.lot = cached->second.puzzleModelLot;
|
||||
info.lot = entry->puzzleModelLot;
|
||||
info.pos = position;
|
||||
info.rot = NiQuaternionConstant::IDENTITY;
|
||||
info.spawnerID = tamer->GetObjectID();
|
||||
@@ -675,6 +635,11 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
UNASSIGNED_SYSTEM_ADDRESS
|
||||
);
|
||||
|
||||
auto* characterComponent = tamer->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
||||
Game::entityManager->SerializeEntity(tamer);
|
||||
}
|
||||
GameMessages::SendTerminateInteraction(m_Tamer, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
||||
|
||||
auto* modelEntity = Game::entityManager->GetEntity(m_ModelId);
|
||||
@@ -714,6 +679,11 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
UNASSIGNED_SYSTEM_ADDRESS
|
||||
);
|
||||
|
||||
auto* characterComponent = tamer->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
||||
Game::entityManager->SerializeEntity(tamer);
|
||||
}
|
||||
GameMessages::SendNotifyTamingModelLoadedOnServer(m_Tamer, tamer->GetSystemAddress());
|
||||
|
||||
GameMessages::SendTerminateInteraction(m_Tamer, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
||||
@@ -731,13 +701,10 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
}
|
||||
|
||||
void PetComponent::StartTimer() {
|
||||
const auto& cached = buildCache.find(m_Parent->GetLOT());
|
||||
const auto* const entry = CDClientManager::GetTable<CDTamingBuildPuzzleTable>()->GetByLOT(m_Parent->GetLOT());
|
||||
if (!entry) return;
|
||||
|
||||
if (cached == buildCache.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Timer = cached->second.timeLimit;
|
||||
m_Timer = entry->timeLimit;
|
||||
}
|
||||
|
||||
void PetComponent::ClientFailTamingMinigame() {
|
||||
@@ -763,6 +730,11 @@ void PetComponent::ClientFailTamingMinigame() {
|
||||
UNASSIGNED_SYSTEM_ADDRESS
|
||||
);
|
||||
|
||||
auto* characterComponent = tamer->GetComponent<CharacterComponent>();
|
||||
if (characterComponent != nullptr) {
|
||||
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
||||
Game::entityManager->SerializeEntity(tamer);
|
||||
}
|
||||
GameMessages::SendNotifyTamingModelLoadedOnServer(m_Tamer, tamer->GetSystemAddress());
|
||||
|
||||
GameMessages::SendTerminateInteraction(m_Tamer, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
||||
@@ -1086,6 +1058,6 @@ void PetComponent::LoadPetNameFromModeration() {
|
||||
}
|
||||
}
|
||||
|
||||
void PetComponent::SetPreconditions(std::string& preconditions) {
|
||||
m_Preconditions = new PreconditionExpression(preconditions);
|
||||
void PetComponent::SetPreconditions(const std::string& preconditions) {
|
||||
m_Preconditions = std::make_optional<PreconditionExpression>(preconditions);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
* Sets preconditions for the pet that need to be met before it can be tamed
|
||||
* @param conditions the preconditions to set
|
||||
*/
|
||||
void SetPreconditions(std::string& conditions);
|
||||
void SetPreconditions(const std::string& conditions);
|
||||
|
||||
/**
|
||||
* Returns the entity that this component belongs to
|
||||
@@ -250,15 +250,10 @@ private:
|
||||
*/
|
||||
static std::unordered_map<LWOOBJID, LWOOBJID> currentActivities;
|
||||
|
||||
/**
|
||||
* Cache of all the minigames and their information from the database
|
||||
*/
|
||||
static std::unordered_map<LOT, PetComponent::PetPuzzleData> buildCache;
|
||||
|
||||
/**
|
||||
* Flags that indicate that a player has tamed a pet, indexed by the LOT of the pet
|
||||
*/
|
||||
static std::map<LOT, int32_t> petFlags;
|
||||
static const std::map<LOT, int32_t> petFlags;
|
||||
|
||||
/**
|
||||
* The ID of the component in the pet component table
|
||||
@@ -349,7 +344,7 @@ private:
|
||||
/**
|
||||
* Preconditions that need to be met before an entity can tame this pet
|
||||
*/
|
||||
PreconditionExpression* m_Preconditions;
|
||||
std::optional<PreconditionExpression> m_Preconditions{};
|
||||
|
||||
/**
|
||||
* Pet information loaded from the CDClientDatabase
|
||||
|
||||
@@ -47,7 +47,7 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
|
||||
m_Direction = NiPoint3(); // * m_DirectionalMultiplier
|
||||
|
||||
if (m_Parent->GetVar<bool>(u"create_physics")) {
|
||||
CreatePhysics();
|
||||
m_dpEntity = CreatePhysicsLnv(m_Scale, ComponentType);
|
||||
}
|
||||
|
||||
if (m_Parent->GetVar<bool>(u"respawnVol")) {
|
||||
@@ -89,105 +89,9 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
|
||||
m_RespawnRot = m_Rotation;
|
||||
}
|
||||
|
||||
/*
|
||||
for (LDFBaseData* data : settings) {
|
||||
if (data) {
|
||||
if (data->GetKey() == u"create_physics") {
|
||||
if (bool(std::stoi(data->GetValueAsString()))) {
|
||||
CreatePhysics(settings);
|
||||
}
|
||||
}
|
||||
|
||||
if (data->GetKey() == u"respawnVol") {
|
||||
if (bool(std::stoi(data->GetValueAsString()))) {
|
||||
m_IsRespawnVolume = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_IsRespawnVolume) {
|
||||
if (data->GetKey() == u"rspPos") {
|
||||
//Joy, we get to split strings!
|
||||
std::stringstream test(data->GetValueAsString());
|
||||
std::string segment;
|
||||
std::vector<std::string> seglist;
|
||||
|
||||
while (std::getline(test, segment, '\x1f')) {
|
||||
seglist.push_back(segment);
|
||||
}
|
||||
|
||||
m_RespawnPos = NiPoint3(std::stof(seglist[0]), std::stof(seglist[1]), std::stof(seglist[2]));
|
||||
}
|
||||
|
||||
if (data->GetKey() == u"rspRot") {
|
||||
//Joy, we get to split strings!
|
||||
std::stringstream test(data->GetValueAsString());
|
||||
std::string segment;
|
||||
std::vector<std::string> seglist;
|
||||
|
||||
while (std::getline(test, segment, '\x1f')) {
|
||||
seglist.push_back(segment);
|
||||
}
|
||||
|
||||
m_RespawnRot = NiQuaternion(std::stof(seglist[0]), std::stof(seglist[1]), std::stof(seglist[2]), std::stof(seglist[3]));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Parent->GetLOT() == 4945) // HF - RespawnPoints
|
||||
{
|
||||
m_IsRespawnVolume = true;
|
||||
m_RespawnPos = m_Position;
|
||||
m_RespawnRot = m_Rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (!m_HasCreatedPhysics) {
|
||||
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS);
|
||||
|
||||
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
|
||||
|
||||
if (physComp == nullptr) return;
|
||||
|
||||
auto* info = physComp->GetByID(componentID);
|
||||
if (info == nullptr || info->physicsAsset == "" || info->physicsAsset == "NO_PHYSICS") return;
|
||||
|
||||
//temp test
|
||||
if (info->physicsAsset == "miscellaneous\\misc_phys_10x1x5.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 10.0f, 5.0f, 1.0f);
|
||||
} else if (info->physicsAsset == "miscellaneous\\misc_phys_640x640.hkx") {
|
||||
// TODO Fix physics simulation to do simulation at high velocities due to bullet through paper problem...
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1638.4f, 13.521004f * 2.0f, 1638.4f);
|
||||
|
||||
// Move this down by 13.521004 units so it is still effectively at the same height as before
|
||||
m_Position = m_Position - NiPoint3Constant::UNIT_Y * 13.521004f;
|
||||
} else if (info->physicsAsset == "env\\trigger_wall_tall.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 10.0f, 25.0f, 1.0f);
|
||||
} else if (info->physicsAsset == "env\\env_gen_placeholderphysics.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 20.0f, 20.0f, 20.0f);
|
||||
} else if (info->physicsAsset == "env\\POI_trigger_wall.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1.0f, 12.5f, 20.0f); // Not sure what the real size is
|
||||
} else if (info->physicsAsset == "env\\NG_NinjaGo\\env_ng_gen_gate_chamber_puzzle_ceiling_tile_falling_phantom.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 18.0f, 5.0f, 15.0f);
|
||||
m_Position += m_Rotation.GetForwardVector() * 7.5f;
|
||||
} else if (info->physicsAsset == "env\\NG_NinjaGo\\ng_flamejet_brick_phantom.HKX") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1.0f, 1.0f, 12.0f);
|
||||
m_Position += m_Rotation.GetForwardVector() * 6.0f;
|
||||
} else if (info->physicsAsset == "env\\Ring_Trigger.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 6.0f, 6.0f, 6.0f);
|
||||
} else if (info->physicsAsset == "env\\vfx_propertyImaginationBall.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 4.5f);
|
||||
} else if (info->physicsAsset == "env\\env_won_fv_gas-blocking-volume.hkx") {
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 390.496826f, 111.467964f, 600.821534f, true);
|
||||
m_Position.y -= (111.467964f * m_Scale) / 2;
|
||||
} else {
|
||||
// LOG_DEBUG("This one is supposed to have %s", info->physicsAsset.c_str());
|
||||
|
||||
//add fallback cube:
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f);
|
||||
}
|
||||
|
||||
if (!m_dpEntity) {
|
||||
m_dpEntity = CreatePhysicsEntity(ComponentType);
|
||||
if (!m_dpEntity) return;
|
||||
m_dpEntity->SetScale(m_Scale);
|
||||
m_dpEntity->SetRotation(m_Rotation);
|
||||
m_dpEntity->SetPosition(m_Position);
|
||||
@@ -201,69 +105,6 @@ PhantomPhysicsComponent::~PhantomPhysicsComponent() {
|
||||
}
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::CreatePhysics() {
|
||||
unsigned char alpha;
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
int type = -1;
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
float width = 0.0f; //aka "radius"
|
||||
float height = 0.0f;
|
||||
|
||||
if (m_Parent->HasVar(u"primitiveModelType")) {
|
||||
type = m_Parent->GetVar<int32_t>(u"primitiveModelType");
|
||||
x = m_Parent->GetVar<float>(u"primitiveModelValueX");
|
||||
y = m_Parent->GetVar<float>(u"primitiveModelValueY");
|
||||
z = m_Parent->GetVar<float>(u"primitiveModelValueZ");
|
||||
} else {
|
||||
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS);
|
||||
|
||||
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
|
||||
|
||||
if (physComp == nullptr) return;
|
||||
|
||||
auto info = physComp->GetByID(componentID);
|
||||
|
||||
if (info == nullptr) return;
|
||||
|
||||
type = info->pcShapeType;
|
||||
width = info->playerRadius;
|
||||
height = info->playerHeight;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 1: { //Make a new box shape
|
||||
NiPoint3 boxSize(x, y, z);
|
||||
if (x == 0.0f) {
|
||||
//LU has some weird values, so I think it's best to scale them down a bit
|
||||
if (height < 0.5f) height = 2.0f;
|
||||
if (width < 0.5f) width = 2.0f;
|
||||
|
||||
//Scale them:
|
||||
width = width * m_Scale;
|
||||
height = height * m_Scale;
|
||||
|
||||
boxSize = NiPoint3(width, height, width);
|
||||
}
|
||||
|
||||
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), boxSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_dpEntity) return;
|
||||
|
||||
m_dpEntity->SetPosition({ m_Position.x, m_Position.y - (height / 2), m_Position.z });
|
||||
|
||||
dpWorld::AddEntity(m_dpEntity);
|
||||
|
||||
m_HasCreatedPhysics = true;
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
|
||||
|
||||
@@ -308,8 +149,9 @@ void ApplyCollisionEffect(const LWOOBJID& target, const ePhysicsEffectType effec
|
||||
controllablePhysicsComponent->SetGravityScale(effectScale);
|
||||
GameMessages::SendSetGravityScale(target, effectScale, targetEntity->GetSystemAddress());
|
||||
}
|
||||
break;
|
||||
}
|
||||
// The other types are not handled by the server
|
||||
|
||||
case ePhysicsEffectType::ATTRACT:
|
||||
case ePhysicsEffectType::FRICTION:
|
||||
case ePhysicsEffectType::PUSH:
|
||||
@@ -317,6 +159,7 @@ void ApplyCollisionEffect(const LWOOBJID& target, const ePhysicsEffectType effec
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// The other types are not handled by the server and are here to handle all cases of the enum.
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::Update(float deltaTime) {
|
||||
@@ -356,24 +199,12 @@ void PhantomPhysicsComponent::SetDirection(const NiPoint3& pos) {
|
||||
m_IsDirectional = true;
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::SpawnVertices() {
|
||||
if (!m_dpEntity) return;
|
||||
|
||||
LOG("%llu", m_Parent->GetObjectID());
|
||||
auto box = static_cast<dpShapeBox*>(m_dpEntity->GetShape());
|
||||
for (auto vert : box->GetVertices()) {
|
||||
LOG("%f, %f, %f", vert.x, vert.y, vert.z);
|
||||
|
||||
EntityInfo info;
|
||||
info.lot = 33;
|
||||
info.pos = vert;
|
||||
info.spawner = nullptr;
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
info.spawnerNodeID = 0;
|
||||
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
void PhantomPhysicsComponent::SpawnVertices() const {
|
||||
if (!m_dpEntity) {
|
||||
LOG("No dpEntity to spawn vertices for %llu:%i", m_Parent->GetObjectID(), m_Parent->GetLOT());
|
||||
return;
|
||||
}
|
||||
PhysicsComponent::SpawnVertices(m_dpEntity);
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::SetDirectionalMultiplier(float mul) {
|
||||
|
||||
@@ -18,6 +18,7 @@ class LDFBaseData;
|
||||
class Entity;
|
||||
class dpEntity;
|
||||
enum class ePhysicsEffectType : uint32_t ;
|
||||
enum class eReplicaComponentType : uint32_t;
|
||||
|
||||
/**
|
||||
* Allows the creation of phantom physics for an entity: a physics object that is generally invisible but can be
|
||||
@@ -34,11 +35,6 @@ public:
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Creates the physics shape for this entity based on LDF data
|
||||
*/
|
||||
void CreatePhysics();
|
||||
|
||||
/**
|
||||
* Sets the direction this physics object is pointed at
|
||||
* @param pos the direction to set
|
||||
@@ -109,7 +105,7 @@ public:
|
||||
/**
|
||||
* Spawns an object at each of the vertices for debugging purposes
|
||||
*/
|
||||
void SpawnVertices();
|
||||
void SpawnVertices() const;
|
||||
|
||||
/**
|
||||
* Legacy stuff no clue what this does
|
||||
@@ -166,11 +162,6 @@ private:
|
||||
*/
|
||||
dpEntity* m_dpEntity;
|
||||
|
||||
/**
|
||||
* Whether or not the physics object has been created yet
|
||||
*/
|
||||
bool m_HasCreatedPhysics = false;
|
||||
|
||||
/**
|
||||
* Whether or not this physics object represents an object that updates the respawn pos of an entity that crosses it
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#include "PhysicsComponent.h"
|
||||
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "NiPoint3.h"
|
||||
#include "NiQuaternion.h"
|
||||
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
|
||||
#include "dpEntity.h"
|
||||
#include "dpWorld.h"
|
||||
#include "dpShapeBox.h"
|
||||
#include "dpShapeSphere.h"
|
||||
|
||||
#include "EntityInfo.h"
|
||||
|
||||
PhysicsComponent::PhysicsComponent(Entity* parent) : Component(parent) {
|
||||
m_Position = NiPoint3Constant::ZERO;
|
||||
m_Rotation = NiQuaternionConstant::IDENTITY;
|
||||
@@ -19,3 +33,190 @@ void PhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitia
|
||||
if (!bIsInitialUpdate) m_DirtyPosition = false;
|
||||
}
|
||||
}
|
||||
|
||||
dpEntity* PhysicsComponent::CreatePhysicsEntity(eReplicaComponentType type) {
|
||||
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), type);
|
||||
|
||||
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
|
||||
|
||||
if (physComp == nullptr) return nullptr;
|
||||
|
||||
auto* info = physComp->GetByID(componentID);
|
||||
if (info == nullptr || info->physicsAsset == "" || info->physicsAsset == "NO_PHYSICS") return nullptr;
|
||||
|
||||
dpEntity* toReturn;
|
||||
if (info->physicsAsset == "miscellaneous\\misc_phys_10x1x5.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 10.0f, 5.0f, 1.0f);
|
||||
} else if (info->physicsAsset == "miscellaneous\\misc_phys_640x640.hkx") {
|
||||
// TODO Fix physics simulation to do simulation at high velocities due to bullet through paper problem...
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 1638.4f, 13.521004f * 2.0f, 1638.4f);
|
||||
|
||||
// Move this down by 13.521004 units so it is still effectively at the same height as before
|
||||
m_Position = m_Position - NiPoint3Constant::UNIT_Y * 13.521004f;
|
||||
} else if (info->physicsAsset == "env\\trigger_wall_tall.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 10.0f, 25.0f, 1.0f);
|
||||
} else if (info->physicsAsset == "env\\env_gen_placeholderphysics.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 20.0f, 20.0f, 20.0f);
|
||||
} else if (info->physicsAsset == "env\\POI_trigger_wall.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 12.5f, 20.0f); // Not sure what the real size is
|
||||
} else if (info->physicsAsset == "env\\NG_NinjaGo\\env_ng_gen_gate_chamber_puzzle_ceiling_tile_falling_phantom.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 18.0f, 5.0f, 15.0f);
|
||||
m_Position += m_Rotation.GetForwardVector() * 7.5f;
|
||||
} else if (info->physicsAsset == "env\\NG_NinjaGo\\ng_flamejet_brick_phantom.HKX") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 1.0f, 12.0f);
|
||||
m_Position += m_Rotation.GetForwardVector() * 6.0f;
|
||||
} else if (info->physicsAsset == "env\\Ring_Trigger.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 6.0f, 6.0f, 6.0f);
|
||||
} else if (info->physicsAsset == "env\\vfx_propertyImaginationBall.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 4.5f);
|
||||
} else if (info->physicsAsset == "env\\env_won_fv_gas-blocking-volume.hkx") {
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 390.496826f, 111.467964f, 600.821534f, true);
|
||||
m_Position.y -= (111.467964f * m_Parent->GetDefaultScale()) / 2;
|
||||
} else {
|
||||
// LOG_DEBUG("This one is supposed to have %s", info->physicsAsset.c_str());
|
||||
|
||||
//add fallback cube:
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
dpEntity* PhysicsComponent::CreatePhysicsLnv(const float scale, const eReplicaComponentType type) const {
|
||||
int pcShapeType = -1;
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
float width = 0.0f; //aka "radius"
|
||||
float height = 0.0f;
|
||||
dpEntity* toReturn = nullptr;
|
||||
|
||||
if (m_Parent->HasVar(u"primitiveModelType")) {
|
||||
pcShapeType = m_Parent->GetVar<int32_t>(u"primitiveModelType");
|
||||
x = m_Parent->GetVar<float>(u"primitiveModelValueX");
|
||||
y = m_Parent->GetVar<float>(u"primitiveModelValueY");
|
||||
z = m_Parent->GetVar<float>(u"primitiveModelValueZ");
|
||||
} else {
|
||||
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), type);
|
||||
|
||||
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
|
||||
|
||||
if (physComp == nullptr) return nullptr;
|
||||
|
||||
auto info = physComp->GetByID(componentID);
|
||||
|
||||
if (info == nullptr) return nullptr;
|
||||
|
||||
pcShapeType = info->pcShapeType;
|
||||
width = info->playerRadius;
|
||||
height = info->playerHeight;
|
||||
}
|
||||
|
||||
switch (pcShapeType) {
|
||||
case 0: { // HKX type
|
||||
break;
|
||||
}
|
||||
case 1: { //Make a new box shape
|
||||
NiPoint3 boxSize(x, y, z);
|
||||
if (x == 0.0f) {
|
||||
//LU has some weird values, so I think it's best to scale them down a bit
|
||||
if (height < 0.5f) height = 2.0f;
|
||||
if (width < 0.5f) width = 2.0f;
|
||||
|
||||
//Scale them:
|
||||
width = width * scale;
|
||||
height = height * scale;
|
||||
|
||||
boxSize = NiPoint3(width, height, width);
|
||||
}
|
||||
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), boxSize);
|
||||
|
||||
toReturn->SetPosition({ m_Position.x, m_Position.y - (height / 2), m_Position.z });
|
||||
break;
|
||||
}
|
||||
case 2: { //Make a new cylinder shape
|
||||
break;
|
||||
}
|
||||
case 3: { //Make a new sphere shape
|
||||
auto [x, y, z] = m_Position;
|
||||
toReturn = new dpEntity(m_Parent->GetObjectID(), width);
|
||||
toReturn->SetPosition({ x, y, z });
|
||||
break;
|
||||
}
|
||||
case 4: { //Make a new capsule shape
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (toReturn) dpWorld::AddEntity(toReturn);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
void PhysicsComponent::SpawnVertices(dpEntity* entity) const {
|
||||
if (!entity) return;
|
||||
|
||||
LOG("Spawning vertices for %llu", m_Parent->GetObjectID());
|
||||
EntityInfo info;
|
||||
info.lot = 33;
|
||||
info.spawner = nullptr;
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
info.spawnerNodeID = 0;
|
||||
|
||||
// These don't use overloaded methods as dPhysics does not link with dGame at the moment.
|
||||
auto box = dynamic_cast<dpShapeBox*>(entity->GetShape());
|
||||
if (box) {
|
||||
for (auto vert : box->GetVertices()) {
|
||||
LOG("Vertex at %f, %f, %f", vert.x, vert.y, vert.z);
|
||||
|
||||
info.pos = vert;
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
}
|
||||
}
|
||||
auto sphere = dynamic_cast<dpShapeSphere*>(entity->GetShape());
|
||||
if (sphere) {
|
||||
auto [x, y, z] = entity->GetPosition(); // Use shapes position instead of the parent's position in case it's different
|
||||
float plusX = x + sphere->GetRadius();
|
||||
float minusX = x - sphere->GetRadius();
|
||||
float plusY = y + sphere->GetRadius();
|
||||
float minusY = y - sphere->GetRadius();
|
||||
float plusZ = z + sphere->GetRadius();
|
||||
float minusZ = z - sphere->GetRadius();
|
||||
|
||||
auto radius = sphere->GetRadius();
|
||||
LOG("Radius: %f", radius);
|
||||
LOG("Plus Vertices %f %f %f", plusX, plusY, plusZ);
|
||||
LOG("Minus Vertices %f %f %f", minusX, minusY, minusZ);
|
||||
|
||||
info.pos = NiPoint3{ x, plusY, z };
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ x, minusY, z };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ plusX, y, z };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ minusX, y, z };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ x, y, plusZ };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ x, y, minusZ };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
info.pos = NiPoint3{ x, y, z };
|
||||
newEntity = Game::entityManager->CreateEntity(info);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ namespace Raknet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
enum class eReplicaComponentType : uint32_t;
|
||||
|
||||
class dpEntity;
|
||||
|
||||
class PhysicsComponent : public Component {
|
||||
public:
|
||||
PhysicsComponent(Entity* parent);
|
||||
@@ -22,6 +26,12 @@ public:
|
||||
const NiQuaternion& GetRotation() const { return m_Rotation; }
|
||||
virtual void SetRotation(const NiQuaternion& rot) { if (m_Rotation == rot) return; m_Rotation = rot; m_DirtyPosition = true; }
|
||||
protected:
|
||||
dpEntity* CreatePhysicsEntity(eReplicaComponentType type);
|
||||
|
||||
dpEntity* CreatePhysicsLnv(const float scale, const eReplicaComponentType type) const;
|
||||
|
||||
void SpawnVertices(dpEntity* entity) const;
|
||||
|
||||
NiPoint3 m_Position;
|
||||
|
||||
NiQuaternion m_Rotation;
|
||||
|
||||
@@ -18,8 +18,8 @@ PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId)
|
||||
|
||||
// Should a result not exist for this default to attached visible
|
||||
if (!result.eof()) {
|
||||
m_PossessionType = static_cast<ePossessionType>(result.getIntField(0, 1)); // Default to Attached Visible
|
||||
m_DepossessOnHit = static_cast<bool>(result.getIntField(1, 0));
|
||||
m_PossessionType = static_cast<ePossessionType>(result.getIntField("possessionType", 1)); // Default to Attached Visible
|
||||
m_DepossessOnHit = static_cast<bool>(result.getIntField("depossessOnHit", 0));
|
||||
} else {
|
||||
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
|
||||
m_DepossessOnHit = false;
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
#include "eObjectBits.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "ItemComponent.h"
|
||||
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include "CppScripts.h"
|
||||
|
||||
@@ -49,11 +51,11 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("id")) {
|
||||
return;
|
||||
}
|
||||
|
||||
templateId = result.getIntField(0);
|
||||
templateId = result.getIntField("id");
|
||||
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
|
||||
@@ -105,7 +107,7 @@ std::vector<NiPoint3> PropertyManagementComponent::GetPaths() const {
|
||||
|
||||
std::vector<float> points;
|
||||
|
||||
std::istringstream stream(result.getStringField(0));
|
||||
std::istringstream stream(result.getStringField("path"));
|
||||
std::string token;
|
||||
|
||||
while (std::getline(stream, token, ' ')) {
|
||||
@@ -152,21 +154,49 @@ void PropertyManagementComponent::SetPrivacyOption(PropertyPrivacyOption value)
|
||||
Database::Get()->UpdatePropertyModerationInfo(info);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::string description) {
|
||||
void PropertyManagementComponent::UpdatePropertyDetails(UpdatePropertyWithFilterCheck& update) {
|
||||
if (owner == LWOOBJID_EMPTY) return;
|
||||
|
||||
propertyName = name;
|
||||
if (update.isProperty) {
|
||||
propertyName = update.name;
|
||||
|
||||
propertyDescription = description;
|
||||
propertyDescription = update.description;
|
||||
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.name = propertyName;
|
||||
info.description = propertyDescription;
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.name = propertyName;
|
||||
info.description = propertyDescription;
|
||||
|
||||
Database::Get()->UpdatePropertyDetails(info);
|
||||
Database::Get()->UpdatePropertyDetails(info);
|
||||
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
} else {
|
||||
auto* entity = Game::entityManager->GetEntity(update.worldId);
|
||||
if (!entity) return;
|
||||
|
||||
if (update.name.empty()) {
|
||||
entity->EraseVar(u"userModelName");
|
||||
} else {
|
||||
entity->SetVar<std::string>(u"userModelName", update.name);
|
||||
}
|
||||
|
||||
if (update.description.empty()) {
|
||||
entity->EraseVar(u"userModelDesc");
|
||||
} else {
|
||||
entity->SetVar<std::string>(u"userModelDesc", update.description);
|
||||
}
|
||||
|
||||
auto* owner = GetOwner();
|
||||
if (!owner) return;
|
||||
|
||||
GameMessages::SendSetName(update.worldId, GeneralUtils::ASCIIToUTF16(update.name), owner->GetSystemAddress());
|
||||
auto* itemComponent = entity->GetComponent<ItemComponent>();
|
||||
if (itemComponent) {
|
||||
itemComponent->UpdateDescription(GeneralUtils::ASCIIToUTF16(update.description));
|
||||
}
|
||||
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
@@ -195,7 +225,7 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
|
||||
auto prop_path = zone->GetPath(m_Parent->GetVarAsString(u"propertyName"));
|
||||
|
||||
if (prop_path){
|
||||
if (prop_path) {
|
||||
if (!prop_path->property.displayName.empty()) name = prop_path->property.displayName;
|
||||
description = prop_path->property.displayDesc;
|
||||
}
|
||||
@@ -325,12 +355,15 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
return;
|
||||
}
|
||||
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
auto* node = new SpawnerNode();
|
||||
|
||||
node->position = position;
|
||||
node->rotation = rotation;
|
||||
for (const auto config : item->GetConfig()) {
|
||||
node->config.push_back(config->Copy());
|
||||
}
|
||||
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
ObjectIDManager::RequestPersistentID([this, node, modelLOT, entity, position, rotation, originalRotation](uint32_t persistentId) {
|
||||
SpawnerInfo info{};
|
||||
@@ -352,11 +385,27 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
|
||||
auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
|
||||
|
||||
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
info.nodes[0]->config.push_back(new LDFData<LWOOBJID>(u"userModelID", info.spawnerID));
|
||||
info.nodes[0]->config.push_back(new LDFData<int>(u"modelType", 2));
|
||||
info.nodes[0]->config.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
info.nodes[0]->config.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
// If empty, insert the default config data since it doesn't exist yet
|
||||
|
||||
if (!node->HasVar(u"modelBehaviors")) {
|
||||
node->config.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
}
|
||||
|
||||
if (!node->HasVar(u"userModelID")) {
|
||||
node->config.push_back(new LDFData<LWOOBJID>(u"userModelID", info.spawnerID));
|
||||
}
|
||||
|
||||
if (!node->HasVar(u"modelType")) {
|
||||
node->config.push_back(new LDFData<int>(u"modelType", 2));
|
||||
}
|
||||
|
||||
if (!node->HasVar(u"propertyObjectID")) {
|
||||
node->config.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
}
|
||||
|
||||
if (!node->HasVar(u"componentWhitelist")) {
|
||||
node->config.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
}
|
||||
|
||||
auto* model = spawner->Spawn();
|
||||
|
||||
@@ -436,7 +485,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
std::vector<LDFBaseData*> settings;
|
||||
|
||||
//fill our settings with BBB gurbage
|
||||
LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintid", model->GetVar<LWOOBJID>(u"blueprintid"));
|
||||
LDFBaseData* ldfBlueprintID = new LDFData<LWOOBJID>(u"blueprintID", model->GetVar<LWOOBJID>(u"blueprintID"));
|
||||
LDFBaseData* userModelDesc = new LDFData<std::u16string>(u"userModelDesc", u"A cool model you made!");
|
||||
LDFBaseData* userModelHasBhvr = new LDFData<bool>(u"userModelHasBhvr", false);
|
||||
LDFBaseData* userModelID = new LDFData<LWOOBJID>(u"userModelID", model->GetVar<LWOOBJID>(u"userModelID"));
|
||||
@@ -484,8 +533,9 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
return;
|
||||
}
|
||||
|
||||
inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::DELETION, INVALID, {}, LWOOBJID_EMPTY, false);
|
||||
inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::DELETION, INVALID, model->GetSettings(), LWOOBJID_EMPTY, false);
|
||||
|
||||
// figure out how to get the actual item we picked up instead of just the first lot we find
|
||||
auto* item = inventoryComponent->FindItemByLot(model->GetLOT());
|
||||
|
||||
if (item == nullptr) {
|
||||
@@ -572,28 +622,21 @@ void PropertyManagementComponent::Load() {
|
||||
|
||||
info.spawnerID = databaseModel.id;
|
||||
|
||||
std::vector<LDFBaseData*> settings;
|
||||
|
||||
//BBB property models need to have extra stuff set for them:
|
||||
if (databaseModel.lot == 14) {
|
||||
LWOOBJID blueprintID = databaseModel.ugcId;
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
|
||||
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID));
|
||||
settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id));
|
||||
if (!node->HasVar(u"blueprintID")) node->config.push_back(new LDFData<LWOOBJID>(u"blueprintID", blueprintID));
|
||||
} else {
|
||||
settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id));
|
||||
settings.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
if (!node->HasVar(u"modelBehaviors")) node->config.push_back(new LDFData<LWOOBJID>(u"modelBehaviors", 0));
|
||||
}
|
||||
|
||||
node->config = settings;
|
||||
if (!node->HasVar(u"modelType")) node->config.push_back(new LDFData<int>(u"modelType", 2));
|
||||
if (!node->HasVar(u"componentWhitelist")) node->config.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
if (!node->HasVar(u"propertyObjectID")) node->config.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
if (!node->HasVar(u"userModelID")) node->config.push_back(new LDFData<LWOOBJID>(u"userModelID", databaseModel.id));
|
||||
|
||||
const auto spawnerId = Game::zoneManager->MakeSpawner(info);
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ enum class PropertyPrivacyOption {
|
||||
/**
|
||||
* Your friends can visit your property
|
||||
*/
|
||||
Friends = 1,
|
||||
Friends = 1,
|
||||
|
||||
/**
|
||||
* Requires Mythran approval, everyone can visit your property
|
||||
*/
|
||||
Public = 2
|
||||
/**
|
||||
* Requires Mythran approval, everyone can visit your property
|
||||
*/
|
||||
Public = 2
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -30,6 +30,13 @@ enum class PropertyPrivacyOption {
|
||||
*/
|
||||
class PropertyManagementComponent final : public Component {
|
||||
public:
|
||||
struct UpdatePropertyWithFilterCheck {
|
||||
LWOOBJID objectId;
|
||||
LWOOBJID worldId;
|
||||
bool isProperty;
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT;
|
||||
PropertyManagementComponent(Entity* parent);
|
||||
static PropertyManagementComponent* Instance();
|
||||
@@ -95,7 +102,7 @@ public:
|
||||
* @param name the name to set for the property
|
||||
* @param description the description to set for the property
|
||||
*/
|
||||
void UpdatePropertyDetails(std::string name, std::string description);
|
||||
void UpdatePropertyDetails(UpdatePropertyWithFilterCheck& update);
|
||||
|
||||
/**
|
||||
* Makes this property owned by the passed player ID, storing it in the database
|
||||
|
||||
@@ -817,8 +817,10 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
|
||||
// Some offset up to make they don't fall through the terrain on a
|
||||
// respawn, seems to fix itself to the track anyhow
|
||||
player.respawnPosition = position + NiPoint3Constant::UNIT_Y * 5;
|
||||
player.respawnRotation = vehicle->GetRotation();
|
||||
if (waypoint.racing.isResetNode) {
|
||||
player.respawnPosition = position + NiPoint3Constant::UNIT_Y * 5;
|
||||
player.respawnRotation = vehicle->GetRotation();
|
||||
}
|
||||
player.respawnIndex = respawnIndex;
|
||||
|
||||
// Reached the start point, lapped
|
||||
|
||||
@@ -117,7 +117,7 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("animation_length")) {
|
||||
result.finalize();
|
||||
|
||||
m_DurationCache[effectId] = 0;
|
||||
@@ -127,7 +127,7 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
|
||||
return;
|
||||
}
|
||||
|
||||
effect.time = static_cast<float>(result.getFloatField(0));
|
||||
effect.time = static_cast<float>(result.getFloatField("animation_length"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
|
||||
@@ -1,16 +1,57 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2023
|
||||
*/
|
||||
// Darkflame Universe
|
||||
// Copyright 2024
|
||||
|
||||
#include "RigidbodyPhantomPhysicsComponent.h"
|
||||
#include "Entity.h"
|
||||
|
||||
#include "dpEntity.h"
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
#include "dpWorld.h"
|
||||
#include "dpShapeBox.h"
|
||||
#include "dpShapeSphere.h"
|
||||
#include"EntityInfo.h"
|
||||
|
||||
RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
|
||||
m_Position = m_Parent->GetDefaultPosition();
|
||||
m_Rotation = m_Parent->GetDefaultRotation();
|
||||
m_Scale = m_Parent->GetDefaultScale();
|
||||
|
||||
if (m_Parent->GetVar<bool>(u"create_physics")) {
|
||||
m_dpEntity = CreatePhysicsLnv(m_Scale, ComponentType);
|
||||
if (!m_dpEntity) {
|
||||
m_dpEntity = CreatePhysicsEntity(ComponentType);
|
||||
if (!m_dpEntity) return;
|
||||
m_dpEntity->SetScale(m_Scale);
|
||||
m_dpEntity->SetRotation(m_Rotation);
|
||||
m_dpEntity->SetPosition(m_Position);
|
||||
dpWorld::AddEntity(m_dpEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
|
||||
}
|
||||
|
||||
void RigidbodyPhantomPhysicsComponent::Update(const float deltaTime) {
|
||||
if (!m_dpEntity) return;
|
||||
|
||||
//Process enter events
|
||||
for (const auto id : m_dpEntity->GetNewObjects()) {
|
||||
m_Parent->OnCollisionPhantom(id);
|
||||
}
|
||||
|
||||
//Process exit events
|
||||
for (const auto id : m_dpEntity->GetRemovedObjects()) {
|
||||
m_Parent->OnCollisionLeavePhantom(id);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidbodyPhantomPhysicsComponent::SpawnVertices() const {
|
||||
if (!m_dpEntity) {
|
||||
LOG("No dpEntity to spawn vertices for %llu:%i", m_Parent->GetObjectID(), m_Parent->GetLOT());
|
||||
return;
|
||||
}
|
||||
PhysicsComponent::SpawnVertices(m_dpEntity);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2023
|
||||
*/
|
||||
// Darkflame Universe
|
||||
// Copyright 2024
|
||||
|
||||
#ifndef __RIGIDBODYPHANTOMPHYSICS_H__
|
||||
#define __RIGIDBODYPHANTOMPHYSICS_H__
|
||||
#ifndef RIGIDBODYPHANTOMPHYSICS_H
|
||||
#define RIGIDBODYPHANTOMPHYSICS_H
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "dCommonVars.h"
|
||||
@@ -13,6 +11,8 @@
|
||||
#include "PhysicsComponent.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class dpEntity;
|
||||
|
||||
/**
|
||||
* Component that handles rigid bodies that can be interacted with, mostly client-side rendered. An example is the
|
||||
* bananas that fall from trees in GF.
|
||||
@@ -23,7 +23,15 @@ public:
|
||||
|
||||
RigidbodyPhantomPhysicsComponent(Entity* parent);
|
||||
|
||||
void Update(const float deltaTime) override;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void SpawnVertices() const;
|
||||
private:
|
||||
float m_Scale{};
|
||||
|
||||
dpEntity* m_dpEntity{};
|
||||
};
|
||||
|
||||
#endif // __RIGIDBODYPHANTOMPHYSICS_H__
|
||||
#endif // RIGIDBODYPHANTOMPHYSICS_H
|
||||
|
||||
@@ -27,12 +27,12 @@ RocketLaunchpadControlComponent::RocketLaunchpadControlComponent(Entity* parent,
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (!result.eof() && !result.fieldIsNull(0)) {
|
||||
m_TargetZone = result.getIntField(0);
|
||||
m_DefaultZone = result.getIntField(1);
|
||||
m_TargetScene = result.getStringField(2);
|
||||
m_AltPrecondition = new PreconditionExpression(result.getStringField(3));
|
||||
m_AltLandingScene = result.getStringField(4);
|
||||
if (!result.eof() && !result.fieldIsNull("targetZone")) {
|
||||
m_TargetZone = result.getIntField("targetZone");
|
||||
m_DefaultZone = result.getIntField("defaultZoneID");
|
||||
m_TargetScene = result.getStringField("targetScene");
|
||||
m_AltPrecondition = new PreconditionExpression(result.getStringField("altLandingPrecondition"));
|
||||
m_AltLandingScene = result.getStringField("altLandingSpawnPointName");
|
||||
}
|
||||
|
||||
result.finalize();
|
||||
|
||||
@@ -99,7 +99,7 @@ void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::B
|
||||
return;
|
||||
}
|
||||
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto behavior_id = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
@@ -227,7 +227,7 @@ void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, B
|
||||
this->m_managedProjectiles.push_back(entry);
|
||||
}
|
||||
|
||||
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID) {
|
||||
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID, const int32_t castType, const NiQuaternion rotationOverride) {
|
||||
uint32_t behaviorId = -1;
|
||||
// try to find it via the cache
|
||||
const auto& pair = m_skillBehaviorCache.find(skillId);
|
||||
@@ -247,11 +247,19 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW
|
||||
return false;
|
||||
}
|
||||
|
||||
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID).success;
|
||||
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID, castType, rotationOverride).success;
|
||||
}
|
||||
|
||||
|
||||
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
|
||||
SkillExecutionResult SkillComponent::CalculateBehavior(
|
||||
const uint32_t skillId,
|
||||
const uint32_t behaviorId,
|
||||
const LWOOBJID target,
|
||||
const bool ignoreTarget,
|
||||
const bool clientInitalized,
|
||||
const LWOOBJID originatorOverride,
|
||||
const int32_t castType,
|
||||
const NiQuaternion rotationOverride) {
|
||||
RakNet::BitStream bitStream{};
|
||||
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
@@ -283,7 +291,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
// Echo start skill
|
||||
EchoStartSkill start;
|
||||
|
||||
start.iCastType = 0;
|
||||
start.iCastType = castType;
|
||||
start.skillID = skillId;
|
||||
start.uiSkillHandle = context->skillUId;
|
||||
start.optionalOriginatorID = context->originator;
|
||||
@@ -294,6 +302,10 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
if (originator != nullptr) {
|
||||
start.originatorRot = originator->GetRotation();
|
||||
}
|
||||
|
||||
if (rotationOverride != NiQuaternionConstant::IDENTITY) {
|
||||
start.originatorRot = rotationOverride;
|
||||
}
|
||||
//start.optionalTargetID = target;
|
||||
|
||||
start.sBitStream.assign(reinterpret_cast<char*>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
|
||||
@@ -413,7 +425,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
return;
|
||||
}
|
||||
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField(0));
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
|
||||
result.finalize();
|
||||
|
||||
@@ -464,7 +476,7 @@ void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID targ
|
||||
behavior->UnCast(&context, { target });
|
||||
}
|
||||
|
||||
SkillComponent::SkillComponent(Entity* parent): Component(parent) {
|
||||
SkillComponent::SkillComponent(Entity* parent) : Component(parent) {
|
||||
this->m_skillUid = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
* @param optionalOriginatorID change the originator of the skill
|
||||
* @return if the case succeeded
|
||||
*/
|
||||
bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY);
|
||||
bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY);
|
||||
|
||||
/**
|
||||
* Initializes a server-side skill calculation.
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
* @param originatorOverride an override for the originator of the skill calculation
|
||||
* @return the result of the skill calculation
|
||||
*/
|
||||
SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY);
|
||||
SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY);
|
||||
|
||||
/**
|
||||
* Register a server-side projectile.
|
||||
|
||||
@@ -369,8 +369,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd
|
||||
|
||||
const auto lot = entity->GetLOT();
|
||||
|
||||
if (lot == 12341 || lot == 5027 || lot == 5028 || lot == 14335 || lot == 14447 || lot == 14449) {
|
||||
iDesiredWaypointIndex = 0;
|
||||
if (lot == 12341 || lot == 5027 || lot == 5028 || lot == 14335 || lot == 14447 || lot == 14449 || lot == 11306 || lot == 11308) {
|
||||
iDesiredWaypointIndex = (lot == 11306 || lot == 11308) ? 1 : 0;
|
||||
iIndex = 0;
|
||||
nextIndex = 0;
|
||||
bStopAtDesiredWaypoint = true;
|
||||
@@ -412,7 +412,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd
|
||||
bitStream.Write(qUnexpectedRotation.w);
|
||||
}
|
||||
|
||||
SEND_PACKET_BROADCAST;
|
||||
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void GameMessages::SendRestoreToPostLoadStats(Entity* entity, const SystemAddress& sysAddr) {
|
||||
@@ -2206,19 +2207,17 @@ void GameMessages::HandleUnUseModel(RakNet::BitStream& inStream, Entity* entity,
|
||||
}
|
||||
|
||||
void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
bool isProperty{};
|
||||
LWOOBJID objectId{};
|
||||
PropertyManagementComponent::UpdatePropertyWithFilterCheck filterCheck{};
|
||||
LWOOBJID playerId{};
|
||||
LWOOBJID worldId{};
|
||||
uint32_t nameLength{};
|
||||
std::u16string name{};
|
||||
uint32_t descriptionLength{};
|
||||
std::u16string description{};
|
||||
|
||||
inStream.Read(isProperty);
|
||||
inStream.Read(objectId);
|
||||
inStream.Read(filterCheck.isProperty);
|
||||
inStream.Read(filterCheck.objectId);
|
||||
inStream.Read(playerId);
|
||||
inStream.Read(worldId);
|
||||
inStream.Read(filterCheck.worldId);
|
||||
|
||||
inStream.Read(descriptionLength);
|
||||
for (uint32_t i = 0; i < descriptionLength; ++i) {
|
||||
@@ -2226,6 +2225,7 @@ void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream&
|
||||
inStream.Read(character);
|
||||
description.push_back(character);
|
||||
}
|
||||
filterCheck.description = GeneralUtils::UTF16ToWTF8(description);
|
||||
|
||||
inStream.Read(nameLength);
|
||||
for (uint32_t i = 0; i < nameLength; ++i) {
|
||||
@@ -2233,8 +2233,10 @@ void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream&
|
||||
inStream.Read(character);
|
||||
name.push_back(character);
|
||||
}
|
||||
filterCheck.name = GeneralUtils::UTF16ToWTF8(name);
|
||||
LOG("names %s desc %s", filterCheck.name.c_str(), filterCheck.description.c_str());
|
||||
|
||||
PropertyManagementComponent::Instance()->UpdatePropertyDetails(GeneralUtils::UTF16ToWTF8(name), GeneralUtils::UTF16ToWTF8(description));
|
||||
PropertyManagementComponent::Instance()->UpdatePropertyDetails(filterCheck);
|
||||
}
|
||||
|
||||
void GameMessages::HandleQueryPropertyData(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
@@ -2663,7 +2665,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent
|
||||
info.spawnerID = entity->GetObjectID();
|
||||
info.spawnerNodeID = 0;
|
||||
|
||||
info.settings.push_back(new LDFData<LWOOBJID>(u"blueprintid", blueprintID));
|
||||
info.settings.push_back(new LDFData<LWOOBJID>(u"blueprintID", blueprintID));
|
||||
info.settings.push_back(new LDFData<int>(u"componentWhitelist", 1));
|
||||
info.settings.push_back(new LDFData<int>(u"modelType", 2));
|
||||
info.settings.push_back(new LDFData<bool>(u"propertyObjectID", true));
|
||||
@@ -4660,7 +4662,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream& inStream, Entity* enti
|
||||
if (!user) return;
|
||||
Entity* player = Game::entityManager->GetEntity(user->GetLoggedInChar());
|
||||
if (!player) return;
|
||||
|
||||
|
||||
// handle buying normal items
|
||||
auto* vendorComponent = entity->GetComponent<VendorComponent>();
|
||||
if (vendorComponent) {
|
||||
@@ -5290,7 +5292,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream& inStream, En
|
||||
bool iLootTypeSourceIsDefault = false;
|
||||
LWOOBJID iLootTypeSource = LWOOBJID_EMPTY;
|
||||
bool iObjIDIsDefault = false;
|
||||
LWOOBJID iObjID;
|
||||
LWOOBJID iObjID = LWOOBJID_EMPTY;
|
||||
bool iObjTemplateIsDefault = false;
|
||||
LOT iObjTemplate = LOT_NULL;
|
||||
bool iRequestingObjIDIsDefault = false;
|
||||
@@ -5354,14 +5356,14 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream& inStream, En
|
||||
if (eInvType == eInventoryType::MODELS) {
|
||||
item->DisassembleModel(iStackCount);
|
||||
}
|
||||
|
||||
auto lot = item->GetLot();
|
||||
item->SetCount(item->GetCount() - iStackCount, true);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
|
||||
auto* missionComponent = entity->GetComponent<MissionComponent>();
|
||||
|
||||
if (missionComponent != nullptr) {
|
||||
missionComponent->Progress(eMissionTaskType::GATHER, item->GetLot(), LWOOBJID_EMPTY, "", -iStackCount);
|
||||
missionComponent->Progress(eMissionTaskType::GATHER, lot, LWOOBJID_EMPTY, "", -iStackCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6197,3 +6199,15 @@ void GameMessages::HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Ent
|
||||
if (!characterComponent) return;
|
||||
characterComponent->SetCurrentInteracting(LWOOBJID_EMPTY);
|
||||
}
|
||||
|
||||
void GameMessages::SendSlashCommandFeedbackText(Entity* entity, std::u16string text) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(entity->GetObjectID());
|
||||
bitStream.Write(eGameMessageType::SLASH_COMMAND_TEXT_FEEDBACK);
|
||||
bitStream.Write<uint32_t>(text.size());
|
||||
bitStream.Write(text);
|
||||
auto sysAddr = entity->GetSystemAddress();
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -664,6 +664,8 @@ namespace GameMessages {
|
||||
void HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||
void HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
|
||||
void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
|
||||
|
||||
void SendSlashCommandFeedbackText(Entity* entity, std::u16string text);
|
||||
};
|
||||
|
||||
#endif // GAMEMESSAGES_H
|
||||
|
||||
@@ -27,6 +27,23 @@
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDPackageComponentTable.h"
|
||||
|
||||
namespace {
|
||||
const std::map<std::string, std::string> ExtraSettingAbbreviations = {
|
||||
{ "assemblyPartLOTs", "ma" },
|
||||
{ "blueprintID", "b" },
|
||||
{ "userModelID", "ui" },
|
||||
{ "userModelName", "un" },
|
||||
{ "userModelDesc", "ud" },
|
||||
{ "userModelHasBhvr", "ub" },
|
||||
{ "userModelBehaviors", "ubh" },
|
||||
{ "userModelBehaviorSourceID", "ubs" },
|
||||
{ "userModelPhysicsType", "up" },
|
||||
{ "userModelMod", "um" },
|
||||
{ "userModelOpt", "uo" },
|
||||
{ "reforgedLOT", "rl" },
|
||||
};
|
||||
}
|
||||
|
||||
Item::Item(const LWOOBJID id, const LOT lot, Inventory* inventory, const uint32_t slot, const uint32_t count, const bool bound, const std::vector<LDFBaseData*>& config, const LWOOBJID parent, LWOOBJID subKey, eLootSourceType lootSourceType) {
|
||||
if (!Inventory::IsValidItem(lot)) {
|
||||
return;
|
||||
@@ -122,6 +139,10 @@ uint32_t Item::GetSlot() const {
|
||||
return slot;
|
||||
}
|
||||
|
||||
std::vector<LDFBaseData*> Item::GetConfig() const {
|
||||
return config;
|
||||
}
|
||||
|
||||
std::vector<LDFBaseData*>& Item::GetConfig() {
|
||||
return config;
|
||||
}
|
||||
@@ -251,7 +272,7 @@ bool Item::Consume() {
|
||||
|
||||
auto skills = skillsTable->Query([this](const CDObjectSkills entry) {
|
||||
return entry.objectTemplate == static_cast<uint32_t>(lot);
|
||||
});
|
||||
});
|
||||
|
||||
auto success = false;
|
||||
|
||||
@@ -405,18 +426,18 @@ void Item::DisassembleModel(uint32_t numToDismantle) {
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
if (result.eof() || result.fieldIsNull("render_asset")) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string renderAsset = std::string(result.getStringField(0));
|
||||
std::string renderAsset = std::string(result.getStringField("render_asset"));
|
||||
|
||||
// normalize path slashes
|
||||
for (auto& c : renderAsset) {
|
||||
if (c == '\\') c = '/';
|
||||
}
|
||||
|
||||
std::string lxfmlFolderName = std::string(result.getStringField(1));
|
||||
std::string lxfmlFolderName = std::string(result.getStringField("LXFMLFolder"));
|
||||
if (!lxfmlFolderName.empty()) lxfmlFolderName.insert(0, "/");
|
||||
|
||||
std::vector<std::string> renderAssetSplit = GeneralUtils::SplitString(renderAsset, '/');
|
||||
@@ -515,3 +536,35 @@ Item::~Item() {
|
||||
|
||||
config.clear();
|
||||
}
|
||||
|
||||
void Item::SaveConfigXml(tinyxml2::XMLElement& i) const {
|
||||
tinyxml2::XMLElement* x = nullptr;
|
||||
|
||||
for (const auto* config : this->config) {
|
||||
const auto& key = GeneralUtils::UTF16ToWTF8(config->GetKey());
|
||||
const auto saveKey = ExtraSettingAbbreviations.find(key);
|
||||
if (saveKey == ExtraSettingAbbreviations.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!x) {
|
||||
x = i.InsertNewChildElement("x");
|
||||
}
|
||||
|
||||
const auto dataToSave = config->GetString(false);
|
||||
x->SetAttribute(saveKey->second.c_str(), dataToSave.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Item::LoadConfigXml(const tinyxml2::XMLElement& i) {
|
||||
const auto* x = i.FirstChildElement("x");
|
||||
if (!x) return;
|
||||
|
||||
for (const auto& pair : ExtraSettingAbbreviations) {
|
||||
const auto* data = x->Attribute(pair.second.c_str());
|
||||
if (!data) continue;
|
||||
|
||||
const auto value = pair.first + "=" + data;
|
||||
config.push_back(LDFBaseData::DataFromString(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "eInventoryType.h"
|
||||
#include "eLootSourceType.h"
|
||||
|
||||
namespace tinyxml2 {
|
||||
class XMLElement;
|
||||
};
|
||||
|
||||
/**
|
||||
* An item that can be stored in an inventory and optionally consumed or equipped
|
||||
* TODO: ideally this should be a component
|
||||
@@ -116,6 +120,12 @@ public:
|
||||
*/
|
||||
std::vector<LDFBaseData*>& GetConfig();
|
||||
|
||||
/**
|
||||
* Returns current config info for this item, e.g. for rockets
|
||||
* @return current config info for this item
|
||||
*/
|
||||
std::vector<LDFBaseData*> GetConfig() const;
|
||||
|
||||
/**
|
||||
* Returns the database info for this item
|
||||
* @return the database info for this item
|
||||
@@ -214,6 +224,10 @@ public:
|
||||
*/
|
||||
void RemoveFromInventory();
|
||||
|
||||
void SaveConfigXml(tinyxml2::XMLElement& i) const;
|
||||
|
||||
void LoadConfigXml(const tinyxml2::XMLElement& i);
|
||||
|
||||
private:
|
||||
/**
|
||||
* The object ID of this item
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
|
||||
ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
this->m_ID = id;
|
||||
this->m_InventoryComponent = inventoryComponent;
|
||||
|
||||
@@ -27,14 +30,16 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
if (result.fieldIsNull(i)) {
|
||||
constexpr std::array rowNames = { "skillSetWith2"sv, "skillSetWith3"sv, "skillSetWith4"sv, "skillSetWith5"sv, "skillSetWith6"sv };
|
||||
for (auto i = 0; i < rowNames.size(); ++i) {
|
||||
const auto rowName = rowNames[i];
|
||||
if (result.fieldIsNull(rowName.data())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT SkillID FROM ItemSetSkills WHERE SkillSetID = ?;");
|
||||
skillQuery.bind(1, result.getIntField(i));
|
||||
skillQuery.bind(1, result.getIntField(rowName.data()));
|
||||
|
||||
auto skillResult = skillQuery.execQuery();
|
||||
|
||||
@@ -43,13 +48,13 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
}
|
||||
|
||||
while (!skillResult.eof()) {
|
||||
if (skillResult.fieldIsNull(0)) {
|
||||
if (skillResult.fieldIsNull("SkillID")) {
|
||||
skillResult.nextRow();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto skillId = skillResult.getIntField(0);
|
||||
const auto skillId = skillResult.getIntField("SkillID");
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
@@ -75,7 +80,7 @@ ItemSet::ItemSet(const uint32_t id, InventoryComponent* inventoryComponent) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string ids = result.getStringField(5);
|
||||
std::string ids = result.getStringField("itemIDs");
|
||||
|
||||
ids.erase(std::remove_if(ids.begin(), ids.end(), ::isspace), ids.end());
|
||||
|
||||
|
||||
@@ -65,24 +65,24 @@ Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
||||
void Mission::LoadFromXml(const tinyxml2::XMLElement& element) {
|
||||
// Start custom XML
|
||||
if (element->Attribute("state") != nullptr) {
|
||||
m_State = static_cast<eMissionState>(std::stoul(element->Attribute("state")));
|
||||
if (element.Attribute("state") != nullptr) {
|
||||
m_State = static_cast<eMissionState>(std::stoul(element.Attribute("state")));
|
||||
}
|
||||
// End custom XML
|
||||
|
||||
if (element->Attribute("cct") != nullptr) {
|
||||
m_Completions = std::stoul(element->Attribute("cct"));
|
||||
if (element.Attribute("cct") != nullptr) {
|
||||
m_Completions = std::stoul(element.Attribute("cct"));
|
||||
|
||||
m_Timestamp = std::stoul(element->Attribute("cts"));
|
||||
m_Timestamp = std::stoul(element.Attribute("cts"));
|
||||
|
||||
if (IsComplete()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto* task = element->FirstChildElement();
|
||||
auto* task = element.FirstChildElement();
|
||||
|
||||
auto index = 0U;
|
||||
|
||||
@@ -132,19 +132,19 @@ void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
||||
void Mission::UpdateXml(tinyxml2::XMLElement& element) {
|
||||
// Start custom XML
|
||||
element->SetAttribute("state", static_cast<unsigned int>(m_State));
|
||||
element.SetAttribute("state", static_cast<unsigned int>(m_State));
|
||||
// End custom XML
|
||||
|
||||
element->DeleteChildren();
|
||||
element.DeleteChildren();
|
||||
|
||||
element->SetAttribute("id", static_cast<unsigned int>(info.id));
|
||||
element.SetAttribute("id", static_cast<unsigned int>(info.id));
|
||||
|
||||
if (m_Completions > 0) {
|
||||
element->SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
||||
element.SetAttribute("cct", static_cast<unsigned int>(m_Completions));
|
||||
|
||||
element->SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
||||
element.SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
|
||||
|
||||
if (IsComplete()) {
|
||||
return;
|
||||
@@ -155,27 +155,27 @@ void Mission::UpdateXml(tinyxml2::XMLElement* element) {
|
||||
if (task->GetType() == eMissionTaskType::COLLECTION ||
|
||||
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
|
||||
|
||||
auto* child = element->GetDocument()->NewElement("sv");
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element->LinkEndChild(child);
|
||||
element.LinkEndChild(child);
|
||||
|
||||
for (auto unique : task->GetUnique()) {
|
||||
auto* uniqueElement = element->GetDocument()->NewElement("sv");
|
||||
auto* uniqueElement = element.GetDocument()->NewElement("sv");
|
||||
|
||||
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
|
||||
|
||||
element->LinkEndChild(uniqueElement);
|
||||
element.LinkEndChild(uniqueElement);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
auto* child = element->GetDocument()->NewElement("sv");
|
||||
auto* child = element.GetDocument()->NewElement("sv");
|
||||
|
||||
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
|
||||
|
||||
element->LinkEndChild(child);
|
||||
element.LinkEndChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,6 +454,16 @@ void Mission::YieldRewards() {
|
||||
}
|
||||
}
|
||||
|
||||
// Even with no repeatable column, reputation is repeatable
|
||||
if (info.reward_reputation > 0) {
|
||||
missionComponent->Progress(eMissionTaskType::EARN_REPUTATION, 0, LWOOBJID_EMPTY, "", info.reward_reputation);
|
||||
auto* const character = entity->GetComponent<CharacterComponent>();
|
||||
if (character) {
|
||||
character->SetReputation(character->GetReputation() + info.reward_reputation);
|
||||
GameMessages::SendUpdateReputation(entity->GetObjectID(), character->GetReputation(), entity->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Completions > 0) {
|
||||
std::vector<std::pair<LOT, uint32_t>> items;
|
||||
|
||||
@@ -532,15 +542,6 @@ void Mission::YieldRewards() {
|
||||
modelInventory->SetSize(modelInventory->GetSize() + info.reward_bankinventory);
|
||||
}
|
||||
|
||||
if (info.reward_reputation > 0) {
|
||||
missionComponent->Progress(eMissionTaskType::EARN_REPUTATION, 0, 0L, "", info.reward_reputation);
|
||||
auto character = entity->GetComponent<CharacterComponent>();
|
||||
if (character) {
|
||||
character->SetReputation(character->GetReputation() + info.reward_reputation);
|
||||
GameMessages::SendUpdateReputation(entity->GetObjectID(), character->GetReputation(), entity->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
if (info.reward_maxhealth > 0) {
|
||||
destroyableComponent->SetMaxHealth(destroyableComponent->GetMaxHealth() + static_cast<float>(info.reward_maxhealth), true);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
Mission(MissionComponent* missionComponent, uint32_t missionId);
|
||||
~Mission();
|
||||
|
||||
void LoadFromXml(tinyxml2::XMLElement* element);
|
||||
void UpdateXml(tinyxml2::XMLElement* element);
|
||||
void LoadFromXml(const tinyxml2::XMLElement& element);
|
||||
void UpdateXml(tinyxml2::XMLElement& element);
|
||||
|
||||
/**
|
||||
* Returns the ID of this mission
|
||||
|
||||
@@ -29,15 +29,14 @@ const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) {
|
||||
return emptyCache;
|
||||
}
|
||||
|
||||
auto* doc = new tinyxml2::XMLDocument();
|
||||
if (doc->Parse(data.str().c_str(), data.str().size()) != 0) {
|
||||
delete doc;
|
||||
tinyxml2::XMLDocument doc;
|
||||
if (doc.Parse(data.str().c_str(), data.str().size()) != 0) {
|
||||
return emptyCache;
|
||||
}
|
||||
|
||||
BrickList parts;
|
||||
|
||||
auto* lxfml = doc->FirstChildElement("LXFML");
|
||||
auto* lxfml = doc.FirstChildElement("LXFML");
|
||||
auto* bricks = lxfml->FirstChildElement("Bricks");
|
||||
std::string searchTerm = "Brick";
|
||||
|
||||
@@ -86,7 +85,5 @@ const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) {
|
||||
|
||||
m_Cache[lxfmlPath] = parts;
|
||||
|
||||
delete doc;
|
||||
|
||||
return m_Cache[lxfmlPath];
|
||||
}
|
||||
|
||||
@@ -8,9 +8,15 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
|
||||
"SlashCommandHandler.cpp"
|
||||
"VanityUtilities.cpp")
|
||||
|
||||
add_subdirectory(SlashCommands)
|
||||
|
||||
foreach(file ${DGAME_DUTILITIES_SLASHCOMMANDS})
|
||||
set(DGAME_DUTILITIES_SOURCES ${DGAME_DUTILITIES_SOURCES} "SlashCommands/${file}")
|
||||
endforeach()
|
||||
|
||||
add_library(dUtilities OBJECT ${DGAME_DUTILITIES_SOURCES})
|
||||
target_precompile_headers(dUtilities REUSE_FROM dGameBase)
|
||||
target_include_directories(dUtilities PUBLIC "."
|
||||
target_include_directories(dUtilities PUBLIC "." "SlashCommands"
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # transitive via PossessableComponent.h
|
||||
|
||||
@@ -130,12 +130,6 @@ bool CheatDetection::VerifyLwoobjidIsSender(const LWOOBJID& id, const SystemAddr
|
||||
|
||||
// This will be true if the player does not possess the entity they are trying to send a packet as.
|
||||
// or if the user does not own the character they are trying to send a packet as.
|
||||
if (invalidPacket) {
|
||||
va_list args;
|
||||
va_start(args, messageIfNotSender);
|
||||
LogAndSaveFailedAntiCheatCheck(id, sysAddr, checkType, messageIfNotSender, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
return !invalidPacket;
|
||||
}
|
||||
|
||||
@@ -94,35 +94,6 @@ void Mail::SendMail(const LWOOBJID sender, const std::string& senderName, LWOOBJ
|
||||
SendNotification(sysAddr, 1); //Show the "one new mail" message
|
||||
}
|
||||
|
||||
//Because we need it:
|
||||
std::string ReadWStringAsString(RakNet::BitStream& bitStream, uint32_t size) {
|
||||
std::string toReturn = "";
|
||||
uint8_t buffer;
|
||||
bool isFinishedReading = false;
|
||||
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
bitStream.Read(buffer);
|
||||
if (!isFinishedReading) toReturn.push_back(buffer);
|
||||
if (buffer == '\0') isFinishedReading = true; //so we don't continue to read garbage as part of the string.
|
||||
bitStream.Read(buffer); //Read the null term
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
void WriteStringAsWString(RakNet::BitStream& bitStream, std::string str, uint32_t size) {
|
||||
uint32_t sizeToFill = size - str.size();
|
||||
|
||||
for (uint32_t i = 0; i < str.size(); ++i) {
|
||||
bitStream.Write(str[i]);
|
||||
bitStream.Write(uint8_t(0));
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sizeToFill; ++i) {
|
||||
bitStream.Write(uint16_t(0));
|
||||
}
|
||||
}
|
||||
|
||||
void Mail::HandleMailStuff(RakNet::BitStream& packet, const SystemAddress& sysAddr, Entity* entity) {
|
||||
int mailStuffID = 0;
|
||||
packet.Read(mailStuffID);
|
||||
@@ -176,11 +147,20 @@ void Mail::HandleSendMail(RakNet::BitStream& packet, const SystemAddress& sysAdd
|
||||
return;
|
||||
}
|
||||
|
||||
std::string subject = ReadWStringAsString(packet, 50);
|
||||
std::string body = ReadWStringAsString(packet, 400);
|
||||
std::string recipient = ReadWStringAsString(packet, 32);
|
||||
LUWString subjectRead(50);
|
||||
packet.Read(subjectRead);
|
||||
|
||||
LUWString bodyRead(400);
|
||||
packet.Read(bodyRead);
|
||||
|
||||
LUWString recipientRead(32);
|
||||
packet.Read(recipientRead);
|
||||
|
||||
const std::string subject = subjectRead.GetAsString();
|
||||
const std::string body = bodyRead.GetAsString();
|
||||
|
||||
//Cleanse recipient:
|
||||
recipient = std::regex_replace(recipient, std::regex("[^0-9a-zA-Z]+"), "");
|
||||
const std::string recipient = std::regex_replace(recipientRead.GetAsString(), std::regex("[^0-9a-zA-Z]+"), "");
|
||||
|
||||
uint64_t unknown64 = 0;
|
||||
LWOOBJID attachmentID;
|
||||
@@ -267,40 +247,44 @@ void Mail::HandleDataRequest(RakNet::BitStream& packet, const SystemAddress& sys
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::MAIL);
|
||||
bitStream.Write(int(MailMessageID::MailData));
|
||||
bitStream.Write(int(0));
|
||||
bitStream.Write(int(0)); // throttled
|
||||
|
||||
bitStream.Write<uint16_t>(playerMail.size());
|
||||
bitStream.Write<uint16_t>(playerMail.size()); // size
|
||||
bitStream.Write<uint16_t>(0);
|
||||
|
||||
for (const auto& mail : playerMail) {
|
||||
bitStream.Write(mail.id); //MailID
|
||||
|
||||
WriteStringAsWString(bitStream, mail.subject.c_str(), 50); //subject
|
||||
WriteStringAsWString(bitStream, mail.body.c_str(), 400); //body
|
||||
WriteStringAsWString(bitStream, mail.senderUsername.c_str(), 32); //sender
|
||||
const LUWString subject(mail.subject, 50);
|
||||
bitStream.Write(subject); //subject
|
||||
const LUWString body(mail.body, 400);
|
||||
bitStream.Write(body); //body
|
||||
const LUWString sender(mail.senderUsername, 32);
|
||||
bitStream.Write(sender); //sender
|
||||
bitStream.Write(uint32_t(0)); // packing
|
||||
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint64_t(0));
|
||||
bitStream.Write(uint64_t(0)); // attachedCurrency
|
||||
|
||||
bitStream.Write(mail.itemID); //Attachment ID
|
||||
LOT lot = mail.itemLOT;
|
||||
if (lot <= 0) bitStream.Write(LOT(-1));
|
||||
else bitStream.Write(lot);
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint32_t(0)); // packing
|
||||
|
||||
bitStream.Write(mail.itemSubkey); //Attachment subKey
|
||||
bitStream.Write<uint16_t>(mail.itemCount); //Attachment count
|
||||
bitStream.Write(mail.itemSubkey); // Attachment subKey
|
||||
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
bitStream.Write<uint16_t>(mail.itemCount); // Attachment count
|
||||
bitStream.Write(uint8_t(0)); // subject type (used for auction)
|
||||
bitStream.Write(uint8_t(0)); // packing
|
||||
bitStream.Write(uint32_t(0)); // packing
|
||||
|
||||
bitStream.Write<uint64_t>(mail.timeSent); //time sent (twice?)
|
||||
bitStream.Write<uint64_t>(mail.timeSent);
|
||||
bitStream.Write<uint64_t>(mail.timeSent); // expiration date
|
||||
bitStream.Write<uint64_t>(mail.timeSent);// send date
|
||||
bitStream.Write<uint8_t>(mail.wasRead); //was read
|
||||
|
||||
bitStream.Write(uint8_t(0));
|
||||
bitStream.Write(uint16_t(0));
|
||||
bitStream.Write(uint32_t(0));
|
||||
bitStream.Write(uint8_t(0)); // isLocalized
|
||||
bitStream.Write(uint16_t(0)); // packing
|
||||
bitStream.Write(uint32_t(0)); // packing
|
||||
}
|
||||
|
||||
Game::server->Send(bitStream, sysAddr, false);
|
||||
|
||||
@@ -33,10 +33,10 @@ Precondition::Precondition(const uint32_t condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->type = static_cast<PreconditionType>(result.fieldIsNull(0) ? 0 : result.getIntField(0));
|
||||
this->type = static_cast<PreconditionType>(result.fieldIsNull("type") ? 0 : result.getIntField("type"));
|
||||
|
||||
if (!result.fieldIsNull(1)) {
|
||||
std::istringstream stream(result.getStringField(1));
|
||||
if (!result.fieldIsNull("targetLOT")) {
|
||||
std::istringstream stream(result.getStringField("targetLOT"));
|
||||
std::string token;
|
||||
|
||||
while (std::getline(stream, token, ',')) {
|
||||
@@ -45,7 +45,7 @@ Precondition::Precondition(const uint32_t condition) {
|
||||
}
|
||||
}
|
||||
|
||||
this->count = result.fieldIsNull(2) ? 1 : result.getIntField(2);
|
||||
this->count = result.fieldIsNull("targetCount") ? 1 : result.getIntField("targetCount");
|
||||
|
||||
result.finalize();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,13 +7,28 @@
|
||||
#define SLASHCOMMANDHANDLER_H
|
||||
|
||||
#include "RakNetTypes.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include <string>
|
||||
|
||||
class Entity;
|
||||
|
||||
struct Command {
|
||||
std::string help;
|
||||
std::string info;
|
||||
std::vector<std::string> aliases;
|
||||
std::function<void(Entity*, const SystemAddress&,const std::string)> handle;
|
||||
eGameMasterLevel requiredLevel = eGameMasterLevel::OPERATOR;
|
||||
};
|
||||
|
||||
namespace SlashCommandHandler {
|
||||
void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr);
|
||||
void SendAnnouncement(const std::string& title, const std::string& message);
|
||||
void RegisterCommand(Command info);
|
||||
void Startup();
|
||||
};
|
||||
|
||||
namespace GMZeroCommands {
|
||||
void Help(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif // SLASHCOMMANDHANDLER_H
|
||||
|
||||
6
dGame/dUtilities/SlashCommands/CMakeLists.txt
Normal file
6
dGame/dUtilities/SlashCommands/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
set(DGAME_DUTILITIES_SLASHCOMMANDS
|
||||
"DEVGMCommands.cpp"
|
||||
"GMGreaterThanZeroCommands.cpp"
|
||||
"GMZeroCommands.cpp"
|
||||
PARENT_SCOPE
|
||||
)
|
||||
1598
dGame/dUtilities/SlashCommands/DEVGMCommands.cpp
Normal file
1598
dGame/dUtilities/SlashCommands/DEVGMCommands.cpp
Normal file
File diff suppressed because it is too large
Load Diff
78
dGame/dUtilities/SlashCommands/DEVGMCommands.h
Normal file
78
dGame/dUtilities/SlashCommands/DEVGMCommands.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef DEVGMCOMMANDS_H
|
||||
#define DEVGMCOMMANDS_H
|
||||
|
||||
namespace DEVGMCommands {
|
||||
void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ToggleNameplate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ToggleSkipCinematics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Kill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Metrics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Announce(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetAnnTitle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetAnnMsg(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ShutdownUniverse(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetMinifig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void TestMap(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ReportProxPhys(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SpawnPhysicsVerts(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Teleport(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ActivateSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void AddMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Boost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Unboost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Buff(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void BuffMe(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void BuffMed(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ClearFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void CompleteMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void CreatePrivate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void DebugUi(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Dismount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ForceSave(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Freecam(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void FreeMoney(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GetNavmeshHeight(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GiveUScore(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GmAddItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Inspect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ListSpawns(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void LocRow(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Lookup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void PlayAnimation(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void PlayEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void PlayLvlFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void PlayRebuildFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Pos(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void RefillStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Reforge(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ResetMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Rot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void RunMacro(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetControlScheme(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetCurrency(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetInventorySize(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetUiState(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Spawn(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SpawnGroup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SpeedBoost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void StartCelebration(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void StopEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Toggle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void TpAll(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void TriggerSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void UnlockEmote(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetSkillSlot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void AddFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GetFactions(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetRewardCode(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Crash(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void RollLoot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void CastSkill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif //!DEVGMCOMMANDS_H
|
||||
325
dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp
Normal file
325
dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp
Normal file
@@ -0,0 +1,325 @@
|
||||
#include "GMGreaterThanZeroCommands.h"
|
||||
|
||||
// Classes
|
||||
#include "Character.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "dServer.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "User.h"
|
||||
|
||||
// Database
|
||||
#include "Database.h"
|
||||
|
||||
// Components
|
||||
#include "DestroyableComponent.h"
|
||||
#include "PropertyManagementComponent.h"
|
||||
|
||||
// Enums
|
||||
#include "eChatMessageType.h"
|
||||
#include "eServerDisconnectIdentifiers.h"
|
||||
#include "eObjectBits.h"
|
||||
|
||||
namespace GMGreaterThanZeroCommands {
|
||||
|
||||
void Kick(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.size() == 1) {
|
||||
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
|
||||
|
||||
std::u16string username = GeneralUtils::UTF8ToUTF16(splitArgs[0]);
|
||||
if (player == nullptr) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + username);
|
||||
return;
|
||||
}
|
||||
|
||||
Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::KICK);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Kicked: " + username);
|
||||
} else {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /kick <username>");
|
||||
}
|
||||
}
|
||||
|
||||
void Ban(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
|
||||
if (splitArgs.size() == 1) {
|
||||
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
|
||||
|
||||
uint32_t accountId = 0;
|
||||
|
||||
if (player == nullptr) {
|
||||
auto characterInfo = Database::Get()->GetCharacterInfo(splitArgs[0]);
|
||||
|
||||
if (characterInfo) {
|
||||
accountId = characterInfo->accountId;
|
||||
}
|
||||
|
||||
if (accountId == 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]));
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
auto* character = player->GetCharacter();
|
||||
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
|
||||
if (user) accountId = user->GetAccountID();
|
||||
}
|
||||
|
||||
if (accountId != 0) Database::Get()->UpdateAccountBan(accountId, true);
|
||||
|
||||
if (player != nullptr) {
|
||||
Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::FREE_TRIAL_EXPIRED);
|
||||
}
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Banned: " + GeneralUtils::ASCIIToUTF16(splitArgs[0]));
|
||||
} else {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /ban <username>");
|
||||
}
|
||||
}
|
||||
|
||||
void MailItem(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.size() < 2) return;
|
||||
|
||||
const auto& playerName = splitArgs[0];
|
||||
|
||||
auto playerInfo = Database::Get()->GetCharacterInfo(playerName);
|
||||
|
||||
uint32_t receiverID = 0;
|
||||
if (!playerInfo) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Failed to find that player");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
receiverID = playerInfo->id;
|
||||
|
||||
const auto lot = GeneralUtils::TryParse<LOT>(splitArgs.at(1));
|
||||
|
||||
if (!lot) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid item lot.");
|
||||
return;
|
||||
}
|
||||
|
||||
IMail::MailInfo mailInsert;
|
||||
mailInsert.senderId = entity->GetObjectID();
|
||||
mailInsert.senderUsername = "Darkflame Universe";
|
||||
mailInsert.receiverId = receiverID;
|
||||
mailInsert.recipient = playerName;
|
||||
mailInsert.subject = "Lost item";
|
||||
mailInsert.body = "This is a replacement item for one you lost.";
|
||||
mailInsert.itemID = LWOOBJID_EMPTY;
|
||||
mailInsert.itemLOT = lot.value();
|
||||
mailInsert.itemSubkey = LWOOBJID_EMPTY;
|
||||
mailInsert.itemCount = 1;
|
||||
Database::Get()->InsertNewMail(mailInsert);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Mail sent");
|
||||
}
|
||||
|
||||
void ApproveProperty(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
if (PropertyManagementComponent::Instance() != nullptr) {
|
||||
PropertyManagementComponent::Instance()->UpdateApprovedStatus(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Mute(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
|
||||
if (splitArgs.size() >= 1) {
|
||||
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
|
||||
|
||||
uint32_t accountId = 0;
|
||||
LWOOBJID characterId = 0;
|
||||
|
||||
if (player == nullptr) {
|
||||
auto characterInfo = Database::Get()->GetCharacterInfo(splitArgs[0]);
|
||||
|
||||
if (characterInfo) {
|
||||
accountId = characterInfo->accountId;
|
||||
characterId = characterInfo->id;
|
||||
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
|
||||
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
|
||||
}
|
||||
|
||||
if (accountId == 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]));
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
auto* character = player->GetCharacter();
|
||||
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
|
||||
if (user) accountId = user->GetAccountID();
|
||||
characterId = player->GetObjectID();
|
||||
}
|
||||
|
||||
time_t expire = 1; // Default to indefinate mute
|
||||
|
||||
if (splitArgs.size() >= 2) {
|
||||
const auto days = GeneralUtils::TryParse<uint32_t>(splitArgs[1]);
|
||||
if (!days) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid days.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::optional<uint32_t> hours;
|
||||
if (splitArgs.size() >= 3) {
|
||||
hours = GeneralUtils::TryParse<uint32_t>(splitArgs[2]);
|
||||
if (!hours) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid hours.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
expire = time(NULL);
|
||||
expire += 24 * 60 * 60 * days.value();
|
||||
expire += 60 * 60 * hours.value_or(0);
|
||||
}
|
||||
|
||||
if (accountId != 0) Database::Get()->UpdateAccountUnmuteTime(accountId, expire);
|
||||
|
||||
char buffer[32] = "brought up for review.\0";
|
||||
|
||||
if (expire != 1) {
|
||||
std::tm* ptm = std::localtime(&expire);
|
||||
// Format: Mo, 15.06.2009 20:20:00
|
||||
std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", ptm);
|
||||
}
|
||||
|
||||
const auto timeStr = GeneralUtils::ASCIIToUTF16(std::string(buffer));
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Muted: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]) + u" until " + timeStr);
|
||||
|
||||
//Notify chat about it
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_MUTE);
|
||||
|
||||
bitStream.Write(characterId);
|
||||
bitStream.Write(expire);
|
||||
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
} else {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /mute <username> <days (optional)> <hours (optional)>");
|
||||
}
|
||||
}
|
||||
|
||||
void Fly(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
auto* character = entity->GetCharacter();
|
||||
|
||||
if (character) {
|
||||
bool isFlying = character->GetIsFlying();
|
||||
|
||||
if (isFlying) {
|
||||
GameMessages::SendSetJetPackMode(entity, false);
|
||||
|
||||
character->SetIsFlying(false);
|
||||
} else {
|
||||
float speedScale = 1.0f;
|
||||
|
||||
if (splitArgs.size() >= 1) {
|
||||
const auto tempScaleStore = GeneralUtils::TryParse<float>(splitArgs.at(0));
|
||||
|
||||
if (tempScaleStore) {
|
||||
speedScale = tempScaleStore.value();
|
||||
} else {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Failed to parse speed scale argument.");
|
||||
}
|
||||
}
|
||||
|
||||
float airSpeed = 20 * speedScale;
|
||||
float maxAirSpeed = 30 * speedScale;
|
||||
float verticalVelocity = 1.5 * speedScale;
|
||||
|
||||
GameMessages::SendSetJetPackMode(entity, true, true, false, 167, airSpeed, maxAirSpeed, verticalVelocity);
|
||||
|
||||
character->SetIsFlying(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AttackImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.empty()) return;
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
const auto state = GeneralUtils::TryParse<int32_t>(splitArgs[0]);
|
||||
|
||||
if (!state) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid state.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (destroyableComponent) destroyableComponent->SetIsImmune(state.value());
|
||||
}
|
||||
|
||||
void GmImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.empty()) return;
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
const auto state = GeneralUtils::TryParse<int32_t>(splitArgs[0]);
|
||||
|
||||
if (!state) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid state.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (destroyableComponent) destroyableComponent->SetIsGMImmune(state.value());
|
||||
}
|
||||
|
||||
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(args), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
std::string name = entity->GetCharacter()->GetName() + " - " + args;
|
||||
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
void ShowAll(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
bool displayZoneData = true;
|
||||
bool displayIndividualPlayers = true;
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
|
||||
if (!splitArgs.empty() && !splitArgs.at(0).empty()) displayZoneData = splitArgs.at(0) == "1";
|
||||
if (splitArgs.size() > 1) displayIndividualPlayers = splitArgs.at(1) == "1";
|
||||
|
||||
ShowAllRequest request {
|
||||
.requestor = entity->GetObjectID(),
|
||||
.displayZoneData = displayZoneData,
|
||||
.displayIndividualPlayers = displayIndividualPlayers
|
||||
};
|
||||
|
||||
CBITSTREAM;
|
||||
request.Serialize(bitStream);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
|
||||
void FindPlayer(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
if (args.empty()) {
|
||||
GameMessages::SendSlashCommandFeedbackText(entity, u"No player Given");
|
||||
return;
|
||||
}
|
||||
|
||||
FindPlayerRequest request {
|
||||
.requestor = entity->GetObjectID(),
|
||||
.playerName = LUWString(args)
|
||||
};
|
||||
|
||||
CBITSTREAM;
|
||||
request.Serialize(bitStream);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
}
|
||||
20
dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.h
Normal file
20
dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef GMGREATERTHANZEROCOMMANDS_H
|
||||
#define GMGREATERTHANZEROCOMMANDS_H
|
||||
|
||||
namespace GMGreaterThanZeroCommands {
|
||||
void Kick(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void MailItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Ban(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ApproveProperty(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Mute(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Fly(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void AttackImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GmImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ShowAll(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void FindPlayer(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif //!GMGREATERTHANZEROCOMMANDS_H
|
||||
232
dGame/dUtilities/SlashCommands/GMZeroCommands.cpp
Normal file
232
dGame/dUtilities/SlashCommands/GMZeroCommands.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
#include "GMZeroCommands.h"
|
||||
|
||||
// Classes
|
||||
#include "Amf3.h"
|
||||
#include "BinaryPathFinder.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "dServer.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Mail.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "SlashCommandHandler.h"
|
||||
#include "VanityUtilities.h"
|
||||
#include "WorldPackets.h"
|
||||
#include "ZoneInstanceManager.h"
|
||||
|
||||
// Components
|
||||
#include "BuffComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "ScriptedActivityComponent.h"
|
||||
#include "SkillComponent.h"
|
||||
|
||||
// Emuns
|
||||
#include "eGameMasterLevel.h"
|
||||
|
||||
namespace GMZeroCommands {
|
||||
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
auto* character = entity->GetComponent<CharacterComponent>();
|
||||
|
||||
if (character == nullptr) {
|
||||
LOG("Failed to find character component!");
|
||||
return;
|
||||
}
|
||||
|
||||
character->SetPvpEnabled(!character->GetPvpEnabled());
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
|
||||
std::stringstream message;
|
||||
message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!";
|
||||
|
||||
ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, GeneralUtils::UTF8ToUTF16(message.str()), true);
|
||||
}
|
||||
|
||||
void Who(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
ChatPackets::SendSystemMessage(
|
||||
sysAddr,
|
||||
u"Players in this instance: (" + GeneralUtils::to_u16string(PlayerManager::GetAllPlayers().size()) + u")"
|
||||
);
|
||||
|
||||
for (auto* player : PlayerManager::GetAllPlayers()) {
|
||||
const auto& name = player->GetCharacter()->GetName();
|
||||
|
||||
ChatPackets::SendSystemMessage(
|
||||
sysAddr,
|
||||
GeneralUtils::UTF8ToUTF16(player == entity ? name + " (you)" : name)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Ping(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
if (!args.empty() && args.starts_with("-l")) {
|
||||
std::stringstream message;
|
||||
message << "Your latest ping: " << std::to_string(Game::server->GetLatestPing(sysAddr)) << "ms";
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str()));
|
||||
} else {
|
||||
std::stringstream message;
|
||||
message << "Your average ping: " << std::to_string(Game::server->GetPing(sysAddr)) << "ms";
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str()));
|
||||
}
|
||||
}
|
||||
|
||||
void FixStats(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
// Reset skill component and buff component
|
||||
auto* skillComponent = entity->GetComponent<SkillComponent>();
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
// If any of the components are nullptr, return
|
||||
if (skillComponent == nullptr || buffComponent == nullptr || destroyableComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset skill component
|
||||
skillComponent->Reset();
|
||||
|
||||
// Reset buff component
|
||||
buffComponent->Reset();
|
||||
|
||||
// Fix the destroyable component
|
||||
destroyableComponent->FixStats();
|
||||
}
|
||||
|
||||
void Credits(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto& customText = VanityUtilities::ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/CREDITS.md").string());
|
||||
|
||||
{
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("state", "Story");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||
}
|
||||
|
||||
entity->AddCallbackTimer(0.5f, [customText, entity]() {
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("visible", true);
|
||||
args.Insert("text", customText);
|
||||
|
||||
LOG("Sending %s", customText.c_str());
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
|
||||
});
|
||||
}
|
||||
|
||||
void Info(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto& customText = VanityUtilities::ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/INFO.md").string());
|
||||
|
||||
{
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("state", "Story");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
|
||||
}
|
||||
|
||||
entity->AddCallbackTimer(0.5f, [customText, entity]() {
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("visible", true);
|
||||
args.Insert("text", customText);
|
||||
|
||||
LOG("Sending %s", customText.c_str());
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
|
||||
});
|
||||
}
|
||||
|
||||
void LeaveZone(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto currentZone = Game::zoneManager->GetZone()->GetZoneID().GetMapID();
|
||||
LWOMAPID newZone = 0;
|
||||
|
||||
if (currentZone == 1001 || currentZone % 100 == 0) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"You are not in an instanced zone.");
|
||||
return;
|
||||
} else {
|
||||
newZone = (currentZone / 100) * 100;
|
||||
}
|
||||
// If new zone would be inaccessible, then default to Avant Gardens.
|
||||
if (!Game::zoneManager->CheckIfAccessibleZone(newZone)) newZone = 1100;
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Leaving zone...");
|
||||
|
||||
const auto objid = entity->GetObjectID();
|
||||
|
||||
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, newZone, 0, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
||||
auto* entity = Game::entityManager->GetEntity(objid);
|
||||
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto sysAddr = entity->GetSystemAddress();
|
||||
|
||||
LOG("Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i", entity->GetCharacter()->GetName().c_str(), zoneID, zoneInstance, zoneClone, mythranShift == true ? "true" : "false", serverIP.c_str(), serverPort);
|
||||
|
||||
if (entity->GetCharacter()) {
|
||||
entity->GetCharacter()->SetZoneID(zoneID);
|
||||
entity->GetCharacter()->SetZoneInstance(zoneInstance);
|
||||
entity->GetCharacter()->SetZoneClone(zoneClone);
|
||||
}
|
||||
|
||||
entity->GetCharacter()->SaveXMLToDatabase();
|
||||
|
||||
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
||||
});
|
||||
}
|
||||
|
||||
void Join(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.empty()) return;
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Requesting private map...");
|
||||
const auto& password = splitArgs[0];
|
||||
|
||||
ZoneInstanceManager::Instance()->RequestPrivateZone(Game::server, false, password, [=](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
||||
LOG("Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i", sysAddr.ToString(), zoneID, zoneInstance, zoneClone, mythranShift == true ? "true" : "false", serverIP.c_str(), serverPort);
|
||||
|
||||
if (entity->GetCharacter()) {
|
||||
entity->GetCharacter()->SetZoneID(zoneID);
|
||||
entity->GetCharacter()->SetZoneInstance(zoneInstance);
|
||||
entity->GetCharacter()->SetZoneClone(zoneClone);
|
||||
}
|
||||
|
||||
entity->GetCharacter()->SaveXMLToDatabase();
|
||||
|
||||
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
||||
});
|
||||
}
|
||||
|
||||
void Die(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
entity->Smash(entity->GetObjectID());
|
||||
}
|
||||
|
||||
void Resurrect(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
ScriptedActivityComponent* scriptedActivityComponent = Game::zoneManager->GetZoneControlObject()->GetComponent<ScriptedActivityComponent>();
|
||||
|
||||
if (scriptedActivityComponent) { // check if user is in activity world and if so, they can't resurrect
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"You cannot resurrect in an activity world.");
|
||||
return;
|
||||
}
|
||||
|
||||
GameMessages::SendResurrect(entity);
|
||||
}
|
||||
|
||||
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
Mail::HandleNotificationRequest(entity->GetSystemAddress(), entity->GetObjectID());
|
||||
}
|
||||
|
||||
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto zoneId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Map: " + (GeneralUtils::to_u16string(zoneId.GetMapID())) + u"\nClone: " + (GeneralUtils::to_u16string(zoneId.GetCloneID())) + u"\nInstance: " + (GeneralUtils::to_u16string(zoneId.GetInstanceID())));
|
||||
}
|
||||
|
||||
//For client side commands
|
||||
void ClientHandled(Entity* entity, const SystemAddress& sysAddr, const std::string args) {}
|
||||
|
||||
};
|
||||
|
||||
21
dGame/dUtilities/SlashCommands/GMZeroCommands.h
Normal file
21
dGame/dUtilities/SlashCommands/GMZeroCommands.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GMZEROCOMMANDS_H
|
||||
#define GMZEROCOMMANDS_H
|
||||
|
||||
namespace GMZeroCommands {
|
||||
void Help(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Credits(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Info(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Die(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Ping(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Who(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void FixStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Join(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void LeaveZone(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Resurrect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void ClientHandled(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif //!GMZEROCOMMANDS_H
|
||||
@@ -112,6 +112,31 @@ void dNavMesh::LoadNavmesh() {
|
||||
m_NavMesh = mesh;
|
||||
}
|
||||
|
||||
NiPoint3 dNavMesh::NearestPoint(const NiPoint3& location, const float halfExtent) const {
|
||||
NiPoint3 toReturn = location;
|
||||
if (m_NavMesh != nullptr) {
|
||||
float pos[3];
|
||||
pos[0] = location.x;
|
||||
pos[1] = location.y;
|
||||
pos[2] = location.z;
|
||||
|
||||
dtPolyRef nearestRef = 0;
|
||||
float polyPickExt[3] = { halfExtent, halfExtent, halfExtent };
|
||||
float nearestPoint[3] = { 0.0f, 0.0f, 0.0f };
|
||||
dtQueryFilter filter{};
|
||||
|
||||
auto hasPoly = m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, nearestPoint);
|
||||
if (hasPoly != DT_SUCCESS) {
|
||||
toReturn = location;
|
||||
} else {
|
||||
toReturn.x = nearestPoint[0];
|
||||
toReturn.y = nearestPoint[1];
|
||||
toReturn.z = nearestPoint[2];
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
float dNavMesh::GetHeightAtPoint(const NiPoint3& location, const float halfExtentsHeight) const {
|
||||
if (m_NavMesh == nullptr) {
|
||||
return location.y;
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
/**
|
||||
* Get the height at a point
|
||||
*
|
||||
*
|
||||
* @param location The location to check for height at. This is the center of the search area.
|
||||
* @param halfExtentsHeight The half extents height of the search area. This is the distance from the center to the top and bottom of the search area.
|
||||
* The larger the value of halfExtentsHeight is, the larger the performance cost of the query.
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
*/
|
||||
float GetHeightAtPoint(const NiPoint3& location, const float halfExtentsHeight = 32.0f) const;
|
||||
std::vector<NiPoint3> GetPath(const NiPoint3& startPos, const NiPoint3& endPos, float speed = 10.0f);
|
||||
|
||||
NiPoint3 NearestPoint(const NiPoint3& location, const float halfExtent = 32.0f) const;
|
||||
bool IsNavmeshLoaded() { return m_NavMesh != nullptr; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -82,7 +82,7 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c
|
||||
if (serverType == ServerType::Auth) bitStream.Write(ServiceId::Auth);
|
||||
else if (serverType == ServerType::World) bitStream.Write(ServiceId::World);
|
||||
else bitStream.Write(ServiceId::General);
|
||||
bitStream.Write<uint64_t>(215523405360);
|
||||
bitStream.Write<uint64_t>(215523470896);
|
||||
|
||||
server->Send(bitStream, sysAddr, false);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,30 @@
|
||||
#include "eConnectionType.h"
|
||||
#include "eChatMessageType.h"
|
||||
|
||||
void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::SHOW_ALL);
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->displayZoneData);
|
||||
bitStream.Write(this->displayIndividualPlayers);
|
||||
}
|
||||
|
||||
void ShowAllRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
inStream.Read(this->requestor);
|
||||
inStream.Read(this->displayZoneData);
|
||||
inStream.Read(this->displayIndividualPlayers);
|
||||
}
|
||||
|
||||
void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::WHO);
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->playerName);
|
||||
}
|
||||
|
||||
void FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
inStream.Read(this->requestor);
|
||||
inStream.Read(this->playerName);
|
||||
}
|
||||
|
||||
void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
@@ -11,6 +11,21 @@ struct SystemAddress;
|
||||
#include <string>
|
||||
#include "dCommonVars.h"
|
||||
|
||||
struct ShowAllRequest{
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
bool displayZoneData = true;
|
||||
bool displayIndividualPlayers = true;
|
||||
void Serialize(RakNet::BitStream& bitStream);
|
||||
void Deserialize(RakNet::BitStream& inStream);
|
||||
};
|
||||
|
||||
struct FindPlayerRequest{
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
LUWString playerName;
|
||||
void Serialize(RakNet::BitStream& bitStream);
|
||||
void Deserialize(RakNet::BitStream& inStream);
|
||||
};
|
||||
|
||||
namespace ChatPackets {
|
||||
void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message);
|
||||
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void HTTPMonitorInfo::Serialize(RakNet::BitStream &bitStream) const {
|
||||
bitStream.Write(port);
|
||||
bitStream.Write<uint8_t>(openWeb);
|
||||
bitStream.Write<uint8_t>(supportsSum);
|
||||
bitStream.Write<uint8_t>(supportsDetail);
|
||||
bitStream.Write<uint8_t>(supportsWho);
|
||||
bitStream.Write<uint8_t>(supportsObjects);
|
||||
}
|
||||
|
||||
void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone) {
|
||||
RakNet::BitStream bitStream;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::LOAD_STATIC_ZONE);
|
||||
@@ -160,3 +169,18 @@ void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success,
|
||||
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::HTTP_MONITOR_INFO_RESPONSE);
|
||||
info.Serialize(bitStream);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void WorldPackets::SendDebugOuput(const SystemAddress& sysAddr, const std::string& data){
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::DEBUG_OUTPUT);
|
||||
bitStream.Write<uint32_t>(data.size());
|
||||
bitStream.Write(data);
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,19 @@ struct SystemAddress;
|
||||
enum class eGameMasterLevel : uint8_t;
|
||||
enum class eCharacterCreationResponse : uint8_t;
|
||||
enum class eRenameResponse : uint8_t;
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
struct HTTPMonitorInfo {
|
||||
uint16_t port = 80;
|
||||
bool openWeb = false;
|
||||
bool supportsSum = false;
|
||||
bool supportsDetail = false;
|
||||
bool supportsWho = false;
|
||||
bool supportsObjects = false;
|
||||
void Serialize(RakNet::BitStream &bitstream) const;
|
||||
};
|
||||
|
||||
namespace WorldPackets {
|
||||
void SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone);
|
||||
@@ -21,6 +34,8 @@ namespace WorldPackets {
|
||||
void SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems);
|
||||
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel);
|
||||
void SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info);
|
||||
void SendDebugOuput(const SystemAddress& sysAddr, const std::string& data);
|
||||
}
|
||||
|
||||
#endif // WORLDPACKETS_H
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_MAP_FV_RACING
|
||||
"RaceFireballs.cpp"
|
||||
"RaceMaelstromGeiser.cpp"
|
||||
"RaceShipLapColumnsServer.cpp"
|
||||
"FvRacingColumns.cpp"
|
||||
PARENT_SCOPE)
|
||||
|
||||
15
dScripts/02_server/Map/FV/Racing/FvRacingColumns.cpp
Normal file
15
dScripts/02_server/Map/FV/Racing/FvRacingColumns.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "FvRacingColumns.h"
|
||||
#include "MovingPlatformComponent.h"
|
||||
|
||||
void FvRacingColumns::OnStartup(Entity* self) {
|
||||
auto* movingPlatformComponent = self->GetComponent<MovingPlatformComponent>();
|
||||
if (!movingPlatformComponent) return;
|
||||
|
||||
movingPlatformComponent->StopPathing();
|
||||
movingPlatformComponent->SetSerialized(true);
|
||||
int32_t pathStart = 0;
|
||||
if (self->HasVar(u"attached_path_start")) {
|
||||
pathStart = self->GetVar<uint32_t>(u"attached_path_start");
|
||||
}
|
||||
movingPlatformComponent->WarpToWaypoint(pathStart);
|
||||
}
|
||||
6
dScripts/02_server/Map/FV/Racing/FvRacingColumns.h
Normal file
6
dScripts/02_server/Map/FV/Racing/FvRacingColumns.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "CppScripts.h"
|
||||
|
||||
class FvRacingColumns : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
};
|
||||
15
dScripts/02_server/Map/FV/Racing/RaceFireballs.cpp
Normal file
15
dScripts/02_server/Map/FV/Racing/RaceFireballs.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "RaceFireballs.h"
|
||||
#include "SkillComponent.h"
|
||||
|
||||
void RaceFireballs::OnStartup(Entity* self) {
|
||||
self->AddTimer("fire", GeneralUtils::GenerateRandomNumber<float>(3.0f, 10.0f));
|
||||
}
|
||||
|
||||
void RaceFireballs::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "fire") {
|
||||
auto* skillComponent = self->GetComponent<SkillComponent>();
|
||||
if (skillComponent) skillComponent->CastSkill(894);
|
||||
self->AddTimer("fire", GeneralUtils::GenerateRandomNumber<float>(3.0f, 10.0f));
|
||||
|
||||
}
|
||||
}
|
||||
9
dScripts/02_server/Map/FV/Racing/RaceFireballs.h
Normal file
9
dScripts/02_server/Map/FV/Racing/RaceFireballs.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class RaceFireballs : public CppScripts::Script
|
||||
{
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "RaceShipLapColumnsServer.h"
|
||||
|
||||
#include "RacingControlComponent.h"
|
||||
#include "MovingPlatformComponent.h"
|
||||
|
||||
void RaceShipLapColumnsServer::OnStartup(Entity* self) {
|
||||
self->SetVar(u"Lap2Complete", false);
|
||||
self->SetVar(u"Lap3Complete", false);
|
||||
}
|
||||
|
||||
void SetMovingToWaypoint(const int32_t waypointIndex, const std::string group) {
|
||||
const auto entities = Game::entityManager->GetEntitiesInGroup(group);
|
||||
if (entities.empty()) return;
|
||||
|
||||
auto* entity = entities[0];
|
||||
entity->SetIsGhostingCandidate(false);
|
||||
|
||||
auto* movingPlatfromComponent = entity->GetComponent<MovingPlatformComponent>();
|
||||
if (!movingPlatfromComponent) return;
|
||||
|
||||
movingPlatfromComponent->SetSerialized(true);
|
||||
movingPlatfromComponent->GotoWaypoint(waypointIndex);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
void RaceShipLapColumnsServer::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
if (!target) return;
|
||||
|
||||
const auto racingControllers = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::RACING_CONTROL);
|
||||
if (racingControllers.empty()) return;
|
||||
|
||||
auto* racingControlComponent = racingControllers[0]->GetComponent<RacingControlComponent>();
|
||||
if (!racingControlComponent) return;
|
||||
|
||||
const auto* player = racingControlComponent->GetPlayerData(target->GetObjectID());
|
||||
if (!player) return;
|
||||
|
||||
if (player->lap == 1 && !self->GetVar<bool>(u"Lap2Complete")) {
|
||||
self->SetVar(u"Lap2Complete", true);
|
||||
SetMovingToWaypoint(1, "Lap2Column");
|
||||
SetMovingToWaypoint(0, "Lap2Ramp");
|
||||
} else if (player->lap == 2 && !self->GetVar<bool>(u"Lap3Complete")) {
|
||||
self->SetVar(u"Lap3Complete", true);
|
||||
SetMovingToWaypoint(1, "Lap3Column");
|
||||
SetMovingToWaypoint(0, "Lap3Ramp");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class RaceShipLapColumnsServer : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
};
|
||||
@@ -17,7 +17,9 @@ void TokenConsoleServer::OnUse(Entity* self, Entity* user) {
|
||||
inv->RemoveItem(6194, bricksToTake);
|
||||
|
||||
//play sound
|
||||
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), "947d0d52-c7f8-4516-8dee-e1593a7fd1d1");
|
||||
if (self->HasVar(u"sound1")) {
|
||||
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), self->GetVarAsString(u"sound1"));
|
||||
}
|
||||
|
||||
//figure out which faction the player belongs to:
|
||||
auto character = user->GetCharacter();
|
||||
|
||||
@@ -39,7 +39,7 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) {
|
||||
const auto useSound = self->GetVar<std::string>(u"sound1");
|
||||
|
||||
if (!useSound.empty()) {
|
||||
GameMessages::SendPlayNDAudioEmitter(self, UNASSIGNED_SYSTEM_ADDRESS, useSound);
|
||||
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), useSound);
|
||||
}
|
||||
|
||||
// Player must be in faction to interact with this entity.
|
||||
|
||||
@@ -56,10 +56,6 @@ void AgSurvivalBuffStation::OnTimerDone(Entity* self, std::string timerName) {
|
||||
auto member = Game::entityManager->GetEntity(memberID);
|
||||
if (member != nullptr && !member->GetIsDead()) {
|
||||
GameMessages::SendDropClientLoot(member, self->GetObjectID(), powerupToDrop, 0, self->GetPosition());
|
||||
} else {
|
||||
// If player left the team or left early erase them from the team variable.
|
||||
team.erase(std::find(team.begin(), team.end(), memberID));
|
||||
self->SetVar<std::vector<LWOOBJID>>(u"BuilderTeam", team);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user