Addition of RandomSpawns configuration.

This commit is contained in:
MobiusDevelopment 2021-03-29 10:29:33 +00:00
parent ea17fe727c
commit fb661375c5
10 changed files with 152 additions and 2 deletions

View File

@ -0,0 +1,20 @@
# ---------------------------------------------------------------------------
# Random Spawn System for Monsters
# ---------------------------------------------------------------------------
# Enable random monster spawns.
# Default: True
EnableRandomMonsterSpawns = True
# Max range for X and Y coords.
# Default: 150
MaxSpawnMobRange = 150
# No random spawns for specific NPC ids.
# MobsSpawnNotRandom = 22138
MobsSpawnNotRandom = 22138,\
18120,18132,18133,18137,18141,18145,18150,18151,18152,18153,18154,18155,18156,18157,18166,\
18170,18171,18183,18184,18185,18186,18187,18191,18195,18196,18197,18198,18199,18212,18220,\
18221,18222,18226,18230,18231,18232,18233,18234,18235,18236,18237,18238,18239,18240,18241,\
18242,18243,18256,31452,31468,31469,31470,31471,31472,31473,31474,31475,31476,31477,31478,\
31479,31480,31481,31482,31483,31484,31485,31486,31487

View File

@ -95,6 +95,7 @@ public class Config
private static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/custom/AutoPotions.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/custom/CustomMailManager.ini";
private static final String MERCHANT_ZERO_SELL_PRICE_CONFIG_FILE = "./config/custom/MerchantZeroSellPrice.ini";
private static final String CUSTOM_RANDOM_SPAWNS_CONFIG_FILE = "./config/custom/RandomSpawns.ini";
private static final String OFFLINE_CONFIG_FILE = "./config/custom/Offline.ini";
private static final String OTHER_CONFIG_FILE = "./config/custom/Other.ini";
private static final String SCHEME_BUFFER_CONFIG_FILE = "./config/custom/SchemeBuffer.ini";
@ -479,6 +480,11 @@ public class Config
public static boolean MERCHANT_ZERO_SELL_PRICE;
public static boolean ENABLE_RANDOM_MONSTER_SPAWNS;
public static int MOB_MIN_SPAWN_RANGE;
public static int MOB_MAX_SPAWN_RANGE;
public static List<Integer> MOBS_LIST_NOT_RANDOM;
public static boolean ALLOW_WEDDING;
public static int WEDDING_PRICE;
public static boolean WEDDING_PUNISH_INFIDELITY;
@ -1707,6 +1713,23 @@ public class Config
MERCHANT_ZERO_SELL_PRICE = merchantZeroSellPriceConfig.getBoolean("MerchantZeroSellPrice", false);
}
public static void loadRandomSpawnsConfig()
{
final PropertiesParser randomSpawnsConfig = new PropertiesParser(CUSTOM_RANDOM_SPAWNS_CONFIG_FILE);
ENABLE_RANDOM_MONSTER_SPAWNS = randomSpawnsConfig.getBoolean("EnableRandomMonsterSpawns", false);
MOB_MAX_SPAWN_RANGE = randomSpawnsConfig.getInt("MaxSpawnMobRange", 150);
MOB_MIN_SPAWN_RANGE = MOB_MAX_SPAWN_RANGE * -1;
if (ENABLE_RANDOM_MONSTER_SPAWNS)
{
final String[] mobsIds = randomSpawnsConfig.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.parseInt(id));
}
}
}
public static void loadWeddingConfig()
{
final PropertiesParser weddingConfig = new PropertiesParser(EVENT_WEDDING_CONFIG_FILE);
@ -3140,6 +3163,7 @@ public class Config
loadAutoPotionsConfig();
loadCustomMailManagerConfig();
loadMerchantZeroPriceConfig();
loadRandomSpawnsConfig();
loadWeddingConfig();
loadRebirthConfig();
loadBankingConfig();

View File

@ -125,6 +125,7 @@ public class NpcInstance extends Creature
public boolean _isCTF_throneSpawn = false;
public boolean _isCTF_Flag = false;
private boolean _isInTown = false;
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
public String _CTF_FlagTeamName;
private int _isSpoiledBy = 0;
private long _lastSocialBroadcast = 0;
@ -1124,6 +1125,15 @@ public class NpcInstance extends Creature
return _isInTown;
}
/**
* Checks if the NPC is a Quest Monster.
* @return {@code true} if the NPC is a Quest Monster, {@code false} otherwise.
*/
public boolean isQuestMonster()
{
return _isQuestMonster;
}
/**
* Open a quest or chat window on client with the text of the NpcInstance in function of the command.<br>
* <br>

View File

@ -62,6 +62,7 @@ public class NpcTemplate extends CreatureTemplate
private final boolean _serverSideName;
private final String _title;
private final boolean _serverSideTitle;
private final boolean _isQuestMonster;
private final String _sex;
private final byte _level;
private final int _rewardExp;
@ -140,8 +141,9 @@ public class NpcTemplate extends CreatureTemplate
_type = set.getString("type");
_name = set.getString("name");
_serverSideName = set.getBoolean("serverSideName");
_title = set.getString("title");
_title = set.getString("title", "");
_serverSideTitle = set.getBoolean("serverSideTitle");
_isQuestMonster = _title.contains("Quest");
_sex = set.getString("sex");
_level = set.getByte("level");
_rewardExp = set.getInt("rewardExp");
@ -526,6 +528,11 @@ public class NpcTemplate extends CreatureTemplate
return _serverSideTitle;
}
public boolean isQuestMonster()
{
return _isQuestMonster;
}
public String getSex()
{
return _sex;

View File

@ -21,9 +21,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.sql.TerritoryTable;
import org.l2jmobius.gameserver.data.xml.WalkerRouteData;
import org.l2jmobius.gameserver.data.xml.ZoneData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.IdManager;
@ -447,6 +449,18 @@ public class Spawn
// Check if npc is in water.
final WaterZone water = ZoneData.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getNpcId()))
{
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);
if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId()))
{
newlocx = randX;
newlocy = randY;
}
}
// Correct Z of monsters.
if (!npc.isFlying() && (water == null))
{

View File

@ -0,0 +1,20 @@
# ---------------------------------------------------------------------------
# Random Spawn System for Monsters
# ---------------------------------------------------------------------------
# Enable random monster spawns.
# Default: True
EnableRandomMonsterSpawns = True
# Max range for X and Y coords.
# Default: 150
MaxSpawnMobRange = 150
# No random spawns for specific NPC ids.
# MobsSpawnNotRandom = 22138
MobsSpawnNotRandom = 22138,\
18120,18132,18133,18137,18141,18145,18150,18151,18152,18153,18154,18155,18156,18157,18166,\
18170,18171,18183,18184,18185,18186,18187,18191,18195,18196,18197,18198,18199,18212,18220,\
18221,18222,18226,18230,18231,18232,18233,18234,18235,18236,18237,18238,18239,18240,18241,\
18242,18243,18256,31452,31468,31469,31470,31471,31472,31473,31474,31475,31476,31477,31478,\
31479,31480,31481,31482,31483,31484,31485,31486,31487

View File

@ -96,6 +96,7 @@ public class Config
private static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/custom/AutoPotions.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/custom/CustomMailManager.ini";
private static final String MERCHANT_ZERO_SELL_PRICE_CONFIG_FILE = "./config/custom/MerchantZeroSellPrice.ini";
private static final String CUSTOM_RANDOM_SPAWNS_CONFIG_FILE = "./config/custom/RandomSpawns.ini";
private static final String OFFLINE_CONFIG_FILE = "./config/custom/Offline.ini";
private static final String OTHER_CONFIG_FILE = "./config/custom/Other.ini";
private static final String SCHEME_BUFFER_CONFIG_FILE = "./config/custom/SchemeBuffer.ini";
@ -498,6 +499,11 @@ public class Config
public static boolean MERCHANT_ZERO_SELL_PRICE;
public static boolean ENABLE_RANDOM_MONSTER_SPAWNS;
public static int MOB_MIN_SPAWN_RANGE;
public static int MOB_MAX_SPAWN_RANGE;
public static List<Integer> MOBS_LIST_NOT_RANDOM;
public static boolean ALLOW_WEDDING;
public static int WEDDING_PRICE;
public static boolean WEDDING_PUNISH_INFIDELITY;
@ -1757,6 +1763,23 @@ public class Config
MERCHANT_ZERO_SELL_PRICE = merchantZeroSellPriceConfig.getBoolean("MerchantZeroSellPrice", false);
}
public static void loadRandomSpawnsConfig()
{
final PropertiesParser randomSpawnsConfig = new PropertiesParser(CUSTOM_RANDOM_SPAWNS_CONFIG_FILE);
ENABLE_RANDOM_MONSTER_SPAWNS = randomSpawnsConfig.getBoolean("EnableRandomMonsterSpawns", false);
MOB_MAX_SPAWN_RANGE = randomSpawnsConfig.getInt("MaxSpawnMobRange", 150);
MOB_MIN_SPAWN_RANGE = MOB_MAX_SPAWN_RANGE * -1;
if (ENABLE_RANDOM_MONSTER_SPAWNS)
{
final String[] mobsIds = randomSpawnsConfig.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.parseInt(id));
}
}
}
public static void loadWeddingConfig()
{
final PropertiesParser weddingConfig = new PropertiesParser(EVENT_WEDDING_CONFIG_FILE);
@ -3209,6 +3232,7 @@ public class Config
loadAutoPotionsConfig();
loadCustomMailManagerConfig();
loadMerchantZeroPriceConfig();
loadRandomSpawnsConfig();
loadWeddingConfig();
loadRebirthConfig();
loadBankingConfig();

View File

@ -127,6 +127,7 @@ public class NpcInstance extends Creature
public boolean _isCTF_throneSpawn = false;
public boolean _isCTF_Flag = false;
private boolean _isInTown = false;
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
public String _CTF_FlagTeamName;
private int _isSpoiledBy = 0;
private long _lastSocialBroadcast = 0;
@ -1126,6 +1127,15 @@ public class NpcInstance extends Creature
return _isInTown;
}
/**
* Checks if the NPC is a Quest Monster.
* @return {@code true} if the NPC is a Quest Monster, {@code false} otherwise.
*/
public boolean isQuestMonster()
{
return _isQuestMonster;
}
/**
* Open a quest or chat window on client with the text of the NpcInstance in function of the command.<br>
* <br>

View File

@ -62,6 +62,7 @@ public class NpcTemplate extends CreatureTemplate
private final boolean _serverSideName;
private final String _title;
private final boolean _serverSideTitle;
private final boolean _isQuestMonster;
private final String _sex;
private final byte _level;
private final int _rewardExp;
@ -140,8 +141,9 @@ public class NpcTemplate extends CreatureTemplate
_type = set.getString("type");
_name = set.getString("name");
_serverSideName = set.getBoolean("serverSideName");
_title = set.getString("title");
_title = set.getString("title", "");
_serverSideTitle = set.getBoolean("serverSideTitle");
_isQuestMonster = _title.contains("Quest");
_sex = set.getString("sex");
_level = set.getByte("level");
_rewardExp = set.getInt("rewardExp");
@ -526,6 +528,11 @@ public class NpcTemplate extends CreatureTemplate
return _serverSideTitle;
}
public boolean isQuestMonster()
{
return _isQuestMonster;
}
public String getSex()
{
return _sex;

View File

@ -21,9 +21,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.sql.TerritoryTable;
import org.l2jmobius.gameserver.data.xml.WalkerRouteData;
import org.l2jmobius.gameserver.data.xml.ZoneData;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.IdManager;
@ -447,6 +449,18 @@ public class Spawn
// Check if npc is in water.
final WaterZone water = ZoneData.getInstance().getZone(newlocx, newlocy, newlocz, WaterZone.class);
// If random spawn system is enabled.
if (Config.ENABLE_RANDOM_MONSTER_SPAWNS && npc.isMonster() && !npc.isQuestMonster() && (WalkerRouteData.getInstance().getRouteForNpc(npc.getNpcId()) == null) && (getInstanceId() == 0) && !npc.isRaid() && !npc.isMinion() && !npc.isFlying() && (water == null) && !Config.MOBS_LIST_NOT_RANDOM.contains(npc.getNpcId()))
{
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);
if (GeoEngine.getInstance().canMoveToTarget(newlocx, newlocy, newlocz, randX, randY, newlocz, getInstanceId()))
{
newlocx = randX;
newlocy = randY;
}
}
// Correct Z of monsters.
if (!npc.isFlying() && (water == null))
{