From 6e0be1da25686363ba929637e3392b914ef2ed8b Mon Sep 17 00:00:00 2001 From: mobius <8391001+MobiusDevelopment@users.noreply.github.com> Date: Fri, 2 Jan 2015 11:21:30 +0000 Subject: [PATCH] Random spawn system for monsters. --- trunk/dist/game/config/Custom.properties | 17 +++++++++++++++ trunk/java/com/l2jserver/Config.java | 17 +++++++++++++++ .../l2jserver/gameserver/model/L2Spawn.java | 21 ++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/trunk/dist/game/config/Custom.properties b/trunk/dist/game/config/Custom.properties index 60a8307eea..06b5c9de0b 100644 --- a/trunk/dist/game/config/Custom.properties +++ b/trunk/dist/game/config/Custom.properties @@ -537,3 +537,20 @@ CustomStartingLocation = False CustomStartingLocX = 50821 CustomStartingLocY = 186527 CustomStartingLocZ = -3625 + + +# --------------------------------------------------------------------------- +# Random Spawn System for Monsters +# --------------------------------------------------------------------------- + +# Enable random monster spawns. +# Default: True +EnableRandomMonsterSpawns = True + +# Max range for X and Y coords. +# Default: 150 +MaxSpawnMobRange = 150 + +# Example: No random spawns for Kasha's Eye. +# MobsSpawnNotRandom = 18812,18813,18814 +MobsSpawnNotRandom = 18812,18813,18814 diff --git a/trunk/java/com/l2jserver/Config.java b/trunk/java/com/l2jserver/Config.java index d0818fb4cd..3f195b47b6 100644 --- a/trunk/java/com/l2jserver/Config.java +++ b/trunk/java/com/l2jserver/Config.java @@ -801,6 +801,10 @@ public final class Config public static int CUSTOM_STARTING_LOC_X; public static int CUSTOM_STARTING_LOC_Y; public static int CUSTOM_STARTING_LOC_Z; + public static boolean ENABLE_RANDOM_MONSTER_SPAWNS; + public static int MOB_MIN_SPAWN_RANGE; + public static int MOB_MAX_SPAWN_RANGE; + public static List MOBS_LIST_NOT_RANDOM; // -------------------------------------------------- // NPC Settings @@ -2563,6 +2567,19 @@ public final class Config CUSTOM_STARTING_LOC_Y = CustomSettings.getInt("CustomStartingLocY", 186527); CUSTOM_STARTING_LOC_Z = CustomSettings.getInt("CustomStartingLocZ", -3625); + ENABLE_RANDOM_MONSTER_SPAWNS = CustomSettings.getBoolean("EnableRandomMonsterSpawns", false); + MOB_MAX_SPAWN_RANGE = CustomSettings.getInt("MaxSpawnMobRange", 150); + MOB_MIN_SPAWN_RANGE = MOB_MAX_SPAWN_RANGE * -1; + if (ENABLE_RANDOM_MONSTER_SPAWNS) + { + String[] mobsIds = CustomSettings.getString("MobsSpawnNotRandom", "18812,18813,18814,22138").split(","); + MOBS_LIST_NOT_RANDOM = new ArrayList<>(mobsIds.length); + for (String id : mobsIds) + { + MOBS_LIST_NOT_RANDOM.add(Integer.valueOf(id)); + } + } + // Load PvP L2Properties file (if exists) final PropertiesParser PVPSettings = new PropertiesParser(PVP_CONFIG_FILE); diff --git a/trunk/java/com/l2jserver/gameserver/model/L2Spawn.java b/trunk/java/com/l2jserver/gameserver/model/L2Spawn.java index cd9ba2cfcc..9a529c9bd2 100644 --- a/trunk/java/com/l2jserver/gameserver/model/L2Spawn.java +++ b/trunk/java/com/l2jserver/gameserver/model/L2Spawn.java @@ -589,10 +589,29 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable } else { - // The L2NpcInstance is spawned at the exact position (Lox, Locy, Locz) + // The L2NpcInstance is spawned at a random position newlocx = getX(); newlocy = getY(); newlocz = getZ(); + + // If random spawn system is enabled + if (Config.ENABLE_RANDOM_MONSTER_SPAWNS) + { + final int randX = newlocx + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); + final int randY = newlocy + Rnd.get(Config.MOB_MIN_SPAWN_RANGE, Config.MOB_MAX_SPAWN_RANGE); + + boolean isQuestMonster = false; + if ((mob.getTitle() != null) && mob.getTitle().contains("Quest")) + { + isQuestMonster = true; + } + + if (mob.isMonster() && !isQuestMonster && !mob.isWalker() && (Config.GEODATA > 0) && GeoData.getInstance().canSeeTarget(newlocx, newlocy, newlocz, randX, randY, newlocz) && (getInstanceId() == 0) && !getTemplate().isUndying() && !mob.isRaid() && !mob.isRaidMinion() && !Config.MOBS_LIST_NOT_RANDOM.contains(mob.getId())) + { + newlocx = randX; + newlocy = randY; + } + } } // don't correct z of flying npc's