Compare commits

..

5 Commits

Author SHA1 Message Date
0e7be44ab6 simplify and address feedback 2023-05-11 10:04:05 -05:00
37f60d9177 Make it more robust like speedboost
add check for default
Fix error in GetActiveSpeedboosts
2023-05-10 20:03:02 -05:00
7d3f538456 Fixup 2023-05-10 19:41:29 -05:00
565b23227e Merge branch 'main' into FallSpeedBehavior 2023-05-10 11:45:57 -05:00
4e5b38d602 Hacky FallSpeedBehavior 2022-07-08 19:04:57 -05:00
14 changed files with 115 additions and 71 deletions

View File

@@ -1485,12 +1485,6 @@ void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16s
}
}
void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
script->OnRequestActivityExit(sender, player, canceled);
}
}
void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType) {
if (!m_PlayerIsReadyForUpdates) return;

View File

@@ -207,7 +207,6 @@ public:
void OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData);
void OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier);
void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled);
void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u"");
void Kill(Entity* murderer = nullptr);

View File

@@ -61,6 +61,7 @@
#include "SpeedBehavior.h"
#include "DamageReductionBehavior.h"
#include "JetPackBehavior.h"
#include "FallSpeedBehavior.h"
#include "ChangeIdleFlagsBehavior.h"
#include "DarkInspirationBehavior.h"
@@ -164,7 +165,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
case BehaviorTemplates::BEHAVIOR_CAR_BOOST:
behavior = new CarBoostBehavior(behaviorId);
break;
case BehaviorTemplates::BEHAVIOR_FALL_SPEED: break;
case BehaviorTemplates::BEHAVIOR_FALL_SPEED:
behavior = new FallSpeedBehavior(behaviorId);
break;
case BehaviorTemplates::BEHAVIOR_SHIELD: break;
case BehaviorTemplates::BEHAVIOR_REPAIR_ARMOR:
behavior = new RepairBehavior(behaviorId);

View File

@@ -22,6 +22,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
"DurationBehavior.cpp"
"EmptyBehavior.cpp"
"EndBehavior.cpp"
"FallSpeedBehavior.cpp"
"ForceMovementBehavior.cpp"
"HealBehavior.cpp"
"ImaginationBehavior.cpp"

View File

