mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-20 21:54:23 +00:00
Compare commits
6 Commits
npc-pathin
...
hatchlings
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2f02d0720 | ||
|
|
7456d6b5c1 | ||
|
|
308412f46e | ||
|
|
56504d9447 | ||
|
|
ce9d4e823c | ||
|
|
0f17e1de3b |
@@ -289,6 +289,14 @@ struct LwoNameValue {
|
||||
this->Erase(GeneralUtils::ASCIIToUTF16(key));
|
||||
}
|
||||
|
||||
ValueType::iterator find(const ValueType::key_type& key) {
|
||||
return this->values.find(key);
|
||||
}
|
||||
|
||||
ValueType::const_iterator find(const ValueType::key_type& key) const {
|
||||
return this->values.find(key);
|
||||
}
|
||||
|
||||
LwoNameValue() = default;
|
||||
|
||||
LwoNameValue(const LwoNameValue& other) {
|
||||
|
||||
@@ -38,3 +38,11 @@ std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObje
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<CDObjectSkills> CDObjectSkillsTable::Get(const LOT lot) const {
|
||||
std::vector<CDObjectSkills> toReturn;
|
||||
for (const auto& entry : GetEntries()) {
|
||||
if (entry.objectTemplate == lot) toReturn.push_back(entry);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
#include "CDTable.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
struct CDObjectSkills {
|
||||
uint32_t objectTemplate; //!< The LOT of the item
|
||||
uint32_t skillID; //!< The Skill ID of the object
|
||||
uint32_t castOnType; //!< ???
|
||||
uint32_t AICombatWeight; //!< ???
|
||||
int32_t AICombatWeight; //!< ???
|
||||
};
|
||||
|
||||
class CDObjectSkillsTable : public CDTable<CDObjectSkillsTable, std::vector<CDObjectSkills>> {
|
||||
@@ -17,5 +18,6 @@ public:
|
||||
void LoadValuesFromDatabase();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDObjectSkills> Query(std::function<bool(CDObjectSkills)> predicate);
|
||||
std::vector<CDObjectSkills> Get(const LOT lot) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -2237,6 +2237,7 @@ bool Entity::MsgRequestServerObjectInfo(GameMessages::RequestServerObjectInfo& r
|
||||
objectInfo.PushDebug<AMFIntValue>("Template ID(LOT)") = GetLOT();
|
||||
objectInfo.PushDebug<AMFStringValue>("Object ID") = std::to_string(GetObjectID());
|
||||
objectInfo.PushDebug<AMFStringValue>("Spawner's Object ID") = std::to_string(GetSpawnerID());
|
||||
objectInfo.PushDebug<AMFStringValue>("Owner override") = std::to_string(m_OwnerOverride);
|
||||
|
||||
auto& componentDetails = objectInfo.PushDebug("Component Information");
|
||||
for (const auto [id, component] : m_Components) {
|
||||
|
||||
@@ -5,20 +5,40 @@
|
||||
|
||||
void NpcCombatSkillBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bit_stream, BehaviorBranchContext branch) {
|
||||
context->skillTime = this->m_npcSkillTime;
|
||||
const auto* const targetEntity = Game::entityManager->GetEntity(branch.target);
|
||||
const auto* const sourceEntity = Game::entityManager->GetEntity(context->caster);
|
||||
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Calculate(context, bit_stream, branch);
|
||||
bool cast = true;
|
||||
// Check that the target is within the cast range
|
||||
if (targetEntity && sourceEntity && this->m_maxRange != 0.0f) {
|
||||
const auto targetPos = targetEntity->GetPosition();
|
||||
const auto sourcePos = sourceEntity->GetPosition();
|
||||
const auto distance = NiPoint3::DistanceSquared(targetPos, sourcePos);
|
||||
cast = distance >= this->m_minRange && distance <= this->m_maxRange;
|
||||
}
|
||||
|
||||
if (cast) {
|
||||
for (auto* behavior : this->m_behaviors) {
|
||||
behavior->Calculate(context, bit_stream, branch);
|
||||
}
|
||||
} else {
|
||||
// We failed to find a valid target, do not continue the behavior
|
||||
context->foundTarget = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NpcCombatSkillBehavior::Load() {
|
||||
this->m_npcSkillTime = GetFloat("npc skill time");
|
||||
this->m_minRange = GetFloat("min range") * 0.9f; // Make the min and max 10% smaller to account for server/client position disagreements
|
||||
this->m_minRange *= this->m_minRange;
|
||||
this->m_maxRange = GetFloat("max range") * 0.9f; // Make the min and max 10% smaller to account for server/client position disagreements
|
||||
this->m_maxRange *= this->m_maxRange;
|
||||
|
||||
const auto parameters = GetParameterNames();
|
||||
|
||||
for (const auto& parameter : parameters) {
|
||||
if (parameter.first.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(parameter.second);
|
||||
for (const auto& [parameter, value] : parameters) {
|
||||
if (parameter.rfind("behavior", 0) == 0) {
|
||||
auto* action = GetAction(value);
|
||||
|
||||
this->m_behaviors.push_back(action);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
float m_npcSkillTime;
|
||||
|
||||
float m_maxRange{};
|
||||
float m_minRange{};
|
||||
|
||||
/*
|
||||
* Inherited
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDObjectSkillsTable.h"
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -43,7 +45,7 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t compo
|
||||
|
||||
//Grab the aggro information from BaseCombatAI:
|
||||
auto componentQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = ?;");
|
||||
"SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius, minRoundLength, maxRoundLength, combatRoundLength FROM BaseCombatAIComponent WHERE id = ?;");
|
||||
componentQuery.bind(1, static_cast<int>(componentID));
|
||||
|
||||
auto componentResult = componentQuery.execQuery();
|
||||
@@ -63,44 +65,37 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t compo
|
||||
|
||||
if (!componentResult.fieldIsNull("hardTetherRadius"))
|
||||
m_HardTetherRadius = componentResult.getFloatField("hardTetherRadius");
|
||||
|
||||
m_MinRoundLength = componentResult.getFloatField("minRoundLength");
|
||||
m_MaxRoundLength = componentResult.getFloatField("maxRoundLength");
|
||||
m_CombatRoundLength = componentResult.getFloatField("combatRoundLength");
|
||||
}
|
||||
|
||||
componentResult.finalize();
|
||||
|
||||
// Get aggro and tether radius from settings and use this if it is present. Only overwrite the
|
||||
// radii if it is greater than the one in the database.
|
||||
if (m_Parent) {
|
||||
auto aggroRadius = m_Parent->GetVar<float>(u"aggroRadius");
|
||||
m_AggroRadius = aggroRadius != 0 ? aggroRadius : m_AggroRadius;
|
||||
auto tetherRadius = m_Parent->GetVar<float>(u"tetherRadius");
|
||||
m_HardTetherRadius = tetherRadius != 0 ? tetherRadius : m_HardTetherRadius;
|
||||
}
|
||||
m_AggroRadius = m_Parent->HasVar(u"aggroRadius") ? m_Parent->GetVar<float>(u"aggroRadius") : m_AggroRadius;
|
||||
m_HardTetherRadius = m_Parent->HasVar(u"tetherRadius") ? m_Parent->GetVar<float>(u"tetherRadius") : m_HardTetherRadius;
|
||||
|
||||
/*
|
||||
* Find skills
|
||||
*/
|
||||
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
|
||||
skillQuery.bind(1, static_cast<int>(parent->GetLOT()));
|
||||
for (const auto objectSkill : CDClientManager::GetTable<CDObjectSkillsTable>()->Get(parent->GetLOT())) {
|
||||
const auto skillBehavior = CDClientManager::GetTable<CDSkillBehaviorTable>()->GetSkillByID(objectSkill.skillID);
|
||||
if (skillBehavior.skillID == objectSkill.skillID) {
|
||||
const auto skillId = skillBehavior.skillID;
|
||||
|
||||
auto result = skillQuery.execQuery();
|
||||
const auto abilityCooldown = skillBehavior.cooldown;
|
||||
|
||||
while (!result.eof()) {
|
||||
const auto skillId = static_cast<uint32_t>(result.getIntField("skillID"));
|
||||
const auto behaviorId = skillBehavior.behaviorID;
|
||||
|
||||
const auto abilityCooldown = static_cast<float>(result.getFloatField("cooldown"));
|
||||
const auto combatWeight = objectSkill.AICombatWeight;
|
||||
|
||||
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
|
||||
auto* behavior = Behavior::CreateBehavior(behaviorId);
|
||||
AiSkillEntry entry = { .skillId = skillId, .cooldown = 0.0f, .abilityCooldown = abilityCooldown, .behavior = behavior, .combatWeight = combatWeight };
|
||||
|
||||
std::stringstream behaviorQuery;
|
||||
|
||||
AiSkillEntry entry = { skillId, 0, abilityCooldown, behavior };
|
||||
|
||||
m_SkillEntries.push_back(entry);
|
||||
|
||||
result.nextRow();
|
||||
m_SkillEntries.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
Stun(1.0f);
|
||||
@@ -248,10 +243,12 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
||||
|
||||
void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
bool hasSkillToCast = false;
|
||||
int32_t maxSkillWeights = 0;
|
||||
for (auto& entry : m_SkillEntries) {
|
||||
if (entry.cooldown > 0.0f) {
|
||||
entry.cooldown -= deltaTime;
|
||||
} else {
|
||||
maxSkillWeights += entry.combatWeight;
|
||||
hasSkillToCast = true;
|
||||
}
|
||||
}
|
||||
@@ -337,14 +334,23 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
LookAt(target->GetPosition());
|
||||
}
|
||||
|
||||
for (auto i = 0; i < m_SkillEntries.size(); ++i) {
|
||||
auto entry = m_SkillEntries.at(i);
|
||||
// Roll to find which skill we'll try to cast
|
||||
auto randomizedWeight = GeneralUtils::GenerateRandomNumber<int32_t>(0, maxSkillWeights);
|
||||
|
||||
if (entry.cooldown > 0) {
|
||||
for (auto& entry : m_SkillEntries) {
|
||||
// Skill isn't cooled off yet
|
||||
if (entry.cooldown > 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto result = skillComponent->CalculateBehavior(entry.skillId, entry.behavior->m_behaviorId, LWOOBJID_EMPTY);
|
||||
randomizedWeight -= entry.combatWeight;
|
||||
|
||||
// if the weight is still greater than 0 continue to the next rolled skill
|
||||
if (randomizedWeight > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto result = skillComponent->CalculateBehavior(entry.skillId, entry.behavior->m_behaviorId, GetTarget());
|
||||
|
||||
if (result.success) {
|
||||
if (m_MovementAI != nullptr) {
|
||||
@@ -359,8 +365,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
|
||||
entry.cooldown = entry.abilityCooldown + m_SkillTime;
|
||||
|
||||
m_SkillEntries[i] = entry;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -755,8 +759,8 @@ void BaseCombatAIComponent::SetTetherSpeed(float value) {
|
||||
m_TetherSpeed = value;
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::Stun(const float time) {
|
||||
if (m_StunImmune || m_StunTime > time) {
|
||||
void BaseCombatAIComponent::Stun(const float time, const bool force) {
|
||||
if (!force && (m_StunImmune || m_StunTime > time)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -914,8 +918,16 @@ bool BaseCombatAIComponent::MsgGetObjectReportInfo(GameMessages::GetObjectReport
|
||||
}
|
||||
|
||||
auto& ignoredThreats = cmptType.PushDebug("Temp Ignored Threats");
|
||||
for (const auto& [id, threat] : m_ThreatEntries) {
|
||||
for (const auto& [id, threat] : m_RemovedThreatList) {
|
||||
ignoredThreats.PushDebug<AMFDoubleValue>(std::to_string(id) + " - Time") = threat;
|
||||
}
|
||||
auto& skillInfo = cmptType.PushDebug("Skill Info");
|
||||
for (const auto& skill : m_SkillEntries) {
|
||||
auto& skillDebug = skillInfo.PushDebug("Skill ID " + std::to_string(skill.skillId));
|
||||
skillDebug.PushDebug<AMFDoubleValue>("Cooldown") = skill.cooldown;
|
||||
skillDebug.PushDebug<AMFDoubleValue>("Ability Cooldown") = skill.abilityCooldown;
|
||||
skillDebug.PushDebug<AMFIntValue>("AI Combat Weight") = skill.combatWeight;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,13 +33,15 @@ enum class AiState : uint32_t {
|
||||
*/
|
||||
struct AiSkillEntry
|
||||
{
|
||||
uint32_t skillId;
|
||||
uint32_t skillId{};
|
||||
|
||||
float cooldown;
|
||||
float cooldown{};
|
||||
|
||||
float abilityCooldown;
|
||||
float abilityCooldown{};
|
||||
|
||||
Behavior* behavior;
|
||||
Behavior* behavior{};
|
||||
|
||||
int32_t combatWeight{};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -181,8 +183,9 @@ public:
|
||||
/**
|
||||
* Stuns the entity for a certain amount of time, will not work if the entity is stun immune
|
||||
* @param time the time to stun the entity, if stunnable
|
||||
* @param force whether or not to force the stun and ignore checks
|
||||
*/
|
||||
void Stun(float time);
|
||||
void Stun(float time, const bool force = false);
|
||||
|
||||
/**
|
||||
* Gets the radius that will cause this entity to get aggro'd, causing a target chase
|
||||
@@ -396,9 +399,17 @@ private:
|
||||
*/
|
||||
bool m_DirtyStateOrTarget = false;
|
||||
|
||||
// Min amount of time to remain as in combat after casting a skill
|
||||
float m_MinRoundLength = 0.0f;
|
||||
|
||||
// max amount of time to remain as in combat after casting a skill
|
||||
float m_MaxRoundLength = 0.0f;
|
||||
|
||||
// The amount of time the entity will be forced to tether for
|
||||
float m_ForcedTetherTime = 0.0f;
|
||||
|
||||
float m_CombatRoundLength = 0.0f;
|
||||
|
||||
// The amount of time a removed threat will be ignored for.
|
||||
std::map<LWOOBJID, float> m_RemovedThreatList;
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
|
||||
m_Info = info;
|
||||
m_AtFinalWaypoint = true;
|
||||
|
||||
m_BaseCombatAI = nullptr;
|
||||
|
||||
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
//Try and fix the insane values:
|
||||
@@ -131,7 +129,11 @@ void MovementAIComponent::Update(const float deltaTime) {
|
||||
|
||||
m_TimeTravelled += deltaTime;
|
||||
|
||||
SetPosition(ApproximateLocation());
|
||||
const auto approxPos = ApproximateLocation();
|
||||
SetPosition(approxPos);
|
||||
// Set the AIs new home based on where our current waypoint is IF we're idle, that way we can return to this
|
||||
// when resuming the pathing after losing aggro while moving the aggro hitbox with us
|
||||
if (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle) m_BaseCombatAI->SetStartingPosition(approxPos);
|
||||
|
||||
if (m_TimeTravelled < m_TimeToTravel) return;
|
||||
m_TimeTravelled = 0.0f;
|
||||
@@ -166,32 +168,43 @@ void MovementAIComponent::Update(const float deltaTime) {
|
||||
SetRotation(QuatUtils::LookAt(source, m_NextWaypoint));
|
||||
}
|
||||
} else {
|
||||
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
||||
const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1;
|
||||
RunWaypointCommands(waypointNum);
|
||||
if (m_CurrentPath.empty()) {
|
||||
if (m_Path) {
|
||||
if (m_Path->pathBehavior == PathBehavior::Loop) {
|
||||
SetPath(m_Path->pathWaypoints);
|
||||
} else if (m_Path->pathBehavior == PathBehavior::Bounce) {
|
||||
m_IsBounced = !m_IsBounced;
|
||||
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
|
||||
if (m_IsBounced) std::ranges::reverse(waypoints);
|
||||
SetPath(waypoints);
|
||||
} else if (m_Path->pathBehavior == PathBehavior::Once) {
|
||||
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
|
||||
if (m_BaseCombatAI) m_BaseCombatAI->SetStartingPosition(m_SourcePosition);
|
||||
// Only try to renew or continue the path if we're in the idle or spawn state and we actually have a combatAI component
|
||||
if (!m_BaseCombatAI || (m_BaseCombatAI && m_BaseCombatAI->GetState() == AiState::idle)) {
|
||||
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
||||
const auto waypointNum = m_IsBounced ? m_CurrentPath.size() : m_CurrentPathWaypointCount - m_CurrentPath.size() - 1;
|
||||
RunWaypointCommands(waypointNum);
|
||||
if (m_CurrentPath.empty()) {
|
||||
if (m_Path) {
|
||||
if (m_Path->pathBehavior == PathBehavior::Loop) {
|
||||
SetPath(m_Path->pathWaypoints);
|
||||
} else if (m_Path->pathBehavior == PathBehavior::Bounce) {
|
||||
m_IsBounced = !m_IsBounced;
|
||||
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
|
||||
if (m_IsBounced) std::ranges::reverse(waypoints);
|
||||
SetPath(waypoints);
|
||||
} else if (m_Path->pathBehavior == PathBehavior::Once) {
|
||||
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Stop();
|
||||
if (m_FollowedTarget != LWOOBJID_EMPTY) {
|
||||
GameMessages::GetPosition getPos;
|
||||
if (!getPos.Send(m_FollowedTarget)) {
|
||||
LOG("Target %llu does not exist anymore to follow", m_FollowedTarget);
|
||||
m_FollowedTarget = LWOOBJID_EMPTY;
|
||||
} else {
|
||||
SetDestination(getPos.pos);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Stop();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SetDestination(m_CurrentPath.top().position);
|
||||
SetDestination(m_CurrentPath.top().position);
|
||||
|
||||
m_CurrentPath.pop();
|
||||
m_CurrentPath.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +231,7 @@ NiPoint3 MovementAIComponent::GetCurrentWaypoint() const {
|
||||
|
||||
NiPoint3 MovementAIComponent::ApproximateLocation() const {
|
||||
auto source = m_SourcePosition;
|
||||
|
||||
if (AtFinalWaypoint()) return source;
|
||||
if (AtFinalWaypoint()) return m_Parent->GetPosition();
|
||||
|
||||
auto destination = m_NextWaypoint;
|
||||
|
||||
@@ -473,7 +485,7 @@ void MovementAIComponent::RunWaypointCommands(uint32_t waypointNum) {
|
||||
break;
|
||||
}
|
||||
case eWaypointCommandType::DELAY: {
|
||||
// Pause(GeneralUtils::TryParse<float>(data).value_or(0.0f));
|
||||
// Pause(GeneralUtils::TryParse<float>(data).value_or(0.0f));
|
||||
break;
|
||||
}
|
||||
case eWaypointCommandType::EMOTE: {
|
||||
@@ -521,12 +533,13 @@ bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInf
|
||||
movementInfo.PushDebug<AMFBoolValue>("Lock Rotation") = m_LockRotation;
|
||||
movementInfo.PushDebug<AMFBoolValue>("Paused") = m_Paused;
|
||||
movementInfo.PushDebug<AMFDoubleValue>("Pulling To Point") = m_PullingToPoint;
|
||||
movementInfo.PushDebug<AMFBoolValue>("At Final Waypoint") = m_AtFinalWaypoint;
|
||||
|
||||
auto& pullPointInfo = movementInfo.PushDebug("Pull Point");
|
||||
pullPointInfo.PushDebug<AMFDoubleValue>("X") = m_PullPoint.x;
|
||||
pullPointInfo.PushDebug<AMFDoubleValue>("Y") = m_PullPoint.y;
|
||||
pullPointInfo.PushDebug<AMFDoubleValue>("Z") = m_PullPoint.z;
|
||||
|
||||
|
||||
// movementInfo.PushDebug<AMFDoubleValue>("Delay") = m_Delay;
|
||||
|
||||
auto& waypoints = movementInfo.PushDebug("Interpolated Waypoints");
|
||||
@@ -551,5 +564,25 @@ bool MovementAIComponent::OnGetObjectReportInfo(GameMessages::GetObjectReportInf
|
||||
pathCopy.pop();
|
||||
}
|
||||
|
||||
movementInfo.PushDebug<AMFStringValue>("Followed Target") = std::to_string(m_FollowedTarget);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MovementAIComponent::FollowTarget(const LWOOBJID target) {
|
||||
if (target == LWOOBJID_EMPTY) {
|
||||
m_FollowedTarget = target;
|
||||
return;
|
||||
}
|
||||
GameMessages::GetPosition getPos;
|
||||
if (!getPos.Send(target)) {
|
||||
LOG("Tried to follow target %llu but they don't exist", target);
|
||||
m_FollowedTarget = LWOOBJID_EMPTY;
|
||||
return;
|
||||
}
|
||||
|
||||
m_FollowedTarget = target;
|
||||
SetMaxSpeed(1.0f);
|
||||
m_CurrentSpeed = 1.0f;
|
||||
SetDestination(getPos.pos);
|
||||
}
|
||||
|
||||
@@ -31,27 +31,27 @@ struct MovementAIInfo {
|
||||
/**
|
||||
* The radius that the entity can wander in
|
||||
*/
|
||||
float wanderRadius;
|
||||
float wanderRadius{};
|
||||
|
||||
/**
|
||||
* The speed at which the entity wanders
|
||||
*/
|
||||
float wanderSpeed;
|
||||
float wanderSpeed{};
|
||||
|
||||
/**
|
||||
* This is only used for the emotes
|
||||
*/
|
||||
float wanderChance;
|
||||
float wanderChance{};
|
||||
|
||||
/**
|
||||
* The min amount of delay before wandering
|
||||
*/
|
||||
float wanderDelayMin;
|
||||
float wanderDelayMin{};
|
||||
|
||||
/**
|
||||
* The max amount of delay before wandering
|
||||
*/
|
||||
float wanderDelayMax;
|
||||
float wanderDelayMax{};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -214,6 +214,8 @@ public:
|
||||
bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo);
|
||||
|
||||
bool HasPath() const { return m_Path != nullptr; }
|
||||
|
||||
void FollowTarget(const LWOOBJID target);
|
||||
private:
|
||||
|
||||
/**
|
||||
@@ -337,6 +339,8 @@ private:
|
||||
|
||||
// The number of waypoints that were on the path in the call to SetPath
|
||||
uint32_t m_CurrentPathWaypointCount{ 0 };
|
||||
|
||||
LWOOBJID m_FollowedTarget{ LWOOBJID_EMPTY };
|
||||
};
|
||||
|
||||
#endif // MOVEMENTAICOMPONENT_H
|
||||
|
||||
@@ -37,6 +37,7 @@ target_include_directories(dScriptsServerBase PUBLIC "."
|
||||
"Minigame"
|
||||
"Minigame/General"
|
||||
"Objects"
|
||||
"Objects/Hatchlings"
|
||||
)
|
||||
target_precompile_headers(dScriptsServerBase REUSE_FROM dScriptsBase)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "RenderComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -48,10 +49,30 @@ void BossSpiderQueenEnemyServer::OnStartup(Entity* self) {
|
||||
combat->SetStunImmune(true);
|
||||
|
||||
m_CurrentBossStage = 1;
|
||||
|
||||
ToggleAttacking(*self, false);
|
||||
self->SetProximityRadius(65.0f, "AggroRadius");
|
||||
// Obtain faction and collision group to save for subsequent resets
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
|
||||
if (name != "AggroRadius" || !entering || !entering->IsPlayer()) return;
|
||||
|
||||
auto playerCount = self->GetVar<int32_t>(u"player_count");
|
||||
|
||||
if (status == "ENTER") {
|
||||
if (playerCount == 0) {
|
||||
ToggleAttacking(*self, true);
|
||||
}
|
||||
playerCount++;
|
||||
} else if (status == "LEAVE") {
|
||||
playerCount--;
|
||||
if (playerCount == 0) {
|
||||
ToggleAttacking(*self, false);
|
||||
}
|
||||
}
|
||||
self->SetVar<int32_t>(u"player_count", playerCount);
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::OnDie(Entity* self, Entity* killer) {
|
||||
if (Game::zoneManager->GetZoneID().GetMapID() == instanceZoneID && killer) {
|
||||
for (const auto& player : PlayerManager::GetAllPlayers()) {
|
||||
@@ -71,6 +92,7 @@ void BossSpiderQueenEnemyServer::OnDie(Entity* self, Entity* killer) {
|
||||
self->SetPosition({ 10000, 0, 10000 });
|
||||
|
||||
Game::entityManager->SerializeEntity(self);
|
||||
ToggleAttacking(*self, false);
|
||||
|
||||
controller->OnFireEventServerSide(self, "ClearProperty");
|
||||
}
|
||||
@@ -634,3 +656,19 @@ float BossSpiderQueenEnemyServer::PlayAnimAndReturnTime(Entity* self, const std:
|
||||
|
||||
return animTimer;
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::ToggleAttacking(Entity& self, bool on) {
|
||||
const auto stoppedFlag = self.GetVarAs<bool>(u"stoppedFlag");
|
||||
|
||||
if (!on) {
|
||||
if (stoppedFlag) return;
|
||||
|
||||
self.SetVar(u"stoppedFlag", true);
|
||||
combat->Stun(100000.0f, true); // forcibly stun so we stop attacking people trying to put on armor
|
||||
} else {
|
||||
if (!stoppedFlag) return;
|
||||
|
||||
self.SetVar(u"stoppedFlag", false);
|
||||
combat->Stun(0.0f, true); // forcibly turn off the stun we put on above
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,10 @@ public:
|
||||
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
|
||||
void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status);
|
||||
|
||||
private:
|
||||
void ToggleAttacking(Entity& self, bool on);
|
||||
//Regular variables:
|
||||
DestroyableComponent* destroyable = nullptr;
|
||||
ControllablePhysicsComponent* controllable = nullptr;
|
||||
|
||||
@@ -14,7 +14,7 @@ void VisToggleNotifierServer::OnMissionDialogueOK(Entity* self, Entity* target,
|
||||
auto spawners = Game::zoneManager->GetSpawnersByName(itr->second);
|
||||
if (spawners.empty()) return;
|
||||
for (const auto spawner : spawners) {
|
||||
auto spawnedObjIds = spawner->GetSpawnedObjectIDs();
|
||||
const auto& spawnedObjIds = spawner->GetSpawnedObjectIDs();
|
||||
for (const auto& objId : spawnedObjIds) {
|
||||
GameMessages::SendNotifyClientObject(objId, u"SetVisibility", visible);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
add_subdirectory(Hatchlings)
|
||||
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS
|
||||
"AgSurvivalBuffStation.cpp"
|
||||
"StinkyFishTarget.cpp"
|
||||
PARENT_SCOPE)
|
||||
"StinkyFishTarget.cpp")
|
||||
|
||||
foreach(file ${DSCRIPTS_SOURCES_02_SERVER_OBJECTS_HATCHLINGS})
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS ${DSCRIPTS_SOURCES_02_SERVER_OBJECTS} "Hatchlings/${file}")
|
||||
endforeach()
|
||||
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS ${DSCRIPTS_SOURCES_02_SERVER_OBJECTS} PARENT_SCOPE)
|
||||
|
||||
3
dScripts/02_server/Objects/Hatchlings/CMakeLists.txt
Normal file
3
dScripts/02_server/Objects/Hatchlings/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS_HATCHLINGS
|
||||
"HatchlingPets.cpp"
|
||||
PARENT_SCOPE)
|
||||
83
dScripts/02_server/Objects/Hatchlings/HatchlingPets.cpp
Normal file
83
dScripts/02_server/Objects/Hatchlings/HatchlingPets.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "HatchlingPets.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "MovementAIComponent.h"
|
||||
|
||||
void HatchlingPets::OnStartup(Entity* self) {
|
||||
self->SetVar(u"follow", false);
|
||||
|
||||
self->SetProximityRadius(5, "StopFollow");
|
||||
self->SetProximityRadius(15, "Wander");
|
||||
self->SetProximityRadius(50, "Teleport");
|
||||
|
||||
Wander(*self, *self->GetOwner());
|
||||
self->AddComponent<MovementAIComponent>(-1, MovementAIInfo{ .wanderRadius = 2.5f });
|
||||
}
|
||||
|
||||
void HatchlingPets::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
|
||||
auto* const parent = self->GetOwner();
|
||||
if (!entering || !entering->IsPlayer() || parent->GetObjectID() != entering->GetObjectID()) return;
|
||||
|
||||
if (name == "StopFollow") {
|
||||
if (status == "ENTER") {
|
||||
if (self->GetVar<bool>(u"follow")) {
|
||||
const auto randomWanderTime = GeneralUtils::GenerateRandomNumber<float>(4, 9);
|
||||
self->AddTimer("StartWander", randomWanderTime);
|
||||
// stop following the player
|
||||
auto* const movementAI = self->GetComponent<MovementAIComponent>();
|
||||
if (movementAI) {
|
||||
movementAI->Stop();
|
||||
movementAI->FollowTarget(LWOOBJID_EMPTY);
|
||||
}
|
||||
self->SetVar(u"follow", false);
|
||||
}
|
||||
}
|
||||
} else if (name == "Wander") {
|
||||
if (status == "LEAVE") {
|
||||
self->CancelAllTimers();
|
||||
// follow the player
|
||||
auto* const movementAI = self->GetComponent<MovementAIComponent>();
|
||||
if (movementAI) {
|
||||
movementAI->Stop();
|
||||
movementAI->FollowTarget(entering->GetObjectID());
|
||||
}
|
||||
self->SetVar(u"follow", true);
|
||||
}
|
||||
} else if (name == "Teleport") {
|
||||
if (status == "LEAVE") {
|
||||
// stop following the player
|
||||
auto* const movementAI = self->GetComponent<MovementAIComponent>();
|
||||
if (movementAI) {
|
||||
movementAI->Stop();
|
||||
movementAI->FollowTarget(LWOOBJID_EMPTY);
|
||||
}
|
||||
GameMessages::GetPosition getPos;
|
||||
getPos.Send(entering->GetObjectID());
|
||||
getPos.pos.z += 5.0f;
|
||||
self->SetPosition(getPos.pos);
|
||||
Game::entityManager->SerializeEntity(*self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HatchlingPets::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "StartWander") {
|
||||
Wander(*self, *self->GetOwner());
|
||||
}
|
||||
}
|
||||
|
||||
void HatchlingPets::Wander(Entity& self, Entity& player) {
|
||||
GameMessages::GetPosition getPos;
|
||||
if (!getPos.Send(player.GetObjectID())) {
|
||||
LOG("Failed to get position for %llu", player.GetObjectID());
|
||||
return;
|
||||
}
|
||||
|
||||
const auto xWander = GeneralUtils::GenerateRandomNumber<float>(0, 20) - 10.0f;
|
||||
const auto zWander = GeneralUtils::GenerateRandomNumber<float>(0, 20) - 10.0f;
|
||||
getPos.pos.x += xWander;
|
||||
getPos.pos.z += zWander;
|
||||
auto* const movementAI = self.GetComponent<MovementAIComponent>();
|
||||
if (movementAI) movementAI->SetDestination(getPos.pos);
|
||||
self.AddTimer("StartWander", GeneralUtils::GenerateRandomNumber<float>(4, 9));
|
||||
}
|
||||
14
dScripts/02_server/Objects/Hatchlings/HatchlingPets.h
Normal file
14
dScripts/02_server/Objects/Hatchlings/HatchlingPets.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef HATCHLINGPETS_H
|
||||
#define HATCHLINGPETS_H
|
||||
|
||||
#include "CppScripts.h"
|
||||
#include "NiPoint3.h"
|
||||
|
||||
class HatchlingPets : public CppScripts::Script {
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
void Wander(Entity& self, Entity& player);
|
||||
};
|
||||
|
||||
#endif //!HATCHLINGPETS_H
|
||||
@@ -166,6 +166,7 @@
|
||||
#include "AgSalutingNpcs.h"
|
||||
#include "BossSpiderQueenEnemyServer.h"
|
||||
#include "RockHydrantSmashable.h"
|
||||
#include "HatchlingPets.h"
|
||||
|
||||
// Misc Scripts
|
||||
#include "ExplodingAsset.h"
|
||||
@@ -423,6 +424,7 @@ namespace {
|
||||
{"scripts\\ai\\NS\\L_NS_CONCERT_INSTRUMENT_QB.lua", []() {return new NsConcertInstrument();}},
|
||||
{"scripts\\ai\\NS\\L_NS_JONNY_FLAG_MISSION_SERVER.lua", []() {return new NsJohnnyMissionServer();}},
|
||||
{"scripts\\02_server\\Objects\\L_STINKY_FISH_TARGET.lua", []() {return new StinkyFishTarget();}},
|
||||
{"scripts\\02_server\\Objects\\Hatchlings\\L_HATCHLING_PETS.lua", []() {return new HatchlingPets();}},
|
||||
{"scripts\\zone\\PROPERTY\\NS\\L_ZONE_NS_PROPERTY.lua", []() {return new ZoneNsProperty();}},
|
||||
{"scripts\\02_server\\Map\\Property\\NS_Med\\L_ZONE_NS_MED_PROPERTY.lua", []() {return new ZoneNsMedProperty();}},
|
||||
{"scripts\\02_server\\Map\\NS\\L_NS_TOKEN_CONSOLE_SERVER.lua", []() {return new NsTokenConsoleServer();}},
|
||||
|
||||
@@ -1019,6 +1019,7 @@ void HandlePacket(Packet* packet) {
|
||||
if (user) {
|
||||
Character* c = user->GetLastUsedChar();
|
||||
if (c != nullptr) {
|
||||
if (Game::entityManager->GetEntity(c->GetObjectID())) return;
|
||||
std::u16string username = GeneralUtils::ASCIIToUTF16(c->GetName());
|
||||
Game::server->GetReplicaManager()->AddParticipant(packet->systemAddress);
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
#include <functional>
|
||||
#include "GeneralUtils.h"
|
||||
#include "dZoneManager.h"
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
|
||||
Spawner::Spawner(const SpawnerInfo info) {
|
||||
Spawner::Spawner(const SpawnerInfo& info) {
|
||||
m_Info = info;
|
||||
m_Active = m_Info.activeOnLoad && info.spawnActivator;
|
||||
m_EntityInfo = EntityInfo();
|
||||
@@ -62,10 +64,6 @@ Spawner::Spawner(const SpawnerInfo info) {
|
||||
}
|
||||
}
|
||||
|
||||
Spawner::~Spawner() {
|
||||
|
||||
}
|
||||
|
||||
Entity* Spawner::Spawn() {
|
||||
std::vector<SpawnerNode*> freeNodes;
|
||||
for (SpawnerNode* node : m_Info.nodes) {
|
||||
@@ -77,9 +75,25 @@ Entity* Spawner::Spawn() {
|
||||
return Spawn(freeNodes);
|
||||
}
|
||||
|
||||
Entity* Spawner::Spawn(std::vector<SpawnerNode*> freeNodes, const bool force) {
|
||||
if (force || ((m_Entities.size() < m_Info.amountMaintained) && (freeNodes.size() > 0) && (m_AmountSpawned < m_Info.maxToSpawn || m_Info.maxToSpawn == -1))) {
|
||||
SpawnerNode* spawnNode = freeNodes[GeneralUtils::GenerateRandomNumber<int>(0, freeNodes.size() - 1)];
|
||||
Entity* Spawner::Spawn(const std::vector<SpawnerNode*>& freeNodes, const bool force) {
|
||||
Entity* spawnedEntity = nullptr;
|
||||
if (force || ((m_Entities.size() < m_Info.amountMaintained) && !freeNodes.empty() && (m_AmountSpawned < m_Info.maxToSpawn || m_Info.maxToSpawn == -1))) {
|
||||
// first sum the weights we were provided
|
||||
int32_t spawnWeight = 0;
|
||||
for (const auto* const node : freeNodes) spawnWeight += node->weight;
|
||||
auto chosenWeight = GeneralUtils::GenerateRandomNumber<int32_t>(1, spawnWeight);
|
||||
|
||||
// Default to 0 incase something goes wrong in this calc
|
||||
// Roll the spawner nodes based on their weights, higher weights = more likely to spawn
|
||||
SpawnerNode* spawnNode = freeNodes[0];
|
||||
for (auto* const node : freeNodes) {
|
||||
chosenWeight -= node->weight;
|
||||
if (chosenWeight <= 0) {
|
||||
spawnNode = node;
|
||||
break; // we rolled a spawner
|
||||
}
|
||||
}
|
||||
|
||||
++m_AmountSpawned;
|
||||
m_EntityInfo.pos = spawnNode->position;
|
||||
m_EntityInfo.rot = spawnNode->rotation;
|
||||
@@ -93,26 +107,24 @@ Entity* Spawner::Spawn(std::vector<SpawnerNode*> freeNodes, const bool force) {
|
||||
m_EntityInfo.spawnerID = m_Info.spawnerID;
|
||||
}
|
||||
|
||||
Entity* rezdE = Game::entityManager->CreateEntity(m_EntityInfo, nullptr);
|
||||
spawnedEntity = Game::entityManager->CreateEntity(m_EntityInfo, nullptr);
|
||||
|
||||
rezdE->GetGroups() = m_Info.groups;
|
||||
spawnedEntity->GetGroups() = m_Info.groups;
|
||||
|
||||
Game::entityManager->ConstructEntity(rezdE);
|
||||
Game::entityManager->ConstructEntity(spawnedEntity);
|
||||
|
||||
m_Entities.insert({ rezdE->GetObjectID(), spawnNode });
|
||||
spawnNode->entities.push_back(rezdE->GetObjectID());
|
||||
m_Entities[spawnedEntity->GetObjectID()] = spawnNode;
|
||||
spawnNode->entities.push_back(spawnedEntity->GetObjectID());
|
||||
if (m_Entities.size() == m_Info.amountMaintained) {
|
||||
m_NeedsUpdate = false;
|
||||
}
|
||||
|
||||
for (const auto& cb : m_EntitySpawnedCallbacks) {
|
||||
cb(rezdE);
|
||||
cb(spawnedEntity);
|
||||
}
|
||||
|
||||
return rezdE;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return spawnedEntity;
|
||||
}
|
||||
|
||||
void Spawner::AddSpawnedEntityDieCallback(std::function<void()> callback) {
|
||||
@@ -148,18 +160,18 @@ void Spawner::SoftReset() {
|
||||
m_NeedsUpdate = true;
|
||||
}
|
||||
|
||||
void Spawner::SetRespawnTime(float time) {
|
||||
void Spawner::SetRespawnTime(const float time) {
|
||||
m_Info.respawnTime = time;
|
||||
|
||||
for (size_t i = 0; i < m_WaitTimes.size(); ++i) {
|
||||
m_WaitTimes[i] = 0;
|
||||
};
|
||||
}
|
||||
|
||||
m_Start = true;
|
||||
m_NeedsUpdate = true;
|
||||
}
|
||||
|
||||
void Spawner::SetNumToMaintain(int32_t value) {
|
||||
void Spawner::SetNumToMaintain(const int32_t value) {
|
||||
m_Info.amountMaintained = value;
|
||||
}
|
||||
|
||||
@@ -177,15 +189,8 @@ void Spawner::Update(const float deltaTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_NeedsUpdate) return;
|
||||
if (!m_Active) return;
|
||||
//if (m_Info.noTimedSpawn) return;
|
||||
if (m_Info.spawnsOnSmash) {
|
||||
if (!m_SpawnSmashFoundGroup) {
|
||||
if (!m_NeedsUpdate || !m_Active || m_Info.spawnsOnSmash) return;
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < m_WaitTimes.size(); ) {
|
||||
m_WaitTimes[i] += deltaTime;
|
||||
if (m_WaitTimes[i] >= m_Info.respawnTime) {
|
||||
@@ -198,22 +203,21 @@ void Spawner::Update(const float deltaTime) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> Spawner::GetSpawnedObjectIDs() const {
|
||||
const std::vector<LWOOBJID> Spawner::GetSpawnedObjectIDs() const {
|
||||
std::vector<LWOOBJID> ids;
|
||||
ids.reserve(m_Entities.size());
|
||||
for (const auto& [objId, spawnerNode] : m_Entities) {
|
||||
for (const auto objId : m_Entities | std::views::keys) {
|
||||
ids.push_back(objId);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
void Spawner::NotifyOfEntityDeath(const LWOOBJID& objectID) {
|
||||
for (std::function<void()> cb : m_SpawnedEntityDieCallbacks) {
|
||||
for (const auto& cb : m_SpawnedEntityDieCallbacks) {
|
||||
cb();
|
||||
}
|
||||
|
||||
m_NeedsUpdate = true;
|
||||
//m_RespawnTime = 10.0f;
|
||||
m_WaitTimes.push_back(0.0f);
|
||||
SpawnerNode* node;
|
||||
|
||||
@@ -221,9 +225,7 @@ void Spawner::NotifyOfEntityDeath(const LWOOBJID& objectID) {
|
||||
if (it != m_Entities.end()) node = it->second;
|
||||
else return;
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
if (!node) return;
|
||||
|
||||
for (size_t i = 0; i < node->entities.size();) {
|
||||
if (node->entities[i] && node->entities[i] == objectID)
|
||||
@@ -249,6 +251,6 @@ void Spawner::Activate() {
|
||||
}
|
||||
}
|
||||
|
||||
void Spawner::SetSpawnLot(LOT lot) {
|
||||
void Spawner::SetSpawnLot(const LOT lot) {
|
||||
m_EntityInfo.lot = lot;
|
||||
}
|
||||
|
||||
@@ -11,12 +11,41 @@
|
||||
#include "LDFFormat.h"
|
||||
#include "EntityInfo.h"
|
||||
|
||||
/**
|
||||
* Any given spawner owns a certain number of spawner nodes
|
||||
* these nodes are where entities are actually spawned
|
||||
* The first spawner nodes waypoint in any given network contains the base config for all the spawner nodes
|
||||
* Then each spawner node after the first may contain duplicate settings which override the base ones
|
||||
* If spawner node 1 has an attached_path of "1", then all spawner nodes in this spawner network will have
|
||||
* an attached_path of "1".
|
||||
* Each spawner node can also specify attached_path of any other value and it will override the one provided by node 1.
|
||||
* If a spawner node does NOT provide an override, the first one will be used
|
||||
* I have no clue why the nodes are pointers, beats me
|
||||
* sn = SpawnerNode
|
||||
* Spawner
|
||||
* ----------------
|
||||
* | sn |
|
||||
* | sn |
|
||||
* | sn |
|
||||
* | |
|
||||
* | sn |
|
||||
* | sn |
|
||||
* -----------------
|
||||
*/
|
||||
struct SpawnerNode {
|
||||
// This spawner nodes position in the world
|
||||
NiPoint3 position = NiPoint3Constant::ZERO;
|
||||
// The rotation of this spawner in the world
|
||||
NiQuaternion rotation = QuatUtils::IDENTITY;
|
||||
// This spawners nodes ID in this spawner network
|
||||
uint32_t nodeID = 0;
|
||||
// The max number of entities that can be spawned by this node
|
||||
uint32_t nodeMax = 1;
|
||||
// The weight (chance) this spawner node has. Higher is more common
|
||||
int32_t weight = 1;
|
||||
// The IDs of entities spawned by this spawner node
|
||||
std::vector<LWOOBJID> entities;
|
||||
// The config of all entities spawned by this node
|
||||
LwoNameValue config;
|
||||
};
|
||||
|
||||
@@ -45,11 +74,10 @@ struct SpawnerInfo {
|
||||
|
||||
class Spawner {
|
||||
public:
|
||||
Spawner(SpawnerInfo info);
|
||||
~Spawner();
|
||||
Spawner(const SpawnerInfo& info);
|
||||
|
||||
Entity* Spawn();
|
||||
Entity* Spawn(std::vector<SpawnerNode*> freeNodes, bool force = false);
|
||||
Entity* Spawn(const std::vector<SpawnerNode*>& freeNodes, bool force = false);
|
||||
void Update(float deltaTime);
|
||||
void NotifyOfEntityDeath(const LWOOBJID& objectID);
|
||||
void Activate();
|
||||
@@ -57,16 +85,16 @@ public:
|
||||
int32_t GetAmountSpawned() { return m_AmountSpawned; };
|
||||
std::string GetName() { return m_Info.name; };
|
||||
std::vector<std::string> GetGroups() { return m_Info.groups; };
|
||||
void AddSpawnedEntityDieCallback(std::function<void()> callback);
|
||||
void AddEntitySpawnedCallback(std::function<void(Entity*)> callback);
|
||||
void SetSpawnLot(LOT lot);
|
||||
void AddSpawnedEntityDieCallback(const std::function<void()> callback);
|
||||
void AddEntitySpawnedCallback(const std::function<void(Entity*)> callback);
|
||||
void SetSpawnLot(const LOT lot);
|
||||
void Reset();
|
||||
void DestroyAllEntities();
|
||||
void SoftReset();
|
||||
void SetRespawnTime(float time);
|
||||
void SetNumToMaintain(int32_t value);
|
||||
void SetRespawnTime(const float time);
|
||||
void SetNumToMaintain(const int32_t value);
|
||||
bool GetIsSpawnSmashGroup() const { return m_SpawnSmashFoundGroup; };
|
||||
std::vector<LWOOBJID> GetSpawnedObjectIDs() const;
|
||||
const std::vector<LWOOBJID> GetSpawnedObjectIDs() const;
|
||||
|
||||
SpawnerInfo m_Info;
|
||||
bool m_Active = true;
|
||||
|
||||
@@ -123,22 +123,25 @@ void Zone::LoadZoneIntoMemory() {
|
||||
if (!data) continue;
|
||||
|
||||
if (data->GetKey() == u"spawner_node_id") {
|
||||
node->nodeID = std::stoi(data->GetValueAsString());
|
||||
node->nodeID = GeneralUtils::TryParse(data->GetValueAsString(), 0);
|
||||
} else if (data->GetKey() == u"spawner_max_per_node") {
|
||||
node->nodeMax = std::stoi(data->GetValueAsString());
|
||||
node->nodeMax = GeneralUtils::TryParse(data->GetValueAsString(), 0);
|
||||
} else if (data->GetKey() == u"groupID") { // Load object group
|
||||
std::string groupStr = data->GetValueAsString();
|
||||
info.groups = GeneralUtils::SplitString(groupStr, ';');
|
||||
info.groups = GeneralUtils::SplitString(data->GetValueAsString(), ';');
|
||||
if (info.groups.back().empty()) info.groups.erase(info.groups.end() - 1);
|
||||
} else if (data->GetKey() == u"grpNameQBShowBricks") {
|
||||
if (data->GetValueAsString().empty()) continue;
|
||||
/*std::string groupStr = data->GetValueAsString();
|
||||
info.groups.push_back(groupStr);*/
|
||||
info.grpNameQBShowBricks = data->GetValueAsString();
|
||||
} else if (data->GetKey() == u"spawner_name") {
|
||||
info.name = data->GetValueAsString();
|
||||
} else if (data->GetKey() == u"weight") {
|
||||
node->weight = GeneralUtils::TryParse(data->GetValueAsString(), 1);
|
||||
if (node->weight <= 0) {
|
||||
LOG("Found a spawner with a weight of <= 0, is this intentional? %s:%i", info.name.c_str(), node->nodeID);
|
||||
node->weight = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info.nodes.push_back(node);
|
||||
}
|
||||
info.templateID = path.spawner.spawnedLOT;
|
||||
|
||||
Reference in New Issue
Block a user