Merge remote-tracking branch 'upstream/main'

This commit is contained in:
EmosewaMC 2022-12-27 19:26:24 -08:00
commit d97f374a90
17 changed files with 145 additions and 82 deletions

View File

@ -48,9 +48,8 @@ void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* b
void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
auto* self = EntityManager::Instance()->GetEntity(context->caster); auto* self = EntityManager::Instance()->GetEntity(context->caster);
if (self == nullptr) { if (self == nullptr) {
Game::logger->Log("TacArcBehavior", "Invalid self for (%llu)!", context->originator); Game::logger->Log("AreaOfEffectBehavior", "Invalid self for (%llu)!", context->originator);
return; return;
} }
@ -79,7 +78,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
auto* entity = EntityManager::Instance()->GetEntity(validTarget); auto* entity = EntityManager::Instance()->GetEntity(validTarget);
if (entity == nullptr) { if (entity == nullptr) {
Game::logger->Log("TacArcBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator); Game::logger->Log("AreaOfEffectBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator);
continue; continue;
} }

View File

@ -61,6 +61,7 @@
#include "DamageReductionBehavior.h" #include "DamageReductionBehavior.h"
#include "JetPackBehavior.h" #include "JetPackBehavior.h"
#include "ChangeIdleFlagsBehavior.h" #include "ChangeIdleFlagsBehavior.h"
#include "DarkInspirationBehavior.h"
//CDClient includes //CDClient includes
#include "CDBehaviorParameterTable.h" #include "CDBehaviorParameterTable.h"
@ -169,7 +170,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
case BehaviorTemplates::BEHAVIOR_SPEED: case BehaviorTemplates::BEHAVIOR_SPEED:
behavior = new SpeedBehavior(behaviorId); behavior = new SpeedBehavior(behaviorId);
break; break;
case BehaviorTemplates::BEHAVIOR_DARK_INSPIRATION: break; case BehaviorTemplates::BEHAVIOR_DARK_INSPIRATION:
behavior = new DarkInspirationBehavior(behaviorId);
break;
case BehaviorTemplates::BEHAVIOR_LOOT_BUFF: case BehaviorTemplates::BEHAVIOR_LOOT_BUFF:
behavior = new LootBuffBehavior(behaviorId); behavior = new LootBuffBehavior(behaviorId);
break; break;

View File

@ -18,6 +18,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
"ClearTargetBehavior.cpp" "ClearTargetBehavior.cpp"
"DamageAbsorptionBehavior.cpp" "DamageAbsorptionBehavior.cpp"
"DamageReductionBehavior.cpp" "DamageReductionBehavior.cpp"
"DarkInspirationBehavior.cpp"
"DurationBehavior.cpp" "DurationBehavior.cpp"
"EmptyBehavior.cpp" "EmptyBehavior.cpp"
"EndBehavior.cpp" "EndBehavior.cpp"

View File

