mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Organize dScripts (#814)
* Organize dScripts whitespace Remove parent scope Remove parent scope from initial setter Remove debug Remove helper programs * Fix NtImagimeterVisibility script Co-authored-by: aronwk-aaron <aronwk.aaron@gmail.com>
This commit is contained in:
65
dScripts/02_server/Objects/AgSurvivalBuffStation.cpp
Normal file
65
dScripts/02_server/Objects/AgSurvivalBuffStation.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "AgSurvivalBuffStation.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "GameMessages.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "TeamManager.h"
|
||||
|
||||
void AgSurvivalBuffStation::OnRebuildComplete(Entity* self, Entity* target) {
|
||||
auto destroyableComponent = self->GetComponent<DestroyableComponent>();
|
||||
// We set the faction to 1 so that the buff station sees players as friendly targets to buff
|
||||
if (destroyableComponent != nullptr) destroyableComponent->SetFaction(1);
|
||||
|
||||
auto skillComponent = self->GetComponent<SkillComponent>();
|
||||
|
||||
if (skillComponent != nullptr) skillComponent->CalculateBehavior(skillIdForBuffStation, behaviorIdForBuffStation, self->GetObjectID());
|
||||
|
||||
self->AddCallbackTimer(smashTimer, [self]() {
|
||||
self->Smash();
|
||||
});
|
||||
self->AddTimer("DropArmor", dropArmorTimer);
|
||||
self->AddTimer("DropLife", dropLifeTimer);
|
||||
self->AddTimer("Dropimagination", dropImaginationTimer);
|
||||
// Since all survival players should be on the same team, we get the team.
|
||||
auto team = TeamManager::Instance()->GetTeam(target->GetObjectID());
|
||||
|
||||
std::vector<LWOOBJID> builderTeam;
|
||||
// Not on a team
|
||||
if (team == nullptr) {
|
||||
builderTeam.push_back(target->GetObjectID());
|
||||
self->SetVar<std::vector<LWOOBJID>>(u"BuilderTeam", builderTeam);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto memberID : team->members) {
|
||||
builderTeam.push_back(memberID);
|
||||
}
|
||||
self->SetVar<std::vector<LWOOBJID>>(u"BuilderTeam", builderTeam);
|
||||
}
|
||||
|
||||
void AgSurvivalBuffStation::OnTimerDone(Entity* self, std::string timerName) {
|
||||
uint32_t powerupToDrop = lifePowerup;
|
||||
if (timerName == "DropArmor") {
|
||||
powerupToDrop = armorPowerup;
|
||||
self->AddTimer("DropArmor", dropArmorTimer);
|
||||
}
|
||||
if (timerName == "DropLife") {
|
||||
powerupToDrop = lifePowerup;
|
||||
self->AddTimer("DropLife", dropLifeTimer);
|
||||
}
|
||||
if (timerName == "Dropimagination") {
|
||||
powerupToDrop = imaginationPowerup;
|
||||
self->AddTimer("Dropimagination", dropImaginationTimer);
|
||||
}
|
||||
auto team = self->GetVar<std::vector<LWOOBJID>>(u"BuilderTeam");
|
||||
for (auto memberID : team) {
|
||||
auto member = EntityManager::Instance()->GetEntity(memberID);
|
||||
if (member != nullptr && !member->GetIsDead()) {
|
||||
GameMessages::SendDropClientLoot(member, self->GetObjectID(), powerupToDrop, 0, self->GetPosition());
|
||||
} else {
|
||||
// If player left the team or left early erase them from the team variable.
|
||||
team.erase(std::find(team.begin(), team.end(), memberID));
|
||||
self->SetVar<std::vector<LWOOBJID>>(u"BuilderTeam", team);
|
||||
}
|
||||
}
|
||||
}
|
52
dScripts/02_server/Objects/AgSurvivalBuffStation.h
Normal file
52
dScripts/02_server/Objects/AgSurvivalBuffStation.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class AgSurvivalBuffStation : public CppScripts::Script
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief When the rebuild of self is complete, we calculate the behavior that is assigned to self in the database.
|
||||
*
|
||||
* @param self The Entity that called this script.
|
||||
* @param target The target of the self that called this script.
|
||||
*/
|
||||
void OnRebuildComplete(Entity* self, Entity* target) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
private:
|
||||
/**
|
||||
* Skill ID for the buff station.
|
||||
*/
|
||||
uint32_t skillIdForBuffStation = 201;
|
||||
/**
|
||||
* Behavior ID for the buff station.
|
||||
*/
|
||||
uint32_t behaviorIdForBuffStation = 1784;
|
||||
/**
|
||||
* Timer for dropping armor.
|
||||
*/
|
||||
float dropArmorTimer = 6.0f;
|
||||
/**
|
||||
* Timer for dropping life.
|
||||
*/
|
||||
float dropLifeTimer = 3.0f;
|
||||
/**
|
||||
* Timer for dropping imagination.
|
||||
*/
|
||||
float dropImaginationTimer = 4.0f;
|
||||
/**
|
||||
* Timer for smashing.
|
||||
*/
|
||||
float smashTimer = 25.0f;
|
||||
/**
|
||||
* LOT for armor powerup.
|
||||
*/
|
||||
LOT armorPowerup = 6431;
|
||||
/**
|
||||
* LOT for life powerup.
|
||||
*/
|
||||
LOT lifePowerup = 177;
|
||||
/**
|
||||
* LOT for imagination powerup.
|
||||
*/
|
||||
LOT imaginationPowerup = 935;
|
||||
};
|
4
dScripts/02_server/Objects/CMakeLists.txt
Normal file
4
dScripts/02_server/Objects/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS
|
||||
"AgSurvivalBuffStation.cpp"
|
||||
"StinkyFishTarget.cpp"
|
||||
PARENT_SCOPE)
|
42
dScripts/02_server/Objects/StinkyFishTarget.cpp
Normal file
42
dScripts/02_server/Objects/StinkyFishTarget.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "StinkyFishTarget.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
void StinkyFishTarget::OnStartup(Entity* self) {
|
||||
auto position = self->GetPosition();
|
||||
position.SetY(position.GetY() - 0.5f);
|
||||
self->SetPosition(position);
|
||||
}
|
||||
|
||||
void StinkyFishTarget::OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) {
|
||||
if (message != "stinkfish" || self->GetVar<bool>(u"used"))
|
||||
return;
|
||||
|
||||
self->SetVar<bool>(u"used", true);
|
||||
self->SetVar<LWOOBJID>(u"player", caster->GetObjectID());
|
||||
|
||||
EntityInfo entityInfo{};
|
||||
entityInfo.pos = self->GetPosition();
|
||||
entityInfo.rot = self->GetRotation();
|
||||
entityInfo.spawnerID = self->GetObjectID();
|
||||
entityInfo.settings = {
|
||||
new LDFData<bool>(u"no_timed_spawn", true)
|
||||
};
|
||||
|
||||
auto* fish = EntityManager::Instance()->CreateEntity(entityInfo);
|
||||
EntityManager::Instance()->ConstructEntity(fish);
|
||||
|
||||
self->SetVar<LWOOBJID>(u"fish", fish->GetObjectID());
|
||||
self->AddTimer("smash", 5.0f);
|
||||
}
|
||||
|
||||
void StinkyFishTarget::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "smash") {
|
||||
const auto playerID = self->GetVar<LWOOBJID>(u"player");
|
||||
auto* fish = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"fish"));
|
||||
|
||||
if (fish != nullptr) {
|
||||
fish->Smash(playerID);
|
||||
self->Smash(playerID);
|
||||
}
|
||||
}
|
||||
}
|
8
dScripts/02_server/Objects/StinkyFishTarget.h
Normal file
8
dScripts/02_server/Objects/StinkyFishTarget.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class StinkyFishTarget : public CppScripts::Script {
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
};
|
Reference in New Issue
Block a user