Skip to content
Open
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
12 changes: 12 additions & 0 deletions Source/lua/lua_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string_view>
#include <utility>

#include <sol/sol.hpp>

Check warning on line 7 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:7:1 [misc-include-cleaner]

included header sol.hpp is not used directly

#include "lua/lua_global.hpp"
#include "monster.h"
Expand All @@ -16,15 +16,15 @@
namespace lua {

template <typename... Args>
void CallLuaEvent(std::string_view name, Args &&...args)

Check warning on line 19 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:19:6 [misc-use-internal-linkage]

function 'CallLuaEvent' can be made static or moved into an anonymous namespace to enforce internal linkage
{
sol::table *events = GetLuaEvents();

Check warning on line 21 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:21:7 [misc-include-cleaner]

no header providing "sol::table" is directly included
if (events == nullptr) {
return;
}

const auto trigger = events->traverse_get<std::optional<sol::object>>(name, "trigger");

Check warning on line 26 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:26:63 [misc-include-cleaner]

no header providing "sol::object" is directly included
if (!trigger.has_value() || !trigger->is<sol::protected_function>()) {

Check warning on line 27 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:27:48 [misc-include-cleaner]

no header providing "sol::protected_function" is directly included
LogError("events.{}.trigger is not a function", name);
return;
}
Expand All @@ -33,7 +33,7 @@
}

template <typename T, typename... Args>
T CallLuaEventReturn(T defaultValue, std::string_view name, Args &&...args)

Check warning on line 36 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:36:3 [misc-use-internal-linkage]

function 'CallLuaEventReturn' can be made static or moved into an anonymous namespace to enforce internal linkage
{
sol::table *events = GetLuaEvents();
if (events == nullptr) {
Expand All @@ -45,7 +45,7 @@
return defaultValue;
}
const sol::protected_function fn = trigger->as<sol::protected_function>();
sol::object result = SafeCallResult(fn(std::forward<Args>(args)...), /*optional=*/true);

Check warning on line 48 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:48:2 [misc-const-correctness]

variable 'result' of type 'sol::object' (aka 'basic_object<basic_reference<false>>') can be declared 'const'
if (result.is<T>()) {
return result.as<T>();
}
Expand Down Expand Up @@ -79,7 +79,19 @@
CallLuaEvent("OnMonsterTakeDamage", monster, damage, damageType);
}

bool OnPlayerDeathDropEar(const Player *player)
{
return CallLuaEventReturn<bool>(true, "OnPlayerDeathDropEar", player);
}
bool OnPlayerDeathDropGold(const Player *player)
{
return CallLuaEventReturn<bool>(true, "OnPlayerDeathDropGold", player);
}
bool OnPlayerDeathDropItem(const Player *player)
{
return CallLuaEventReturn<bool>(true, "OnPlayerDeathDropItem", player);
}
void OnPlayerGainExperience(const Player *player, uint32_t exp)

Check warning on line 94 in Source/lua/lua_event.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/lua/lua_event.cpp:94:51 [misc-include-cleaner]

no header providing "uint32_t" is directly included
{
CallLuaEvent("OnPlayerGainExperience", player, exp);
}
Expand Down
3 changes: 3 additions & 0 deletions Source/lua/lua_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ void StoreOpened(std::string_view name);

void OnMonsterTakeDamage(const Monster *monster, int damage, int damageType);

bool OnPlayerDeathDropEar(const Player *player);
bool OnPlayerDeathDropGold(const Player *player);
bool OnPlayerDeathDropItem(const Player *player);
void OnPlayerGainExperience(const Player *player, uint32_t exp);
void OnPlayerTakeDamage(const Player *player, int damage, int damageType);

Expand Down
16 changes: 13 additions & 3 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_timer.h>
#else
#include <SDL.h>

Check warning on line 14 in Source/player.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/player.cpp:14:1 [misc-include-cleaner]

included header SDL.h is not used directly
#endif

#include <fmt/core.h>

#include "control/control.hpp"
#include "controls/control_mode.hpp"
#include "controls/plrctrls.h"

Check warning on line 21 in Source/player.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/player.cpp:21:1 [misc-include-cleaner]

included header plrctrls.h is not used directly
#include "cursor.h"
#include "dead.h"
#ifdef _DEBUG
Expand Down Expand Up @@ -2689,9 +2689,19 @@
gamemenu_off();
}

const bool dropGold = !gbIsMultiplayer || !(player.isOnLevel(16) || player.isOnArenaLevel());
const bool dropItems = dropGold && deathReason == DeathReason::MonsterOrTrap;
const bool dropEar = dropGold && deathReason == DeathReason::Player;
bool dropGold = !gbIsMultiplayer || !(player.isOnLevel(16) || player.isOnArenaLevel());
bool dropItems = dropGold && deathReason == DeathReason::MonsterOrTrap;
bool dropEar = dropGold && deathReason == DeathReason::Player;

if (dropGold && !lua::OnPlayerDeathDropGold(&player)) {
dropGold = false;
}
if (dropItems && !lua::OnPlayerDeathDropItem(&player)) {
dropItems = false;
}
if (dropEar && !lua::OnPlayerDeathDropEar(&player)) {
dropEar = false;
}

player.Say(HeroSpeech::AuughUh);

Expand Down
12 changes: 12 additions & 0 deletions assets/lua/devilutionx/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ local events = {
---Called when Player gains experience.
OnPlayerGainExperience = CreateEvent(),
__doc_OnPlayerGainExperience = "Called when Player gains experience.",

---Called when Player dies to determine if gold is dropped. Return false to prevent gold drop.
OnPlayerDeathDropGold = CreateEvent(),
__doc_OnPlayerDeathDropGold = "Called when Player dies to determine if gold is dropped. Return false to prevent gold drop.",

---Called when Player dies to determine if items are dropped. Return false to prevent item drop.
OnPlayerDeathDropItem = CreateEvent(),
__doc_OnPlayerDeathDropItem = "Called when Player dies to determine if items are dropped. Return false to prevent item drop.",

---Called when Player dies to determine if an ear is dropped. Return false to prevent ear drop.
OnPlayerDeathDropEar = CreateEvent(),
__doc_OnPlayerDeathDropEar = "Called when Player dies to determine if an ear is dropped. Return false to prevent ear drop.",
}

---Registers a custom event type with the given name.
Expand Down
Loading