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

Mob Rate #274

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ worlds:
why_am_i_recommended: Welcome to Scania!
channels: 3
exp_rate: 10
mob_rate: 1.0 #Mob count multiplier
max_mob_per_spawnpoint: 1 #Must be equal or higher than mob_rate
meso_rate: 10
drop_rate: 10
boss_drop_rate: 10 #NOTE: Boss drop rate OVERRIDES common drop rate, for bosses-only.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/client/command/CommandsExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
import client.command.commands.gm4.HorntailCommand;
import client.command.commands.gm4.ItemVacCommand;
import client.command.commands.gm4.MesoRateCommand;
import client.command.commands.gm4.MobRateCommand;
import client.command.commands.gm4.MobpointRateCommand;
import client.command.commands.gm4.PapCommand;
import client.command.commands.gm4.PianusCommand;
import client.command.commands.gm4.PinkbeanCommand;
Expand Down Expand Up @@ -507,6 +509,8 @@ private void registerLv4Commands() {
addCommand("questrate", 4, QuestRateCommand.class);
addCommand("travelrate", 4, TravelRateCommand.class);
addCommand("fishrate", 4, FishingRateCommand.class);
addCommand("mobrate", 4, MobRateCommand.class);
addCommand("mobpoint", 4, MobpointRateCommand.class);
addCommand("itemvac", 4, ItemVacCommand.class);
addCommand("forcevac", 4, ForceVacCommand.class);
addCommand("zakum", 4, ZakumCommand.class);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/client/command/commands/gm4/MobRateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package client.command.commands.gm4;

import client.Character;
import client.Client;
import client.command.Command;
import tools.PacketCreator;

public class MobRateCommand extends Command {
{
setDescription("Set mob spawn rate.");
}

@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
if (params.length < 1) {
player.yellowMessage("Syntax: !mobrate <newrate>");
player.yellowMessage("Current Mob Rate: " + c.getWorldServer().getMobrate());
return;
}

float mobrate = Math.max(Float.parseFloat(params[0]), 1f);
c.getWorldServer().setMobrate(mobrate);
c.getWorldServer().broadcastPacket(PacketCreator.serverNotice(6, "[Rate] Mob Spawn Rate has been changed to " + mobrate + "x."));
}
}
26 changes: 26 additions & 0 deletions src/main/java/client/command/commands/gm4/MobpointRateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package client.command.commands.gm4;

import client.Character;
import client.Client;
import client.command.Command;
import tools.PacketCreator;

