Skip to content

Commit

Permalink
fix: erase forgeable monsters and reduce spawn time (#3014)
Browse files Browse the repository at this point in the history
• Influenced and Fiendish monsters wrong
• New buffs: https://tibia.fandom.com/wiki/Fiendish_and_Influenced_Creatures#Strength
• Influenced monsters taking a long time to spawn
• Only replace forgeable monsters when necessary
  • Loading branch information
murilo09 authored Oct 28, 2024
1 parent ef97a60 commit 5244ed5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ forgeAmountMultiplier = 3
forgeMinSlivers = 3
forgeMaxSlivers = 7
forgeInfluencedLimit = 300
forgeFiendishLimit = 3
forgeFiendishLimit = 4
forgeFiendishIntervalType = "hour"
forgeFiendishIntervalTime = "1"

Expand Down
2 changes: 1 addition & 1 deletion data/libs/functions/monster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Monster.setFiendish(self, position, player)
if fiendishMonster then
Game.removeFiendishMonster(fiendishMonster:getId())
end
if Game.makeFiendishMonster(self:getId(), true) ~= 0 then
if Game.makeFiendishMonster(self:getId(), false) ~= 0 then
success = "set sucessfully a new fiendish monster"
else
success = "have error to set fiendish monster"
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ void Monster::configureForgeSystem() {
}

// Change health based in stacks
float percentToIncrement = static_cast<float>((forgeStack * 6) + 100) / 100.f;
const auto percentToIncrement = 1 + (15 * forgeStack + 35) / 100.f;
auto newHealth = static_cast<int32_t>(std::ceil(static_cast<float>(healthMax) * percentToIncrement));

healthMax = newHealth;
Expand Down
5 changes: 4 additions & 1 deletion src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ class Monster final : public Creature {

float getDefenseMultiplier() const {
float multiplier = mType->getDefenseMultiplier();
return multiplier * std::pow(1.02f, getForgeStack());
if (auto stacks = getForgeStack(); stacks > 0) {
multiplier *= (1 + (0.1 * stacks));
}
return multiplier;
}

bool isDead() const override {
Expand Down
29 changes: 17 additions & 12 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10073,7 +10073,7 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr
forgeableMonsters.clear();
// If the forgeable monsters haven't been created
// Then we'll create them so they don't return in the next if (forgeableMonsters.empty())
for (auto [monsterId, monster] : monsters) {
for (const auto &[monsterId, monster] : monsters) {
auto monsterTile = monster->getTile();
if (!monster || !monsterTile) {
continue;
Expand All @@ -10092,7 +10092,9 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr
}

// If you're trying to create a new fiendish and it's already max size, let's remove one of them
if (getFiendishMonsters().size() >= 3) {
if (auto fiendishLimit = g_configManager().getNumber(FORGE_FIENDISH_CREATURES_LIMIT);
// Condition
getFiendishMonsters().size() >= fiendishLimit) {
monster->clearFiendishStatus();
removeFiendishMonster(monsterId);
break;
Expand Down Expand Up @@ -10212,7 +10214,7 @@ bool Game::removeInfluencedMonster(uint32_t id, bool create /* = false*/) {

if (create) {
g_dispatcher().scheduleEvent(
200 * 1000, [this] { makeInfluencedMonster(); }, "Game::makeInfluencedMonster"
10 * 1000, [this] { makeInfluencedMonster(); }, "Game::makeInfluencedMonster"
);
}
} else {
Expand All @@ -10230,7 +10232,7 @@ bool Game::removeFiendishMonster(uint32_t id, bool create /* = true*/) {

if (create) {
g_dispatcher().scheduleEvent(
300 * 1000, [this] { makeFiendishMonster(0, false); }, "Game::makeFiendishMonster"
270 * 1000, [this] { makeFiendishMonster(0, false); }, "Game::makeFiendishMonster"
);
}
} else {
Expand All @@ -10241,15 +10243,18 @@ bool Game::removeFiendishMonster(uint32_t id, bool create /* = true*/) {
}

void Game::updateForgeableMonsters() {
forgeableMonsters.clear();
for (const auto &[monsterId, monster] : monsters) {
auto monsterTile = monster->getTile();
if (!monsterTile) {
continue;
}
if (auto influencedLimit = g_configManager().getNumber(FORGE_INFLUENCED_CREATURES_LIMIT);
forgeableMonsters.size() < influencedLimit) {
forgeableMonsters.clear();
for (const auto &[monsterId, monster] : monsters) {
const auto &monsterTile = monster->getTile();
if (!monsterTile) {
continue;
}

if (monster->canBeForgeMonster() && !monsterTile->hasFlag(TILESTATE_NOLOGOUT)) {
forgeableMonsters.push_back(monster->getID());
if (monster->canBeForgeMonster() && !monsterTile->hasFlag(TILESTATE_NOLOGOUT)) {
forgeableMonsters.push_back(monster->getID());
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ int GameFunctions::luaGameGetInfluencedMonsters(lua_State* L) {
const auto monsters = g_game().getInfluencedMonsters();
lua_createtable(L, static_cast<int>(monsters.size()), 0);
int index = 0;
for (const auto &monsterId : monsters) {
for (const auto monsterId : monsters) {
++index;
lua_pushnumber(L, monsterId);
lua_rawseti(L, -2, index);
Expand Down Expand Up @@ -763,7 +763,7 @@ int GameFunctions::luaGameGetFiendishMonsters(lua_State* L) {

lua_createtable(L, static_cast<int>(monsters.size()), 0);
int index = 0;
for (const auto &monsterId : monsters) {
for (const auto monsterId : monsters) {
++index;
lua_pushnumber(L, monsterId);
lua_rawseti(L, -2, index);
Expand Down

0 comments on commit 5244ed5

Please sign in to comment.