Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(skymp5-server): add spawnDelay property #1723

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "PercentagesBinding.h"
#include "PosBinding.h"
#include "ProfileIdBinding.h"
#include "SpawnDelayBinding.h"
#include "SpawnPointBinding.h"
#include "TypeBinding.h"
#include "WorldOrCellDescBinding.h"
Expand Down Expand Up @@ -49,6 +50,7 @@ PropertyBindingFactory::CreateStandardPropertyBindings()
result["idx"] = std::make_shared<IdxBinding>();
result["consoleCommandsAllowed"] =
std::make_shared<ConsoleCommandsAllowedBinding>();
result["spawnDelay"] = std::make_shared<SpawnDelayBinding>();
return result;
}

Expand Down
22 changes: 22 additions & 0 deletions skymp5-server/cpp/addon/property_bindings/SpawnDelayBinding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "SpawnDelayBinding.h"
#include "NapiHelper.h"

Napi::Value SpawnDelayBinding::Get(Napi::Env env, ScampServer& scampServer,
uint32_t formId)
{
auto& partOne = scampServer.GetPartOne();

auto& actor = partOne->worldState.GetFormAt<MpActor>(formId);
return Napi::Number::New(env, actor.GetRespawnTime());
}

void SpawnDelayBinding::Set(Napi::Env env, ScampServer& scampServer,
uint32_t formId, Napi::Value newValue)
{
auto& partOne = scampServer.GetPartOne();

auto newSpawnDelay = NapiHelper::ExtractFloat(newValue, "newSpawnDelay");

auto& actor = partOne->worldState.GetFormAt<MpActor>(formId);
actor.SetRespawnTime(newSpawnDelay);
}
12 changes: 12 additions & 0 deletions skymp5-server/cpp/addon/property_bindings/SpawnDelayBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "PropertyBinding.h"

class SpawnDelayBinding : public PropertyBinding
{
public:
std::string GetPropertyName() const override { return "spawnDelay"; }
Napi::Value Get(Napi::Env env, ScampServer& scampServer,
uint32_t formId) override;
void Set(Napi::Env env, ScampServer& scampServer, uint32_t formId,
Napi::Value newValue) override;
};