Skip to content

Commit

Permalink
feat: Monster overspawn (#4328)
Browse files Browse the repository at this point in the history
Authored-By: Marcin Michalski <57528542+marmichalski@users.noreply.github.com>
  • Loading branch information
omarcopires committed Feb 18, 2023
1 parent c1f7f4d commit 8326237
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ rateSpawn = 1
-- despawnRadius is how many tiles away it can be from its spawn position
-- removeOnDespawn will remove the monster if true or teleport it back to its spawn position if false
-- walkToSpawnRadius is the allowed distance that the monster will stay away from spawn position when left with no targets, 0 to disable
-- monsterOverspawn can be used instead of removeOnDespawn option, this will start respawn process of the monster when it goes out of deSpawn* boundaries.
-- Setting both removeOnDespawn and monsterOverspawn to true prioritizes the latter.
deSpawnRange = 2
deSpawnRadius = 50
removeOnDespawn = true
walkToSpawnRadius = 15
monsterOverspawn = false

-- Stamina
staminaSystem = true
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ bool ConfigManager::load()
boolean[PLAYER_CONSOLE_LOGS] = getGlobalBoolean(L, "showPlayerLogInConsole", true);
boolean[TWO_FACTOR_AUTH] = getGlobalBoolean(L, "enableTwoFactorAuth", true);
boolean[CHECK_DUPLICATE_STORAGE_KEYS] = getGlobalBoolean(L, "checkDuplicateStorageKeys", false);
boolean[MONSTER_OVERSPAWN] = getGlobalBoolean(L, "monsterOverspawn", false);

string[DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high");
string[SERVER_NAME] = getGlobalString(L, "serverName", "");
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ConfigManager
PLAYER_CONSOLE_LOGS,
TWO_FACTOR_AUTH,
CHECK_DUPLICATE_STORAGE_KEYS,
MONSTER_OVERSPAWN,

LAST_BOOLEAN_CONFIG /* this must be the last one */
};
Expand Down
1 change: 1 addition & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,7 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::STAMINA_REGEN_MINUTE);
registerEnumIn("configKeys", ConfigManager::STAMINA_REGEN_PREMIUM);
registerEnumIn("configKeys", ConfigManager::HOUSE_DOOR_SHOW_PRICE);
registerEnumIn("configKeys", ConfigManager::MONSTER_OVERSPAWN);

// os
registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime);
Expand Down
18 changes: 13 additions & 5 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,20 @@ void Monster::onThink(uint32_t interval)
}

if (!isInSpawnRange(position)) {
g_game.addMagicEffect(this->getPosition(), CONST_ME_POFF);
if (g_config.getBoolean(ConfigManager::REMOVE_ON_DESPAWN)) {
g_game.removeCreature(this, false);
if (g_config.getBoolean(ConfigManager::MONSTER_OVERSPAWN)) {
if (spawn) {
spawn->removeMonster(this);
spawn->startSpawnCheck();
spawn = nullptr;
}
} else {
g_game.internalTeleport(this, masterPos);
setIdle(true);
g_game.addMagicEffect(this->getPosition(), CONST_ME_POFF);
if (g_config.getBoolean(ConfigManager::REMOVE_ON_DESPAWN)) {
g_game.removeCreature(this, false);
} else {
g_game.internalTeleport(this, masterPos);
setIdle(true);
}
}
} else {
updateIdleStatus();
Expand Down

0 comments on commit 8326237

Please sign in to comment.