Skip to content

Commit

Permalink
Merge branch 'main' into fix_login_another_account
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE authored Sep 14, 2024
2 parents c08791d + e4f0cdb commit 96e9963
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
33 changes: 33 additions & 0 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4027,6 +4027,9 @@
<attribute key="count" value="2"/>
<attribute key="damage" value="20"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="2001" article="an" name="unlit campfire">
<attribute key="primarytype" value="illumination"/>
Expand Down Expand Up @@ -4342,6 +4345,9 @@
</attribute>
<attribute key="duration" value="120"/>
<attribute key="decayTo" value="2132"/>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="2132" article="a" name="fire field">
<attribute key="type" value="magicfield"/>
Expand Down Expand Up @@ -20590,6 +20596,9 @@
<attribute key="field" value="fire">
<attribute key="damage" value="300"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
<attribute key="replaceable" value="0"/>
</item>
<item fromid="7474" toid="7475" article="a" name="sarcophagus">
Expand Down Expand Up @@ -26310,6 +26319,9 @@
<attribute key="count" value="7"/>
<attribute key="damage" value="10"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
<attribute key="replaceable" value="0"/>
</item>
<item id="10070" article="a" name="fire field">
Expand All @@ -26319,6 +26331,9 @@
<attribute key="count" value="7"/>
<attribute key="damage" value="10"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
<attribute key="replaceable" value="0"/>
</item>
<item id="10071" article="a" name="fire field">
Expand All @@ -26328,6 +26343,9 @@
<attribute key="count" value="7"/>
<attribute key="damage" value="10"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
<attribute key="replaceable" value="0"/>
</item>
<item fromid="10072" toid="10081" name="zaoan decoration"/>
Expand Down Expand Up @@ -45774,20 +45792,29 @@ hands of its owner. Granted by TibiaRoyal.com"/>
<attribute key="ticks" value="10000"/>
<attribute key="damage" value="25"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="23366" article="an" name="energy trap">
<attribute key="type" value="magicfield"/>
<attribute key="field" value="energy">
<attribute key="ticks" value="10000"/>
<attribute key="damage" value="25"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="23367" article="a" name="toxic trap">
<attribute key="type" value="magicfield"/>
<attribute key="field" value="poison">
<attribute key="ticks" value="10000"/>
<attribute key="damage" value="25"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="23368" article="a" name="poison trap">
<attribute key="type" value="magicfield"/>
Expand All @@ -45796,6 +45823,9 @@ hands of its owner. Granted by TibiaRoyal.com"/>
<attribute key="damage" value="100"/>
<attribute key="start" value="5"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="23369" article="a" name="blade trap"/>
<item id="23370" article="a" name="spike trap"/>
Expand Down Expand Up @@ -58245,6 +58275,9 @@ hands of its owner. Granted by TibiaRoyal.com"/>
<attribute key="ticks" value="10000"/>
<attribute key="damage" value="25"/>
</attribute>
<attribute key="script" value="moveevent">
<attribute key="eventType" value="stepin"/>
</attribute>
</item>
<item id="31381" name="nothing">
<attribute key="primarytype" value="natural tiles"/>
Expand Down
13 changes: 11 additions & 2 deletions src/lua/functions/core/game/config_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ int ConfigFunctions::luaConfigManagerGetBoolean(lua_State* L) {
}

int ConfigFunctions::luaConfigManagerGetFloat(lua_State* L) {
auto key = getNumber<ConfigKey_t>(L, -1);
// configManager.getFloat(key, shouldRound = true)

// Ensure the first argument (key) is provided and is a valid enum
auto key = getNumber<ConfigKey_t>(L, 1);
if (!key) {
reportErrorFunc("Wrong enum");
return 1;
}

lua_pushnumber(L, g_configManager().getFloat(key, __FUNCTION__));
// Check if the second argument (shouldRound) is provided and is a boolean; default to true if not provided
bool shouldRound = getBoolean(L, 2, true);
float value = g_configManager().getFloat(key, __FUNCTION__);
double finalValue = shouldRound ? static_cast<double>(std::round(value * 100.0) / 100.0) : value;

g_logger().debug("[{}] key: {}, finalValue: {}, shouldRound: {}", __METHOD_NAME__, magic_enum::enum_name(key), finalValue, shouldRound);
lua_pushnumber(L, finalValue);
return 1;
}
27 changes: 27 additions & 0 deletions src/lua/functions/core/game/config_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ class ConfigFunctions final : LuaScriptInterface {
static void init(lua_State* L);

private:
/**
* @brief Retrieves a float configuration value from the configuration manager, with an optional rounding.
*
* This function is a Lua binding used to get a float value from the configuration manager. It requires
* a key as the first argument, which should be a valid enumeration. An optional second boolean argument
* specifies whether the retrieved float should be rounded to two decimal places.
*
* @param L Pointer to the Lua state. The first argument must be a valid enum key, and the second argument (optional)
* can be a boolean indicating whether to round the result.
*
* @return Returns 1 after pushing the result onto the Lua stack, indicating the number of return values.
*
* @exception reportErrorFunc Throws an error if the first argument is not a valid enum.
*
* Usage:
* local result = ConfigManager.getFloat(ConfigKey.SomeKey)
* local result_rounded = ConfigManager.getFloat(ConfigKey.SomeKey, false)
*
* Detailed behavior:
* 1. Extracts the key from the first Lua stack argument as an enumeration of type `ConfigKey_t`.
* 2. Checks if the second argument is provided; if not, defaults to true for rounding.
* 3. Retrieves the float value associated with the key from the configuration manager.
* 4. If rounding is requested, rounds the value to two decimal places.
* 5. Logs the method call and the obtained value using the debug logger.
* 6. Pushes the final value (rounded or original) back onto the Lua stack.
* 7. Returns 1 to indicate a single return value.
*/
static int luaConfigManagerGetFloat(lua_State* L);
static int luaConfigManagerGetBoolean(lua_State* L);
static int luaConfigManagerGetNumber(lua_State* L);
Expand Down

0 comments on commit 96e9963

Please sign in to comment.