Remove inlines

Clean up macros

more tomorrow

Cleanup and optimize CDActivities table

Remove unused include

Further work on CDActivityRewards

Update MasterServer.cpp

Further animations work

Activities still needs work for a better PK.

fix type

All of these replacements worked

Create internal interface for animations

Allows for user to just call GetAnimationTIme or PlayAnimation rather than passing in arbitrary true false statements
This commit is contained in:
David Markowitz
2023-03-20 06:10:52 -07:00
parent 7671cc6865
commit b432a3f5da
84 changed files with 631 additions and 607 deletions

View File

@@ -592,8 +592,9 @@ void Entity::Initialize() {
m_Components.insert(std::make_pair(eReplicaComponentType::BOUNCER, comp));
}
if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER) > 0 && m_TemplateID != 2365) || m_Character) {
RenderComponent* render = new RenderComponent(this);
int32_t renderaComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
if ((renderaComponentId > 0 && m_TemplateID != 2365) || m_Character) {
RenderComponent* render = new RenderComponent(this, renderaComponentId);
m_Components.insert(std::make_pair(eReplicaComponentType::RENDER, render));
}

View File

@@ -277,13 +277,11 @@ void LeaderboardManager::SendLeaderboard(uint32_t gameID, InfoType infoType, boo
}
LeaderboardType LeaderboardManager::GetLeaderboardType(uint32_t gameID) {
auto* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([=](const CDActivities& entry) {
return (entry.ActivityID == gameID);
});
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
auto activityResult = activitiesTable->GetActivity(gameID);
for (const auto& activity : activities) {
return static_cast<LeaderboardType>(activity.leaderboardType);
if (activityResult.FoundData()) {
return static_cast<LeaderboardType>(activityResult.Data().leaderboardType);
}
return LeaderboardType::None;

View File

@@ -22,7 +22,7 @@
#include "Database.h"
#include "EntityInfo.h"
#include "eMissionTaskType.h"
#include "RenderComponent.h"
std::unordered_map<LOT, PetComponent::PetPuzzleData> PetComponent::buildCache{};
std::unordered_map<LWOOBJID, LWOOBJID> PetComponent::currentActivities{};
@@ -525,7 +525,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
}
GameMessages::SendPlayFXEffect(tamer, -1, u"petceleb", "", LWOOBJID_EMPTY, 1, 1, true);
GameMessages::SendPlayAnimation(tamer, u"rebuild-celebrate");
RenderComponent::PlayAnimation(tamer, u"rebuild-celebrate");
EntityInfo info{};
info.lot = cached->second.puzzleModelLot;

View File

@@ -7,6 +7,8 @@
#include "RebuildComponent.h"
#include "Game.h"
#include "dLogger.h"
#include "RenderComponent.h"
#include "EntityManager.h"
RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t componentID) : Component(parent) {
m_ComponentID = componentID;
@@ -56,23 +58,10 @@ void RailActivatorComponent::OnUse(Entity* originator) {
GameMessages::SendPlayFXEffect(originator->GetObjectID(), m_StartEffect.first, m_StartEffect.second,
std::to_string(m_StartEffect.first));
}
float animationLength = 0.5f;
if (!m_StartAnimation.empty()) {
GameMessages::SendPlayAnimation(originator, m_StartAnimation);
}
float animationLength;
if (m_StartAnimation == u"whirlwind-rail-up-earth") {
animationLength = 1.5f;
} else if (m_StartAnimation == u"whirlwind-rail-up-lightning") {
animationLength = 0.5f;
} else if (m_StartAnimation == u"whirlwind-rail-up-ice") {
animationLength = 0.5f;
} else if (m_StartAnimation == u"whirlwind-rail-up-fire") {
animationLength = 0.5f;
} else {
animationLength = 0.5f;
animationLength = RenderComponent::PlayAnimation(originator, m_StartAnimation);
}
const auto originatorID = originator->GetObjectID();
@@ -111,7 +100,7 @@ void RailActivatorComponent::OnRailMovementReady(Entity* originator) const {
}
if (!m_LoopAnimation.empty()) {
GameMessages::SendPlayAnimation(originator, m_LoopAnimation);
RenderComponent::PlayAnimation(originator, m_LoopAnimation);
}
GameMessages::SendSetRailMovement(originator->GetObjectID(), m_PathDirection, m_Path, m_PathStart,
@@ -146,7 +135,7 @@ void RailActivatorComponent::OnCancelRailMovement(Entity* originator) {
}
if (!m_StopAnimation.empty()) {
GameMessages::SendPlayAnimation(originator, m_StopAnimation);
RenderComponent::PlayAnimation(originator, m_StopAnimation);
}
// Remove the player after they've signalled they're done railing

View File

@@ -16,6 +16,7 @@
#include "Preconditions.h"
#include "Loot.h"
#include "TeamManager.h"
#include "RenderComponent.h"
#include "CppScripts.h"
@@ -510,7 +511,7 @@ void RebuildComponent::CompleteRebuild(Entity* user) {
character->SetPlayerFlag(flagNumber, true);
}
}
GameMessages::SendPlayAnimation(user, u"rebuild-celebrate", 1.09f);
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
}
void RebuildComponent::ResetRebuild(bool failed) {
@@ -520,7 +521,7 @@ void RebuildComponent::ResetRebuild(bool failed) {
GameMessages::SendEnableRebuild(m_Parent, false, false, failed, eFailReason::REASON_NOT_GIVEN, m_ResetTime, builder->GetObjectID());
if (failed) {
GameMessages::SendPlayAnimation(builder, u"rebuild-fail");
RenderComponent::PlayAnimation(builder, u"rebuild-fail");
}
}

View File

@@ -11,72 +11,34 @@
#include "GameMessages.h"
#include "Game.h"
#include "dLogger.h"
#include "CDAnimationsTable.h"
std::unordered_map<int32_t, float> RenderComponent::m_DurationCache{};
RenderComponent::RenderComponent(Entity* parent) : Component(parent) {
RenderComponent::RenderComponent(Entity* parent, int32_t componentId): Component(parent) {
m_Effects = std::vector<Effect*>();
m_LastAnimationName = "";
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM RenderComponent WHERE id = ?;");
query.bind(1, componentId);
auto result = query.execQuery();
return;
/*
auto* table = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
const auto entry = table->GetByIDAndType(parent->GetLOT(), eReplicaComponentType::RENDER);
std::stringstream query;
query << "SELECT effect1, effect2, effect3, effect4, effect5, effect6 FROM RenderComponent WHERE id = " << std::to_string(entry) << ";";
auto result = CDClientDatabase::ExecuteQuery(query.str());
if (result.eof())
{
return;
}
for (auto i = 0; i < 6; ++i)
{
if (result.fieldIsNull(i))
{
continue;
}
const auto id = result.getIntField(i);
if (id <= 0)
{
continue;
}
query.clear();
query << "SELECT effectType, effectName FROM BehaviorEffect WHERE effectID = " << std::to_string(id) << ";";
auto effectResult = CDClientDatabase::ExecuteQuery(query.str());
while (!effectResult.eof())
{
const auto type = effectResult.fieldIsNull(0) ? "" : std::string(effectResult.getStringField(0));
const auto name = effectResult.fieldIsNull(1) ? "" : std::string(effectResult.getStringField(1));
auto* effect = new Effect();
effect->name = name;
effect->type = GeneralUtils::ASCIIToUTF16(type);
effect->scale = 1;
effect->effectID = id;
effect->secondary = LWOOBJID_EMPTY;
m_Effects.push_back(effect);
effectResult.nextRow();
if (!result.eof()) {
auto animationGroupIDs = std::string(result.getStringField("animationGroupIDs", ""));
if (!animationGroupIDs.empty()) {
auto* animationsTable = CDClientManager::Instance().GetTable<CDAnimationsTable>();
auto groupIdsSplit = GeneralUtils::SplitString(animationGroupIDs, ',');
for (auto& groupId : groupIdsSplit) {
int32_t groupIdInt;
if (!GeneralUtils::TryParse(groupId, groupIdInt)) {
Game::logger->Log("RenderComponent", "bad animation group Id %s", groupId.c_str());
continue;
}
m_animationGroupIds.push_back(groupIdInt);
animationsTable->CacheAnimationGroup(groupIdInt);
}
}
}
result.finalize();
*/
}
RenderComponent::~RenderComponent() {
@@ -224,3 +186,47 @@ void RenderComponent::StopEffect(const std::string& name, const bool killImmedia
std::vector<Effect*>& RenderComponent::GetEffects() {
return m_Effects;
}
float RenderComponent::PlayAnimation(Entity* self, const std::u16string& animation, float priority, float scale) {
if (!self) return 0.0f;
return RenderComponent::PlayAnimation(self, GeneralUtils::UTF16ToWTF8(animation), priority, scale);
}
float RenderComponent::PlayAnimation(Entity* self, const std::string& animation, float priority, float scale) {
if (!self) return 0.0f;
return RenderComponent::DoAnimation(self, animation, true, priority, scale);
}
float RenderComponent::GetAnimationTime(Entity* self, const std::u16string& animation) {
if (!self) return 0.0f;
return RenderComponent::GetAnimationTime(self, GeneralUtils::UTF16ToWTF8(animation));
}
float RenderComponent::GetAnimationTime(Entity* self, const std::string& animation) {
if (!self) return 0.0f;
return RenderComponent::DoAnimation(self, animation, false);
}
float RenderComponent::DoAnimation(Entity* self, const std::string& animation, bool sendAnimation, float priority, float scale) {
if (!self) return 0.0f;
auto* renderComponent = self->GetComponent<RenderComponent>();
if (!renderComponent) return 0.0f;
Game::logger->Log("RenderComponent", "looking up animation %s playing anim %i priority %f scale %f", animation.c_str(), sendAnimation, priority, scale);
auto* animationsTable = CDClientManager::Instance().GetTable<CDAnimationsTable>();
for (auto& groupId : renderComponent->m_animationGroupIds) {
Game::logger->Log("RenderComponent", "checking id %i with previous being %s", groupId, renderComponent->GetLastAnimationName().c_str());
auto animationGroup = animationsTable->GetAnimation(animation, renderComponent->GetLastAnimationName(), groupId);
if (animationGroup.FoundData()) {
auto data = animationGroup.Data();
Game::logger->Log("RenderComponent", "animation %s priority %f length %f", data.animation_name.c_str(), data.priority, data.animation_length);
if (sendAnimation) GameMessages::SendPlayAnimation(self, GeneralUtils::ASCIIToUTF16(animation), priority, scale);
renderComponent->SetLastAnimationName(data.animation_name);
return data.animation_length;
}
}
Game::logger->Log("RenderComponent", "unable to find animation %s for lot %i", animation.c_str(), self->GetLOT());
return 0.0f;
}

View File

@@ -58,7 +58,7 @@ class RenderComponent : public Component {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::RENDER;
RenderComponent(Entity* entity);
RenderComponent(Entity* entity, int32_t componentId = -1);
~RenderComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
@@ -104,6 +104,16 @@ public:
*/
std::vector<Effect*>& GetEffects();
static float DoAnimation(Entity* self, const std::string& animation, bool sendAnimation, float priority = 0.0f, float scale = 1.0f);
static float PlayAnimation(Entity* self, const std::u16string& animation, float priority = 0.0f, float scale = 1.0f);
static float PlayAnimation(Entity* self, const std::string& animation, float priority = 0.0f, float scale = 1.0f);
static float GetAnimationTime(Entity* self, const std::string& animation);
static float GetAnimationTime(Entity* self, const std::u16string& animation);
const std::string& GetLastAnimationName() const { return m_LastAnimationName; };
void SetLastAnimationName(const std::string& name) { m_LastAnimationName = name; };
private:
/**
@@ -111,6 +121,11 @@ private:
*/
std::vector<Effect*> m_Effects;
std::vector<int32_t> m_animationGroupIds;
// The last animationName that was played
std::string m_LastAnimationName;
/**
* Cache of queries that look for the length of each effect, indexed by effect ID
*/

View File

@@ -26,13 +26,13 @@
#include "CDActivityRewardsTable.h"
#include "CDActivitiesTable.h"
ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID) : Component(parent) {
ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID): Component(parent) {
m_ActivityID = activityID;
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });
auto activityResult = activitiesTable->GetActivity(m_ActivityID);
for (CDActivities activity : activities) {
m_ActivityInfo = activity;
if (activityResult.FoundData()) {
m_ActivityInfo = activityResult.Data();
const auto mapID = m_ActivityInfo.instanceMapID;
@@ -57,6 +57,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
if (destroyableComponent) {
// check for LMIs and set the loot LMIs
Game::logger->Log("ScriptedActivityComponent", "i am %i with lmi %i", m_Parent->GetLOT(), destroyableComponent->GetLootMatrixID());
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); });
@@ -64,13 +65,13 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
if (activityRewards.size() > 0) {
startingLMI = activityRewards[0].LootMatrixIndex;
Game::logger->Log("ScriptedActivityComponent", "index 0 is %i %i", activityRewards[0].LootMatrixIndex, activityRewards[0].objectTemplate);
}
if (startingLMI > 0) {
// now time for bodge :)
std::vector<CDActivityRewards> objectTemplateActivities = activityRewardsTable->Query([=](CDActivityRewards entry) {return (activityRewards[0].objectTemplate == entry.objectTemplate); });
for (const auto& item : objectTemplateActivities) {
Game::logger->Log("ScriptedActivityComponent", "%i added loot matrix with rating %i index %i objectTemplate %i", m_Parent->GetLOT(), item.activityRating, item.LootMatrixIndex, item.objectTemplate);
if (item.activityRating > 0 && item.activityRating < 5) {
m_ActivityLootMatrices.insert({ item.activityRating, item.LootMatrixIndex });
}
@@ -99,21 +100,22 @@ void ScriptedActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool
void ScriptedActivityComponent::ReloadConfig() {
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });
for (auto activity : activities) {
auto mapID = m_ActivityInfo.instanceMapID;
auto activityResult = activitiesTable->GetActivity(m_ActivityID);
if (activityResult.FoundData()) {
auto data = activityResult.Data();
auto mapID = data.instanceMapID;
if ((mapID == 1203 || mapID == 1261 || mapID == 1303 || mapID == 1403) && Game::config->GetValue("solo_racing") == "1") {
m_ActivityInfo.minTeamSize = 1;
m_ActivityInfo.minTeams = 1;
} else {
m_ActivityInfo.minTeamSize = activity.minTeamSize;
m_ActivityInfo.minTeams = activity.minTeams;
m_ActivityInfo.minTeamSize = data.minTeamSize;
m_ActivityInfo.minTeams = data.minTeams;
}
}
}
void ScriptedActivityComponent::HandleMessageBoxResponse(Entity* player, const std::string& id) {
if (m_ActivityInfo.ActivityID == 103) {
if (m_ActivityID == 103) {
return;
}
@@ -125,7 +127,7 @@ void ScriptedActivityComponent::HandleMessageBoxResponse(Entity* player, const s
}
void ScriptedActivityComponent::PlayerJoin(Entity* player) {
if (m_ActivityInfo.ActivityID == 103 || PlayerIsInQueue(player) || !IsValidActivity(player)) {
if (m_ActivityID == 103 || PlayerIsInQueue(player) || !IsValidActivity(player)) {
return;
}
@@ -390,7 +392,7 @@ void ScriptedActivityComponent::PlayerReady(Entity* player, bool bReady) {
}
ActivityInstance* ScriptedActivityComponent::NewInstance() {
auto* instance = new ActivityInstance(m_Parent, m_ActivityInfo);
auto* instance = new ActivityInstance(m_Parent, this, m_ActivityInfo);
m_Instances.push_back(instance);
return instance;
}
@@ -557,12 +559,12 @@ void ActivityInstance::StartZone() {
void ActivityInstance::RewardParticipant(Entity* participant) {
auto* missionComponent = participant->GetComponent<MissionComponent>();
if (missionComponent) {
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityInfo.ActivityID);
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_OwningComponent->GetActivityID());
}
// First, get the activity data
auto* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == m_ActivityInfo.ActivityID); });
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == m_OwningComponent->GetActivityID()); });
if (!activityRewards.empty()) {
uint32_t minCoins = 0;

View File

@@ -15,13 +15,18 @@
#include "CDActivitiesTable.h"
class ScriptedActivityComponent;
/**
* Represents an instance of an activity, having participants and score
*/
class ActivityInstance {
public:
ActivityInstance(Entity* parent, CDActivities activityInfo) { m_Parent = parent; m_ActivityInfo = activityInfo; };
//~ActivityInstance();
ActivityInstance(Entity* parent, ScriptedActivityComponent* parentComponent, CDActivities activityInfo) {
m_Parent = parent;
m_OwningComponent = parentComponent;
m_ActivityInfo = activityInfo;
};
/**
* Adds an entity to this activity
@@ -88,6 +93,11 @@ private:
*/
Entity* m_Parent;
/**
* The component that owns this activity (the ScriptedActivityComponent)
*/
ScriptedActivityComponent* m_OwningComponent;
/**
* All the participants of this activity
*/
@@ -212,7 +222,7 @@ public:
* Returns the ID of this activity
* @return the ID of this activity
*/
int GetActivityID() { return m_ActivityInfo.ActivityID; }
int GetActivityID() { return m_ActivityID; }
/**
* Returns if this activity has a lobby, e.g. if it needs to instance players to some other map

View File

@@ -1,6 +1,7 @@
#include "SwitchComponent.h"
#include "EntityManager.h"
#include "eTriggerEventType.h"
#include "RenderComponent.h"
std::vector<SwitchComponent*> SwitchComponent::petSwitches;
@@ -59,7 +60,7 @@ void SwitchComponent::EntityEnter(Entity* entity) {
if (m_PetBouncer != nullptr) {
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 2602, u"pettriggeractive", "BounceEffect", LWOOBJID_EMPTY, 1, 1, true);
GameMessages::SendPlayAnimation(m_Parent, u"engaged", 0, 1);
RenderComponent::PlayAnimation(m_Parent, u"engaged");
m_PetBouncer->SetPetBouncerEnabled(true);
} else {
EntityManager::Instance()->SerializeEntity(m_Parent);

View File

@@ -34,6 +34,7 @@
#include "eRacingTaskParam.h"
#include "eMissionTaskType.h"
#include "eMissionState.h"
#include "RenderComponent.h"
#include <sstream>
#include <future>
@@ -5110,7 +5111,7 @@ void GameMessages::HandlePlayEmote(RakNet::BitStream* inStream, Entity* entity)
if (emote) sAnimationName = emote->animationName;
}
GameMessages::SendPlayAnimation(entity, GeneralUtils::ASCIIToUTF16(sAnimationName));
RenderComponent::PlayAnimation(entity, sAnimationName);
}
void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {

View File

@@ -17,6 +17,7 @@
#include "MissionComponent.h"
#include "eMissionState.h"
#include "eReplicaComponentType.h"
#include "Metrics.hpp"
LootGenerator::LootGenerator() {
CDLootTableTable* lootTableTable = CDClientManager::Instance().GetTable<CDLootTableTable>();

View File

@@ -76,6 +76,7 @@
#include "TriggerComponent.h"
#include "eServerDisconnectIdentifiers.h"
#include "eReplicaComponentType.h"
#include "RenderComponent.h"
#include "CDObjectsTable.h"
#include "CDZoneTableTable.h"
@@ -418,11 +419,11 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if ((chatCommand == "playanimation" || chatCommand == "playanim") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
std::u16string anim = GeneralUtils::ASCIIToUTF16(args[0], args[0].size());
GameMessages::SendPlayAnimation(entity, anim);
RenderComponent::PlayAnimation(entity, anim);
auto* possessorComponent = entity->GetComponent<PossessorComponent>();
if (possessorComponent) {
auto* possessedComponent = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
if (possessedComponent) GameMessages::SendPlayAnimation(possessedComponent, anim);
if (possessedComponent) RenderComponent::PlayAnimation(possessedComponent, anim);
}
}
@@ -1955,7 +1956,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
EntityManager::Instance()->SerializeEntity(closest);
} else if (args[1] == "-a" && args.size() >= 3) {
GameMessages::SendPlayAnimation(closest, GeneralUtils::UTF8ToUTF16(args[2]));
RenderComponent::PlayAnimation(closest, args.at(2));
} else if (args[1] == "-s") {
for (auto* entry : closest->GetSettings()) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::UTF8ToUTF16(entry->GetString()));