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:
David Markowitz
2022-11-03 10:57:54 -07:00
committed by GitHub
parent b974eed8f5
commit 8d37d9b681
567 changed files with 886 additions and 252 deletions

View 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);
}
}
}

View 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;
};

View File

@@ -0,0 +1,4 @@
set(DSCRIPTS_SOURCES_02_SERVER_OBJECTS
"AgSurvivalBuffStation.cpp"
"StinkyFishTarget.cpp"
PARENT_SCOPE)

View 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);
}
}
}

View 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;
};