Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry Pick: Monster overspawn #4328

Merged
merged 2 commits into from
Feb 18, 2023
Merged
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
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