mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Merge branch 'main' into Log-Line-Cleaning
This commit is contained in:
@@ -74,7 +74,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
|
||||
includeFaction = 1;
|
||||
}
|
||||
|
||||
for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction))
|
||||
for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction, m_TargetSelf == 1))
|
||||
{
|
||||
auto* entity = EntityManager::Instance()->GetEntity(validTarget);
|
||||
|
||||
@@ -155,4 +155,6 @@ void AreaOfEffectBehavior::Load()
|
||||
this->m_ignoreFaction = GetInt("ignore_faction");
|
||||
|
||||
this->m_includeFaction = GetInt("include_faction");
|
||||
|
||||
this->m_TargetSelf = GetInt("target_self");
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@ public:
|
||||
int32_t m_ignoreFaction;
|
||||
|
||||
int32_t m_includeFaction;
|
||||
|
||||
int32_t m_TargetSelf;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
|
@@ -149,7 +149,7 @@ void BehaviorContext::SyncBehavior(const uint32_t syncId, RakNet::BitStream* bit
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
behavior->Sync(this, bitStream, branch);
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ void BehaviorContext::Reset()
|
||||
this->scheduledUpdates.clear();
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction) const
|
||||
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf) const
|
||||
{
|
||||
auto* entity = EntityManager::Instance()->GetEntity(this->caster);
|
||||
|
||||
@@ -353,21 +353,20 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && !entity->HasComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS) && targets.empty()))
|
||||
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty()))
|
||||
{
|
||||
DestroyableComponent* destroyableComponent;
|
||||
DestroyableComponent* destroyableComponent;
|
||||
if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent))
|
||||
{
|
||||
return targets;
|
||||
}
|
||||
|
||||
auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS);
|
||||
|
||||
for (auto* candidate : entities)
|
||||
{
|
||||
const auto id = candidate->GetObjectID();
|
||||
|
||||
if (destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction))
|
||||
if ((id != entity->GetObjectID() || targetSelf) && destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction))
|
||||
{
|
||||
targets.push_back(id);
|
||||
}
|
||||
|
@@ -102,7 +102,7 @@ struct BehaviorContext
|
||||
|
||||
void Reset();
|
||||
|
||||
std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0) const;
|
||||
std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0, const bool targetSelf = false) const;
|
||||
|
||||
explicit BehaviorContext(LWOOBJID originator, bool calculation = false);
|
||||
|
||||
|
@@ -1,44 +1,81 @@
|
||||
#include "ForceMovementBehavior.h"
|
||||
|
||||
#include "BehaviorBranchContext.h"
|
||||
#include "BehaviorContext.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch)
|
||||
{
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t handle;
|
||||
|
||||
bitStream->Read(handle);
|
||||
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
uint32_t handle;
|
||||
bitStream->Read(handle);
|
||||
context->RegisterSyncBehavior(handle, this, branch);
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
|
||||
{
|
||||
uint32_t next;
|
||||
uint32_t next;
|
||||
bitStream->Read(next);
|
||||
|
||||
bitStream->Read(next);
|
||||
LWOOBJID target;
|
||||
bitStream->Read(target);
|
||||
|
||||
LWOOBJID target;
|
||||
branch.target = target;
|
||||
auto* behavior = CreateBehavior(next);
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
bitStream->Read(target);
|
||||
void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* behavior = CreateBehavior(next);
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
|
||||
branch.target = target;
|
||||
if (m_Forward == 1) {
|
||||
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
|
||||
}
|
||||
|
||||
behavior->Handle(context, bitStream, branch);
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
const auto skillHandle = context->GetUniqueSkillId();
|
||||
bitStream->Write(skillHandle);
|
||||
|
||||
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::Load()
|
||||
{
|
||||
this->m_hitAction = GetAction("hit_action");
|
||||
|
||||
this->m_hitEnemyAction = GetAction("hit_action_enemy");
|
||||
|
||||
this->m_hitFactionAction = GetAction("hit_action_faction");
|
||||
this->m_hitAction = GetAction("hit_action");
|
||||
this->m_hitEnemyAction = GetAction("hit_action_enemy");
|
||||
this->m_hitFactionAction = GetAction("hit_action_faction");
|
||||
this->m_Duration = GetFloat("duration");
|
||||
this->m_Forward = GetFloat("forward");
|
||||
this->m_Left = GetFloat("left");
|
||||
this->m_Yaw = GetFloat("yaw");
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
|
||||
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
|
||||
controllablePhysicsComponent->SetVelocity({});
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
this->m_hitAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
|
||||
}
|
||||
|
@@ -9,6 +9,11 @@ public:
|
||||
Behavior* m_hitEnemyAction;
|
||||
|
||||
Behavior* m_hitFactionAction;
|
||||
|
||||
float_t m_Duration;
|
||||
float_t m_Forward;
|
||||
float_t m_Left;
|
||||
float_t m_Yaw;
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
@@ -18,8 +23,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void SyncCalculation(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
|
||||
void Load() override;
|
||||
|
@@ -129,6 +129,9 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
|
||||
BaseCombatAIComponent::~BaseCombatAIComponent() {
|
||||
if (m_dpEntity)
|
||||
dpWorld::Instance().RemoveEntity(m_dpEntity);
|
||||
|
||||
if (m_dpEntityEnemy)
|
||||
dpWorld::Instance().RemoveEntity(m_dpEntityEnemy);
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::Update(const float deltaTime) {
|
||||
|
@@ -769,26 +769,33 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
if (team != nullptr && m_Parent->GetComponent<BaseCombatAIComponent>() != nullptr)
|
||||
{
|
||||
LWOOBJID specificOwner = LWOOBJID_EMPTY;
|
||||
auto* scriptedActivityComponent = m_Parent->GetComponent<ScriptedActivityComponent>();
|
||||
uint32_t teamSize = team->members.size();
|
||||
uint32_t lootMatrixId = GetLootMatrixID();
|
||||
|
||||
if (team->lootOption == 0) // Round robin
|
||||
{
|
||||
specificOwner = TeamManager::Instance()->GetNextLootOwner(team);
|
||||
if (scriptedActivityComponent) {
|
||||
lootMatrixId = scriptedActivityComponent->GetLootMatrixForTeamSize(teamSize);
|
||||
}
|
||||
|
||||
for (const auto memberId : team->members)
|
||||
{
|
||||
if (specificOwner != LWOOBJID_EMPTY && memberId != specificOwner) continue;
|
||||
if (team->lootOption == 0) { // Round robin
|
||||
specificOwner = TeamManager::Instance()->GetNextLootOwner(team);
|
||||
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = EntityManager::Instance()->GetEntity(specificOwner);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
if (member) LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
|
||||
Loot::DropLoot(member, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
if (member == nullptr) continue;
|
||||
|
||||
LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Loot::DropLoot(owner, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
else { // drop loot for non team user
|
||||
LootGenerator::Instance().DropLoot(owner, m_Parent, GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -815,7 +822,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
coinsTotal -= coinsToLoose;
|
||||
|
||||
Loot::DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
|
||||
LootGenerator::Instance().DropLoot(m_Parent, m_Parent, -1, coinsToLoose, coinsToLoose);
|
||||
}
|
||||
|
||||
character->SetCoins(coinsTotal);
|
||||
|
@@ -317,7 +317,9 @@ void RacingControlComponent::OnRequestDie(Entity *player) {
|
||||
return;
|
||||
}
|
||||
|
||||
racingPlayer.smashedTimes++;
|
||||
if (!racingPlayer.noSmashOnReload) {
|
||||
racingPlayer.smashedTimes++;
|
||||
}
|
||||
|
||||
// Reset player to last checkpoint
|
||||
GameMessages::SendRacingSetPlayerResetInfo(
|
||||
@@ -390,7 +392,7 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity *player,
|
||||
// Calculate the score, different loot depending on player count
|
||||
const auto score = m_LoadedPlayers * 10 + data->finished;
|
||||
|
||||
Loot::GiveActivityLoot(player, m_Parent, m_ActivityID, score);
|
||||
LootGenerator::Instance().GiveActivityLoot(player, m_Parent, m_ActivityID, score);
|
||||
|
||||
// Giving rewards
|
||||
GameMessages::SendNotifyRacingClient(
|
||||
|
@@ -452,7 +452,7 @@ void RebuildComponent::CompleteRebuild(Entity* user) {
|
||||
missionComponent->Progress(MissionTaskType::MISSION_TASK_TYPE_ACTIVITY, m_ActivityId);
|
||||
}
|
||||
|
||||
Loot::DropActivityLoot(builder, m_Parent, m_ActivityId, 1);
|
||||
LootGenerator::Instance().DropActivityLoot(builder, m_Parent, m_ActivityId, 1);
|
||||
}
|
||||
|
||||
m_Builder = LWOOBJID_EMPTY;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include "GeneralUtils.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "dConfig.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activityID) : Component(parent)
|
||||
{
|
||||
@@ -43,6 +44,31 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent) {
|
||||
// check for LMIs and set the loot LMIs
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable<CDActivityRewardsTable>("ActivityRewards");
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); });
|
||||
|
||||
uint32_t startingLMI = 0;
|
||||
|
||||
if (activityRewards.size() > 0) {
|
||||
startingLMI = activityRewards[0].LootMatrixIndex;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (item.activityRating > 0 && item.activityRating < 5) {
|
||||
m_ActivityLootMatrices.insert({ item.activityRating, item.LootMatrixIndex });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptedActivityComponent::~ScriptedActivityComponent()
|
||||
@@ -524,7 +550,7 @@ void ActivityInstance::RewardParticipant(Entity* participant) {
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
|
||||
Loot::DropLoot(participant, m_Parent, activityRewards[0].LootMatrixIndex, minCoins, maxCoins);
|
||||
LootGenerator::Instance().DropLoot(participant, m_Parent, activityRewards[0].LootMatrixIndex, minCoins, maxCoins);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -328,6 +328,13 @@ public:
|
||||
* @param mapID the map ID to set
|
||||
*/
|
||||
void SetInstanceMapID(uint32_t mapID) { m_ActivityInfo.instanceMapID = mapID; };
|
||||
|
||||
/**
|
||||
* Returns the LMI that this activity points to for a team size
|
||||
* @param teamSize the team size to get the LMI for
|
||||
* @return the LMI that this activity points to for a team size
|
||||
*/
|
||||
uint32_t GetLootMatrixForTeamSize(uint32_t teamSize) { return m_ActivityLootMatrices[teamSize]; }
|
||||
private:
|
||||
|
||||
/**
|
||||
@@ -349,6 +356,11 @@ private:
|
||||
* All the activity score for the players in this activity
|
||||
*/
|
||||
std::vector<ActivityPlayer*> m_ActivityPlayers;
|
||||
|
||||
/**
|
||||
* LMIs for team sizes
|
||||
*/
|
||||
std::unordered_map<uint32_t, uint32_t> m_ActivityLootMatrices;
|
||||
};
|
||||
|
||||
#endif // SCRIPTEDACTIVITYCOMPONENT_H
|
||||
|
@@ -333,14 +333,14 @@ bool Item::UseNonEquip()
|
||||
{
|
||||
std::unordered_map<LOT, int32_t> result {};
|
||||
|
||||
Loot::CalculateLootMatrix(pack.LootMatrixIndex, entityParent, result);
|
||||
result = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
||||
|
||||
if (!inventory->GetComponent()->HasSpaceForLoot(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Loot::GiveLoot(inventory->GetComponent()->GetParent(), result);
|
||||
LootGenerator::Instance().GiveLoot(inventory->GetComponent()->GetParent(), result);
|
||||
}
|
||||
|
||||
inventory->GetComponent()->RemoveItem(lot, 1);
|
||||
|
@@ -1,384 +1,389 @@
|
||||
#include "Loot.h"
|
||||
#include "GameMessages.h"
|
||||
|
||||
#include "CDClientManager.h"
|
||||
#include "CDLootMatrixTable.h"
|
||||
#include "CDLootTableTable.h"
|
||||
|
||||
#include "SimplePhysicsComponent.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "TeamManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
std::vector<CDLootTable> Loot::GetLootOfRarity(const std::vector<CDLootTable> &lootTable, uint32_t rarity) {
|
||||
std::vector<CDLootTable> refinedLoot;
|
||||
for (auto loot : lootTable) {
|
||||
CDItemComponent item = Inventory::FindItemComponent(loot.itemid);
|
||||
if (item.rarity == rarity) {
|
||||
refinedLoot.push_back(loot);
|
||||
}
|
||||
else if (item.rarity == 0) {
|
||||
refinedLoot.push_back(loot); // powerups
|
||||
}
|
||||
}
|
||||
#include "Loot.h"
|
||||
|
||||
return refinedLoot;
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDItemComponentTable.h"
|
||||
#include "CDLootMatrixTable.h"
|
||||
#include "CDLootTableTable.h"
|
||||
#include "CDRarityTableTable.h"
|
||||
#include "Character.h"
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "MissionComponent.h"
|
||||
|
||||
LootGenerator::LootGenerator() {
|
||||
CDLootTableTable* lootTableTable = CDClientManager::Instance()->GetTable<CDLootTableTable>("LootTable");
|
||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
|
||||
CDItemComponentTable* itemComponentTable = CDClientManager::Instance()->GetTable<CDItemComponentTable>("ItemComponent");
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::Instance()->GetTable<CDLootMatrixTable>("LootMatrix");
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::Instance()->GetTable<CDRarityTableTable>("RarityTable");
|
||||
|
||||
// ==============================
|
||||
// Cache Item Rarities
|
||||
// ==============================
|
||||
|
||||
std::vector<uint32_t> uniqueItems;
|
||||
|
||||
for (const CDLootTable& loot : lootTableTable->GetEntries()) {
|
||||
uniqueItems.push_back(loot.itemid);
|
||||
}
|
||||
|
||||
// filter out duplicates
|
||||
std::sort(uniqueItems.begin(), uniqueItems.end());
|
||||
uniqueItems.erase(std::unique(uniqueItems.begin(), uniqueItems.end()), uniqueItems.end());
|
||||
|
||||
for (const uint32_t itemID : uniqueItems) {
|
||||
uint32_t itemComponentID = componentsRegistryTable->GetByIDAndType(itemID, COMPONENT_TYPE_ITEM);
|
||||
const CDItemComponent& item = itemComponentTable->GetItemComponentByID(itemComponentID);
|
||||
|
||||
m_ItemRarities.insert({itemID, item.rarity});
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Cache Rarity Tables
|
||||
// ==============================
|
||||
|
||||
std::vector<uint32_t> uniqueRarityIndices;
|
||||
|
||||
for (const CDRarityTable& rarity : rarityTableTable->GetEntries()) {
|
||||
uniqueRarityIndices.push_back(rarity.RarityTableIndex);
|
||||
}
|
||||
|
||||
// filter out duplicates
|
||||
std::sort(uniqueRarityIndices.begin(), uniqueRarityIndices.end());
|
||||
uniqueRarityIndices.erase(std::unique(uniqueRarityIndices.begin(), uniqueRarityIndices.end()), uniqueRarityIndices.end());
|
||||
|
||||
for (const uint32_t index : uniqueRarityIndices) {
|
||||
std::vector<CDRarityTable> table = rarityTableTable->Query([index](const CDRarityTable& entry) { return entry.RarityTableIndex == index; });
|
||||
|
||||
RarityTable rarityTable;
|
||||
|
||||
for (const CDRarityTable& entry : table) {
|
||||
RarityTableEntry rarity{entry.rarity, entry.randmax};
|
||||
rarityTable.push_back(rarity);
|
||||
}
|
||||
|
||||
// sort in descending order based on randMax
|
||||
std::sort(rarityTable.begin(), rarityTable.end(), [](const RarityTableEntry& x, const RarityTableEntry& y) { return x.randMax > y.randMax; });
|
||||
|
||||
m_RarityTables.insert({index, rarityTable});
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Cache Loot Matrices
|
||||
// ==============================
|
||||
|
||||
std::vector<uint32_t> uniqueMatrixIndices;
|
||||
|
||||
for (const CDLootMatrix& matrix : lootMatrixTable->GetEntries()) {
|
||||
uniqueMatrixIndices.push_back(matrix.LootMatrixIndex);
|
||||
}
|
||||
|
||||
// filter out duplicates
|
||||
std::sort(uniqueMatrixIndices.begin(), uniqueMatrixIndices.end());
|
||||
uniqueMatrixIndices.erase(std::unique(uniqueMatrixIndices.begin(), uniqueMatrixIndices.end()), uniqueMatrixIndices.end());
|
||||
|
||||
for (const uint32_t index : uniqueMatrixIndices) {
|
||||
std::vector<CDLootMatrix> matrix = lootMatrixTable->Query([index](const CDLootMatrix& entry) { return entry.LootMatrixIndex == index; });
|
||||
|
||||
LootMatrix lootMatrix;
|
||||
|
||||
for (const CDLootMatrix& entry : matrix) {
|
||||
LootMatrixEntry matrixEntry{entry.LootTableIndex, entry.RarityTableIndex, entry.percent, entry.minToDrop, entry.maxToDrop};
|
||||
lootMatrix.push_back(matrixEntry);
|
||||
}
|
||||
|
||||
m_LootMatrices.insert({index, lootMatrix});
|
||||
}
|
||||
|
||||
// ==============================
|
||||
// Cache Loot Tables
|
||||
// ==============================
|
||||
|
||||
std::vector<uint32_t> uniqueTableIndices;
|
||||
|
||||
for (const CDLootTable& entry : lootTableTable->GetEntries()) {
|
||||
uniqueTableIndices.push_back(entry.LootTableIndex);
|
||||
}
|
||||
|
||||
// filter out duplicates
|
||||
std::sort(uniqueTableIndices.begin(), uniqueTableIndices.end());
|
||||
uniqueTableIndices.erase(std::unique(uniqueTableIndices.begin(), uniqueTableIndices.end()), uniqueTableIndices.end());
|
||||
|
||||
for (const uint32_t index : uniqueTableIndices) {
|
||||
std::vector<CDLootTable> entries = lootTableTable->Query([index](const CDLootTable& entry) { return entry.LootTableIndex == index; });
|
||||
|
||||
LootTable lootTable;
|
||||
|
||||
for (const CDLootTable& entry : entries) {
|
||||
LootTableEntry tableEntry{(LOT)entry.itemid, entry.MissionDrop};
|
||||
lootTable.push_back(tableEntry);
|
||||
}
|
||||
|
||||
// sort by item rarity descending
|
||||
std::sort(lootTable.begin(), lootTable.end(), [&](const LootTableEntry& x, const LootTableEntry& y) {
|
||||
return m_ItemRarities[x.itemID] > m_ItemRarities[y.itemID];
|
||||
});
|
||||
|
||||
m_LootTables.insert({index, lootTable});
|
||||
}
|
||||
}
|
||||
|
||||
void Loot::GiveLoot(Entity* user, uint32_t lootMatrixID) {
|
||||
user = user->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
std::unordered_map<LOT, int32_t> LootGenerator::RollLootMatrix(Entity* player, uint32_t matrixIndex) {
|
||||
auto* missionComponent = player->GetComponent<MissionComponent>();
|
||||
|
||||
std::unordered_map<LOT, int32_t> result {};
|
||||
std::unordered_map<LOT, int32_t> drops;
|
||||
|
||||
CalculateLootMatrix(lootMatrixID, user, result);
|
||||
if (missionComponent == nullptr) {
|
||||
return drops;
|
||||
}
|
||||
|
||||
GiveLoot(user, result);
|
||||
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
||||
|
||||
for (const LootMatrixEntry& entry : matrix) {
|
||||
if (GeneralUtils::GenerateRandomNumber<float>(0, 1) < entry.percent) {
|
||||
const LootTable& lootTable = m_LootTables[entry.lootTableIndex];
|
||||
const RarityTable& rarityTable = m_RarityTables[entry.rarityTableIndex];
|
||||
|
||||
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
||||
for (uint32_t i = 0; i < dropCount; ++i) {
|
||||
uint32_t maxRarity = 1;
|
||||
|
||||
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
|
||||
for (const RarityTableEntry& rarity : rarityTable) {
|
||||
if (rarity.randMax >= rarityRoll) {
|
||||
maxRarity = rarity.rarity;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool rarityFound = false;
|
||||
std::vector<LootTableEntry> possibleDrops;
|
||||
|
||||
for (const LootTableEntry& loot : lootTable) {
|
||||
uint32_t rarity = m_ItemRarities[loot.itemID];
|
||||
|
||||
if (rarity == maxRarity) {
|
||||
possibleDrops.push_back(loot);
|
||||
rarityFound = true;
|
||||
} else if (rarity < maxRarity && !rarityFound) {
|
||||
possibleDrops.push_back(loot);
|
||||
maxRarity = rarity;
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleDrops.size() > 0) {
|
||||
LootTableEntry drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
||||
|
||||
// filter out uneeded mission items
|
||||
if (drop.isMissionDrop && !missionComponent->RequiresItem(drop.itemID))
|
||||
continue;
|
||||
|
||||
// convert faction token proxy
|
||||
if (drop.itemID == 13763) {
|
||||
if (missionComponent->GetMissionState(545) == MissionState::MISSION_STATE_COMPLETE)
|
||||
drop.itemID = 8318; // "Assembly Token"
|
||||
else if (missionComponent->GetMissionState(556) == MissionState::MISSION_STATE_COMPLETE)
|
||||
drop.itemID = 8321; // "Venture League Token"
|
||||
else if (missionComponent->GetMissionState(567) == MissionState::MISSION_STATE_COMPLETE)
|
||||
drop.itemID = 8319; // "Sentinels Token"
|
||||
else if (missionComponent->GetMissionState(578) == MissionState::MISSION_STATE_COMPLETE)
|
||||
drop.itemID = 8320; // "Paradox Token"
|
||||
}
|
||||
|
||||
if (drop.itemID == 13763) {
|
||||
continue;
|
||||
} // check if we aren't in faction
|
||||
|
||||
if (drops.find(drop.itemID) == drops.end()) {
|
||||
drops.insert({drop.itemID, 1});
|
||||
} else {
|
||||
++drops[drop.itemID];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
void Loot::DropLoot(Entity* user, Entity* killedObject, uint32_t lootMatrixID, uint32_t minCoins, uint32_t maxCoins) {
|
||||
user = user->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
std::unordered_map<LOT, int32_t> LootGenerator::RollLootMatrix(uint32_t matrixIndex) {
|
||||
std::unordered_map<LOT, int32_t> drops;
|
||||
|
||||
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
|
||||
const LootMatrix& matrix = m_LootMatrices[matrixIndex];
|
||||
|
||||
if (inventoryComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (const LootMatrixEntry& entry : matrix) {
|
||||
if (GeneralUtils::GenerateRandomNumber<float>(0, 1) < entry.percent) {
|
||||
const LootTable& lootTable = m_LootTables[entry.lootTableIndex];
|
||||
const RarityTable& rarityTable = m_RarityTables[entry.rarityTableIndex];
|
||||
|
||||
std::unordered_map<LOT, int32_t> result {};
|
||||
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minDrop, entry.maxDrop);
|
||||
for (uint32_t i = 0; i < dropCount; ++i) {
|
||||
uint32_t maxRarity = 1;
|
||||
|
||||
CalculateLootMatrix(lootMatrixID, user, result);
|
||||
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
|
||||
DropLoot(user, killedObject, result, minCoins, maxCoins);
|
||||
for (const RarityTableEntry& rarity : rarityTable) {
|
||||
if (rarity.randMax >= rarityRoll) {
|
||||
maxRarity = rarity.rarity;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool rarityFound = false;
|
||||
std::vector<LootTableEntry> possibleDrops;
|
||||
|
||||
for (const LootTableEntry& loot : lootTable) {
|
||||
uint32_t rarity = m_ItemRarities[loot.itemID];
|
||||
|
||||
if (rarity == maxRarity) {
|
||||
possibleDrops.push_back(loot);
|
||||
rarityFound = true;
|
||||
} else if (rarity < maxRarity && !rarityFound) {
|
||||
possibleDrops.push_back(loot);
|
||||
maxRarity = rarity;
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleDrops.size() > 0) {
|
||||
const LootTableEntry& drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
||||
|
||||
if (drops.find(drop.itemID) == drops.end()) {
|
||||
drops.insert({drop.itemID, 1});
|
||||
} else {
|
||||
++drops[drop.itemID];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
void Loot::GiveLoot(Entity* user, std::unordered_map<LOT, int32_t>& result) {
|
||||
user = user->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
void LootGenerator::GiveLoot(Entity* player, uint32_t matrixIndex) {
|
||||
player = player->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
|
||||
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
||||
|
||||
if (inventoryComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& pair : result) {
|
||||
inventoryComponent->AddItem(pair.first, pair.second);
|
||||
}
|
||||
GiveLoot(player, result);
|
||||
}
|
||||
|
||||
void Loot::DropLoot(Entity* user, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
||||
user = user->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
void LootGenerator::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = user->GetComponent<InventoryComponent>();
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
const auto spawnPosition = killedObject->GetPosition();
|
||||
|
||||
const auto source = killedObject->GetObjectID();
|
||||
|
||||
for (const auto& pair : result) {
|
||||
for (int i = 0; i < pair.second; ++i) {
|
||||
GameMessages::SendDropClientLoot(user, source, pair.first, 0, spawnPosition, 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
|
||||
GameMessages::SendDropClientLoot(user, source, LOT_NULL, coins, spawnPosition);
|
||||
for (const auto& pair : result) {
|
||||
inventoryComponent->AddItem(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
void Loot::DropActivityLoot(Entity* user, Entity* source, uint32_t activityID, int32_t rating)
|
||||
{
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable<CDActivityRewardsTable>("ActivityRewards");
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
void LootGenerator::GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable<CDActivityRewardsTable>("ActivityRewards");
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
|
||||
const CDActivityRewards* selectedReward = nullptr;
|
||||
for (const auto& activityReward : activityRewards)
|
||||
{
|
||||
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating))
|
||||
{
|
||||
selectedReward = &activityReward;
|
||||
}
|
||||
}
|
||||
const CDActivityRewards* selectedReward = nullptr;
|
||||
for (const auto& activityReward : activityRewards) {
|
||||
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating)) {
|
||||
selectedReward = &activityReward;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedReward == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!selectedReward)
|
||||
return;
|
||||
|
||||
uint32_t minCoins = 0;
|
||||
uint32_t maxCoins = 0;
|
||||
uint32_t minCoins = 0;
|
||||
uint32_t maxCoins = 0;
|
||||
|
||||
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable<CDCurrencyTableTable>("CurrencyTable");
|
||||
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([=](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
||||
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable<CDCurrencyTableTable>("CurrencyTable");
|
||||
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
||||
|
||||
if (currencyTable.size() > 0) {
|
||||
minCoins = currencyTable[0].minvalue;
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
if (currencyTable.size() > 0) {
|
||||
minCoins = currencyTable[0].minvalue;
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
|
||||
Loot::DropLoot(user, source, selectedReward->LootMatrixIndex, minCoins, maxCoins);
|
||||
GiveLoot(player, selectedReward->LootMatrixIndex);
|
||||
|
||||
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
|
||||
auto* character = player->GetCharacter();
|
||||
|
||||
character->SetCoins(character->GetCoins() + coins);
|
||||
}
|
||||
|
||||
void Loot::GiveActivityLoot(Entity* user, Entity* source, uint32_t activityID, int32_t rating)
|
||||
{
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable<CDActivityRewardsTable>("ActivityRewards");
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
const CDActivityRewards* selectedReward = nullptr;
|
||||
for (const auto& activityReward : activityRewards)
|
||||
{
|
||||
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating))
|
||||
{
|
||||
selectedReward = &activityReward;
|
||||
}
|
||||
}
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
|
||||
if (selectedReward == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
uint32_t minCoins = 0;
|
||||
uint32_t maxCoins = 0;
|
||||
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
||||
|
||||
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable<CDCurrencyTableTable>("CurrencyTable");
|
||||
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([=](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
||||
|
||||
if (currencyTable.size() > 0) {
|
||||
minCoins = currencyTable[0].minvalue;
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
|
||||
Loot::GiveLoot(user, selectedReward->LootMatrixIndex);
|
||||
|
||||
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
|
||||
auto* charactert = user->GetCharacter();
|
||||
|
||||
charactert->SetCoins(charactert->GetCoins() + coins);
|
||||
DropLoot(player, killedObject, result, minCoins, maxCoins);
|
||||
}
|
||||
|
||||
void Loot::CalculateLootMatrix(uint32_t lootMatrixID, Entity* user, std::unordered_map<LOT, int32_t>& result)
|
||||
{
|
||||
user = user->GetOwner();
|
||||
void LootGenerator::DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* missionComponent = user->GetComponent<MissionComponent>();
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
|
||||
// Get our loot for this LOT's lootMatrixID:
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::Instance()->GetTable<CDLootMatrixTable>("LootMatrix");
|
||||
CDLootTableTable* lootTableTable = CDClientManager::Instance()->GetTable<CDLootTableTable>("LootTable");
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::Instance()->GetTable<CDRarityTableTable>("RarityTable");
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
std::vector<CDLootMatrix> lootMatrix = lootMatrixTable->Query([lootMatrixID](CDLootMatrix entry) { return (entry.LootMatrixIndex == lootMatrixID); });
|
||||
const auto spawnPosition = killedObject->GetPosition();
|
||||
|
||||
// Now, loop through each entry
|
||||
for (uint32_t i = 0; i < lootMatrix.size(); ++i) {
|
||||
// Now, determine whether or not we should drop this
|
||||
float chanceToDrop = 1.0 - lootMatrix[i].percent;
|
||||
float shouldDrop = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
const auto source = killedObject->GetObjectID();
|
||||
|
||||
const auto rarityTableIndex = lootMatrix[i].RarityTableIndex;
|
||||
for (const auto& pair : result) {
|
||||
for (int i = 0; i < pair.second; ++i) {
|
||||
GameMessages::SendDropClientLoot(player, source, pair.first, 0, spawnPosition, 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CDRarityTable> rarityTable = rarityTableTable->Query([rarityTableIndex](CDRarityTable entry) { return (entry.RarityTableIndex == rarityTableIndex); });
|
||||
|
||||
std::sort(rarityTable.begin(), rarityTable.end());
|
||||
uint32_t coins = (int)(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
|
||||
if (shouldDrop < chanceToDrop) {
|
||||
// We are not able to drop this item, so continue
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we reached here, we are able to drop the item
|
||||
uint32_t minToDrop = lootMatrix[i].minToDrop;
|
||||
uint32_t maxToDrop = lootMatrix[i].maxToDrop;
|
||||
|
||||
// Now determine the number we will drop of items from this table
|
||||
uint32_t numToDrop = GeneralUtils::GenerateRandomNumber<uint32_t>(minToDrop, maxToDrop);
|
||||
|
||||
// Now, query the loot matrix index
|
||||
const auto lootTableIndex = lootMatrix[i].LootTableIndex;
|
||||
|
||||
std::vector<CDLootTable> lootTable = lootTableTable->Query([lootTableIndex](CDLootTable entry) { return (entry.LootTableIndex == lootTableIndex); });
|
||||
|
||||
// Now randomize these entries
|
||||
if (lootTable.size() > 1) {
|
||||
std::shuffle(std::begin(lootTable), std::end(lootTable), Game::randomEngine);
|
||||
}
|
||||
|
||||
uint32_t addedItems = 0;
|
||||
|
||||
if (lootTable.empty()) continue;
|
||||
|
||||
while (addedItems < numToDrop) {
|
||||
addedItems++;
|
||||
|
||||
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
|
||||
// im sorry
|
||||
uint32_t highestRarity = 1; // LOOT_COMMON
|
||||
float highestRandMax = 0.0f;
|
||||
for (const auto& rarity : rarityTable) {
|
||||
if (rarityRoll > rarity.randmax && rarity.randmax > highestRandMax) {
|
||||
highestRandMax = rarity.randmax;
|
||||
highestRarity = rarity.rarity + 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CDLootTable> refinedLoot;
|
||||
|
||||
if (lootTable.size() == 1)
|
||||
{
|
||||
refinedLoot = lootTable;
|
||||
}
|
||||
else
|
||||
{
|
||||
refinedLoot = GetLootOfRarity(lootTable, highestRarity);
|
||||
|
||||
bool continueLoop = false;
|
||||
while (refinedLoot.empty())
|
||||
{
|
||||
if (highestRarity == 1)
|
||||
{
|
||||
continueLoop = true;
|
||||
break;
|
||||
}
|
||||
|
||||
highestRarity -= 1;
|
||||
|
||||
refinedLoot = GetLootOfRarity(lootTable, highestRarity);
|
||||
|
||||
if (!refinedLoot.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (continueLoop) continue;
|
||||
}
|
||||
|
||||
int randomTable = GeneralUtils::GenerateRandomNumber<int>(0, refinedLoot.size() - 1);
|
||||
|
||||
const auto& selectedTable = refinedLoot[randomTable];
|
||||
|
||||
uint32_t itemLOT = selectedTable.itemid;
|
||||
bool isMissionItem = selectedTable.MissionDrop;
|
||||
|
||||
if (isMissionItem && missionComponent != nullptr)
|
||||
{
|
||||
// TODO: this executes a query in a hot path, might be worth refactoring away
|
||||
if (!missionComponent->RequiresItem(itemLOT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (lootTable.size() > numToDrop)
|
||||
{
|
||||
for (size_t i = 0; i < lootTable.size(); i++)
|
||||
{
|
||||
if (lootTable[i].id == selectedTable.id)
|
||||
{
|
||||
lootTable.erase(lootTable.begin() + i);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto& it = result.find(itemLOT);
|
||||
if (it != result.end()) {
|
||||
it->second++;
|
||||
}
|
||||
else {
|
||||
result.emplace(itemLOT, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tokenCount = 0;
|
||||
|
||||
const auto& tokens = result.find(13763);
|
||||
|
||||
if (tokens != result.end()) {
|
||||
tokenCount = tokens->second;
|
||||
|
||||
result.erase(tokens);
|
||||
}
|
||||
|
||||
if (tokenCount == 0 || user == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (missionComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOT tokenId = -1;
|
||||
|
||||
if (missionComponent->GetMissionState(545) == MissionState::MISSION_STATE_COMPLETE) // "Join Assembly!"
|
||||
{
|
||||
tokenId = 8318; // "Assembly Token"
|
||||
}
|
||||
|
||||
if (missionComponent->GetMissionState(556) == MissionState::MISSION_STATE_COMPLETE) // "Join Venture League!"
|
||||
{
|
||||
tokenId = 8321; // "Venture League Token"
|
||||
}
|
||||
|
||||
if (missionComponent->GetMissionState(567) == MissionState::MISSION_STATE_COMPLETE) // "Join The Sentinels!"
|
||||
{
|
||||
tokenId = 8319; // "Sentinels Token"
|
||||
}
|
||||
|
||||
if (missionComponent->GetMissionState(578) == MissionState::MISSION_STATE_COMPLETE) // "Join Paradox!"
|
||||
{
|
||||
tokenId = 8320; // "Paradox Token"
|
||||
}
|
||||
|
||||
if (tokenId != -1)
|
||||
{
|
||||
result.emplace(tokenId, tokenCount);
|
||||
}
|
||||
GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition);
|
||||
}
|
||||
|
||||
void Loot::DropItem(Entity* user, Entity* sourceObject, LOT item, int32_t currency, int32_t count, bool useTeam, bool freeForAll)
|
||||
{
|
||||
if (sourceObject == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void LootGenerator::DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating) {
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance()->GetTable<CDActivityRewardsTable>("ActivityRewards");
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([activityID](CDActivityRewards entry) { return (entry.objectTemplate == activityID); });
|
||||
|
||||
const auto sourceID = sourceObject->GetObjectID();
|
||||
const auto sourcePosition = sourceObject->GetPosition();
|
||||
const CDActivityRewards* selectedReward = nullptr;
|
||||
for (const auto& activityReward : activityRewards) {
|
||||
if (activityReward.activityRating <= rating && (selectedReward == nullptr || activityReward.activityRating > selectedReward->activityRating)) {
|
||||
selectedReward = &activityReward;
|
||||
}
|
||||
}
|
||||
|
||||
// If useTeam, drop the item once for each team member.
|
||||
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
|
||||
if (selectedReward == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != nullptr && useTeam)
|
||||
{
|
||||
for (const auto& memberID : team->members)
|
||||
{
|
||||
// Get the team member from its ID.
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberID);
|
||||
uint32_t minCoins = 0;
|
||||
uint32_t maxCoins = 0;
|
||||
|
||||
if (member == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CDCurrencyTableTable* currencyTableTable = CDClientManager::Instance()->GetTable<CDCurrencyTableTable>("CurrencyTable");
|
||||
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([selectedReward](CDCurrencyTable entry) { return (entry.currencyIndex == selectedReward->CurrencyIndex && entry.npcminlevel == 1); });
|
||||
|
||||
// Drop the item.
|
||||
GameMessages::SendDropClientLoot(member, sourceID, item, currency, sourcePosition, count);
|
||||
}
|
||||
if (currencyTable.size() > 0) {
|
||||
minCoins = currencyTable[0].minvalue;
|
||||
maxCoins = currencyTable[0].maxvalue;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GameMessages::SendDropClientLoot(user, sourceID, item, currency, sourcePosition, count);
|
||||
DropLoot(player, source, selectedReward->LootMatrixIndex, minCoins, maxCoins);
|
||||
}
|
||||
|
@@ -1,31 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include <unordered_map>
|
||||
#include "Singleton.h"
|
||||
#include <vector>
|
||||
#include "CDClientManager.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
struct RarityTableEntry {
|
||||
uint32_t rarity;
|
||||
float randMax;
|
||||
};
|
||||
|
||||
typedef std::vector<RarityTableEntry> RarityTable;
|
||||
|
||||
struct LootMatrixEntry {
|
||||
uint32_t lootTableIndex;
|
||||
uint32_t rarityTableIndex;
|
||||
float percent;
|
||||
uint32_t minDrop;
|
||||
uint32_t maxDrop;
|
||||
};
|
||||
|
||||
typedef std::vector<LootMatrixEntry> LootMatrix;
|
||||
|
||||
struct LootTableEntry {
|
||||
LOT itemID;
|
||||
bool isMissionDrop;
|
||||
};
|
||||
|
||||
typedef std::vector<LootTableEntry> LootTable;
|
||||
|
||||
// used for glue code with Entity and Player classes
|
||||
namespace Loot {
|
||||
struct Info {
|
||||
LWOOBJID id;
|
||||
LOT lot;
|
||||
uint32_t count;
|
||||
};
|
||||
struct Info {
|
||||
LWOOBJID id;
|
||||
LOT lot;
|
||||
uint32_t count;
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<CDLootTable> GetLootOfRarity(const std::vector<CDLootTable> &lootTable, uint32_t rarity);
|
||||
|
||||
void DropActivityLoot(Entity* user, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
class LootGenerator : public Singleton<LootGenerator> {
|
||||
public:
|
||||
LootGenerator();
|
||||
|
||||
void GiveActivityLoot(Entity* user, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
std::unordered_map<LOT, int32_t> RollLootMatrix(Entity* player, uint32_t matrixIndex);
|
||||
std::unordered_map<LOT, int32_t> RollLootMatrix(uint32_t matrixIndex);
|
||||
void GiveLoot(Entity* player, uint32_t matrixIndex);
|
||||
void GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result);
|
||||
void GiveActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropLoot(Entity* player, Entity* killedObject, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropLoot(Entity* player, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropActivityLoot(Entity* player, Entity* source, uint32_t activityID, int32_t rating = 0);
|
||||
|
||||
void CalculateLootMatrix(uint32_t lootMatrixID, Entity* user, std::unordered_map<LOT, int32_t>& result);
|
||||
|
||||
void GiveLoot(Entity* user, uint32_t lootMatrixID);
|
||||
|
||||
void DropLoot(Entity* user, Entity* killedObject, uint32_t lootMatrixID, uint32_t minCoins, uint32_t maxCoins);
|
||||
|
||||
void GiveLoot(Entity* user, std::unordered_map<LOT, int32_t>& result);
|
||||
|
||||
void DropLoot(Entity* user, Entity* killedObject, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);
|
||||
|
||||
void DropItem(Entity* user, Entity* sourceObject, LOT item, int32_t currency, int32_t count, bool useTeam = false, bool freeForAll = false);
|
||||
};
|
||||
private:
|
||||
std::unordered_map<uint32_t, uint8_t> m_ItemRarities;
|
||||
std::unordered_map<uint32_t, RarityTable> m_RarityTables;
|
||||
std::unordered_map<uint32_t, LootMatrix> m_LootMatrices;
|
||||
std::unordered_map<uint32_t, LootTable> m_LootTables;
|
||||
};
|
||||
|
@@ -407,7 +407,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
if (chatCommand == "setMinifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0
|
||||
if (chatCommand == "setminifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0
|
||||
int32_t minifigItemId;
|
||||
if (!GeneralUtils::TryParse(args[1], minifigItemId)) {
|
||||
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig Item Id ID.");
|
||||
@@ -434,7 +434,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
charComp->m_Character->SetMouth(minifigItemId);
|
||||
} else if (lowerName == "righthand") {
|
||||
charComp->m_Character->SetRightHand(minifigItemId);
|
||||
} else if (lowerName == "shirt") {
|
||||
} else if (lowerName == "shirtcolor") {
|
||||
charComp->m_Character->SetShirtColor(minifigItemId);
|
||||
} else if (lowerName == "hands") {
|
||||
charComp->m_Character->SetLeftHand(minifigItemId);
|
||||
@@ -1691,6 +1691,43 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
|
||||
return;
|
||||
}
|
||||
|
||||
if (chatCommand == "rollloot" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_OPERATOR && args.size() >= 3) {
|
||||
uint32_t lootMatrixIndex = 0;
|
||||
uint32_t targetLot = 0;
|
||||
uint32_t loops = 1;
|
||||
|
||||
if (!GeneralUtils::TryParse(args[0], lootMatrixIndex)) return;
|
||||
if (!GeneralUtils::TryParse(args[1], targetLot)) return;
|
||||
if (!GeneralUtils::TryParse(args[2], loops)) return;
|
||||
|
||||
uint64_t totalRuns = 0;
|
||||
|
||||
for (uint32_t i = 0; i < loops; i++) {
|
||||
while (true) {
|
||||
auto lootRoll = LootGenerator::Instance().RollLootMatrix(lootMatrixIndex);
|
||||
totalRuns += 1;
|
||||
bool doBreak = false;
|
||||
for (const auto& kv : lootRoll) {
|
||||
if ((uint32_t)kv.first == targetLot) {
|
||||
doBreak = true;
|
||||
}
|
||||
}
|
||||
if (doBreak) break;
|
||||
}
|
||||
}
|
||||
|
||||
std::u16string message = u"Ran loot drops looking for "
|
||||
+ GeneralUtils::to_u16string(targetLot)
|
||||
+ u", "
|
||||
+ GeneralUtils::to_u16string(loops)
|
||||
+ u" times. It ran "
|
||||
+ GeneralUtils::to_u16string(totalRuns)
|
||||
+ u" times. Averaging out at "
|
||||
+ GeneralUtils::to_u16string((float) totalRuns / loops);
|
||||
|
||||
ChatPackets::SendSystemMessage(sysAddr, message);
|
||||
}
|
||||
|
||||
if (chatCommand == "inspect" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 1)
|
||||
{
|
||||
Entity* closest = nullptr;
|
||||
|
Reference in New Issue
Block a user