2021-12-05 17:54:36 +00:00
|
|
|
/*
|
|
|
|
* Darkflame Universe
|
|
|
|
* Copyright 2018
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkillComponent.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "BehaviorContext.h"
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "Behavior.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
|
|
#include "dServer.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "Game.h"
|
2023-08-05 02:28:07 +00:00
|
|
|
#include "BitstreamUtils.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "BaseCombatAIComponent.h"
|
|
|
|
#include "ScriptComponent.h"
|
|
|
|
#include "BuffComponent.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EchoStartSkill.h"
|
|
|
|
#include "DoClientProjectileImpact.h"
|
2023-02-10 08:30:17 +00:00
|
|
|
#include "CDClientManager.h"
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDSkillBehaviorTable.h"
|
2023-05-03 21:38:32 +00:00
|
|
|
#include "eConnectionType.h"
|
|
|
|
#include "eClientMessageType.h"
|
2023-03-17 14:36:21 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
ProjectileSyncEntry::ProjectileSyncEntry() {
|
|
|
|
}
|
|
|
|
|
2023-02-10 08:30:17 +00:00
|
|
|
std::unordered_map<uint32_t, uint32_t> SkillComponent::m_skillBehaviorCache = {};
|
|
|
|
|
2022-04-25 10:25:07 +00:00
|
|
|
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
|
|
|
|
|
|
|
|
context->caster = m_Parent->GetObjectID();
|
|
|
|
|
2022-04-25 10:25:07 +00:00
|
|
|
context->skillID = skillID;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_managedBehaviors.insert_or_assign(skillUid, context);
|
|
|
|
|
|
|
|
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
|
|
|
|
|
|
|
const auto branch = BehaviorBranchContext(target, 0);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
behavior->Handle(context, bitStream, branch);
|
|
|
|
|
|
|
|
context->ExecuteUpdates();
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return !context->failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream* bitStream) {
|
|
|
|
const auto index = this->m_managedBehaviors.find(skillUid);
|
|
|
|
|
|
|
|
if (index == this->m_managedBehaviors.end()) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("SkillComponent", "Failed to find skill with uid (%i)!", skillUid, syncId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* context = index->second;
|
|
|
|
|
|
|
|
context->SyncBehavior(syncId, bitStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::BitStream* bitStream, const LWOOBJID target) {
|
|
|
|
auto index = -1;
|
|
|
|
|
|
|
|
for (auto i = 0u; i < this->m_managedProjectiles.size(); ++i) {
|
|
|
|
const auto& projectile = this->m_managedProjectiles.at(i);
|
|
|
|
|
|
|
|
if (projectile.id == projectileId) {
|
|
|
|
index = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (index == -1) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("SkillComponent", "Failed to find projectile id (%llu)!", projectileId);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto sync_entry = this->m_managedProjectiles.at(index);
|
|
|
|
|
2022-01-13 03:48:27 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
|
|
|
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
|
2022-01-15 19:02:14 +00:00
|
|
|
query.bind(1, (int)sync_entry.lot);
|
2022-01-13 03:48:27 +00:00
|
|
|
|
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-07 02:12:47 +00:00
|
|
|
if (result.eof()) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!", sync_entry.lot);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto behavior_id = static_cast<uint32_t>(result.getIntField(0));
|
|
|
|
|
|
|
|
result.finalize();
|
|
|
|
|
|
|
|
auto* behavior = Behavior::CreateBehavior(behavior_id);
|
|
|
|
|
|
|
|
auto branch = sync_entry.branchContext;
|
|
|
|
|
|
|
|
branch.isProjectile = true;
|
|
|
|
|
|
|
|
if (target != LWOOBJID_EMPTY) {
|
|
|
|
branch.target = target;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
behavior->Handle(sync_entry.context, bitStream, branch);
|
|
|
|
|
|
|
|
this->m_managedProjectiles.erase(this->m_managedProjectiles.begin() + index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::RegisterPlayerProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot) {
|
|
|
|
ProjectileSyncEntry entry;
|
|
|
|
|
|
|
|
entry.context = context;
|
|
|
|
entry.branchContext = branch;
|
|
|
|
entry.lot = lot;
|
|
|
|
entry.id = projectileId;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_managedProjectiles.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::Update(const float deltaTime) {
|
2023-03-04 07:16:37 +00:00
|
|
|
if (!m_Parent->HasComponent(eReplicaComponentType::BASE_COMBAT_AI) && m_Parent->GetLOT() != 1) {
|
2021-12-05 17:54:36 +00:00
|
|
|
CalculateUpdate(deltaTime);
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:57:47 +00:00
|
|
|
if (m_Parent->IsPlayer()) {
|
|
|
|
for (const auto& pair : this->m_managedBehaviors) pair.second->UpdatePlayerSyncs(deltaTime);
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::map<uint32_t, BehaviorContext*> keep{};
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (const auto& pair : this->m_managedBehaviors) {
|
|
|
|
auto* context = pair.second;
|
|
|
|
|
|
|
|
if (context == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (context->clientInitalized) {
|
|
|
|
context->CalculateUpdate(deltaTime);
|
|
|
|
} else {
|
|
|
|
context->Update(deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup old behaviors
|
|
|
|
if (context->syncEntries.empty() && context->timerEntries.empty()) {
|
|
|
|
auto any = false;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (const auto& projectile : this->m_managedProjectiles) {
|
|
|
|
if (projectile.context == context) {
|
|
|
|
any = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!any) {
|
|
|
|
context->Reset();
|
|
|
|
|
|
|
|
delete context;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
context = nullptr;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
keep.insert_or_assign(pair.first, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_managedBehaviors = keep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::Reset() {
|
|
|
|
for (const auto& behavior : this->m_managedBehaviors) {
|
|
|
|
delete behavior.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_managedProjectiles.clear();
|
|
|
|
this->m_managedBehaviors.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::Interrupt() {
|
2022-12-16 21:23:38 +00:00
|
|
|
// TODO: need to check immunities on the destroyable component, but they aren't implemented
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* combat = m_Parent->GetComponent<BaseCombatAIComponent>();
|
2022-12-16 21:23:38 +00:00
|
|
|
if (combat != nullptr && combat->GetStunImmune()) return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-04-05 13:57:47 +00:00
|
|
|
for (const auto& behavior : this->m_managedBehaviors) {
|
|
|
|
for (const auto& behaviorEndEntry : behavior.second->endEntries) {
|
|
|
|
behaviorEndEntry.behavior->End(behavior.second, behaviorEndEntry.branchContext, behaviorEndEntry.second);
|
|
|
|
}
|
|
|
|
behavior.second->endEntries.clear();
|
|
|
|
if (m_Parent->IsPlayer()) continue;
|
|
|
|
behavior.second->Interrupt();
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, BehaviorContext* context, const BehaviorBranchContext& branch, const LOT lot, const float maxTime,
|
|
|
|
const NiPoint3& startPosition, const NiPoint3& velocity, const bool trackTarget, const float trackRadius) {
|
|
|
|
ProjectileSyncEntry entry;
|
|
|
|
|
|
|
|
entry.context = context;
|
|
|
|
entry.branchContext = branch;
|
|
|
|
entry.lot = lot;
|
|
|
|
entry.calculation = true;
|
|
|
|
entry.time = 0;
|
|
|
|
entry.maxTime = maxTime;
|
|
|
|
entry.id = projectileId;
|
|
|
|
entry.startPosition = startPosition;
|
|
|
|
entry.lastPosition = startPosition;
|
|
|
|
entry.velocity = velocity;
|
|
|
|
entry.trackTarget = trackTarget;
|
|
|
|
entry.trackRadius = trackRadius;
|
|
|
|
|
|
|
|
this->m_managedProjectiles.push_back(entry);
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:57:47 +00:00
|
|
|
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID) {
|
2023-02-10 08:30:17 +00:00
|
|
|
uint32_t behaviorId = -1;
|
|
|
|
// try to find it via the cache
|
|
|
|
const auto& pair = m_skillBehaviorCache.find(skillId);
|
|
|
|
|
|
|
|
// if it's not in the cache look it up and cache it
|
|
|
|
if (pair == m_skillBehaviorCache.end()) {
|
2023-03-17 14:36:21 +00:00
|
|
|
auto skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
|
2023-02-10 08:30:17 +00:00
|
|
|
behaviorId = skillTable->GetSkillByID(skillId).behaviorID;
|
|
|
|
m_skillBehaviorCache.insert_or_assign(skillId, behaviorId);
|
|
|
|
} else {
|
|
|
|
behaviorId = pair->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if we got back a valid behavior
|
|
|
|
if (behaviorId == -1) {
|
|
|
|
Game::logger->LogDebug("SkillComponent", "Tried to cast skill %i but found no behavior", skillId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID).success;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
|
|
|
|
auto* bitStream = new RakNet::BitStream();
|
|
|
|
|
|
|
|
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
|
|
|
|
|
|
|
auto* context = new BehaviorContext(originatorOverride != LWOOBJID_EMPTY ? originatorOverride : this->m_Parent->GetObjectID(), true);
|
|
|
|
|
|
|
|
context->caster = m_Parent->GetObjectID();
|
|
|
|
|
2023-04-18 17:48:03 +00:00
|
|
|
context->skillID = skillId;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
context->clientInitalized = clientInitalized;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
context->foundTarget = target != LWOOBJID_EMPTY || ignoreTarget || clientInitalized;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
behavior->Calculate(context, bitStream, { target, 0 });
|
|
|
|
|
|
|
|
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
|
|
|
script->OnSkillCast(m_Parent, skillId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!context->foundTarget) {
|
|
|
|
delete bitStream;
|
|
|
|
delete context;
|
|
|
|
|
|
|
|
// Invalid attack
|
|
|
|
return { false, 0 };
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_managedBehaviors.insert_or_assign(context->skillUId, context);
|
|
|
|
|
|
|
|
if (!clientInitalized) {
|
|
|
|
// Echo start skill
|
2023-01-07 05:17:05 +00:00
|
|
|
EchoStartSkill start;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
start.iCastType = 0;
|
|
|
|
start.skillID = skillId;
|
|
|
|
start.uiSkillHandle = context->skillUId;
|
|
|
|
start.optionalOriginatorID = context->originator;
|
2022-12-31 11:56:30 +00:00
|
|
|
start.optionalTargetID = target;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* originator = Game::entityManager->GetEntity(context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (originator != nullptr) {
|
|
|
|
start.originatorRot = originator->GetRotation();
|
|
|
|
}
|
|
|
|
//start.optionalTargetID = target;
|
|
|
|
|
|
|
|
start.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
|
|
|
|
|
|
|
// Write message
|
|
|
|
RakNet::BitStream message;
|
|
|
|
|
2023-08-05 02:28:07 +00:00
|
|
|
BitstreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
2021-12-05 17:54:36 +00:00
|
|
|
message.Write(this->m_Parent->GetObjectID());
|
|
|
|
start.Serialize(&message);
|
|
|
|
|
|
|
|
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
context->ExecuteUpdates();
|
|
|
|
|
|
|
|
delete bitStream;
|
|
|
|
|
|
|
|
// Valid attack
|
|
|
|
return { true, context->skillTime };
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::CalculateUpdate(const float deltaTime) {
|
|
|
|
if (this->m_managedBehaviors.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto& managedBehavior : this->m_managedBehaviors) {
|
|
|
|
if (managedBehavior.second == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
managedBehavior.second->CalculateUpdate(deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& managedProjectile : this->m_managedProjectiles) {
|
|
|
|
auto entry = managedProjectile;
|
|
|
|
|
|
|
|
if (!entry.calculation) continue;
|
|
|
|
|
|
|
|
entry.time += deltaTime;
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* origin = Game::entityManager->GetEntity(entry.context->originator);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (origin == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto targets = origin->GetTargetsInPhantom();
|
|
|
|
|
|
|
|
const auto position = entry.startPosition + (entry.velocity * entry.time);
|
|
|
|
|
|
|
|
for (const auto& targetId : targets) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* target = Game::entityManager->GetEntity(targetId);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
const auto targetPosition = target->GetPosition();
|
|
|
|
|
|
|
|
const auto closestPoint = Vector3::ClosestPointOnLine(entry.lastPosition, position, targetPosition);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto distance = Vector3::DistanceSquared(targetPosition, closestPoint);
|
|
|
|
|
|
|
|
if (distance > 3 * 3) {
|
2022-12-16 06:10:58 +00:00
|
|
|
// TODO There is supposed to be an implementation for homing projectiles here
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.branchContext.target = targetId;
|
|
|
|
|
|
|
|
SyncProjectileCalculation(entry);
|
|
|
|
|
|
|
|
entry.time = entry.maxTime;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.lastPosition = position;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
managedProjectile = entry;
|
|
|
|
}
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<ProjectileSyncEntry> valid;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (auto& entry : this->m_managedProjectiles) {
|
|
|
|
if (entry.calculation) {
|
|
|
|
if (entry.time >= entry.maxTime) {
|
|
|
|
entry.branchContext.target = LWOOBJID_EMPTY;
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
SyncProjectileCalculation(entry);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
valid.push_back(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_managedProjectiles = valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) const {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* other = Game::entityManager->GetEntity(entry.branchContext.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-07 02:12:47 +00:00
|
|
|
if (other == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (entry.branchContext.target != LWOOBJID_EMPTY) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("SkillComponent", "Invalid projectile target (%llu)!", entry.branchContext.target);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-13 03:48:27 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
|
|
|
"SELECT behaviorID FROM SkillBehavior WHERE skillID = (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
|
|
|
|
query.bind(1, (int)entry.lot);
|
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-07 02:12:47 +00:00
|
|
|
if (result.eof()) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("SkillComponent", "Failed to find skill id for (%i)!", entry.lot);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto behaviorId = static_cast<uint32_t>(result.getIntField(0));
|
|
|
|
|
|
|
|
result.finalize();
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
|
|
|
|
|
|
|
auto* bitStream = new RakNet::BitStream();
|
|
|
|
|
|
|
|
behavior->Calculate(entry.context, bitStream, entry.branchContext);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2023-01-07 05:17:05 +00:00
|
|
|
DoClientProjectileImpact projectileImpact;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
projectileImpact.sBitStream.assign((char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed());
|
|
|
|
projectileImpact.i64OwnerID = this->m_Parent->GetObjectID();
|
|
|
|
projectileImpact.i64OrgID = entry.id;
|
|
|
|
projectileImpact.i64TargetID = entry.branchContext.target;
|
|
|
|
|
|
|
|
RakNet::BitStream message;
|
|
|
|
|
2023-08-05 02:28:07 +00:00
|
|
|
BitstreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
2021-12-05 17:54:36 +00:00
|
|
|
message.Write(this->m_Parent->GetObjectID());
|
|
|
|
projectileImpact.Serialize(&message);
|
|
|
|
|
|
|
|
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
|
|
|
|
|
|
|
|
entry.context->ExecuteUpdates();
|
|
|
|
|
|
|
|
delete bitStream;
|
|
|
|
}
|
|
|
|
|
2022-01-01 09:46:05 +00:00
|
|
|
void SkillComponent::HandleUnmanaged(const uint32_t behaviorId, const LWOOBJID target, LWOOBJID source) {
|
|
|
|
auto* context = new BehaviorContext(source);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
context->unmanaged = true;
|
|
|
|
context->caster = target;
|
|
|
|
|
|
|
|
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
|
|
|
|
|
|
|
auto* bitStream = new RakNet::BitStream();
|
|
|
|
|
|
|
|
behavior->Handle(context, bitStream, { target });
|
|
|
|
|
|
|
|
delete bitStream;
|
|
|
|
|
2022-01-15 19:02:14 +00:00
|
|
|
delete context;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID target) {
|
|
|
|
auto* context = new BehaviorContext(target);
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
context->caster = target;
|
|
|
|
|
|
|
|
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
|
|
|
|
|
|
|
behavior->UnCast(context, { target });
|
2022-01-15 19:02:14 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
delete context;
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:57:47 +00:00
|
|
|
SkillComponent::SkillComponent(Entity* parent): Component(parent) {
|
2021-12-05 17:54:36 +00:00
|
|
|
this->m_skillUid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkillComponent::~SkillComponent() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkillComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
|
|
|
if (bIsInitialUpdate) outBitStream->Write0();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get a unique skill ID for syncing behaviors to the client
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Unique skill ID</returns>
|
|
|
|
uint32_t SkillComponent::GetUniqueSkillId() {
|
|
|
|
return ++this->m_skillUid;
|
|
|
|
}
|