mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-16 20:24:39 -06:00
Compare commits
13 Commits
EmosewaMC-
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40fef36530 | ||
|
|
bf020baa17 | ||
|
|
a713216540 | ||
|
|
ea86a708e4 | ||
|
|
ca7424cbeb | ||
|
|
991e55f305 | ||
|
|
5410acffaa | ||
|
|
86f8601bbd | ||
|
|
4658318a3a | ||
| 11d44ffb98 | |||
|
|
2fb16420f3 | ||
|
|
96089a8d9a | ||
|
|
eac50acfcc |
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -937,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
|
||||
|
||||
@@ -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(static_cast<float>(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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user