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

feat: random monsters spawn #1802

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ 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 @@ -211,6 +212,7 @@ buyAolCommandFee = 0
buyBlessCommandFee = 0
teleportPlayerToVocationRoom = true
toggleReceiveReward = false
randomMonsterSpawn = false

-- Teleport summon
-- Set to true will never remove the summon
Expand Down
1 change: 1 addition & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ 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: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ 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: 29 additions & 16 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ void SpawnMonster::startup() {
for (const auto &it : spawnMonsterMap) {
uint32_t spawnMonsterId = it.first;
const spawnBlock_t &sb = it.second;
spawnMonster(spawnMonsterId, sb.monsterType, sb.pos, sb.direction, true);
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);
}
}
}

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

spawnBlock_t &sb = it.second;
const spawnBlock_t &sb = it.second;

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

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

if (sb.monsterType->info.isBlockable) {
spawnMonster(spawnMonsterId, sb.monsterType, sb.pos, sb.direction);
} else {
scheduleSpawn(spawnMonsterId, sb, 3 * NONBLOCKABLE_SPAWN_MONSTER_INTERVAL);
}
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; // Manter a posição original
currentSb.direction = sb.direction; // Manter a direção original
dudantas marked this conversation as resolved.
Show resolved Hide resolved
} else {
currentSb = sb;
}

if (++spawnMonsterCount >= static_cast<uint32_t>(g_configManager().getNumber(RATE_SPAWN))) {
break;
}
if (currentSb.monsterType->info.isBlockable) {
spawnMonster(spawnMonsterId, currentSb.monsterType, currentSb.pos, currentSb.direction, true);
} else {
scheduleSpawn(spawnMonsterId, currentSb, 3 * NONBLOCKABLE_SPAWN_MONSTER_INTERVAL);
}

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

Expand Down
1 change: 1 addition & 0 deletions src/lua/functions/core/game/config_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ 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
Loading