Skip to content

Commit

Permalink
feat(skymp5-server): add weapon type dependent stamina consumption (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
barkinlove authored Aug 31, 2023
1 parent e4f22fc commit c8c61f7
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 99 deletions.
19 changes: 19 additions & 0 deletions docs/docs_server_configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,22 @@ how they should be spawned: in interior or exterior. By default all the npcs are
// ...
}
```

## weaponStaminaModifiers

This setting is only available with game mod file "SweetPie.esp".
This option allows you to flexibly adjust stamina forfeits of players' attacks using keywords set in the Creation Kit.
In case this field is not provided, some default, yet hardcoded, values are in use.

```json5
{
// ...
"weaponStaminaModifiers": {
"WeapTypeDagger": 4.0,
"WeapTypeShortSword": 5.0,
"WeapTypeSword": 6.0,
...
}
// ...
}
```
22 changes: 22 additions & 0 deletions skymp5-server/cpp/addon/ScampServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ ScampServer::ScampServer(const Napi::CallbackInfo& info)

auto serverSettings = nlohmann::json::parse(buffer.str());

if (serverSettings.find("weaponStaminaModifiers") !=
serverSettings.end()) {
if (serverSettings.at("weaponStaminaModifiers").is_object()) {
auto modifiers = serverSettings.at("weaponStaminaModifiers")
.get<std::unordered_map<std::string, float>>();
if (modifiers.empty()) {
logger->info("\"weaponStaminaModifiers field is empty. Using "
"default values for stamina managment instead.\"");
} else {
logger->info(
"Using keywords based stamina forfeits for players attacks");
}
partOne->animationSystem.SetWeaponStaminaModifiers(
std::move(modifiers));
}
} else {
logger->info("\"weaponStaminaModifiers field is missing. Using "
"default values for stamina managment instead.\"");
}

if (serverSettings["logLevel"].is_string()) {
const auto level = spdlog::level::from_str(serverSettings["logLevel"]);
logger->set_level(level);
Expand Down Expand Up @@ -280,6 +300,8 @@ ScampServer::ScampServer(const Napi::CallbackInfo& info)
partOne->worldState.AttachScriptStorage(scriptStorage);

partOne->AttachEspm(espm);
partOne->animationSystem.Init(&partOne->worldState);

this->serverSettings = serverSettings;
this->logger = logger;

Expand Down
11 changes: 1 addition & 10 deletions skymp5-server/cpp/server_guest_lib/ActionListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,7 @@ void ActionListener::OnUpdateAnimation(const RawMessageData& rawMsgData,
return;
}

if (!partOne.animationSystem) {
std::vector<std::string> espmFiles = espmProvider->espmFiles;

std::set<std::string> s;
s = { espmFiles.begin(), espmFiles.end() };
bool isSweetpie = s.count("SweetPie.esp") != 0;

partOne.animationSystem = std::make_unique<AnimationSystem>(isSweetpie);
}
partOne.animationSystem->Process(actor, animationData);
partOne.animationSystem.Process(actor, animationData);

SendToNeighbours(idx, rawMsgData);
}
Expand Down
Loading

0 comments on commit c8c61f7

Please sign in to comment.