mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Add Animation Table logic
This commit is contained in:
@@ -593,9 +593,9 @@ void Entity::Initialize() {
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::BOUNCER, comp));
|
||||
}
|
||||
|
||||
int32_t renderaComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
|
||||
if ((renderaComponentId > 0 && m_TemplateID != 2365) || m_Character) {
|
||||
RenderComponent* render = new RenderComponent(this, renderaComponentId);
|
||||
int32_t renderComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
|
||||
if ((renderComponentId > 0 && m_TemplateID != 2365) || m_Character) {
|
||||
RenderComponent* render = new RenderComponent(this, renderComponentId);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::RENDER, render));
|
||||
}
|
||||
|
||||
|
@@ -277,11 +277,13 @@ void LeaderboardManager::SendLeaderboard(uint32_t gameID, InfoType infoType, boo
|
||||
}
|
||||
|
||||
LeaderboardType LeaderboardManager::GetLeaderboardType(uint32_t gameID) {
|
||||
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
auto activityResult = activitiesTable->GetActivity(gameID);
|
||||
auto* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([=](const CDActivities& entry) {
|
||||
return (entry.ActivityID == gameID);
|
||||
});
|
||||
|
||||
if (activityResult.FoundData()) {
|
||||
return static_cast<LeaderboardType>(activityResult.Data().leaderboardType);
|
||||
for (const auto& activity : activities) {
|
||||
return static_cast<LeaderboardType>(activity.leaderboardType);
|
||||
}
|
||||
|
||||
return LeaderboardType::None;
|
||||
|
@@ -18,6 +18,8 @@ std::unordered_map<int32_t, float> RenderComponent::m_DurationCache{};
|
||||
RenderComponent::RenderComponent(Entity* parent, int32_t componentId): Component(parent) {
|
||||
m_Effects = std::vector<Effect*>();
|
||||
m_LastAnimationName = "";
|
||||
if (componentId == -1) return;
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM RenderComponent WHERE id = ?;");
|
||||
query.bind(1, componentId);
|
||||
auto result = query.execQuery();
|
||||
@@ -210,23 +212,21 @@ float RenderComponent::GetAnimationTime(Entity* self, const std::string& animati
|
||||
|
||||
|
||||
float RenderComponent::DoAnimation(Entity* self, const std::string& animation, bool sendAnimation, float priority, float scale) {
|
||||
if (!self) return 0.0f;
|
||||
float returnlength = 0.0f;
|
||||
if (!self) return returnlength;
|
||||
auto* renderComponent = self->GetComponent<RenderComponent>();
|
||||
if (!renderComponent) return 0.0f;
|
||||
if (!renderComponent) return returnlength;
|
||||
|
||||
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;
|
||||
returnlength = data.animation_length;
|
||||
}
|
||||
}
|
||||
Game::logger->Log("RenderComponent", "unable to find animation %s for lot %i", animation.c_str(), self->GetLOT());
|
||||
return 0.0f;
|
||||
if (sendAnimation) GameMessages::SendPlayAnimation(self, GeneralUtils::ASCIIToUTF16(animation), priority, scale);
|
||||
if (returnlength == 0.0f) Game::logger->Log("RenderComponent", "WARNING: Unable to find animation %s for lot %i in any group.", animation.c_str(), self->GetLOT());
|
||||
return returnlength;
|
||||
}
|
||||
|
@@ -104,6 +104,22 @@ public:
|
||||
*/
|
||||
std::vector<Effect*>& GetEffects();
|
||||
|
||||
/**
|
||||
* Verifies that an animation can be played on this entity by checking
|
||||
* if it has the animation assigned to its group. If it does, the animation is echo'd
|
||||
* down to all clients to be played and the duration of the played animation is returned.
|
||||
* If the animation did not exist or the function was called in an invalid state, 0 is returned.
|
||||
*
|
||||
* The logic here matches the exact client logic.
|
||||
*
|
||||
* @param self The entity that wants to play an animation
|
||||
* @param animation The animation_type (animationID in the client) to be played.
|
||||
* @param sendAnimation Whether or not to echo the animation down to all clients.
|
||||
* @param priority The priority of the animation. Only used if sendAnimation is true.
|
||||
* @param scale The scale of the animation. Only used if sendAnimation is true.
|
||||
*
|
||||
* @return The duration of the animation that was played.
|
||||
*/
|
||||
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);
|
||||
|
@@ -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>();
|
||||
auto activityResult = activitiesTable->GetActivity(m_ActivityID);
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });
|
||||
|
||||
if (activityResult.FoundData()) {
|
||||
m_ActivityInfo = activityResult.Data();
|
||||
for (CDActivities activity : activities) {
|
||||
m_ActivityInfo = activity;
|
||||
|
||||
const auto mapID = m_ActivityInfo.instanceMapID;
|
||||
|
||||
@@ -57,7 +57,6 @@ 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()); });
|
||||
|
||||
@@ -65,13 +64,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 });
|
||||
}
|
||||
@@ -100,22 +99,21 @@ void ScriptedActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool
|
||||
|
||||
void ScriptedActivityComponent::ReloadConfig() {
|
||||
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
auto activityResult = activitiesTable->GetActivity(m_ActivityID);
|
||||
if (activityResult.FoundData()) {
|
||||
auto data = activityResult.Data();
|
||||
auto mapID = data.instanceMapID;
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });
|
||||
for (auto activity : activities) {
|
||||
auto mapID = m_ActivityInfo.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 = data.minTeamSize;
|
||||
m_ActivityInfo.minTeams = data.minTeams;
|
||||
m_ActivityInfo.minTeamSize = activity.minTeamSize;
|
||||
m_ActivityInfo.minTeams = activity.minTeams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptedActivityComponent::HandleMessageBoxResponse(Entity* player, const std::string& id) {
|
||||
if (m_ActivityID == 103) {
|
||||
if (m_ActivityInfo.ActivityID == 103) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,7 +125,7 @@ void ScriptedActivityComponent::HandleMessageBoxResponse(Entity* player, const s
|
||||
}
|
||||
|
||||
void ScriptedActivityComponent::PlayerJoin(Entity* player) {
|
||||
if (m_ActivityID == 103 || PlayerIsInQueue(player) || !IsValidActivity(player)) {
|
||||
if (m_ActivityInfo.ActivityID == 103 || PlayerIsInQueue(player) || !IsValidActivity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -392,7 +390,7 @@ void ScriptedActivityComponent::PlayerReady(Entity* player, bool bReady) {
|
||||
}
|
||||
|
||||
ActivityInstance* ScriptedActivityComponent::NewInstance() {
|
||||
auto* instance = new ActivityInstance(m_Parent, this, m_ActivityInfo);
|
||||
auto* instance = new ActivityInstance(m_Parent, m_ActivityInfo);
|
||||
m_Instances.push_back(instance);
|
||||
return instance;
|
||||
}
|
||||
@@ -559,12 +557,12 @@ void ActivityInstance::StartZone() {
|
||||
void ActivityInstance::RewardParticipant(Entity* participant) {
|
||||
auto* missionComponent = participant->GetComponent<MissionComponent>();
|
||||
if (missionComponent) {
|
||||
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_OwningComponent->GetActivityID());
|
||||
missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityInfo.ActivityID);
|
||||
}
|
||||
|
||||
// First, get the activity data
|
||||
auto* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == m_OwningComponent->GetActivityID()); });
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == m_ActivityInfo.ActivityID); });
|
||||
|
||||
if (!activityRewards.empty()) {
|
||||
uint32_t minCoins = 0;
|
||||
|
@@ -15,18 +15,13 @@
|
||||
|
||||
#include "CDActivitiesTable.h"
|
||||
|
||||
class ScriptedActivityComponent;
|
||||
|
||||
/**
|
||||
* Represents an instance of an activity, having participants and score
|
||||
*/
|
||||
class ActivityInstance {
|
||||
public:
|
||||
ActivityInstance(Entity* parent, ScriptedActivityComponent* parentComponent, CDActivities activityInfo) {
|
||||
m_Parent = parent;
|
||||
m_OwningComponent = parentComponent;
|
||||
m_ActivityInfo = activityInfo;
|
||||
};
|
||||
ActivityInstance(Entity* parent, CDActivities activityInfo) { m_Parent = parent; m_ActivityInfo = activityInfo; };
|
||||
//~ActivityInstance();
|
||||
|
||||
/**
|
||||
* Adds an entity to this activity
|
||||
@@ -93,11 +88,6 @@ private:
|
||||
*/
|
||||
Entity* m_Parent;
|
||||
|
||||
/**
|
||||
* The component that owns this activity (the ScriptedActivityComponent)
|
||||
*/
|
||||
ScriptedActivityComponent* m_OwningComponent;
|
||||
|
||||
/**
|
||||
* All the participants of this activity
|
||||
*/
|
||||
@@ -222,7 +212,7 @@ public:
|
||||
* Returns the ID of this activity
|
||||
* @return the ID of this activity
|
||||
*/
|
||||
int GetActivityID() { return m_ActivityID; }
|
||||
int GetActivityID() { return m_ActivityInfo.ActivityID; }
|
||||
|
||||
/**
|
||||
* Returns if this activity has a lobby, e.g. if it needs to instance players to some other map
|
||||
|
@@ -17,7 +17,6 @@
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionState.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "Metrics.hpp"
|
||||
|
||||
LootGenerator::LootGenerator() {
|
||||
CDLootTableTable* lootTableTable = CDClientManager::Instance().GetTable<CDLootTableTable>();
|
||||
|
Reference in New Issue
Block a user