Skip to content

Commit

Permalink
Revert "feat: random monsters spawn" (opentibiabr#1822)
Browse files Browse the repository at this point in the history
Reverts opentibiabr#1802

Reason: the change caused bugs in the spawn system.
  • Loading branch information
dudantas authored Nov 15, 2023
1 parent b8bfcaa commit 565ab60
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
2 changes: 0 additions & 2 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ onlyPremiumAccount = false
-- NOTE: buyBlessCommandFee will add fee when player buy bless by command (!bless), active changing value between 1 and 100 (fee percent. ex: 3 = 3%, 30 = 30%)
-- NOTE: teleportPlayerToVocationRoom will enable oressa to teleport player to his/her room vocation
-- NOTE: toggleReceiveReward = true, will enable players to choose one of reward exercise weapon by command !reward
-- NOTE: randomMonsterSpawn = true, will enable monsters from the same spawn to be randomized between them, thus making a variable hunt
weatherRain = false
thunderEffect = false
allConsoleLog = false
Expand All @@ -220,7 +219,6 @@ buyAolCommandFee = 0
buyBlessCommandFee = 0
teleportPlayerToVocationRoom = true
toggleReceiveReward = false
randomMonsterSpawn = false

-- Teleport summon
-- Set to true will never remove the summon
Expand Down
1 change: 0 additions & 1 deletion src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ enum booleanConfig_t {
PARTY_AUTO_SHARE_EXPERIENCE,
PARTY_SHARE_LOOT_BOOSTS,
RESET_SESSIONS_ON_STARTUP,
RANDOM_MONSTER_SPAWN,
TOGGLE_WHEELSYSTEM,
TOGGLE_ATTACK_SPEED_ONFIST,
VIP_SYSTEM_ENABLED,
Expand Down
1 change: 0 additions & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ bool ConfigManager::load() {
boolean[OPTIMIZE_DATABASE] = getGlobalBoolean(L, "startupDatabaseOptimization", true);
boolean[TOGGLE_MAP_CUSTOM] = getGlobalBoolean(L, "toggleMapCustom", true);
boolean[TOGGLE_MAINTAIN_MODE] = getGlobalBoolean(L, "toggleMaintainMode", false);
boolean[RANDOM_MONSTER_SPAWN] = getGlobalBoolean(L, "randomMonsterSpawn", false);
string[MAINTAIN_MODE_MESSAGE] = getGlobalString(L, "maintainModeMessage", "");

string[IP] = getGlobalString(L, "ip", "127.0.0.1");
Expand Down
45 changes: 16 additions & 29 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,7 @@ void SpawnMonster::startup() {
for (const auto &it : spawnMonsterMap) {
uint32_t spawnMonsterId = it.first;
const spawnBlock_t &sb = it.second;
if (g_configManager().getBoolean(RANDOM_MONSTER_SPAWN)) {
const spawnBlock_t &randSb = std::next(spawnMonsterMap.begin(), uniform_random(0, spawnMonsterMap.size() - 1))->second;
spawnMonster(spawnMonsterId, randSb.monsterType, sb.pos, sb.direction, true);
} else {
spawnMonster(spawnMonsterId, sb.monsterType, sb.pos, sb.direction, true);
}
spawnMonster(spawnMonsterId, sb.monsterType, sb.pos, sb.direction, true);
}
}

Expand All @@ -220,35 +215,27 @@ void SpawnMonster::checkSpawnMonster() {
continue;
}

const spawnBlock_t &sb = it.second;

spawnBlock_t &sb = it.second;
if (!sb.monsterType->canSpawn(sb.pos)) {
spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME();
continue;
}

if (sb.monsterType->info.isBlockable && findPlayer(sb.pos)) {
spawnMonsterMap[spawnMonsterId].lastSpawn = OTSYS_TIME();
sb.lastSpawn = OTSYS_TIME();
continue;
}

spawnBlock_t currentSb;
if (g_configManager().getBoolean(RANDOM_MONSTER_SPAWN)) {
currentSb = std::next(spawnMonsterMap.begin(), uniform_random(0, spawnMonsterMap.size() - 1))->second;
currentSb.pos = sb.pos;
currentSb.direction = sb.direction;
} else {
currentSb = sb;
}
if (OTSYS_TIME() >= sb.lastSpawn + sb.interval) {
if (sb.monsterType->info.isBlockable && findPlayer(sb.pos)) {
sb.lastSpawn = OTSYS_TIME();
continue;
}

if (currentSb.monsterType->info.isBlockable) {
spawnMonster(spawnMonsterId, currentSb.monsterType, currentSb.pos, currentSb.direction, true);
} else {
scheduleSpawn(spawnMonsterId, currentSb, 3 * NONBLOCKABLE_SPAWN_MONSTER_INTERVAL);
}
if (sb.monsterType->info.isBlockable) {
spawnMonster(spawnMonsterId, sb.monsterType, sb.pos, sb.direction);
} else {
scheduleSpawn(spawnMonsterId, sb, 3 * NONBLOCKABLE_SPAWN_MONSTER_INTERVAL);
}

if (++spawnMonsterCount >= static_cast<uint32_t>(g_configManager().getNumber(RATE_SPAWN))) {
break;
if (++spawnMonsterCount >= static_cast<uint32_t>(g_configManager().getNumber(RATE_SPAWN))) {
break;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/lua/functions/core/game/config_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void ConfigFunctions::init(lua_State* L) {
registerEnumIn(L, "configKeys", RED_SKULL_DURATION);
registerEnumIn(L, "configKeys", BLACK_SKULL_DURATION);
registerEnumIn(L, "configKeys", ORANGE_SKULL_DURATION);
registerEnumIn(L, "configKeys", RANDOM_MONSTER_SPAWN);
registerEnumIn(L, "configKeys", RATE_MONSTER_HEALTH);
registerEnumIn(L, "configKeys", RATE_MONSTER_ATTACK);
registerEnumIn(L, "configKeys", RATE_MONSTER_DEFENSE);
Expand Down

0 comments on commit 565ab60

Please sign in to comment.