mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 02:43:44 +00:00
refactor: death, stun, buff and knockback game messages as structs
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>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "DestroyableComponent.h"
|
||||
#include "CombatMessages.h"
|
||||
#include "LevelProgressionComponent.h"
|
||||
#include "EconomyLedger.h"
|
||||
#include "BitStream.h"
|
||||
#include "Logger.h"
|
||||
@@ -779,7 +781,15 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
|
||||
const auto isPlayer = m_Parent->IsPlayer();
|
||||
|
||||
GameMessages::SendDie(m_Parent, source, source, true, killType, deathType, 0, 0, 0, isPlayer, true, 1);
|
||||
GameMessages::Die die;
|
||||
die.target = m_Parent->GetObjectID();
|
||||
die.bClientDeath = isPlayer;
|
||||
die.bSpawnLoot = true;
|
||||
die.deathType = deathType;
|
||||
die.killType = killType;
|
||||
die.killerID = source;
|
||||
die.lootOwnerID = source;
|
||||
die.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
//NANI?!
|
||||
if (!isPlayer) {
|
||||
@@ -870,18 +880,19 @@ void DestroyableComponent::SetStatusImmunity(
|
||||
if (bImmuneToPullToPoint) m_ImmuneToPullToPointCount += 1;
|
||||
}
|
||||
|
||||
GameMessages::SendSetStatusImmunity(
|
||||
m_Parent->GetObjectID(), state, m_Parent->GetSystemAddress(),
|
||||
bImmuneToBasicAttack,
|
||||
bImmuneToDamageOverTime,
|
||||
bImmuneToKnockback,
|
||||
bImmuneToInterrupt,
|
||||
bImmuneToSpeed,
|
||||
bImmuneToImaginationGain,
|
||||
bImmuneToImaginationLoss,
|
||||
bImmuneToQuickbuildInterrupt,
|
||||
bImmuneToPullToPoint
|
||||
);
|
||||
GameMessages::SetStatusImmunity statusImmunity;
|
||||
statusImmunity.target = m_Parent->GetObjectID();
|
||||
statusImmunity.StateChangeType = state;
|
||||
statusImmunity.bImmuneToBasicAttack = bImmuneToBasicAttack;
|
||||
statusImmunity.bImmuneToDOT = bImmuneToDamageOverTime;
|
||||
statusImmunity.bImmuneToKnockback = bImmuneToKnockback;
|
||||
statusImmunity.bImmuneToInterrupt = bImmuneToInterrupt;
|
||||
statusImmunity.bImmuneToSpeed = bImmuneToSpeed;
|
||||
statusImmunity.bImmuneToImaginationGain = bImmuneToImaginationGain;
|
||||
statusImmunity.bImmuneToImaginationLoss = bImmuneToImaginationLoss;
|
||||
statusImmunity.bImmuneToQuickbuildInterrupt = bImmuneToQuickbuildInterrupt;
|
||||
statusImmunity.bImmuneToPullToPoint = bImmuneToPullToPoint;
|
||||
statusImmunity.Send(m_Parent->GetSystemAddress());
|
||||
}
|
||||
|
||||
void DestroyableComponent::FixStats() {
|
||||
@@ -1222,3 +1233,36 @@ bool DestroyableComponent::OnIsDead(GameMessages::IsDead& isDead) {
|
||||
isDead.bDead = m_IsDead || (GetHealth() == 0 && GetArmor() == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DestroyableComponent::Resurrect(Entity& entityRef) {
|
||||
Entity* entity = &entityRef;
|
||||
// Restore the players health after the animation for respawning has finished.
|
||||
// This is when the health appered back in live, not immediately upon requesting respawn
|
||||
// Add a half second in case someone decides to cheat and move during the death animation
|
||||
// and just make sure the client has time to be ready.
|
||||
constexpr float respawnTime = 3.66700005531311f + 0.5f;
|
||||
entity->AddCallbackTimer(respawnTime, [=]() {
|
||||
GameMessages::PlayerResurrectionFinished msg;
|
||||
entity->NotifyPlayerResurrectionFinished(msg);
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr && entity->GetLOT() == 1) {
|
||||
destroyableComponent->SetIsDead(false);
|
||||
auto* levelComponent = entity->GetComponent<LevelProgressionComponent>();
|
||||
if (levelComponent) {
|
||||
int32_t healthToRestore = levelComponent->GetLevel() >= 45 ? 8 : 4;
|
||||
if (healthToRestore > destroyableComponent->GetMaxHealth()) healthToRestore = destroyableComponent->GetMaxHealth();
|
||||
destroyableComponent->SetHealth(healthToRestore);
|
||||
|
||||
int32_t imaginationToRestore = levelComponent->GetLevel() >= 45 ? 20 : 6;
|
||||
if (imaginationToRestore > destroyableComponent->GetMaxImagination()) imaginationToRestore = destroyableComponent->GetMaxImagination();
|
||||
destroyableComponent->SetImagination(imaginationToRestore);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GameMessages::Resurrect resurrect;
|
||||
resurrect.target = entity->GetObjectID();
|
||||
resurrect.bRezImmediately = false;
|
||||
resurrect.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user