public class MobpointRateCommand extends Command {
{
setDescription("Set max mob per spawnpoint rate. (Should always be equal or higher than mob rate)");
}

@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
if (params.length < 1) {
player.yellowMessage("Syntax: !mobpoint <newrate>");
player.yellowMessage("Current Mob Point Rate: " + c.getWorldServer().getMobperspawnpoint());
return;
}

int maxmobperspawnpoint = Math.max(Integer.parseInt(params[0]), 1);
c.getWorldServer().setMobperspawnpoint(maxmobperspawnpoint);
c.getWorldServer().broadcastPacket(PacketCreator.serverNotice(6, "[Rate] Max Mob Per Spawnpoint Rate has been changed to " + maxmobperspawnpoint + "x."));
}
}
2 changes: 2 additions & 0 deletions src/main/java/config/WorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class WorldConfig {
public String why_am_i_recommended = "";
public int channels = 1;
public int exp_rate = 1;
public float mob_rate = 1;
public int max_mob_per_spawnpoint = 1;
public int meso_rate = 1;
public int drop_rate = 1;
public int boss_drop_rate = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ private int initWorld() {
log.info("Starting world {}", i);

int exprate = YamlConfig.config.worlds.get(i).exp_rate;
float mobrate = YamlConfig.config.worlds.get(i).mob_rate;
int mobperspawnpoint = YamlConfig.config.worlds.get(i).max_mob_per_spawnpoint;
int mesorate = YamlConfig.config.worlds.get(i).meso_rate;
int droprate = YamlConfig.config.worlds.get(i).drop_rate;
int bossdroprate = YamlConfig.config.worlds.get(i).boss_drop_rate;
Expand All @@ -438,10 +440,8 @@ private int initWorld() {
String event_message = YamlConfig.config.worlds.get(i).event_message;
String why_am_i_recommended = YamlConfig.config.worlds.get(i).why_am_i_recommended;

World world = new World(i,
flag,
event_message,
exprate, droprate, bossdroprate, mesorate, questrate, travelrate, fishingrate);
World world = new World(i, flag, event_message, exprate, droprate, bossdroprate, mesorate, questrate,
travelrate, fishingrate, mobrate, mobperspawnpoint);

Map<Integer, String> channelInfo = new HashMap<>();
long bootTime = getCurrentTime();
Expand Down Expand Up @@ -1477,7 +1477,7 @@ public void transferWorldCharacterEntry(Character chr, Integer toWorld) { // use
lgnWLock.unlock();
}
}

/*
public void deleteAccountEntry(Integer accountid) { is this even a thing?
lgnWLock.lock();
Expand All @@ -1487,7 +1487,7 @@ public void deleteAccountEntry(Integer accountid) { is this even a thing?
} finally {
lgnWLock.unlock();
}

for (World wserv : this.getWorlds()) {
wserv.clearAccountCharacterView(accountid);
wserv.unregisterAccountStorage(accountid);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/net/server/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public class World {
private int questrate;
private int travelrate;
private int fishingrate;
private float mobrate;
private int mobperspawnpoint;
private final String eventmsg;
private final List<Channel> channels = new ArrayList<>();
private final Map<Integer, Byte> pnpcStep = new HashMap<>();
Expand Down Expand Up @@ -200,7 +202,8 @@ public class World {
private ScheduledFuture<?> timeoutSchedule;
private ScheduledFuture<?> hpDecSchedule;

public World(int world, int flag, String eventmsg, int exprate, int droprate, int bossdroprate, int mesorate, int questrate, int travelrate, int fishingrate) {
public World(int world, int flag, String eventmsg, int exprate, int droprate, int bossdroprate, int mesorate,
int questrate, int travelrate, int fishingrate, float mobrate, int mobperspawnpoint) {
this.id = world;
this.flag = flag;
this.eventmsg = eventmsg;
Expand All @@ -211,6 +214,8 @@ public World(int world, int flag, String eventmsg, int exprate, int droprate, in
this.questrate = questrate;
this.travelrate = travelrate;
this.fishingrate = fishingrate;
this.mobrate = mobrate;
this.mobperspawnpoint = mobperspawnpoint;
runningPartyId.set(1000000001); // partyid must not clash with charid to solve update item looting issues, found thanks to Vcoc
runningMessengerId.set(1);

Expand Down Expand Up @@ -458,6 +463,22 @@ public void setFishingRate(int quest) {
this.fishingrate = quest;
}

public float getMobrate() {
return mobrate;
}

public void setMobrate(float mobrate) {
this.mobrate = mobrate;
}

public int getMobperspawnpoint() {
return mobperspawnpoint;
}

public void setMobperspawnpoint(int mobperspawnpoint) {
this.mobperspawnpoint = mobperspawnpoint;
}

public void loadAccountCharactersView(Integer accountId, List<Character> chars) {
SortedMap<Integer, Character> charsMap = new TreeMap<>();
for (Character chr : chars) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/server/life/SpawnPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public boolean getDenySpawn() {
}

public boolean shouldSpawn() {
if (denySpawn || mobTime < 0 || spawnedMonsters.get() > 0) {
return shouldSpawn(1);
}

public boolean shouldSpawn(int maxSpawnedMonsters) {
Monster mob = LifeFactory.getMonster(monster);
int max = mob != null && mob.isBoss() ? 1 : maxSpawnedMonsters;
if (denySpawn || mobTime < 0 || spawnedMonsters.get() >= max) {
return false;
}
return nextPossibleSpawn <= Server.getInstance().getCurrentTime();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/server/maps/MapleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3530,12 +3530,12 @@ private int getNumShouldSpawn(int numPlayers) {
System.out.println("----------------------------------");
*/

float maxMob = monsterSpawn.size() * getWorldServer().getMobrate();

if (YamlConfig.config.server.USE_ENABLE_FULL_RESPAWN) {
return (monsterSpawn.size() - spawnedMonstersOnMap.get());
return (int) Math.ceil(maxMob) - spawnedMonstersOnMap.get();
}

int maxNumShouldSpawn = (int) Math.ceil(getCurrentSpawnRate(numPlayers) * monsterSpawn.size());
return maxNumShouldSpawn - spawnedMonstersOnMap.get();
return (int) Math.ceil(getCurrentSpawnRate(numPlayers) * maxMob) - spawnedMonstersOnMap.get();
}

public void respawn() {
Expand All @@ -3561,7 +3561,7 @@ public void respawn() {
Collections.shuffle(randomSpawn);
short spawned = 0;
for (SpawnPoint spawnPoint : randomSpawn) {
if (spawnPoint.shouldSpawn()) {
if (spawnPoint.shouldSpawn(getWorldServer().getMobperspawnpoint())) {
spawnMonster(spawnPoint.getMonster());
spawned++;

Expand Down
Loading