@ -0,0 +1,52 @@
#include "DarkInspirationBehavior.h"
#include "BehaviorBranchContext.h"
#include "Entity.h"
#include "DestroyableComponent.h"
#include "EntityManager.h"
#include "BehaviorContext.h"
void DarkInspirationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (target == nullptr) {
Game::logger->LogDebug("DarkInspirationBehavior", "Failed to find target (%llu)!", branch.target);
return;
}
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
if (destroyableComponent == nullptr) {
return;
}
if (destroyableComponent->HasFaction(m_FactionList)) {
this->m_ActionIfFactionMatches->Handle(context, bitStream, branch);
}
}
void DarkInspirationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (target == nullptr) {
Game::logger->LogDebug("DarkInspirationBehavior", "Failed to find target (%llu)!", branch.target);
return;
}
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
if (destroyableComponent == nullptr) {
return;
}
if (destroyableComponent->HasFaction(m_FactionList)) {
this->m_ActionIfFactionMatches->Calculate(context, bitStream, branch);
}
}
void DarkInspirationBehavior::Load() {
this->m_ActionIfFactionMatches = GetAction("action");
this->m_FactionList = GetInt("faction_list");
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "Behavior.h"
class DarkInspirationBehavior final : public Behavior
{
public:
/*
* Inherited
*/
explicit DarkInspirationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override;
private:
Behavior* m_ActionIfFactionMatches;
uint32_t m_FactionList;
};

View File

@ -170,17 +170,10 @@ void BuffComponent::ApplyBuffEffect(int32_t id) {
destroyable->SetMaxImagination(destroyable->GetMaxImagination() + maxImagination); destroyable->SetMaxImagination(destroyable->GetMaxImagination() + maxImagination);
} else if (parameter.name == "speed") { } else if (parameter.name == "speed") {
const auto speed = parameter.value;
auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
if (controllablePhysicsComponent == nullptr) return; const auto speed = parameter.value;
controllablePhysicsComponent->AddSpeedboost(speed);
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
controllablePhysicsComponent->SetSpeedMultiplier(current + ((speed - 500.0f) / 500.0f));
EntityManager::Instance()->SerializeEntity(this->GetParent());
} }
} }
} }
@ -213,17 +206,10 @@ void BuffComponent::RemoveBuffEffect(int32_t id) {
destroyable->SetMaxImagination(destroyable->GetMaxImagination() - maxImagination); destroyable->SetMaxImagination(destroyable->GetMaxImagination() - maxImagination);
} else if (parameter.name == "speed") { } else if (parameter.name == "speed") {
const auto speed = parameter.value;
auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = this->GetParent()->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
if (controllablePhysicsComponent == nullptr) return; const auto speed = parameter.value;
controllablePhysicsComponent->RemoveSpeedboost(speed);
const auto current = controllablePhysicsComponent->GetSpeedMultiplier();
controllablePhysicsComponent->SetSpeedMultiplier(current - ((speed - 500.0f) / 500.0f));
EntityManager::Instance()->SerializeEntity(this->GetParent());
} }
} }
} }

View File

@ -694,7 +694,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
auto* inventoryComponent = owner->GetComponent<InventoryComponent>(); auto* inventoryComponent = owner->GetComponent<InventoryComponent>();
if (inventoryComponent != nullptr && isEnemy) { if (inventoryComponent != nullptr && isEnemy) {
inventoryComponent->TriggerPassiveAbility(PassiveAbilityTrigger::EnemySmashed); inventoryComponent->TriggerPassiveAbility(PassiveAbilityTrigger::EnemySmashed, m_Parent);
} }
auto* missions = owner->GetComponent<MissionComponent>(); auto* missions = owner->GetComponent<MissionComponent>();

View File

@ -1196,9 +1196,9 @@ void InventoryComponent::RemoveItemSkills(const LOT lot) {
} }
} }
void InventoryComponent::TriggerPassiveAbility(PassiveAbilityTrigger trigger) { void InventoryComponent::TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target) {
for (auto* set : m_Itemsets) { for (auto* set : m_Itemsets) {
set->TriggerPassiveAbility(trigger); set->TriggerPassiveAbility(trigger, target);
} }
} }

View File

