mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 19:03:43 +00:00
Converts the combat messages to NetGameMsgs in CombatMessages.{h,cpp}:
Die, Resurrect, SetResurrectRestoreValues, SetPlayerAllowedRespawn
(SendToClient, as before), Knockback, SetStunned, SetStunImmunity,
SetStatusImmunity, AddBuff, RemoveBuff, AddRunSpeedModifier,
RemoveRunSpeedModifier and DeactivateBubbleBuffFromServer, and the
received RequestDie, RequestSmashPlayer, RequestResurrect, Resurrect,
ActivateBubbleBuff and DeactivateBubbleBuff. Smash and UnSmash move
here from GameMessages.h (Smash's ghostCapacity is ghostOpacity, the
client's name) and gain a Deserialize.
The callers (DestroyableComponent, BuffComponent,
ControllablePhysicsComponent, QuickBuildComponent, RacingControl,
RailActivator and the scripts) build the structs. SendResurrect's
respawn timer moves to DestroyableComponent::Resurrect. The received
messages are registered in GameMessageHandler's map and their switch
cases are deleted, along with the unused HandleRequestDie overload and
the Send* functions nothing called (SendSmash, SendUnSmash, the run
speed modifiers, SendActivateBubbleBuffFromServer). Handler logic is
unchanged.
No wire change and no change in recipients. Verified byte for byte
against a frozen verbatim copy of the old functions over an input grid
(every optional field, bool patterns, empty and long strings), received
messages compared with the old handlers' read sequences and truncated
payloads rejected, hand computed golden bytes, round trips, and a
deliberate width mutation made the tests fail.
Known difference from the client, not changed here: DLU writes
SetStatusImmunity's nine flags in its own order; the client reads them
alphabetically (GameMessage::SetStatusImmunity::Serialize @ 00d8f140).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
6.1 KiB
C++
166 lines
6.1 KiB
C++
#include "BaseEnemyApe.h"
|
|
#include "BaseCombatAIComponent.h"
|
|
#include "DestroyableComponent.h"
|
|
#include "GameMessages.h"
|
|
#include "EffectsMessages.h"
|
|
#include "CombatMessages.h"
|
|
#include "EntityManager.h"
|
|
#include "EntityInfo.h"
|
|
#include "SkillComponent.h"
|
|
#include "eAnimationFlags.h"
|
|
#include "RenderComponent.h"
|
|
#include "eStateChangeType.h"
|
|
|
|
void BaseEnemyApe::OnStartup(Entity* self) {
|
|
self->SetVar<uint32_t>(u"timesStunned", 2);
|
|
self->SetVar<bool>(u"knockedOut", false);
|
|
}
|
|
|
|
void BaseEnemyApe::OnDie(Entity* self, Entity* killer) {
|
|
auto* anchor = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"QB"));
|
|
if (anchor != nullptr && !anchor->GetIsDead()) {
|
|
anchor->Smash(self->GetObjectID(), eKillType::SILENT);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::OnSkillCast(Entity* self, uint32_t skillID) {
|
|
const auto groundPoundSkill = self->GetVar<uint32_t>(u"GroundPoundSkill") != 0 ? self->GetVar<uint32_t>(u"GroundPoundSkill") : 725;
|
|
const auto spawnQuickBuildTime = self->GetVar<float_t>(u"spawnQBTime") != 0.0f ? self->GetVar<float_t>(u"spawnQBTime") : 5.0f;
|
|
|
|
if (skillID == groundPoundSkill && self->GetVar<LWOOBJID>(u"QB") == LWOOBJID_EMPTY) {
|
|
self->AddTimer("spawnQBTime", spawnQuickBuildTime);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::OnHit(Entity* self, Entity* attacker) {
|
|
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
|
if (destroyableComponent != nullptr && destroyableComponent->GetArmor() < 1 && !self->GetBoolean(u"knockedOut")) {
|
|
StunApe(self, true);
|
|
self->CancelTimer("spawnQBTime");
|
|
auto* skillComponent = self->GetComponent<SkillComponent>();
|
|
if (skillComponent) {
|
|
skillComponent->Reset();
|
|
}
|
|
RenderComponent::PlayAnimation(self, u"disable", 1.7f);
|
|
GameMessages::ChangeIdleFlags idleFlags;
|
|
idleFlags.target = self->GetObjectID();
|
|
idleFlags.flagsOn = eAnimationFlags::IDLE_NONE;
|
|
idleFlags.flagsOff = eAnimationFlags::IDLE_COMBAT;
|
|
idleFlags.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
const auto reviveTime = self->GetVar<float_t>(u"reviveTime") != 0.0f
|
|
? self->GetVar<float_t>(u"reviveTime") : 12.0f;
|
|
self->AddTimer("reviveTime", reviveTime);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) {
|
|
if (timerName == "reviveTime") {
|
|
|
|
// Revives the ape, giving it back some armor
|
|
const auto timesStunned = self->GetVar<uint32_t>(u"timesStunned");
|
|
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
|
if (destroyableComponent != nullptr) {
|
|
destroyableComponent->SetArmor(destroyableComponent->GetMaxArmor() / timesStunned);
|
|
}
|
|
Game::entityManager->SerializeEntity(self);
|
|
GameMessages::ChangeIdleFlags idleFlags;
|
|
idleFlags.target = self->GetObjectID();
|
|
idleFlags.flagsOn = eAnimationFlags::IDLE_COMBAT;
|
|
idleFlags.flagsOff = eAnimationFlags::IDLE_NONE;
|
|
idleFlags.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
self->SetVar<uint32_t>(u"timesStunned", timesStunned + 1);
|
|
StunApe(self, false);
|
|
|
|
} else if (timerName == "spawnQBTime" && self->GetVar<LWOOBJID>(u"QB") == LWOOBJID_EMPTY) {
|
|
// Spawn QB in front of ape.
|
|
const auto position = self->GetPosition();
|
|
const auto rotation = self->GetRotation();
|
|
|
|
const auto backwardVector = QuatUtils::Forward(rotation) * -1;
|
|
const auto objectPosition = NiPoint3(
|
|
position.GetX() - (backwardVector.GetX() * 8),
|
|
position.GetY(),
|
|
position.GetZ() - (backwardVector.GetZ() * 8)
|
|
);
|
|
|
|
EntityInfo entityInfo{};
|
|
|
|
entityInfo.pos = position;
|
|
entityInfo.rot = rotation;
|
|
entityInfo.pos.SetY(entityInfo.pos.GetY() + 13.0f);
|
|
|
|
entityInfo.spawnerID = self->GetObjectID();
|
|
entityInfo.lot = self->GetVar<LOT>(u"QuickbuildAnchorLOT") != 0
|
|
? self->GetVar<LOT>(u"QuickbuildAnchorLOT") : 7549;
|
|
entityInfo.settings.Insert<std::string>(u"rebuild_activators",
|
|
std::to_string(objectPosition.GetX()) + "\x1f" +
|
|
std::to_string(objectPosition.GetY()) + "\x1f" +
|
|
std::to_string(objectPosition.GetZ()));
|
|
entityInfo.settings.Insert<bool>(u"no_timed_spawn", true);
|
|
entityInfo.settings.Insert<LWOOBJID>(u"ape", self->GetObjectID());
|
|
|
|
auto* anchor = Game::entityManager->CreateEntity(entityInfo, nullptr, self);
|
|
Game::entityManager->ConstructEntity(anchor);
|
|
self->SetVar<LWOOBJID>(u"QB", anchor->GetObjectID());
|
|
|
|
} else if (timerName == "anchorDamageTimer") {
|
|
|
|
// Attacks the ape with some god skill
|
|
const auto* player = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"smasher"));
|
|
if (player == nullptr) {
|
|
return;
|
|
}
|
|
|
|
auto* skillComponent = self->GetComponent<SkillComponent>();
|
|
if (skillComponent != nullptr) {
|
|
skillComponent->CalculateBehavior(1273, 29446, self->GetObjectID(), true, false, player->GetObjectID());
|
|
}
|
|
|
|
self->SetVar<LWOOBJID>(u"QB", LWOOBJID_EMPTY);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
|
|
int32_t param3) {
|
|
if (args == "rebuildDone" && sender != nullptr) {
|
|
self->SetVar<LWOOBJID>(u"smasher", sender->GetObjectID());
|
|
const auto anchorDamageDelayTime = self->GetVar<float_t>(u"AnchorDamageDelayTime") != 0.0f ? self->GetVar<float_t>(u"AnchorDamageDelayTime") : 0.5f;
|
|
self->AddTimer("anchorDamageTimer", anchorDamageDelayTime);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::StunApe(Entity* self, bool stunState) {
|
|
auto* combatAIComponent = self->GetComponent<BaseCombatAIComponent>();
|
|
if (combatAIComponent != nullptr) {
|
|
combatAIComponent->SetDisabled(stunState);
|
|
combatAIComponent->SetStunned(stunState);
|
|
|
|
auto* skillComponent = self->GetComponent<SkillComponent>();
|
|
if (skillComponent != nullptr) {
|
|
skillComponent->Interrupt();
|
|
}
|
|
|
|
GameMessages::SetStunned stun;
|
|
stun.target = self->GetObjectID();
|
|
stun.StateChangeType = stunState ? eStateChangeType::PUSH : eStateChangeType::POP;
|
|
stun.Originator = self->GetObjectID();
|
|
stun.bCantAttack = true;
|
|
stun.bCantEquip = true;
|
|
stun.bCantInteract = true;
|
|
stun.bCantJump = true;
|
|
stun.bCantMove = true;
|
|
stun.bCantTurn = true;
|
|
stun.bCantUseItem = true;
|
|
stun.bDontTerminateInteract = true;
|
|
stun.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
self->SetBoolean(u"knockedOut", stunState);
|
|
}
|
|
}
|
|
|
|
void BaseEnemyApe::OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) {
|
|
if (self.GetVar<LWOOBJID>(u"QB") == childRemoved.childID) {
|
|
self.SetVar<LWOOBJID>(u"QB", LWOOBJID_EMPTY);
|
|
}
|
|
}
|