@@ -0,0 +1,50 @@
#include "FallSpeedBehavior.h"
#include "ControllablePhysicsComponent.h"
#include "BehaviorContext.h"
#include "BehaviorBranchContext.h"
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
// make sure required parameter has non-default value
if (m_PercentSlowed == 0.0f) return;
auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (!target) return;
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
EntityManager::Instance()->SerializeEntity(target);
if (branch.duration > 0.0f) {
context->RegisterTimerBehavior(this, branch);
} else if (branch.start > 0) {
context->RegisterEndBehavior(this, branch);
}
}
void FallSpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
Handle(context, bitStream, branch);
}
void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
End(context, branch, second);
}
void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
End(context, branch, LWOOBJID_EMPTY);
}
void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
auto* target = EntityManager::Instance()->GetEntity(branch.target);
if (!target) return;
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
controllablePhysicsComponent->SetGravityScale(1);
EntityManager::Instance()->SerializeEntity(target);
}
void FallSpeedBehavior::Load(){
m_PercentSlowed = GetFloat("percent_slowed");
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Behavior.h"
class FallSpeedBehavior final : public Behavior
{
public:
explicit FallSpeedBehavior(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 Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
void Load() override;
private:
float m_PercentSlowed;
};

View File

@@ -320,7 +320,7 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
// Recalculate speedboost since we removed one
m_SpeedBoost = 0.0f;
if (m_ActiveSpeedBoosts.size() == 0) { // no active speed boosts left, so return to base speed
if (m_ActiveSpeedBoosts.empty()) { // no active speed boosts left, so return to base speed
auto* levelProgressionComponent = m_Parent->GetComponent<LevelProgressionComponent>();
if (levelProgressionComponent) m_SpeedBoost = levelProgressionComponent->GetSpeedBase();
} else { // Used the last applied speedboost

View File

@@ -276,7 +276,7 @@ public:
* The speed boosts of this component.
* @return All active Speed boosts for this component.
*/
std::vector<float> GetActiveSpeedboosts() { return m_ActivePickupRadiusScales; };
std::vector<float> GetActiveSpeedboosts() { return m_ActiveSpeedBoosts; };
/**
* Activates the Bubble Buff

View File

@@ -677,9 +677,6 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
case eGameMessageType::ZONE_SUMMARY_DISMISSED:
GameMessages::HandleZoneSummaryDismissed(inStream, entity);
break;
case eGameMessageType::REQUEST_ACTIVITY_EXIT:
GameMessages::HandleRequestActivityExit(inStream, entity);
break;
default:
// Game::logger->Log("GameMessageHandler", "Unknown game message ID: %i", messageID);
break;

View File

@@ -91,7 +91,6 @@
#include "eReplicaComponentType.h"
#include "eClientMessageType.h"
#include "eGameMessageType.h"
#include "ActivityManager.h"
#include "CDComponentsRegistryTable.h"
#include "CDObjectsTable.h"
@@ -6205,15 +6204,3 @@ void GameMessages::SendShowBillboardInteractIcon(const SystemAddress& sysAddr, L
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) SEND_PACKET_BROADCAST
else SEND_PACKET
}
void GameMessages::HandleRequestActivityExit(RakNet::BitStream* inStream, Entity* entity) {
bool canceled = false;
inStream->Read(canceled);
if (!canceled) return;
LWOOBJID player_id = LWOOBJID_EMPTY;
inStream->Read(player_id);
auto player = EntityManager::Instance()->GetEntity(player_id);
if (!entity || !player) return;
entity->RequestActivityExit(entity, player_id, canceled);
}

View File

@@ -648,7 +648,6 @@ namespace GameMessages {
void SendDeactivateBubbleBuffFromServer(LWOOBJID objectId, const SystemAddress& sysAddr);
void HandleZoneSummaryDismissed(RakNet::BitStream* inStream, Entity* entity);
void HandleRequestActivityExit(RakNet::BitStream* inStream, Entity* entity);
};
#endif // GAMEMESSAGES_H

View File

@@ -349,15 +349,6 @@ namespace CppScripts {
* @param itemObjId The items Object ID
*/
virtual void OnFactionTriggerItemUnequipped(Entity* itemOwner, LWOOBJID itemObjId) {};
/**
* Handles exiting a scripted activity
*
* @param sender
* @param player the player to remove
* @param canceled if it was done via the cancel button
*/
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){};
};
Script* GetScript(Entity* parent, const std::string& scriptName);

View File

@@ -135,26 +135,38 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
}
}
void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier,
const std::u16string& userData) {
auto* player = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
if (!player) return;
if (player != nullptr) {
if (button == 1 && identifier == u"Shooting_Gallery_Stop") {
UpdatePlayer(self, player->GetObjectID(), true);
RemovePlayer(player->GetObjectID());
StopGame(self, true);
return;
}
if (identifier == u"Scoreboardinfo") {
GameMessages::SendDisplayMessageBox(player->GetObjectID(), true,
dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(),
u"Shooting_Gallery_Retry", 2, u"Retry?",
u"", player->GetSystemAddress());
} else {
if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay")) || identifier == u"SG1" || button == 0) {
if (IsPlayerInActivity(self, player->GetObjectID())) return;
self->SetNetworkVar<bool>(ClearVariable, true);
StartGame(self);
} else if (button == 0 && ((identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay"))){
RemovePlayer(player->GetObjectID());
UpdatePlayer(self, player->GetObjectID(), true);
} else if (button == 1 && identifier == u"Shooting_Gallery_Exit") {
UpdatePlayer(self, player->GetObjectID(), true);
RemovePlayer(player->GetObjectID());
if (identifier == u"Scoreboardinfo") {
GameMessages::SendDisplayMessageBox(player->GetObjectID(), true,
dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(),
u"Shooting_Gallery_Retry?", 2, u"Retry?",
u"", player->GetSystemAddress());
} else {
if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay"))
|| identifier == u"SG1" || button == 0) {
if (identifier == u"RePlay") {
static_cast<Player*>(player)->SendToZone(1300);
return;
}
self->SetNetworkVar<bool>(ClearVariable, true);
StartGame(self);
} else if (button == 1 && identifier == u"Shooting_Gallery_Exit") {
UpdatePlayer(self, player->GetObjectID(), true);
RemovePlayer(player->GetObjectID());
}
}
}
}
@@ -255,13 +267,14 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) {
if (self->GetVar<bool>(GameStartedVariable)) {
const auto spawnNumber = (uint32_t)std::stoi(name.substr(7));
const auto& activeSpawns = self->GetVar<std::vector<SGEnemy>>(ActiveSpawnsVariable);
if (activeSpawns.size() < spawnNumber) {
Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size());
return;
}
const auto& toSpawn = activeSpawns.at(spawnNumber);
const auto pathIndex = GeneralUtils::GenerateRandomNumber<float_t>(0, toSpawn.spawnPaths.size() - 1);
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex));
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(
toSpawn.spawnPaths.at(pathIndex)
);
if (!path) {
Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex);
return;
@@ -328,7 +341,6 @@ SGCannon::OnActivityTimerUpdate(Entity* self, const std::string& name, float_t t
}
void SGCannon::StartGame(Entity* self) {
if (self->GetVar<bool>(GameStartedVariable)) return;
self->SetNetworkVar<uint32_t>(TimeLimitVariable, self->GetVar<uint32_t>(TimeLimitVariable));
self->SetNetworkVar<bool>(AudioStartIntroVariable, true);
self->SetVar<LOT>(CurrentRewardVariable, LOT_NULL);
@@ -435,14 +447,6 @@ void SGCannon::RemovePlayer(LWOOBJID playerID) {
}
}
void SGCannon::OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled){
if (canceled){
StopGame(self, canceled);
RemovePlayer(player);
}
}
void SGCannon::StartChargedCannon(Entity* self, uint32_t optionalTime) {
optionalTime = optionalTime == 0 ? constants.chargedTime : optionalTime;
self->SetVar<bool>(SuperChargePausedVariable, false);

View File

@@ -63,11 +63,12 @@ public:
void OnStartup(Entity* self) override;
void OnPlayerLoaded(Entity* self, Entity* player) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1,
int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier,
const std::u16string& userData) override;
void OnActivityTimerDone(Entity* self, const std::string& name) override;
void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override;
void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override;
private:
static std::vector<std::vector<SGEnemy>> GetWaves();
static SGConstants GetConstants();