@ -283,7 +283,7 @@ public:
* Triggers one of the passive abilities from the equipped item set * Triggers one of the passive abilities from the equipped item set
* @param trigger the trigger to fire * @param trigger the trigger to fire
*/ */
void TriggerPassiveAbility(PassiveAbilityTrigger trigger); void TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target = nullptr);
/** /**
* Returns if the entity has any of the passed passive abilities equipped * Returns if the entity has any of the passed passive abilities equipped

View File

@ -4728,13 +4728,13 @@ void GameMessages::HandleSellToVendor(RakNet::BitStream* inStream, Entity* entit
float sellScalar = vend->GetSellScalar(); float sellScalar = vend->GetSellScalar();
if (Inventory::IsValidItem(itemComp.currencyLOT)) { if (Inventory::IsValidItem(itemComp.currencyLOT)) {
const auto altCurrency = (itemComp.altCurrencyCost * sellScalar) * count; const auto altCurrency = static_cast<uint32_t>(itemComp.altCurrencyCost * sellScalar) * count;
inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency), eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens. inv->AddItem(itemComp.currencyLOT, std::floor(altCurrency), eLootSourceType::LOOT_SOURCE_VENDOR); // Return alt currencies like faction tokens.
} }
//inv->RemoveItem(count, -1, iObjID); //inv->RemoveItem(count, -1, iObjID);
inv->MoveItemToInventory(item, eInventoryType::VENDOR_BUYBACK, count, true, false, true); inv->MoveItemToInventory(item, eInventoryType::VENDOR_BUYBACK, count, true, false, true);
character->SetCoins(std::floor(character->GetCoins() + ((itemComp.baseValue * sellScalar) * count)), eLootSourceType::LOOT_SOURCE_VENDOR); character->SetCoins(std::floor(character->GetCoins() + (static_cast<uint32_t>(itemComp.baseValue * sellScalar) * count)), eLootSourceType::LOOT_SOURCE_VENDOR);
//EntityManager::Instance()->SerializeEntity(player); // so inventory updates //EntityManager::Instance()->SerializeEntity(player); // so inventory updates
GameMessages::SendVendorTransactionResult(entity, sysAddr); GameMessages::SendVendorTransactionResult(entity, sysAddr);
} }
@ -5763,11 +5763,7 @@ void GameMessages::HandleUseNonEquipmentItem(RakNet::BitStream* inStream, Entity
auto* item = inv->FindItemById(itemConsumed); auto* item = inv->FindItemById(itemConsumed);
if (item == nullptr) { if (item) item->UseNonEquip(item);
return;
}
item->UseNonEquip();
} }
void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entity) { void GameMessages::HandleMatchRequest(RakNet::BitStream* inStream, Entity* entity) {

View File

@ -262,7 +262,7 @@ bool Item::Consume() {
return success; return success;
} }
void Item::UseNonEquip() { void Item::UseNonEquip(Item* item) {
LOT thisLot = this->GetLot(); LOT thisLot = this->GetLot();
if (!GetInventory()) { if (!GetInventory()) {
Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot()); Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot());
@ -292,6 +292,9 @@ void Item::UseNonEquip() {
} }
// This precondition response is taken care of in SpawnPet(). // This precondition response is taken care of in SpawnPet().
} else { } else {
bool success = false;
auto inventory = item->GetInventory();
if (inventory && inventory->GetType() == eInventoryType::ITEMS) {
auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry"); auto* compRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE); const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_PACKAGE);
@ -320,7 +323,7 @@ void Item::UseNonEquip() {
} }
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) { if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION); LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
playerInventoryComponent->RemoveItem(lot, 1); item->SetCount(item->GetCount() - 1);
} else { } else {
success = false; success = false;
} }
@ -333,6 +336,7 @@ void Item::UseNonEquip() {
success = false; success = false;
} }
} }
}
Game::logger->LogDebug("Item", "Player %llu %s used item %i", playerEntity->GetObjectID(), success ? "successfully" : "unsuccessfully", thisLot); Game::logger->LogDebug("Item", "Player %llu %s used item %i", playerEntity->GetObjectID(), success ? "successfully" : "unsuccessfully", thisLot);
GameMessages::SendUseItemResult(playerInventoryComponent->GetParent(), thisLot, success); GameMessages::SendUseItemResult(playerInventoryComponent->GetParent(), thisLot, success);
} }

View File

@ -195,7 +195,7 @@ public:
/** /**
* Uses this item if its non equip, essentially an interface for the linked GM * Uses this item if its non equip, essentially an interface for the linked GM
*/ */
void UseNonEquip(); void UseNonEquip(Item* item);
/** /**
* Disassembles the part LOTs of this item back into the inventory, if it has any * Disassembles the part LOTs of this item back into the inventory, if it has any

View File

@ -180,9 +180,9 @@ void ItemSet::Update(float deltaTime) {
} }
} }
void ItemSet::TriggerPassiveAbility(PassiveAbilityTrigger trigger) { void ItemSet::TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target) {
for (auto& passiveAbility : m_PassiveAbilities) { for (auto& passiveAbility : m_PassiveAbilities) {
passiveAbility.Trigger(trigger); passiveAbility.Trigger(trigger, target);
} }
} }

View File

@ -52,7 +52,7 @@ public:
* Triggers all the passive abilities in this item set that match this trigger * Triggers all the passive abilities in this item set that match this trigger
* @param trigger the trigger to use to trigger passive abilities * @param trigger the trigger to use to trigger passive abilities
*/ */
void TriggerPassiveAbility(PassiveAbilityTrigger trigger); void TriggerPassiveAbility(PassiveAbilityTrigger trigger, Entity* target = nullptr);
/** /**
* Returns the skills that can be equipped for a specified amount of equipped items * Returns the skills that can be equipped for a specified amount of equipped items

View File

@ -16,12 +16,12 @@ ItemSetPassiveAbility::ItemSetPassiveAbility(PassiveAbilityTrigger trigger, Enti
ItemSetPassiveAbility::~ItemSetPassiveAbility() { ItemSetPassiveAbility::~ItemSetPassiveAbility() {
} }
void ItemSetPassiveAbility::Trigger(PassiveAbilityTrigger trigger) { void ItemSetPassiveAbility::Trigger(PassiveAbilityTrigger trigger, Entity* target) {
if (m_Trigger != trigger || m_Cooldown > 0.0f) { if (m_Trigger != trigger || m_Cooldown > 0.0f) {
return; return;
} }
Activate(); Activate(target);
} }
void ItemSetPassiveAbility::Update(float deltaTime) { void ItemSetPassiveAbility::Update(float deltaTime) {
@ -30,9 +30,9 @@ void ItemSetPassiveAbility::Update(float deltaTime) {
} }
} }
void ItemSetPassiveAbility::Activate() { void ItemSetPassiveAbility::Activate(Entity* target) {
if (m_Trigger == PassiveAbilityTrigger::EnemySmashed) { if (m_Trigger == PassiveAbilityTrigger::EnemySmashed) {
OnEnemySmshed(); OnEnemySmshed(target);
return; return;
} }
@ -195,7 +195,7 @@ std::vector<ItemSetPassiveAbility> ItemSetPassiveAbility::FindAbilities(uint32_t
return abilities; return abilities;
} }
void ItemSetPassiveAbility::OnEnemySmshed() { void ItemSetPassiveAbility::OnEnemySmshed(Entity* target) {
auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>(); auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();
auto* skillComponent = m_Parent->GetComponent<SkillComponent>(); auto* skillComponent = m_Parent->GetComponent<SkillComponent>();
@ -293,8 +293,8 @@ void ItemSetPassiveAbility::OnEnemySmshed() {
break; break;
} }
case ItemSetPassiveAbilityID::ShinobiRank3: { case ItemSetPassiveAbilityID::ShinobiRank3: {
if (equippedCount < 4) return; if (equippedCount < 4 || !target) return;
destroyableComponent->Imagine(3); skillComponent->CalculateBehavior(695, 11399, target->GetObjectID());
break; break;
} }

View File

@ -30,12 +30,12 @@ public:
* Attempts to trigger a passive ability for this item set, if this is the wrong trigger this is a no-op * Attempts to trigger a passive ability for this item set, if this is the wrong trigger this is a no-op
* @param trigger the trigger to attempt to fire * @param trigger the trigger to attempt to fire
*/ */
void Trigger(PassiveAbilityTrigger trigger); void Trigger(PassiveAbilityTrigger trigger, Entity* target = nullptr);
/** /**
* Activates the passive ability * Activates the passive ability
*/ */
void Activate(); void Activate(Entity* target = nullptr);
/** /**
* Finds all the passive abilities associated with a certain item set * Finds all the passive abilities associated with a certain item set
@ -47,7 +47,7 @@ public:
static std::vector<ItemSetPassiveAbility> FindAbilities(uint32_t itemSetID, Entity* parent, ItemSet* itemSet); static std::vector<ItemSetPassiveAbility> FindAbilities(uint32_t itemSetID, Entity* parent, ItemSet* itemSet);
private: private:
void OnEnemySmshed(); void OnEnemySmshed(Entity* target = nullptr);
/** /**
* The means of triggering this ability * The means of triggering this ability

View File

@ -12,7 +12,7 @@ void PropertyFXDamage::OnCollisionPhantom(Entity* self, Entity* target) {
if (skills != nullptr && targetStats != nullptr) { if (skills != nullptr && targetStats != nullptr) {
auto targetFactions = targetStats->GetFactionIDs(); auto targetFactions = targetStats->GetFactionIDs();
if (std::find(targetFactions.begin(), targetFactions.end(), 1) != targetFactions.end()) { if (std::find(targetFactions.begin(), targetFactions.end(), 1) != targetFactions.end()) {
skills->CalculateBehavior(11386, 692, target->GetObjectID()); skills->CalculateBehavior(692, 11386, target->GetObjectID());
} }
} }
} }