Compare commits

..

23 Commits

Author SHA1 Message Date
9a76ceae66 Update macOS version in CI workflow 2025-12-16 14:32:20 -06:00
e342bb7d35 Remove Xcode version switch from build workflow
Removed the command to switch Xcode version in macOS workflow.
2025-12-16 13:55:44 -06:00
e5c0c68b80 Update macOS condition for XCode installation step 2025-12-16 13:53:41 -06:00
18162837ea fix: Update macOS version to latest in workflow 2025-12-16 13:50:10 -06:00
David Markowitz
40fef36530 fix: coins dropping on killer (#1948)
tested that when a player dies the coins spawn on their body instead
2025-12-13 22:00:58 -08:00
David Markowitz
bf020baa17 fix: temp fixes for ghosting so I can continue being on break (#1947)
* fix: temp fixes for ghosting so I can continue being on break

disables the ghost feature for now so i can continue my break

* Update GhostComponent.cpp
2025-12-08 20:39:33 -08:00
David Markowitz
a713216540 fix: saving gm invis for non gms (#1940) 2025-11-18 22:04:07 -06:00
David Markowitz
ea86a708e4 fix: uninitialized memory (#1937) 2025-11-18 19:06:03 -08:00
David Markowitz
ca7424cbeb fix: chest loot not working (#1933)
* fix bons and dragon loot

* fix chest server loot
2025-11-16 16:17:49 -06:00
David Markowitz
991e55f305 feat: dont drop loot for dead players if configured in the zone activity settings (#1935)
* feat: dont drop loot for dead players if configured in the zone activity settings

* fix errors

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dGame/dComponents/ActivityComponent.h

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dGame/dUtilities/Loot.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 16:17:26 -06:00
David Markowitz
5410acffaa fix: chat server crash (#1931)
* fix: chat server crash

* Update dChatServer/ChatServer.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 13:48:57 -08:00
David Markowitz
86f8601bbd feat: various debug command improvements (#1934)
* feat: various debug command improvements

* add missing utility function

* Update dGame/dUtilities/SlashCommands/DEVGMCommands.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-16 13:48:16 -08:00
David Markowitz
4658318a3a fix: deactivate bubble buff from server too (#1936) 2025-11-16 13:46:59 -08:00
11d44ffb98 feat: proper gminvs with ghosting (#1920)
* feat: proper gminvis ghosting

* address feedback

---------

Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com>
2025-11-15 16:43:33 -08:00
David Markowitz
2fb16420f3 fix: ape anchor not respawning (#1927)
* fix: ape anchor not respawning

* add return

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-15 13:30:02 -08:00
David Markowitz
96089a8d9a fix: fb race activityid (#1929) 2025-11-15 13:29:11 -08:00
David Markowitz
eac50acfcc fix: correct mission tracking (#1930)
checked that live captures did not track achievements in this count
2025-11-15 13:29:03 -08:00
David Markowitz
ca60787055 fix: ffa -> shared loot for activities (#1925) 2025-10-26 01:01:21 -07:00
David Markowitz
396dcb0465 feat: add logger feature to log on function entry and exit (#1924)
* feat: add logger feature to log on function entry and exit

* i didnt save the file
2025-10-25 14:53:49 -05:00
David Markowitz
6e545eb1b9 Update Loot.cpp (#1923) 2025-10-24 21:53:00 -07:00
David Markowitz
46aac016fd fix: unintended stopping (#1922) 2025-10-23 23:41:16 -05:00
David Markowitz
83823fa64f fix: resurrect not available for non-gms (#1919) 2025-10-20 23:05:22 -07:00
David Markowitz
0dd504c803 feat: behavior states (#1918) 2025-10-20 01:16:36 -05:00
47 changed files with 470 additions and 512 deletions

View File

@@ -13,7 +13,7 @@ jobs:
continue-on-error: true
strategy:
matrix:
os: [ windows-2022, ubuntu-22.04, macos-13 ]
os: [ windows-2022, ubuntu-22.04, macos-14 ]
steps:
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
@@ -26,10 +26,9 @@ jobs:
vs-version: '[17,18)'
msbuild-architecture: x64
- name: Install libssl and switch to XCode 15.2 (Mac Only)
if: ${{ matrix.os == 'macos-13' }}
if: ${{ matrix.os == 'macos-14' }}
run: |
brew install openssl@3
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer
- name: Get CMake 3.x
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c
with:

View File

@@ -202,8 +202,11 @@ int main(int argc, char** argv) {
//Delete our objects here:
Database::Destroy("ChatServer");
delete Game::server;
Game::server = nullptr;
delete Game::logger;
Game::logger = nullptr;
delete Game::config;
Game::config = nullptr;
return EXIT_SUCCESS;
}

View File

@@ -477,7 +477,7 @@ TeamData* TeamContainer::CreateLocalTeam(std::vector<LWOOBJID> members) {
}
}
newTeam->lootFlag = 1;
newTeam->lootFlag = 0;
TeamStatusUpdate(newTeam);

View File

@@ -96,3 +96,17 @@ bool Logger::GetLogToConsole() const {
}
return toReturn;
}
FuncEntry::FuncEntry(const char* funcName, const char* fileName, const uint32_t line) {
m_FuncName = funcName;
if (!m_FuncName) m_FuncName = "Unknown";
m_Line = line;
m_FileName = fileName;
LOG("--> %s::%s:%i", m_FileName, m_FuncName, m_Line);
}
FuncEntry::~FuncEntry() {
if (!m_FuncName || !m_FileName) return;
LOG("<-- %s::%s:%i", m_FileName, m_FuncName, m_Line);
}

View File

@@ -32,6 +32,19 @@ constexpr const char* GetFileNameFromAbsolutePath(const char* path) {
#define LOG(message, ...) do { auto str_ = FILENAME_AND_LINE; Game::logger->Log(str_, message, ##__VA_ARGS__); } while(0)
#define LOG_DEBUG(message, ...) do { auto str_ = FILENAME_AND_LINE; Game::logger->LogDebug(str_, message, ##__VA_ARGS__); } while(0)
// Place this right at the start of a function. Will log a message when called and then once you leave the function.
#define LOG_ENTRY auto str_ = GetFileNameFromAbsolutePath(__FILE__); FuncEntry funcEntry_(__FUNCTION__, str_, __LINE__)
class FuncEntry {
public:
FuncEntry(const char* funcName, const char* fileName, const uint32_t line);
~FuncEntry();
private:
const char* m_FuncName = nullptr;
const char* m_FileName = nullptr;
uint32_t m_Line = 0;
};
// Writer class for writing data to files.
class Writer {
public:

View File

@@ -11,65 +11,6 @@ Vector3 QuatUtils::Euler(const NiQuaternion& quat) {
return glm::eulerAngles(quat);
}
NiQuaternion NiQuaternion::operator*(const float scalar) const noexcept {
return NiQuaternion(this->w * scalar, this->x * scalar, this->y * scalar, this->z * scalar);
}
NiQuaternion& NiQuaternion::operator*=(const NiQuaternion& q) {
auto& [ow, ox, oy, oz] = q;
auto [cw, cx, cy, cz] = *this; // Current rotation copied because otherwise it screws up the math
this->w = cw * ow - cx * ox - cy * oy - cz * oz;
this->x = cw * ox + cx * ow + cy * oz - cz * oy;
this->y = cw * oy + cy * ow + cz * ox - cx * oz;
this->z = cw * oz + cz * ow + cx * oy - cy * ox;
return *this;
}
NiQuaternion NiQuaternion::operator* (const NiQuaternion& q) const {
auto& [ow, ox, oy, oz] = q;
return NiQuaternion
(
/* w */w * ow - x * ox - y * oy - z * oz,
/* x */w * ox + x * ow + y * oz - z * oy,
/* y */w * oy + y * ow + z * ox - x * oz,
/* z */w * oz + z * ow + x * oy - y * ox
);
}
NiQuaternion NiQuaternion::operator/(const float& q) const noexcept {
return NiQuaternion(this->w / q, this->x / q, this->y / q, this->z / q);
}
void NiQuaternion::Normalize() {
float length = Dot(*this);
float invLength = 1.0f / std::sqrt(length);
*this = *this * invLength;
}
float NiQuaternion::Dot(const NiQuaternion& q) const noexcept {
return (this->w * q.w) + (this->x * q.x) + (this->y * q.y) + (this->z * q.z);
}
void NiQuaternion::Inverse() noexcept {
NiQuaternion copy = *this;
copy.Conjugate();
const float inv = 1.0f / Dot(*this);
*this = copy / inv;
}
void NiQuaternion::Conjugate() noexcept {
x = -x;
y = -y;
z = -z;
}
NiQuaternion NiQuaternion::Diff(const NiQuaternion& q) const noexcept {
NiQuaternion inv = *this;
inv.Inverse();
return inv * q;
}
// MARK: Helper Functions
//! Look from a specific point in space to another point in space (Y-locked)

View File

@@ -59,7 +59,7 @@ constexpr LWOINSTANCEID LWOINSTANCEID_INVALID = -1; //!< Invalid LWOINSTANCEID
constexpr LWOMAPID LWOMAPID_INVALID = -1; //!< Invalid LWOMAPID
constexpr uint64_t LWOZONEID_INVALID = 0; //!< Invalid LWOZONEID
constexpr float PI = 3.14159265358979323846264338327950288f;
constexpr float PI = 3.14159f;
//============ STRUCTS ==============

View File

@@ -1,23 +0,0 @@
// Darkflame Universe
// Copyright 2025
#ifndef DMATH_H
#define DMATH_H
#include <cmath>
namespace Math {
constexpr float PI = 3.14159265358979323846264338327950288f;
constexpr float RATIO_DEG_TO_RAD = PI / 180.0f;
constexpr float RATIO_RAD_TO_DEG = 180.0f / PI;
inline float DegToRad(float degrees) {
return degrees * RATIO_DEG_TO_RAD;
}
inline float RadToDeg(float radians) {
return radians * RATIO_RAD_TO_DEG;
}
};
#endif //!DMATH_H

View File

@@ -1,6 +1,5 @@
#include "CDActivitiesTable.h"
void CDActivitiesTable::LoadValuesFromDatabase() {
// First, get the size of the table
uint32_t size = 0;
@@ -56,3 +55,13 @@ std::vector<CDActivities> CDActivitiesTable::Query(std::function<bool(CDActiviti
return data;
}
std::optional<const CDActivities> CDActivitiesTable::GetActivity(const uint32_t activityID) {
auto& entries = GetEntries();
for (const auto& entry : entries) {
if (entry.ActivityID == activityID) {
return entry;
}
}
return std::nullopt;
}

View File

@@ -2,6 +2,7 @@
// Custom Classes
#include "CDTable.h"
#include <optional>
struct CDActivities {
uint32_t ActivityID;
@@ -31,4 +32,5 @@ public:
// Queries the table with a custom "where" clause
std::vector<CDActivities> Query(std::function<bool(CDActivities)> predicate);
std::optional<const CDActivities> GetActivity(const uint32_t activityID);
};

View File

@@ -189,6 +189,10 @@ Entity::~Entity() {
}
if (m_ParentEntity) {
GameMessages::ChildRemoved removedMsg{};
removedMsg.childID = m_ObjectID;
removedMsg.target = m_ParentEntity->GetObjectID();
removedMsg.Send();
m_ParentEntity->RemoveChild(this);
}
}
@@ -198,6 +202,7 @@ void Entity::Initialize() {
RegisterMsg<GameMessages::DropClientLoot>(this, &Entity::MsgDropClientLoot);
RegisterMsg<GameMessages::GetFactionTokenType>(this, &Entity::MsgGetFactionTokenType);
RegisterMsg<GameMessages::PickupItem>(this, &Entity::MsgPickupItem);
RegisterMsg<GameMessages::ChildRemoved>(this, &Entity::MsgChildRemoved);
/**
* Setup trigger
*/
@@ -499,7 +504,7 @@ void Entity::Initialize() {
auto& systemAddress = m_Character->GetParentUser() ? m_Character->GetParentUser()->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS;
AddComponent<CharacterComponent>(characterID, m_Character, systemAddress)->LoadFromXml(m_Character->GetXMLDoc());
AddComponent<GhostComponent>(characterID);
AddComponent<GhostComponent>(characterID)->LoadFromXml(m_Character->GetXMLDoc());
}
const auto inventoryID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY);
@@ -2352,3 +2357,8 @@ bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) {
return true;
}
bool Entity::MsgChildRemoved(GameMessages::GameMsg& msg) {
GetScript()->OnChildRemoved(*this, static_cast<GameMessages::ChildRemoved&>(msg));
return true;
}

View File

@@ -180,6 +180,7 @@ public:
bool MsgGetFlag(GameMessages::GameMsg& msg);
bool MsgGetFactionTokenType(GameMessages::GameMsg& msg);
bool MsgPickupItem(GameMessages::GameMsg& msg);
bool MsgChildRemoved(GameMessages::GameMsg& msg);
// This is expceted to never return nullptr, an assert checks this.
CppScripts::Script* const GetScript() const;

View File

@@ -361,16 +361,24 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
LOG("Attempted to construct null entity");
return;
}
// Don't construct GM invisible entities unless it's for the GM themselves
// GMs can see other GMs if they are the same or lower level
GameMessages::GetGMInvis getGMInvisMsg;
getGMInvisMsg.Send(entity->GetObjectID());
if (getGMInvisMsg.bGMInvis && sysAddr != entity->GetSystemAddress()) {
auto* toUser = UserManager::Instance()->GetUser(sysAddr);
if (!toUser) return;
auto* constructedUser = UserManager::Instance()->GetUser(entity->GetSystemAddress());
if (!constructedUser) return;
if (toUser->GetMaxGMLevel() < constructedUser->GetMaxGMLevel()) return;
}
if (entity->GetNetworkId() == 0) {
uint16_t networkId;
if (!m_LostNetworkIds.empty()) {
networkId = m_LostNetworkIds.top();
m_LostNetworkIds.pop();
} else {
networkId = ++m_NetworkIdCounter;
}
} else networkId = ++m_NetworkIdCounter;
entity->SetNetworkId(networkId);
}
@@ -379,10 +387,8 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
if (std::find(m_EntitiesToGhost.begin(), m_EntitiesToGhost.end(), entity) == m_EntitiesToGhost.end()) {
m_EntitiesToGhost.push_back(entity);
}
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
CheckGhosting(entity);
return;
}
}
@@ -413,14 +419,9 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
Game::server->Send(stream, sysAddr, false);
}
if (entity->IsPlayer()) {
if (entity->GetGMLevel() > eGameMasterLevel::CIVILIAN) {
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, sysAddr);
}
}
}
void EntityManager::ConstructAllEntities(const SystemAddress& sysAddr) {
void EntityManager::ConstructAllEntities(const SystemAddress& sysAddr) {
//ZoneControl is special:
ConstructEntity(m_ZoneControlEntity, sysAddr);
@@ -488,11 +489,7 @@ void EntityManager::QueueGhostUpdate(LWOOBJID playerID) {
void EntityManager::UpdateGhosting() {
for (const auto playerID : m_PlayersToUpdateGhosting) {
auto* player = PlayerManager::GetPlayer(playerID);
if (player == nullptr) {
continue;
}
if (!player) continue;
UpdateGhosting(player);
}
@@ -519,6 +516,7 @@ void EntityManager::UpdateGhosting(Entity* player) {
const auto distance = NiPoint3::DistanceSquared(referencePoint, entityPoint);
auto ghostingDistanceMax = m_GhostDistanceMaxSquared;
auto ghostingDistanceMin = m_GhostDistanceMinSqaured;
@@ -555,35 +553,25 @@ void EntityManager::UpdateGhosting(Entity* player) {
}
void EntityManager::CheckGhosting(Entity* entity) {
if (entity == nullptr) {
return;
}
if (!entity) return;
const auto& referencePoint = entity->GetPosition();
for (auto* player : PlayerManager::GetAllPlayers()) {
auto* ghostComponent = player->GetComponent<GhostComponent>();
if (!ghostComponent) continue;
const auto& entityPoint = ghostComponent->GetGhostReferencePoint();
const auto id = entity->GetObjectID();
const auto observed = ghostComponent->IsObserved(id);
const auto distance = NiPoint3::DistanceSquared(referencePoint, entityPoint);
if (observed && distance > m_GhostDistanceMaxSquared) {
ghostComponent->GhostEntity(id);
DestructEntity(entity, player->GetSystemAddress());
entity->SetObservers(entity->GetObservers() - 1);
} else if (!observed && m_GhostDistanceMinSqaured > distance) {
ghostComponent->ObserveEntity(id);
ConstructEntity(entity, player->GetSystemAddress());
entity->SetObservers(entity->GetObservers() + 1);
}
}

View File

@@ -31,7 +31,7 @@ public:
std::string& GetSessionKey() { return m_SessionKey; }
SystemAddress& GetSystemAddress() { return m_SystemAddress; }
eGameMasterLevel GetMaxGMLevel() { return m_MaxGMLevel; }
eGameMasterLevel GetMaxGMLevel() const { return m_MaxGMLevel; }
uint32_t GetLastCharID() { return m_LastCharID; }
void SetLastCharID(uint32_t newCharID) { m_LastCharID = newCharID; }

View File

@@ -10,7 +10,9 @@ void AndBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream,
}
void AndBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, const BehaviorBranchContext branch) {
LOG_ENTRY;
for (auto* behavior : this->m_behaviors) {
LOG("%i calculating %i", m_behaviorId, behavior->GetBehaviorID());
behavior->Calculate(context, bitStream, branch);
}
}

View File

@@ -95,4 +95,6 @@ public:
Behavior& operator=(const Behavior& other) = default;
Behavior& operator=(Behavior&& other) = default;
uint32_t GetBehaviorID() const { return m_behaviorId; }
};

View File

@@ -215,6 +215,10 @@ public:
*/
int GetActivityID() { return m_ActivityInfo.ActivityID; }
// Whether or not team loot should be dropped on death for this activity
// if true, and a player is supposed to get loot, they are skipped
bool GetNoTeamLootOnDeath() const { return m_ActivityInfo.noTeamLootOnDeath; }
/**
* Returns if this activity has a lobby, e.g. if it needs to instance players to some other map
* @return true if this activity has a lobby, false otherwise

View File

@@ -515,12 +515,12 @@ void CharacterComponent::RocketUnEquip(Entity* player) {
}
void CharacterComponent::TrackMissionCompletion(bool isAchievement) {
UpdatePlayerStatistic(MissionsCompleted);
// Achievements are tracked separately for the zone
if (isAchievement) {
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
GetZoneStatisticsForMap(mapID).m_AchievementsCollected++;
} else {
UpdatePlayerStatistic(MissionsCompleted);
}
}

View File

@@ -88,6 +88,7 @@ DestroyableComponent::DestroyableComponent(Entity* parent, const int32_t compone
RegisterMsg<GetObjectReportInfo>(this, &DestroyableComponent::OnGetObjectReportInfo);
RegisterMsg<GameMessages::SetFaction>(this, &DestroyableComponent::OnSetFaction);
RegisterMsg<GameMessages::IsDead>(this, &DestroyableComponent::OnIsDead);
}
DestroyableComponent::~DestroyableComponent() {
@@ -754,7 +755,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
const auto isPlayer = m_Parent->IsPlayer();
GameMessages::SendDie(m_Parent, source, source, true, killType, deathType, 0, 0, 0, isPlayer, false, 1);
GameMessages::SendDie(m_Parent, source, source, true, killType, deathType, 0, 0, 0, isPlayer, true, 1);
//NANI?!
if (!isPlayer) {
@@ -784,8 +785,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
lootMsg.sourceID = source;
lootMsg.item = LOT_NULL;
lootMsg.Send();
lootMsg.Send(m_Parent->GetSystemAddress());
character->SetCoins(coinsTotal, eLootSourceType::PICKUP);
character->SetCoins(coinsTotal, eLootSourceType::DELETION);
}
}
@@ -1191,3 +1191,9 @@ bool DestroyableComponent::OnSetFaction(GameMessages::GameMsg& msg) {
SetFaction(modifyFaction.factionID, modifyFaction.bIgnoreChecks);
return true;
}
bool DestroyableComponent::OnIsDead(GameMessages::GameMsg& msg) {
auto& isDeadMsg = static_cast<GameMessages::IsDead&>(msg);
isDeadMsg.bDead = m_IsDead || (GetHealth() == 0 && GetArmor() == 0);
return true;
}

View File

@@ -472,6 +472,7 @@ public:
bool OnGetObjectReportInfo(GameMessages::GameMsg& msg);
bool OnSetFaction(GameMessages::GameMsg& msg);
bool OnIsDead(GameMessages::GameMsg& msg);
void SetIsDead(const bool value) { m_IsDead = value; }

View File

@@ -1,4 +1,9 @@
#include "GhostComponent.h"
#include "PlayerManager.h"
#include "Character.h"
#include "ControllablePhysicsComponent.h"
#include "UserManager.h"
#include "User.h"
#include "Amf3.h"
#include "GameMessages.h"
@@ -8,6 +13,8 @@ GhostComponent::GhostComponent(Entity* parent, const int32_t componentID) : Comp
m_GhostOverridePoint = NiPoint3Constant::ZERO;
m_GhostOverride = false;
RegisterMsg<GameMessages::ToggleGMInvis>(this, &GhostComponent::OnToggleGMInvis);
RegisterMsg<GameMessages::GetGMInvis>(this, &GhostComponent::OnGetGMInvis);
RegisterMsg<GameMessages::GetObjectReportInfo>(this, &GhostComponent::MsgGetObjectReportInfo);
}
@@ -22,6 +29,26 @@ GhostComponent::~GhostComponent() {
}
}
void GhostComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* objElement = doc.FirstChildElement("obj");
if (!objElement) return;
auto* ghstElement = objElement->FirstChildElement("ghst");
if (!ghstElement) return;
m_IsGMInvisible = ghstElement->BoolAttribute("i");
}
void GhostComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
auto* objElement = doc.FirstChildElement("obj");
if (!objElement) return;
auto* ghstElement = objElement->FirstChildElement("ghst");
if (ghstElement) objElement->DeleteChild(ghstElement);
// Only save if GM invisible
const auto* const user = UserManager::Instance()->GetUser(m_Parent->GetSystemAddress());
if (!m_IsGMInvisible || !user || user->GetMaxGMLevel() < eGameMasterLevel::FORUM_MODERATOR) return;
ghstElement = objElement->InsertNewChildElement("ghst");
if (ghstElement) ghstElement->SetAttribute("i", m_IsGMInvisible);
}
void GhostComponent::SetGhostReferencePoint(const NiPoint3& value) {
m_GhostReferencePoint = value;
}
@@ -61,6 +88,45 @@ void GhostComponent::GhostEntity(LWOOBJID id) {
m_ObservedEntities.erase(id);
}
bool GhostComponent::OnToggleGMInvis(GameMessages::GameMsg& msg) {
// TODO: disabled for now while bugs are fixed
return false;
auto& gmInvisMsg = static_cast<GameMessages::ToggleGMInvis&>(msg);
gmInvisMsg.bStateOut = !m_IsGMInvisible;
m_IsGMInvisible = !m_IsGMInvisible;
LOG_DEBUG("GM Invisibility toggled to: %s", m_IsGMInvisible ? "true" : "false");
gmInvisMsg.Send(UNASSIGNED_SYSTEM_ADDRESS);
auto* thisUser = UserManager::Instance()->GetUser(m_Parent->GetSystemAddress());
for (const auto& player : PlayerManager::GetAllPlayers()) {
if (!player || player->GetObjectID() == m_Parent->GetObjectID()) continue;
auto* toUser = UserManager::Instance()->GetUser(player->GetSystemAddress());
if (m_IsGMInvisible) {
if (toUser->GetMaxGMLevel() < thisUser->GetMaxGMLevel()) {
Game::entityManager->DestructEntity(m_Parent, player->GetSystemAddress());
}
} else {
if (toUser->GetMaxGMLevel() >= thisUser->GetMaxGMLevel()) {
Game::entityManager->ConstructEntity(m_Parent, player->GetSystemAddress());
auto* controllableComp = m_Parent->GetComponent<ControllablePhysicsComponent>();
controllableComp->SetDirtyPosition(true);
}
}
}
Game::entityManager->SerializeEntity(m_Parent);
return true;
}
bool GhostComponent::OnGetGMInvis(GameMessages::GameMsg& msg) {
LOG_DEBUG("GM Invisibility requested: %s", m_IsGMInvisible ? "true" : "false");
auto& gmInvisMsg = static_cast<GameMessages::GetGMInvis&>(msg);
// TODO: disabled for now while bugs are fixed
// gmInvisMsg.bGMInvis = m_IsGMInvisible;
// return gmInvisMsg.bGMInvis;
gmInvisMsg.bGMInvis = false;
return false;
}
bool GhostComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
auto& cmptType = reportMsg.info->PushDebug("Ghost");

View File

@@ -7,11 +7,17 @@
class NiPoint3;
namespace tinyxml2 {
class XMLDocument;
}
class GhostComponent final : public Component {
public:
static inline const eReplicaComponentType ComponentType = eReplicaComponentType::GHOST;
GhostComponent(Entity* parent, const int32_t componentID);
~GhostComponent() override;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void SetGhostOverride(bool value) { m_GhostOverride = value; };
@@ -39,9 +45,14 @@ public:
void GhostEntity(const LWOOBJID id);
bool OnToggleGMInvis(GameMessages::GameMsg& msg);
bool OnGetGMInvis(GameMessages::GameMsg& msg);
bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
private:
NiPoint3 m_GhostReferencePoint;
NiPoint3 m_GhostOverridePoint;
@@ -51,6 +62,9 @@ private:
std::unordered_set<LWOOBJID> m_LimboConstructions;
bool m_GhostOverride;
bool m_IsGMInvisible{ false };
};
#endif //!__GHOSTCOMPONENT__H__

View File

@@ -18,7 +18,6 @@ ModelComponent::ModelComponent(Entity* parent, const int32_t componentID) : Comp
using namespace GameMessages;
m_OriginalPosition = m_Parent->GetDefaultPosition();
m_OriginalRotation = m_Parent->GetDefaultRotation();
LOG("%f %f %f %f", m_OriginalRotation.x, m_OriginalRotation.y, m_OriginalRotation.z, m_OriginalRotation.w);
m_IsPaused = false;
m_NumListeningInteract = 0;
@@ -30,23 +29,22 @@ ModelComponent::ModelComponent(Entity* parent, const int32_t componentID) : Comp
bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) {
auto& reset = static_cast<GameMessages::ResetModelToDefaults&>(msg);
for (auto& behavior : m_Behaviors) behavior.HandleMsg(reset);
GameMessages::UnSmash unsmash;
unsmash.target = GetParent()->GetObjectID();
unsmash.duration = 0.0f;
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
if (reset.bResetBehaviors) for (auto& behavior : m_Behaviors) behavior.HandleMsg(reset);
m_Parent->SetPosition(m_OriginalPosition);
m_Parent->SetRotation(m_OriginalRotation);
if (reset.bUnSmash) {
GameMessages::UnSmash unsmash;
unsmash.target = GetParent()->GetObjectID();
unsmash.duration = 0.0f;
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
m_NumActiveUnSmash = 0;
}
if (reset.bResetPos) m_Parent->SetPosition(m_OriginalPosition);
if (reset.bResetRot) m_Parent->SetRotation(m_OriginalRotation);
m_Parent->SetVelocity(NiPoint3Constant::ZERO);
GameMessages::SetAngularVelocity setAngVel;
setAngVel.target = m_Parent->GetObjectID();
setAngVel.angVelocity = NiPoint3Constant::ZERO;
setAngVel.Send();
m_Speed = 3.0f;
m_NumListeningInteract = 0;
m_NumActiveUnSmash = 0;
m_NumActiveAttack = 0;
GameMessages::SetFaction set{};
@@ -309,38 +307,6 @@ void ModelComponent::SetVelocity(const NiPoint3& velocity) const {
m_Parent->SetVelocity(velocity);
}
bool ModelComponent::TrySetAngularVelocity(const NiPoint3& angularVelocity) const {
GameMessages::GetAngularVelocity getAngVel{};
getAngVel.target = m_Parent->GetObjectID();
if (!getAngVel.Send()) {
LOG("Couldn't get angular velocity for %llu", m_Parent->GetObjectID());
return false;
}
GameMessages::SetAngularVelocity setAngVel{};
setAngVel.target = m_Parent->GetObjectID();
if (angularVelocity != NiPoint3Constant::ZERO) {
setAngVel.angVelocity = getAngVel.angVelocity;
const auto [x, y, z] = angularVelocity * m_Speed;
if (x != 0.0f) {
if (getAngVel.angVelocity.x != 0.0f) return false;
setAngVel.angVelocity.x = x;
} else if (y != 0.0f) {
if (getAngVel.angVelocity.y != 0.0f) return false;
setAngVel.angVelocity.y = y;
} else if (z != 0.0f) {
if (getAngVel.angVelocity.z != 0.0f) return false;
setAngVel.angVelocity.z = z;
}
} else {
setAngVel.angVelocity = angularVelocity;
}
LOG("Setting angular velocity to %f %f %f", setAngVel.angVelocity.x, setAngVel.angVelocity.y, setAngVel.angVelocity.z);
setAngVel.Send();
return true;
}
void ModelComponent::OnChatMessageReceived(const std::string& sMessage) {
for (auto& behavior : m_Behaviors) behavior.OnChatMessageReceived(sMessage);
}

View File

@@ -145,11 +145,6 @@ public:
// Force sets the velocity to a value.
void SetVelocity(const NiPoint3& velocity) const;
// Attempts to set the angular velocity of the model.
// If the axis currently has a velocity of zero, returns true.
// If the axis is currently controlled by a behavior, returns false.
bool TrySetAngularVelocity(const NiPoint3& angularVelocity) const;
void OnChatMessageReceived(const std::string& sMessage);
void OnHit();
@@ -167,8 +162,6 @@ public:
// Decrements the number of strips listening for an attack.
// If this is the last strip removing an attack, it will reset the factions to the default of -1.
void RemoveAttack();
float GetSpeed() const noexcept { return m_Speed; }
private:
// Loads a behavior from the database.

View File

@@ -15,11 +15,8 @@
#include "StringifiedEnum.h"
#include "Amf3.h"
SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, int32_t componentID) : PhysicsComponent(parent, componentID) {
using namespace GameMessages;
RegisterMsg<GetObjectReportInfo>(this, &SimplePhysicsComponent::OnGetObjectReportInfo);
RegisterMsg<GameMessages::GetAngularVelocity>(this, &SimplePhysicsComponent::OnGetAngularVelocity);
RegisterMsg<GameMessages::SetAngularVelocity>(this, &SimplePhysicsComponent::OnSetAngularVelocity);
SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) {
RegisterMsg(MessageType::Game::GET_OBJECT_REPORT_INFO, this, &SimplePhysicsComponent::OnGetObjectReportInfo);
m_Position = m_Parent->GetDefaultPosition();
m_Rotation = m_Parent->GetDefaultRotation();
@@ -41,20 +38,10 @@ SimplePhysicsComponent::~SimplePhysicsComponent() {
}
void SimplePhysicsComponent::Update(const float deltaTime) {
if (m_Velocity != NiPoint3Constant::ZERO) {
m_Position += m_Velocity * deltaTime;
m_DirtyPosition = true;
Game::entityManager->SerializeEntity(m_Parent);
}
if (m_AngularVelocity != NiPoint3Constant::ZERO) {
m_Rotation.Normalize();
const auto vel = NiQuaternion::FromEulerAngles(m_AngularVelocity * deltaTime);
m_Rotation *= vel;
const auto euler = m_Rotation.GetEulerAngles();
m_DirtyPosition = true;
Game::entityManager->SerializeEntity(m_Parent);
}
if (m_Velocity == NiPoint3Constant::ZERO) return;
m_Position += m_Velocity * deltaTime;
m_DirtyPosition = true;
Game::entityManager->SerializeEntity(m_Parent);
}
void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
@@ -65,12 +52,8 @@ void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIs
outBitStream.Write(m_DirtyVelocity || bIsInitialUpdate);
if (m_DirtyVelocity || bIsInitialUpdate) {
outBitStream.Write(m_Velocity.x);
outBitStream.Write(m_Velocity.y);
outBitStream.Write(m_Velocity.z);
outBitStream.Write(m_AngularVelocity.x);
outBitStream.Write(m_AngularVelocity.y);
outBitStream.Write(m_AngularVelocity.z);
outBitStream.Write(m_Velocity);
outBitStream.Write(m_AngularVelocity);
m_DirtyVelocity = false;
}
@@ -109,18 +92,3 @@ bool SimplePhysicsComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
info.PushDebug<AMFStringValue>("Climbable Type") = StringifiedEnum::ToString(m_ClimbableType).data();
return true;
}
bool SimplePhysicsComponent::OnSetAngularVelocity(GameMessages::GameMsg& msg) {
auto& setAngVel = static_cast<GameMessages::SetAngularVelocity&>(msg);
m_DirtyVelocity |= setAngVel.bForceFlagDirty || (m_AngularVelocity != setAngVel.angVelocity);
m_AngularVelocity = setAngVel.angVelocity;
LOG("Velocity is now %f %f %f", m_AngularVelocity.x, m_AngularVelocity.y, m_AngularVelocity.z);
Game::entityManager->SerializeEntity(m_Parent);
return true;
}
bool SimplePhysicsComponent::OnGetAngularVelocity(GameMessages::GameMsg& msg) {
auto& getAngVel = static_cast<GameMessages::GetAngularVelocity&>(msg);
getAngVel.angVelocity = m_AngularVelocity;
return true;
}

View File

@@ -61,9 +61,6 @@ public:
*/
void SetAngularVelocity(const NiPoint3& value) { m_AngularVelocity = value; m_DirtyVelocity = true; }
bool OnSetAngularVelocity(GameMessages::GameMsg& msg);
bool OnGetAngularVelocity(GameMessages::GameMsg& msg);
/**
* Returns the physics motion state
* @return the physics motion state

View File

@@ -1847,18 +1847,6 @@ void GameMessages::SendNotifyClientFailedPrecondition(LWOOBJID objectId, const S
SEND_PACKET;
}
void GameMessages::SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(objectId);
bitStream.Write(MessageType::Game::TOGGLE_GM_INVIS);
bitStream.Write(enabled); // does not matter?
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST;
SEND_PACKET;
}
void GameMessages::SendSetName(LWOOBJID objectID, std::u16string name, const SystemAddress& sysAddr) {
CBITSTREAM;
CMSGHEADER;
@@ -5943,6 +5931,7 @@ void GameMessages::HandleUpdatePlayerStatistic(RakNet::BitStream& inStream, Enti
void GameMessages::HandleDeactivateBubbleBuff(RakNet::BitStream& inStream, Entity* entity) {
auto controllablePhysicsComponent = entity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent) controllablePhysicsComponent->DeactivateBubbleBuff();
GameMessages::SendDeactivateBubbleBuffFromServer(entity->GetObjectID(), entity->GetSystemAddress());
}
void GameMessages::HandleActivateBubbleBuff(RakNet::BitStream& inStream, Entity* entity) {
@@ -6449,4 +6438,8 @@ namespace GameMessages {
stream.Write(lootID);
stream.Write(lootOwnerID);
}
void ToggleGMInvis::Serialize(RakNet::BitStream& stream) const {
stream.Write(bStateOut);
}
}

View File

@@ -243,8 +243,6 @@ namespace GameMessages {
bool cancelOnLogout = false, bool cancelOnRemoveBuff = true, bool cancelOnUi = false,
bool cancelOnUnequip = false, bool cancelOnZone = false, bool addedByTeammate = false, bool applyOnTeammates = false, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
void SendToggleGMInvis(LWOOBJID objectId, bool enabled, const SystemAddress& sysAddr);
void SendSetName(LWOOBJID objectID, std::u16string name, const SystemAddress& sysAddr);
// Property messages
@@ -848,6 +846,11 @@ namespace GameMessages {
struct ResetModelToDefaults : public GameMsg {
ResetModelToDefaults() : GameMsg(MessageType::Game::RESET_MODEL_TO_DEFAULTS) {}
bool bResetPos{ true };
bool bResetRot{ true };
bool bUnSmash{ true };
bool bResetBehaviors{ true };
};
struct EmotePlayed : public GameMsg {
@@ -873,22 +876,6 @@ namespace GameMessages {
bool bIgnoreChecks{ false };
};
struct GetAngularVelocity : public GameMsg {
GetAngularVelocity() : GameMsg(MessageType::Game::GET_ANGULAR_VELOCITY) {}
NiPoint3 angVelocity{};
};
struct SetAngularVelocity : public GameMsg {
SetAngularVelocity() : GameMsg(MessageType::Game::SET_ANGULAR_VELOCITY) {}
NiPoint3 angVelocity{};
bool bIgnoreDirtyFlags{};
bool bForceFlagDirty{};
};
struct DropClientLoot : public GameMsg {
DropClientLoot() : GameMsg(MessageType::Game::DROP_CLIENT_LOOT) {}
@@ -948,5 +935,31 @@ namespace GameMessages {
LWOOBJID lootID{};
LWOOBJID lootOwnerID{};
};
struct ToggleGMInvis : public GameMsg {
ToggleGMInvis() : GameMsg(MessageType::Game::TOGGLE_GM_INVIS) {}
void Serialize(RakNet::BitStream& stream) const override;
bool bStateOut{ false };
};
struct GetGMInvis : public GameMsg {
GetGMInvis() : GameMsg(MessageType::Game::GET_GM_INVIS) {}
bool bGMInvis{ false };
};
struct ChildRemoved : public GameMsg {
ChildRemoved() : GameMsg(MessageType::Game::CHILD_REMOVED) {}
LWOOBJID childID{};
};
struct IsDead : public GameMsg {
IsDead() : GameMsg(MessageType::Game::IS_DEAD) {}
bool bDead{};
};
};
#endif // GAMEMESSAGES_H

View File

@@ -5,6 +5,7 @@
#include "ControlBehaviorMsgs.h"
#include "tinyxml2.h"
#include "ModelComponent.h"
#include "StringifiedEnum.h"
#include <ranges>
@@ -178,13 +179,32 @@ void PropertyBehavior::Deserialize(const tinyxml2::XMLElement& behavior) {
}
void PropertyBehavior::Update(float deltaTime, ModelComponent& modelComponent) {
for (auto& state : m_States | std::views::values) state.Update(deltaTime, modelComponent);
auto& activeState = GetActiveState();
UpdateResult updateResult{};
activeState.Update(deltaTime, modelComponent, updateResult);
if (updateResult.newState.has_value() && updateResult.newState.value() != m_ActiveState) {
LOG("Behavior %llu is changing from state %s to %s", m_BehaviorId, StringifiedEnum::ToString(m_ActiveState).data(), StringifiedEnum::ToString(updateResult.newState.value()).data());
GameMessages::ResetModelToDefaults resetMsg{};
resetMsg.bResetPos = false;
resetMsg.bResetRot = false;
resetMsg.bUnSmash = false;
modelComponent.OnResetModelToDefaults(resetMsg);
HandleMsg(resetMsg);
m_ActiveState = updateResult.newState.value();
}
}
void PropertyBehavior::OnChatMessageReceived(const std::string& sMessage) {
for (auto& state : m_States | std::views::values) state.OnChatMessageReceived(sMessage);
auto& activeState = GetActiveState();
activeState.OnChatMessageReceived(sMessage);
}
void PropertyBehavior::OnHit() {
for (auto& state : m_States | std::views::values) state.OnHit();
auto& activeState = GetActiveState();
activeState.OnHit();
}
State& PropertyBehavior::GetActiveState() {
DluAssert(m_States.contains(m_ActiveState));
return m_States[m_ActiveState];
}

View File

@@ -1,18 +1,23 @@
#ifndef __PROPERTYBEHAVIOR__H__
#define __PROPERTYBEHAVIOR__H__
#include "BehaviorStates.h"
#include "State.h"
#include <optional>
namespace tinyxml2 {
class XMLElement;
}
enum class BehaviorState : uint32_t;
class AMFArrayValue;
class BehaviorMessageBase;
class ModelComponent;
struct UpdateResult {
std::optional<BehaviorState> newState;
};
/**
* Represents the Entity of a Property Behavior and holds data associated with the behavior
*/
@@ -45,6 +50,7 @@ public:
void OnHit();
private:
State& GetActiveState();
// The current active behavior state. Behaviors can only be in ONE state at a time.
BehaviorState m_ActiveState;

View File

@@ -163,8 +163,8 @@ void State::Deserialize(const tinyxml2::XMLElement& state) {
}
}
void State::Update(float deltaTime, ModelComponent& modelComponent) {
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent);
void State::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent, updateResult);
}
void State::OnChatMessageReceived(const std::string& sMessage) {

View File

@@ -9,6 +9,7 @@ namespace tinyxml2 {
class AMFArrayValue;
class ModelComponent;
struct UpdateResult;
class State {
public:
@@ -21,7 +22,7 @@ public:
void Serialize(tinyxml2::XMLElement& state) const;
void Deserialize(const tinyxml2::XMLElement& state);
void Update(float deltaTime, ModelComponent& modelComponent);
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
void OnChatMessageReceived(const std::string& sMessage);
void OnHit();

View File

@@ -9,7 +9,6 @@
#include "PropertyManagementComponent.h"
#include "PlayerManager.h"
#include "SimplePhysicsComponent.h"
#include "dMath.h"
#include "dChatFilter.h"
@@ -106,7 +105,7 @@ void Strip::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
m_WaitingForAction = false;
m_PausedTime = 0.0f;
m_NextActionIndex = 0;
m_InActionTranslation = NiPoint3Constant::ZERO;
m_InActionMove = NiPoint3Constant::ZERO;
m_PreviousFramePosition = NiPoint3Constant::ZERO;
}
@@ -161,91 +160,48 @@ void Strip::SpawnDrop(LOT dropLOT, Entity& entity) {
}
}
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
auto& entity = *modelComponent.GetParent();
auto& nextAction = GetNextAction();
auto number = nextAction.GetValueParameterDouble();
auto valueStr = nextAction.GetValueParameterString();
auto numberAsInt = static_cast<int32_t>(number);
auto nextActionType = GetNextAction().GetType();
LOG("~number: %f, nextActionType: %s", static_cast<float>(number), nextActionType.data());
LOG_DEBUG("Processing Strip Action: %s with number %.2f and string %s", nextActionType.data(), number, valueStr.data());
// TODO replace with switch case and nextActionType with enum
/* BEGIN Move */
if (nextActionType == "MoveRight" || nextActionType == "MoveLeft") {
m_IsRotating = false;
// X axis
bool isMoveLeft = nextActionType == "MoveLeft";
int negative = isMoveLeft ? -1 : 1;
// Default velocity is 3 units per second.
if (modelComponent.TrySetVelocity(NiPoint3Constant::UNIT_X * negative)) {
m_PreviousFramePosition = entity.GetPosition();
m_InActionTranslation.x = isMoveLeft ? -number : number;
m_InActionMove.x = isMoveLeft ? -number : number;
}
} else if (nextActionType == "FlyUp" || nextActionType == "FlyDown") {
m_IsRotating = false;
// Y axis
bool isFlyDown = nextActionType == "FlyDown";
int negative = isFlyDown ? -1 : 1;
// Default velocity is 3 units per second.
if (modelComponent.TrySetVelocity(NiPoint3Constant::UNIT_Y * negative)) {
m_PreviousFramePosition = entity.GetPosition();
m_InActionTranslation.y = isFlyDown ? -number : number;
m_InActionMove.y = isFlyDown ? -number : number;
}
} else if (nextActionType == "MoveForward" || nextActionType == "MoveBackward") {
m_IsRotating = false;
// Z axis
bool isMoveBackward = nextActionType == "MoveBackward";
int negative = isMoveBackward ? -1 : 1;
// Default velocity is 3 units per second.
if (modelComponent.TrySetVelocity(NiPoint3Constant::UNIT_Z * negative)) {
m_PreviousFramePosition = entity.GetPosition();
m_InActionTranslation.z = isMoveBackward ? -number : number;
m_InActionMove.z = isMoveBackward ? -number : number;
}
}
/* END Move */
/* BEGIN Rotate */
else if (nextActionType == "Spin" || nextActionType == "SpinNegative") {
const float radians = Math::DegToRad(number);
bool isSpinNegative = nextActionType == "SpinNegative";
float negative = isSpinNegative ? -0.261799f : 0.261799f;
// Default angular velocity is 3 units per second.
if (modelComponent.TrySetAngularVelocity(NiPoint3Constant::UNIT_Y * negative)) {
m_IsRotating = true;
m_InActionTranslation.y = isSpinNegative ? -number : number;
m_PreviousFrameRotation = entity.GetRotation();
// d/vi = t
// radians/velocity = time
// only care about the time, direction is irrelevant here
}
} else if (nextActionType == "Tilt" || nextActionType == "TiltNegative") {
const float radians = Math::DegToRad(number);
bool isRotateLeft = nextActionType == "TiltNegative";
float negative = isRotateLeft ? -0.261799f : 0.261799f;
// Default angular velocity is 3 units per second.
if (modelComponent.TrySetAngularVelocity(NiPoint3Constant::UNIT_X * negative)) {
m_IsRotating = true;
m_InActionTranslation.x = isRotateLeft ? -number : number;
m_PreviousFrameRotation = entity.GetRotation();
}
} else if (nextActionType == "Roll" || nextActionType == "RollNegative") {
const float radians = Math::DegToRad(number);
bool isRotateDown = nextActionType == "RollNegative";
float negative = isRotateDown ? -0.261799f : 0.261799f;
// Default angular velocity is 3 units per second.
if (modelComponent.TrySetAngularVelocity(NiPoint3Constant::UNIT_Z * negative)) {
m_IsRotating = true;
m_InActionTranslation.z = isRotateDown ? -number : number;
m_PreviousFrameRotation = entity.GetRotation();
}
}
/* END Rotate */
/* BEGIN Navigation */
else if (nextActionType == "SetSpeed") {
modelComponent.SetSpeed(number);
@@ -268,7 +224,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
modelComponent.AddUnSmash();
m_PausedTime = number;
// since it may take time for the message to relay to clients
m_PausedTime = number + 0.5f;
} else if (nextActionType == "Wait") {
m_PausedTime = number;
} else if (nextActionType == "Chat") {
@@ -303,6 +260,21 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
}
/* END Gameplay */
/* BEGIN StateMachine */
else if (nextActionType == "ChangeStateHome") {
updateResult.newState = BehaviorState::HOME_STATE;
} else if (nextActionType == "ChangeStateCircle") {
updateResult.newState = BehaviorState::CIRCLE_STATE;
} else if (nextActionType == "ChangeStateSquare") {
updateResult.newState = BehaviorState::SQUARE_STATE;
} else if (nextActionType == "ChangeStateDiamond") {
updateResult.newState = BehaviorState::DIAMOND_STATE;
} else if (nextActionType == "ChangeStateTriangle") {
updateResult.newState = BehaviorState::TRIANGLE_STATE;
} else if (nextActionType == "ChangeStateStar") {
updateResult.newState = BehaviorState::STAR_STATE;
}
/* END StateMachine*/
else {
static std::set<std::string> g_WarnedActions;
if (!g_WarnedActions.contains(nextActionType.data())) {
@@ -330,37 +302,36 @@ void Strip::RemoveStates(ModelComponent& modelComponent) const {
}
bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
if (m_IsRotating) return true;
auto& entity = *modelComponent.GetParent();
const auto& currentPos = entity.GetPosition();
const auto diff = currentPos - m_PreviousFramePosition;
const auto [moveX, moveY, moveZ] = m_InActionTranslation;
const auto [moveX, moveY, moveZ] = m_InActionMove;
m_PreviousFramePosition = currentPos;
// Only want to subtract from the move if one is being performed.
// Starts at true because we may not be doing a move at all.
// If one is being done, then one of the move_ variables will be non-zero
bool moveFinished = true;
NiPoint3 finalPositionAdjustment = NiPoint3Constant::ZERO;
if (moveX != 0.0f) {
m_InActionTranslation.x -= diff.x;
m_InActionMove.x -= diff.x;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionTranslation.x) != std::signbit(moveX);
finalPositionAdjustment.x = m_InActionTranslation.x;
moveFinished = std::signbit(m_InActionMove.x) != std::signbit(moveX);
finalPositionAdjustment.x = m_InActionMove.x;
} else if (moveY != 0.0f) {
m_InActionTranslation.y -= diff.y;
m_InActionMove.y -= diff.y;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionTranslation.y) != std::signbit(moveY);
finalPositionAdjustment.y = m_InActionTranslation.y;
moveFinished = std::signbit(m_InActionMove.y) != std::signbit(moveY);
finalPositionAdjustment.y = m_InActionMove.y;
} else if (moveZ != 0.0f) {
m_InActionTranslation.z -= diff.z;
m_InActionMove.z -= diff.z;
// If the sign bit is different between the two numbers, then we have finished our move.
moveFinished = std::signbit(m_InActionTranslation.z) != std::signbit(moveZ);
finalPositionAdjustment.z = m_InActionTranslation.z;
moveFinished = std::signbit(m_InActionMove.z) != std::signbit(moveZ);
finalPositionAdjustment.z = m_InActionMove.z;
}
// Once done, set the in action move & velocity to zero
if (moveFinished && m_InActionTranslation != NiPoint3Constant::ZERO) {
if (moveFinished && m_InActionMove != NiPoint3Constant::ZERO) {
auto entityVelocity = entity.GetVelocity();
// Zero out only the velocity that was acted on
if (moveX != 0.0f) entityVelocity.x = 0.0f;
@@ -370,82 +341,19 @@ bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
// Do the final adjustment so we will have moved exactly the requested units
entity.SetPosition(entity.GetPosition() + finalPositionAdjustment);
m_InActionTranslation = NiPoint3Constant::ZERO;
m_InActionMove = NiPoint3Constant::ZERO;
}
return moveFinished;
}
bool Strip::CheckRotation(float deltaTime, ModelComponent& modelComponent) {
if (!m_IsRotating) return true;
GameMessages::GetAngularVelocity getAngVel{};
getAngVel.target = modelComponent.GetParent()->GetObjectID();
getAngVel.Send();
const auto curRotation = modelComponent.GetParent()->GetRotation();
const auto diff = m_PreviousFrameRotation.Diff(curRotation).GetEulerAngles();
LOG("Diff: x=%f, y=%f, z=%f", std::abs(Math::RadToDeg(diff.x)), std::abs(Math::RadToDeg(diff.y)), std::abs(Math::RadToDeg(diff.z)));
LOG("Velocity: x=%f, y=%f, z=%f", Math::RadToDeg(getAngVel.angVelocity.x) * deltaTime, Math::RadToDeg(getAngVel.angVelocity.y) * deltaTime, Math::RadToDeg(getAngVel.angVelocity.z) * deltaTime);
m_PreviousFrameRotation = curRotation;
auto angVel = diff;
angVel.x = std::abs(Math::RadToDeg(angVel.x));
angVel.y = std::abs(Math::RadToDeg(angVel.y));
angVel.z = std::abs(Math::RadToDeg(angVel.z));
const auto [rotateX, rotateY, rotateZ] = m_InActionTranslation;
bool rotateFinished = true;
NiPoint3 finalRotationAdjustment = NiPoint3Constant::ZERO;
if (rotateX != 0.0f) {
m_InActionTranslation.x -= angVel.x;
rotateFinished = std::signbit(m_InActionTranslation.x) != std::signbit(rotateX);
finalRotationAdjustment.x = Math::DegToRad(m_InActionTranslation.x);
} else if (rotateY != 0.0f) {
m_InActionTranslation.y -= angVel.y;
rotateFinished = std::signbit(m_InActionTranslation.y) != std::signbit(rotateY);
finalRotationAdjustment.y = Math::DegToRad(m_InActionTranslation.y);
} else if (rotateZ != 0.0f) {
m_InActionTranslation.z -= angVel.z;
rotateFinished = std::signbit(m_InActionTranslation.z) != std::signbit(rotateZ);
finalRotationAdjustment.z = Math::DegToRad(m_InActionTranslation.z);
}
if (rotateFinished && m_InActionTranslation != NiPoint3Constant::ZERO) {
LOG("Rotation finished, zeroing angVel");
angVel.x = Math::DegToRad(angVel.x);
angVel.y = Math::DegToRad(angVel.y);
angVel.z = Math::DegToRad(angVel.z);
if (rotateX != 0.0f) getAngVel.angVelocity.x = 0.0f;
else if (rotateY != 0.0f) getAngVel.angVelocity.y = 0.0f;
else if (rotateZ != 0.0f) getAngVel.angVelocity.z = 0.0f;
GameMessages::SetAngularVelocity setAngVel{};
setAngVel.target = modelComponent.GetParent()->GetObjectID();
setAngVel.angVelocity = getAngVel.angVelocity;
setAngVel.Send();
// Do the final adjustment so we will have rotated exactly the requested units
auto currentRot = modelComponent.GetParent()->GetRotation();
NiQuaternion finalAdjustment = NiQuaternion::FromEulerAngles(finalRotationAdjustment);
currentRot *= finalAdjustment;
currentRot.Normalize();
modelComponent.GetParent()->SetRotation(currentRot);
m_InActionTranslation = NiPoint3Constant::ZERO;
m_IsRotating = false;
}
LOG("angVel: x=%f, y=%f, z=%f", m_InActionTranslation.x, m_InActionTranslation.y, m_InActionTranslation.z);
return rotateFinished;
}
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
// No point in running a strip with only one action.
// Strips are also designed to have 2 actions or more to run.
if (!HasMinimumActions()) return;
// Return if this strip has an active movement or rotation action
// Return if this strip has an active movement action
if (!CheckMovement(deltaTime, modelComponent)) return;
if (!CheckRotation(deltaTime, modelComponent)) return;
// Don't run this strip if we're paused.
m_PausedTime -= deltaTime;
@@ -463,6 +371,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
// Check for trigger blocks and if not a trigger block proc this blocks action
if (m_NextActionIndex == 0) {
LOG("Behavior strip started %s", nextAction.GetType().data());
if (nextAction.GetType() == "OnInteract") {
modelComponent.AddInteract();
} else if (nextAction.GetType() == "OnChat") {
@@ -473,7 +382,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
Game::entityManager->SerializeEntity(entity);
m_WaitingForAction = true;
} else { // should be a normal block
ProcNormalAction(deltaTime, modelComponent);
ProcNormalAction(deltaTime, modelComponent, updateResult);
}
}

View File

@@ -12,6 +12,7 @@ namespace tinyxml2 {
class AMFArrayValue;
class ModelComponent;
struct UpdateResult;
class Strip {
public:
@@ -33,13 +34,9 @@ public:
// Checks the movement logic for whether or not to proceed
// Returns true if the movement can continue, false if it needs to wait more.
bool CheckMovement(float deltaTime, ModelComponent& modelComponent);
// Checks the rotation logic for whether or not to proceed
// Returns true if the rotation can continue, false if it needs to wait more.
bool CheckRotation(float deltaTime, ModelComponent& modelComponent);
void Update(float deltaTime, ModelComponent& modelComponent);
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
void SpawnDrop(LOT dropLOT, Entity& entity);
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent);
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
void RemoveStates(ModelComponent& modelComponent) const;
// 2 actions are required for strips to work
@@ -51,9 +48,6 @@ private:
// Indicates this Strip is waiting for an action to be taken upon it to progress to its actions
bool m_WaitingForAction{ false };
// True if this strip is currently rotating
bool m_IsRotating{ false };
// The amount of time this strip is paused for. Any interactions with this strip should be bounced if this is greater than 0.
// Actions that do not use time do not use this (ex. positions).
float m_PausedTime{ 0.0f };
@@ -67,17 +61,13 @@ private:
// The location of this strip on the UGBehaviorEditor UI
StripUiPosition m_Position;
// The current actions remaining translation to the target
// The current actions remaining distance to the target
// Only 1 of these vertexs' will be active at once for any given strip.
NiPoint3 m_InActionTranslation{};
NiPoint3 m_InActionMove{};
// The position of the parent model on the previous frame
NiPoint3 m_PreviousFramePosition{};
NiPoint3 m_RotationRemaining{};
NiQuaternion m_PreviousFrameRotation{};
NiPoint3 m_SavedVelocity{};
};

View File

@@ -21,6 +21,8 @@
#include "TeamManager.h"
#include "CDObjectsTable.h"
#include "ObjectIDManager.h"
#include "CDActivitiesTable.h"
#include "ScriptedActivityComponent.h"
namespace {
std::unordered_set<uint32_t> CachedMatrices;
@@ -142,13 +144,17 @@ void DropFactionLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
// Drops 1 token for each player on a team
// token drops are always given to every player on the team.
void DropFactionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
void DropFactionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg, const bool noTeamLootOnDeath = false) {
for (const auto member : team.members) {
GameMessages::GetPosition memberPosMsg{};
memberPosMsg.target = member;
memberPosMsg.Send();
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
GameMessages::IsDead isDeadMsg{};
// Skip dead players
if (noTeamLootOnDeath && isDeadMsg.Send(member) && isDeadMsg.bDead) continue;
GameMessages::GetFactionTokenType factionTokenType{};
factionTokenType.target = member;
// If we're not in a faction, this message will return false
@@ -186,7 +192,7 @@ void DropPowerupLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
// Drop the power up with no owner
// Power ups can be picked up by anyone on a team, however unlike actual loot items,
// if multiple clients say they picked one up, we let them pick it up.
void DropPowerupLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
void DropPowerupLoot(const Team& team, GameMessages::DropClientLoot& lootMsg, const bool noTeamLootOnDeath = false) {
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
lootMsg.ownerID = LWOOBJID_EMPTY; // By setting ownerID to empty, any client that gets this DropClientLoot message can pick up the item.
CalcFinalDropPos(lootMsg);
@@ -198,6 +204,10 @@ void DropPowerupLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
memberPosMsg.Send();
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
GameMessages::IsDead isDeadMsg{};
// Skip dead players
if (noTeamLootOnDeath && isDeadMsg.Send(member) && isDeadMsg.bDead) continue;
lootMsg.target = member;
// By sending this message with the same ID to all players on the team, all players on the team are allowed to pick it up.
lootMsg.Send();
@@ -230,7 +240,7 @@ void DropMissionLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
// Check if the item needs to be dropped for anyone on the team
// Only players who need the item will have it dropped
void DropMissionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
void DropMissionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg, const bool noTeamLootOnDeath = false) {
GameMessages::MissionNeedsLot needMsg{};
needMsg.item = lootMsg.item;
for (const auto member : team.members) {
@@ -239,6 +249,10 @@ void DropMissionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
memberPosMsg.Send();
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
GameMessages::IsDead isDeadMsg{};
// Skip dead players
if (noTeamLootOnDeath && isDeadMsg.Send(member) && isDeadMsg.bDead) continue;
needMsg.target = member;
// Will return false if the item is not required
if (needMsg.Send()) {
@@ -274,19 +288,24 @@ void DropRegularLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
// Drop a regular piece of loot.
// Most items will go through this.
// Finds the next loot owner on the team the is in range of the kill and gives them this reward.
void DropRegularLoot(Team& team, GameMessages::DropClientLoot& lootMsg) {
void DropRegularLoot(Team& team, GameMessages::DropClientLoot& lootMsg, const bool noTeamLootOnDeath = false) {
auto earningPlayer = LWOOBJID_EMPTY;
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
CalcFinalDropPos(lootMsg);
GameMessages::GetPosition memberPosMsg{};
GameMessages::IsDead isDeadMsg{};
// Find the next loot owner. Eventually this will run into the `player` passed into this function, since those will
// have the same ID, this loop will only ever run at most 4 times.
do {
earningPlayer = team.GetNextLootOwner();
memberPosMsg.target = earningPlayer;
memberPosMsg.Send();
} while (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS);
if (noTeamLootOnDeath) {
isDeadMsg.target = earningPlayer;
// Skip dead players
isDeadMsg.Send();
}
} while (isDeadMsg.bDead || (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS));
if (team.lootOption == 0 /* Shared loot */) {
lootMsg.target = earningPlayer;
lootMsg.ownerID = earningPlayer;
@@ -304,7 +323,7 @@ void DropRegularLoot(Team& team, GameMessages::DropClientLoot& lootMsg) {
DistrbuteMsgToTeam(lootMsg, team);
}
void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDropInfo>& rolledItems, uint32_t minCoins, uint32_t maxCoins) {
void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDropInfo>& rolledItems, uint32_t minCoins, uint32_t maxCoins, const bool noTeamLootOnDeath) {
player = player->GetOwner(); // if the owner is overwritten, we collect that here
const auto playerID = player->GetObjectID();
if (!player || !player->IsPlayer()) {
@@ -342,45 +361,53 @@ void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDro
const CDObjects& object = objectsTable->GetByID(lootLot);
if (lootLot == TOKEN_PROXY) {
team ? DropFactionLoot(*team, lootMsg) : DropFactionLoot(*player, lootMsg);
team ? DropFactionLoot(*team, lootMsg, noTeamLootOnDeath) : DropFactionLoot(*player, lootMsg);
} else if (info.table.MissionDrop) {
team ? DropMissionLoot(*team, lootMsg) : DropMissionLoot(*player, lootMsg);
team ? DropMissionLoot(*team, lootMsg, noTeamLootOnDeath) : DropMissionLoot(*player, lootMsg);
} else if (object.type == "Powerup") {
team ? DropPowerupLoot(*team, lootMsg) : DropPowerupLoot(*player, lootMsg);
team ? DropPowerupLoot(*team, lootMsg, noTeamLootOnDeath) : DropPowerupLoot(*player, lootMsg);
} else {
team ? DropRegularLoot(*team, lootMsg) : DropRegularLoot(*player, lootMsg);
team ? DropRegularLoot(*team, lootMsg, noTeamLootOnDeath) : DropRegularLoot(*player, lootMsg);
}
}
}
// Coin roll is divided up between the members, rounded up, then dropped for each player
const uint32_t coinRoll = static_cast<uint32_t>(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
const auto droppedCoins = team ? std::ceil(coinRoll / team->members.size()) : coinRoll;
// Filter out dead player if we need to
std::vector<LWOOBJID> lootEarners;
if (team) {
for (auto member : team->members) {
GameMessages::DropClientLoot lootMsg{};
lootMsg.target = member;
lootMsg.ownerID = member;
lootMsg.currency = droppedCoins;
lootMsg.spawnPos = spawnPosition;
lootMsg.sourceID = source;
lootMsg.item = LOT_NULL;
CalcFinalDropPos(lootMsg);
lootMsg.Send();
const auto* const memberEntity = Game::entityManager->GetEntity(member);
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
if (noTeamLootOnDeath) {
for (const auto member : team->members) {
GameMessages::IsDead isDeadMsg{};
isDeadMsg.target = member;
if (isDeadMsg.Send() && !isDeadMsg.bDead) {
lootEarners.push_back(member);
}
}
} else {
lootEarners = team->members;
}
} else {
lootEarners.push_back(playerID);
}
// Coin roll is divided up between the members, rounded up, then dropped for each player
const uint32_t coinRoll = static_cast<uint32_t>(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
// Just in case its empty don't allow divide by 0
const auto droppedCoins = lootEarners.empty() ? coinRoll : static_cast<uint32_t>(std::ceil(static_cast<float>(coinRoll) / lootEarners.size()));
// Drops coins for each alive member of a team (or just a player)
for (auto member : lootEarners) {
GameMessages::DropClientLoot lootMsg{};
lootMsg.target = playerID;
lootMsg.ownerID = playerID;
lootMsg.target = member;
lootMsg.ownerID = member;
lootMsg.currency = droppedCoins;
lootMsg.spawnPos = spawnPosition;
lootMsg.sourceID = source;
lootMsg.item = LOT_NULL;
CalcFinalDropPos(lootMsg);
lootMsg.Send();
lootMsg.Send(player->GetSystemAddress());
const auto* const memberEntity = Game::entityManager->GetEntity(member);
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
}
}
@@ -533,6 +560,9 @@ void Loot::GiveActivityLoot(Entity* player, const LWOOBJID source, uint32_t acti
void Loot::DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {
player = player->GetOwner(); // if the owner is overwritten, we collect that here
auto* scriptedActivityComponent = Game::entityManager->GetZoneControlEntity()->GetComponent<ScriptedActivityComponent>();
const bool noTeamLootOnDeath = scriptedActivityComponent ? scriptedActivityComponent->GetNoTeamLootOnDeath() : false;
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (!inventoryComponent)
@@ -540,7 +570,7 @@ void Loot::DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex,
const auto result = ::RollLootMatrix(matrixIndex);
::DropLoot(player, source, result, minCoins, maxCoins);
::DropLoot(player, source, result, minCoins, maxCoins, noTeamLootOnDeath);
}
void Loot::DropActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating) {

View File

@@ -893,10 +893,10 @@ void SlashCommandHandler::Startup() {
Command GmInvisCommand{
.help = "Toggles invisibility for the character",
.info = "Toggles invisibility for the character, though it's currently a bit buggy. Requires nonzero GM Level for the character, but the account must have a GM level of 8",
.info = "Toggles invisibility for the character, making them invisible to other players and lower GM levels",
.aliases = { "gminvis" },
.handle = GMGreaterThanZeroCommands::GmInvis,
.requiredLevel = eGameMasterLevel::DEVELOPER
.requiredLevel = eGameMasterLevel::FORUM_MODERATOR
};
RegisterCommand(GmInvisCommand);
@@ -1052,7 +1052,7 @@ void SlashCommandHandler::Startup() {
.info = "Resurrects the player",
.aliases = { "resurrect" },
.handle = GMZeroCommands::Resurrect,
.requiredLevel = eGameMasterLevel::CIVILIAN
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ResurrectCommand);

View File

@@ -26,6 +26,8 @@
#include "Database.h"
#include "CDObjectsTable.h"
#include "CDRewardCodesTable.h"
#include "CDLootMatrixTable.h"
#include "CDLootTableTable.h"
// Components
#include "BuffComponent.h"
@@ -89,7 +91,8 @@ namespace DEVGMCommands {
GameMessages::SendChatModeUpdate(entity->GetObjectID(), eGameMasterLevel::CIVILIAN);
entity->SetGMLevel(eGameMasterLevel::CIVILIAN);
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::ToggleGMInvis msg;
msg.Send(entity->GetObjectID());
GameMessages::SendSlashCommandFeedbackText(entity, u"Your game master level has been changed, you may not be able to use all commands.");
}
@@ -176,14 +179,15 @@ namespace DEVGMCommands {
charComp->m_Character->SetRightHand(minifigItemId);
} else {
Game::entityManager->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity, entity->GetSystemAddress());
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig item to change, try one of the following: Eyebrows, Eyes, HairColor, HairStyle, Pants, LeftHand, Mouth, RightHand, Shirt, Hands");
return;
}
Game::entityManager->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity, entity->GetSystemAddress());
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(lowerName) + u" set to " + (GeneralUtils::to_u16string(minifigItemId)));
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); // need to retoggle because it gets reenabled on creation of new character
}
void PlayAnimation(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -377,8 +381,6 @@ namespace DEVGMCommands {
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
SlashCommandHandler::HandleChatCommand(GeneralUtils::ASCIIToUTF16(line), &entity, sysAddr);
}
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Unknown macro! Is the filename right?");
}
}
@@ -743,11 +745,40 @@ namespace DEVGMCommands {
auto tables = query.execQuery();
std::map<LOT, std::string> lotToName{};
std::map<std::string, LOT> nameToLot{};
while (!tables.eof()) {
std::string message = std::to_string(tables.getIntField("id")) + " - " + tables.getStringField("name");
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(message, message.size()));
const auto lot = tables.getIntField("id");
const auto name = tables.getStringField("name");
lotToName[lot] = name;
nameToLot[name] = lot;
tables.nextRow();
}
// if there arent a ton of results, print them to chat instead
if (lotToName.size() < 5) {
std::stringstream ss;
ss << "Lookup results for \"" << args << "\":";
for (const auto& [lot, name] : lotToName) {
ss << "\nLOT: " << lot << " - Name: " << name;
}
ChatPackets::SendSystemMessage(sysAddr, ss.str());
} else {
AMFArrayValue response;
response.Insert("visible", true);
response.Insert("objectID", "Search Results for: " + args);
response.Insert("serverInfo", true);
auto* const info = response.InsertArray("data");
auto& lotSort = info->PushDebug("Sorted by LOT");
for (const auto& [lot, name] : lotToName) {
auto& entry = lotSort.PushDebug<AMFStringValue>(std::to_string(lot)) = name;
}
auto& nameSort = info->PushDebug("Sorted by Name");
for (const auto& [name, lot] : nameToLot) {
auto& entry = nameSort.PushDebug<AMFStringValue>(name) = std::to_string(lot);
}
GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr);
}
}
void Spawn(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -1247,38 +1278,30 @@ namespace DEVGMCommands {
}
void Metrics(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
AMFArrayValue response;
response.Insert("visible", true);
response.Insert("objectID", "Metrics");
response.Insert("serverInfo", true);
auto* info = response.InsertArray("data");
for (const auto variable : Metrics::GetAllMetrics()) {
auto& metricData = info->PushDebug(StringifiedEnum::ToString(variable));
auto* metric = Metrics::GetMetric(variable);
if (metric == nullptr) {
continue;
}
ChatPackets::SendSystemMessage(
sysAddr,
GeneralUtils::ASCIIToUTF16(Metrics::MetricVariableToString(variable)) +
u": " +
GeneralUtils::to_u16string(Metrics::ToMiliseconds(metric->average)) +
u"ms"
);
metricData.PushDebug<AMFStringValue>("Maximum") = std::to_string(Metrics::ToMiliseconds(metric->max)) + "ms";
metricData.PushDebug<AMFStringValue>("Minimum") = std::to_string(Metrics::ToMiliseconds(metric->min)) + "ms";
metricData.PushDebug<AMFStringValue>("Average") = std::to_string(Metrics::ToMiliseconds(metric->average)) + "ms";
metricData.PushDebug<AMFStringValue>("Measurements Count") = std::to_string(metric->measurementSize);
}
ChatPackets::SendSystemMessage(
sysAddr,
u"Peak RSS: " + GeneralUtils::to_u16string(static_cast<float>(static_cast<double>(Metrics::GetPeakRSS()) / 1.024e6)) +
u"MB"
);
ChatPackets::SendSystemMessage(
sysAddr,
u"Current RSS: " + GeneralUtils::to_u16string(static_cast<float>(static_cast<double>(Metrics::GetCurrentRSS()) / 1.024e6)) +
u"MB"
);
ChatPackets::SendSystemMessage(
sysAddr,
u"Process ID: " + GeneralUtils::to_u16string(Metrics::GetProcessID())
);
auto& processInfo = info->PushDebug("Process Info");
processInfo.PushDebug<AMFStringValue>("Peak RSS") = std::to_string(static_cast<double>(Metrics::GetPeakRSS()) / 1.024e6) + "MB";
processInfo.PushDebug<AMFStringValue>("Current RSS") = std::to_string(static_cast<double>(Metrics::GetCurrentRSS()) / 1.024e6) + "MB";
processInfo.PushDebug<AMFIntValue>("Process ID") = Metrics::GetProcessID();
GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, sysAddr);
}
void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
@@ -1310,19 +1333,30 @@ namespace DEVGMCommands {
const auto loops = GeneralUtils::TryParse<uint32_t>(splitArgs[2]);
if (!loops) return;
auto* const lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
auto* const lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
bool found = false;
for (const auto& entry : lootMatrixTable->GetMatrix(lootMatrixIndex.value())) {
for (const auto& loot : lootTableTable->GetTable(entry.LootTableIndex)) {
found = targetLot.value() == loot.itemid;
if (found) break;
}
}
if (!found) {
std::stringstream ss;
ss << "Target LOT " << targetLot.value() << " not found in loot matrix " << lootMatrixIndex.value() << ".";
ChatPackets::SendSystemMessage(sysAddr, ss.str());
return;
}
uint64_t totalRuns = 0;
for (uint32_t i = 0; i < loops; i++) {
while (true) {
const auto lootRoll = Loot::RollLootMatrix(nullptr, lootMatrixIndex.value());
totalRuns += 1;
bool doBreak = false;
for (const auto& kv : lootRoll) {
if (static_cast<uint32_t>(kv.first) == targetLot) {
doBreak = true;
}
}
if (doBreak) break;
if (lootRoll.contains(targetLot.value())) break;
}
}

View File

@@ -275,7 +275,8 @@ namespace GMGreaterThanZeroCommands {
}
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::ToggleGMInvis msg;
msg.Send(entity->GetObjectID());
}
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args) {

View File

@@ -58,6 +58,10 @@ void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel
SEND_PACKET_BROADCAST;
}
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::string& message, const bool broadcast) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message), broadcast);
}
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);

View File

@@ -58,6 +58,7 @@ 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::string& message, bool broadcast = false);
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
void SendMessageFail(const SystemAddress& sysAddr);
void SendRoutedMsg(const LUBitStream& msg, const LWOOBJID targetID, const SystemAddress& sysAddr);

View File

@@ -92,7 +92,7 @@ void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) {
new LDFData<LWOOBJID>(u"ape", self->GetObjectID())
};
auto* anchor = Game::entityManager->CreateEntity(entityInfo);
auto* anchor = Game::entityManager->CreateEntity(entityInfo, nullptr, self);
Game::entityManager->ConstructEntity(anchor);
self->SetVar<LWOOBJID>(u"QB", anchor->GetObjectID());
@@ -140,3 +140,9 @@ void BaseEnemyApe::StunApe(Entity* self, bool stunState) {
self->SetBoolean(u"knockedOut", stunState);
}
}
void BaseEnemyApe::OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) {
if (self.GetVar<LWOOBJID>(u"QB") == childRemoved.childID) {
self.SetVar<LWOOBJID>(u"QB", LWOOBJID_EMPTY);
}
}

View File

@@ -10,6 +10,7 @@ public:
void OnTimerDone(Entity* self, std::string timerName) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) override;
void OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) override;
private:
static void StunApe(Entity* self, bool stunState);
};

View File

@@ -20,24 +20,10 @@ void TreasureChestDragonServer::OnUse(Entity* self, Entity* user) {
if (scriptedActivityComponent == nullptr) {
return;
}
auto rating = 1;
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
if (team != nullptr) {
rating = team->members.size();
for (const auto member : team->members) {
auto* memberObject = Game::entityManager->GetEntity(member);
if (memberObject == nullptr) continue;
Loot::DropActivityLoot(memberObject, self->GetObjectID(), scriptedActivityComponent->GetActivityID(), rating);
}
} else {
Loot::DropActivityLoot(user, self->GetObjectID(), scriptedActivityComponent->GetActivityID(), rating);
}
Loot::DropActivityLoot(user, self->GetObjectID(), scriptedActivityComponent->GetActivityID(), team ? team->members.size() : 1);
self->Smash(self->GetObjectID());
}

View File

@@ -4,6 +4,7 @@
#include "EntityManager.h"
#include "dZoneManager.h"
#include "Loot.h"
#include "dServer.h"
void MinigameTreasureChestServer::OnUse(Entity* self, Entity* user) {
auto* sac = self->GetComponent<ScriptedActivityComponent>();
@@ -18,25 +19,9 @@ void MinigameTreasureChestServer::OnUse(Entity* self, Entity* user) {
UpdatePlayer(self, user->GetObjectID());
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
uint32_t activityRating = 0;
if (team != nullptr) {
for (const auto& teamMemberID : team->members) {
auto* teamMember = Game::entityManager->GetEntity(teamMemberID);
if (teamMember != nullptr) {
activityRating = CalculateActivityRating(self, teamMemberID);
if (self->GetLOT() == frakjawChestId) activityRating = team->members.size();
Loot::DropActivityLoot(teamMember, self->GetObjectID(), sac->GetActivityID(), activityRating);
}
}
} else {
activityRating = CalculateActivityRating(self, user->GetObjectID());
if (self->GetLOT() == frakjawChestId) activityRating = 1;
Loot::DropActivityLoot(user, self->GetObjectID(), sac->GetActivityID(), activityRating);
}
uint32_t activityRating = CalculateActivityRating(self, user->GetObjectID());
if (self->GetLOT() == frakjawChestId || Game::server->GetZoneID() == 1204) activityRating = team != nullptr ? team->members.size() : 1;
Loot::DropActivityLoot(user, self->GetObjectID(), sac->GetActivityID(), activityRating);
sac->PlayerRemove(user->GetObjectID());

View File

@@ -383,6 +383,8 @@ namespace CppScripts {
* @param fire The child info
*/
virtual void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {};
virtual void OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) {};
};
Script* const GetScript(Entity* parent, const std::string& scriptName);

View File

@@ -19,7 +19,7 @@ void NsWinterRaceServer::OnStartup(Entity* self) {
raceSet.push_back(make_unique<LDFData<std::u16string>>("Race_PathName", u"MainPath"));
raceSet.push_back(make_unique<LDFData<int32_t>>("Current_Lap", 1));
raceSet.push_back(make_unique<LDFData<int32_t>>("Number_of_Laps", 3));
raceSet.push_back(make_unique<LDFData<int32_t>>("activityID", 42));
raceSet.push_back(make_unique<LDFData<int32_t>>("activityID", 60));
raceSet.push_back(make_unique<LDFData<int32_t>>("Place_1", 100));
raceSet.push_back(make_unique<LDFData<int32_t>>("Place_2", 90));

View File

@@ -184,7 +184,7 @@ static void DLOG(char ch, void *param) {
static size_t len{};
if (ch != '\n') buf[len++] = ch; // we provide the newline in our logger
if (ch == '\n' || len >= sizeof(buf)) {
LOG_DEBUG("%.*s", static_cast<int>(len), buf);
if (Game::logger) LOG_DEBUG("%.*s", static_cast<int>(len), buf);
len = 0;
}
}