Skip to content

Commit

Permalink
feat(skymp5-server): add spawnDelay property to gamemode API (skyrim-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Oct 25, 2023
1 parent a9c5de7 commit 1604dbf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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;
};

0 comments on commit 1604dbf

Please sign in to comment.