More PQ-esque script modules + HP Bar on some bosses
Completed (hopefully, now!) implementation of automated modules for PQ scripting. Added HP bar for some bosses that wouldn't display it before (like King Slime, Alishar and CRog).
This commit is contained in:
@@ -1118,7 +1118,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
|
||||
private void eventChangedMap(int map) {
|
||||
if (getEventInstance() != null) getEventInstance().changedMap(MapleCharacter.this, map);
|
||||
if (getEventInstance() != null) getEventInstance().changedMap(this, map);
|
||||
}
|
||||
|
||||
public void changeMap(int map) {
|
||||
|
||||
@@ -335,7 +335,7 @@ public class Commands {
|
||||
player.message("@bosshp: Displays the remaining HP of the bosses on your map.");
|
||||
if(ServerConstants.USE_DEBUG) {
|
||||
player.message("@debugpos: Displays the coordinates on the map the player is currently located.");
|
||||
player.message("@debugmapcount: Displays the current number of registered players in the map the player is located.");
|
||||
player.message("@debugmap: Displays info about the current map the player is located.");
|
||||
player.message("@debugevent: Displays the name of the event in which the player is currently registered.");
|
||||
player.message("@debugreactors: Displays current info for all reactors on the map the the player is currently located.");
|
||||
}
|
||||
@@ -650,9 +650,9 @@ public class Commands {
|
||||
}
|
||||
break;
|
||||
|
||||
case "debugmapcount":
|
||||
case "debugmap":
|
||||
if(ServerConstants.USE_DEBUG) {
|
||||
player.dropMessage("Current map count: (" + player.getMap().getAllPlayers().size() + ").");
|
||||
player.dropMessage("Current map id " + player.getMap().getId() + ", event: '" + ((player.getMap().getEventInstance() != null) ? player.getMap().getEventInstance().getName() : "null") + "'; Players: " + player.getMap().getAllPlayers().size() + ", Mobs: " + player.getMap().getMonsters().size() + ".");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public final class Channel {
|
||||
public Channel(final int world, final int channel) {
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
this.mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), world, channel);
|
||||
this.mapFactory = new MapleMapFactory(null, MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), world, channel);
|
||||
try {
|
||||
eventSM = new EventScriptManager(this, getEvents());
|
||||
port = 7575 + this.channel - 1;
|
||||
|
||||
@@ -142,7 +142,6 @@ public final class PartyOperationHandler extends AbstractMaplePacketHandler {
|
||||
case 6: {
|
||||
int newLeader = slea.readInt();
|
||||
MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
|
||||
party.setLeader(newLeadr);
|
||||
world.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -346,6 +346,9 @@ public class World {
|
||||
party.updateMember(target);
|
||||
break;
|
||||
case CHANGE_LEADER:
|
||||
if(party.getLeader().getPlayer().getEventInstance() != null) {
|
||||
party.getLeader().getPlayer().getEventInstance().changedLeader(target.getPlayer());
|
||||
}
|
||||
party.setLeader(target);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -63,6 +63,7 @@ import client.inventory.ModifyInventory;
|
||||
import client.inventory.PetDataFactory;
|
||||
import constants.ItemConstants;
|
||||
import constants.ServerConstants;
|
||||
import server.life.MapleNPC;
|
||||
|
||||
public class AbstractPlayerInteraction {
|
||||
|
||||
@@ -694,6 +695,19 @@ public class AbstractPlayerInteraction {
|
||||
c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(newItem);
|
||||
c.announce(MaplePacketCreator.modifyInventory(false, Collections.singletonList(new ModifyInventory(0, newItem))));
|
||||
}
|
||||
|
||||
public void spawnNpc(int npcId, Point pos, MapleMap map) {
|
||||
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
||||
if (npc != null) {
|
||||
npc.setPosition(pos);
|
||||
npc.setCy(pos.y);
|
||||
npc.setRx0(pos.x + 50);
|
||||
npc.setRx1(pos.x - 50);
|
||||
npc.setFh(map.getFootholds().findBelow(pos).getId());
|
||||
map.addMapObject(npc);
|
||||
map.broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnMonster(int id, int x, int y) {
|
||||
MapleMonster monster = MapleLifeFactory.getMonster(id);
|
||||
|
||||
@@ -51,10 +51,13 @@ import tools.DatabaseConnection;
|
||||
import client.MapleCharacter;
|
||||
import constants.ItemConstants;
|
||||
import constants.ServerConstants;
|
||||
import java.awt.Point;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import scripting.AbstractPlayerInteraction;
|
||||
import server.life.MapleLifeFactory;
|
||||
import server.life.MapleNPC;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
@@ -96,10 +99,13 @@ public class EventInstanceManager {
|
||||
// registers all opened gates on the event. Will help late characters to encounter next stages gates already opened
|
||||
private Set<Integer> openedGates = new HashSet<>();
|
||||
|
||||
// forces deletion of items not supposed to be holding out of the event, dealt on a player's leave moment.
|
||||
private Set<Integer> exclusiveItems = new HashSet<>();
|
||||
|
||||
public EventInstanceManager(EventManager em, String name) {
|
||||
this.em = em;
|
||||
this.name = name;
|
||||
mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), (byte) 0, (byte) 1);//Fk this
|
||||
mapFactory = new MapleMapFactory(this, MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), (byte) 0, (byte) 1);//Fk this
|
||||
mapFactory.setChannel(em.getChannelServer().getId());
|
||||
}
|
||||
|
||||
@@ -113,21 +119,18 @@ public class EventInstanceManager {
|
||||
|
||||
public void giveEventPlayersExp(int gain, int mapId) {
|
||||
if(gain == 0) return;
|
||||
|
||||
List<MapleCharacter> players = getPlayerList();
|
||||
|
||||
rL.lock();
|
||||
try {
|
||||
if(mapId == -1) {
|
||||
for(MapleCharacter mc: chars) {
|
||||
mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
if(mapId == -1) {
|
||||
for(MapleCharacter mc: players) {
|
||||
mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
else {
|
||||
for(MapleCharacter mc: chars) {
|
||||
if(mc.getMapId() == mapId) mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(MapleCharacter mc: players) {
|
||||
if(mc.getMapId() == mapId) mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,22 +140,20 @@ public class EventInstanceManager {
|
||||
|
||||
public void giveEventPlayersMeso(int gain, int mapId) {
|
||||
if(gain == 0) return;
|
||||
|
||||
rL.lock();
|
||||
try {
|
||||
if(mapId == -1) {
|
||||
for(MapleCharacter mc: chars) {
|
||||
mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
|
||||
List<MapleCharacter> players = getPlayerList();
|
||||
|
||||
if(mapId == -1) {
|
||||
for(MapleCharacter mc: players) {
|
||||
mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
else {
|
||||
for(MapleCharacter mc: chars) {
|
||||
if(mc.getMapId() == mapId) mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
else {
|
||||
for(MapleCharacter mc: players) {
|
||||
if(mc.getMapId() == mapId) mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void registerPlayer(MapleCharacter chr) {
|
||||
@@ -270,6 +271,7 @@ public class EventInstanceManager {
|
||||
try {
|
||||
chars.remove(chr);
|
||||
gridRemove(chr);
|
||||
dropExclusiveItems(chr);
|
||||
} finally {
|
||||
wL.unlock();
|
||||
}
|
||||
@@ -296,11 +298,19 @@ public class EventInstanceManager {
|
||||
rL.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<MapleCharacter> getPlayerList() {
|
||||
rL.lock();
|
||||
try {
|
||||
return new LinkedList<>(chars);
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerMonster(MapleMonster mob) {
|
||||
if (!mob.getStats().isFriendly()) { //We cannot register moon bunny
|
||||
mobs.add(mob);
|
||||
mob.setEventInstance(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +329,14 @@ public class EventInstanceManager {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void changedLeader(MapleCharacter ldr) {
|
||||
try {
|
||||
em.getIv().invokeFunction("changedLeader", this, ldr);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void monsterKilled(MapleMonster mob) {
|
||||
mobs.remove(mob);
|
||||
@@ -408,20 +426,24 @@ public class EventInstanceManager {
|
||||
|
||||
wL.lock();
|
||||
try {
|
||||
for(MapleCharacter chr: chars) chr.setEventInstance(null);
|
||||
chars.clear();
|
||||
|
||||
mobs.clear();
|
||||
|
||||
mapFactory.dispose();
|
||||
mapFactory = null;
|
||||
} finally {
|
||||
wL.unlock();
|
||||
}
|
||||
|
||||
cancelSchedule();
|
||||
|
||||
mobs.clear();
|
||||
killCount.clear();
|
||||
mapFactory = null;
|
||||
|
||||
if (expedition != null) {
|
||||
em.getChannelServer().getExpeditions().remove(expedition);
|
||||
}
|
||||
em.disposeInstance(name);
|
||||
if(!eventCleared) em.disposeInstance(name);
|
||||
em = null;
|
||||
}
|
||||
|
||||
@@ -464,6 +486,7 @@ public class EventInstanceManager {
|
||||
|
||||
public MapleMap getMapInstance(int mapId) {
|
||||
MapleMap map = mapFactory.getMap(mapId);
|
||||
map.setEventInstance(this);
|
||||
|
||||
if (!mapFactory.isMapLoaded(mapId)) {
|
||||
if (em.getProperty("shuffleReactors") != null && em.getProperty("shuffleReactors").equals("true")) {
|
||||
@@ -488,6 +511,10 @@ public class EventInstanceManager {
|
||||
public Properties getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public int getIntProperty(String key) {
|
||||
return Integer.parseInt(props.getProperty(key));
|
||||
}
|
||||
|
||||
public void leftParty(MapleCharacter chr) {
|
||||
try {
|
||||
@@ -527,26 +554,31 @@ public class EventInstanceManager {
|
||||
|
||||
public final MapleMap setInstanceMap(final int mapid) { //gets instance map from the channelserv
|
||||
if (disposed) {
|
||||
return this.getMapFactory().getMap(mapid);
|
||||
return getMapFactory().getMap(mapid);
|
||||
}
|
||||
mapIds.add(mapid);
|
||||
isInstanced.add(false);
|
||||
return this.getMapFactory().getMap(mapid);
|
||||
return getMapFactory().getMap(mapid);
|
||||
}
|
||||
|
||||
public final boolean disposeIfPlayerBelow(final byte size, final int towarp) {
|
||||
if (disposed) {
|
||||
return true;
|
||||
}
|
||||
if(chars == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MapleMap map = null;
|
||||
if (towarp > 0) {
|
||||
map = this.getMapFactory().getMap(towarp);
|
||||
}
|
||||
|
||||
List<MapleCharacter> players = getPlayerList();
|
||||
|
||||
rL.lock();
|
||||
try {
|
||||
if (chars != null && chars.size() < size) {
|
||||
for (MapleCharacter chr : chars) {
|
||||
if (players.size() < size) {
|
||||
for (MapleCharacter chr : players) {
|
||||
if (chr == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -562,12 +594,24 @@ public class EventInstanceManager {
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void spawnNpc(int npcId, Point pos, MapleMap map) {
|
||||
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
||||
if (npc != null) {
|
||||
npc.setPosition(pos);
|
||||
npc.setCy(pos.y);
|
||||
npc.setRx0(pos.x + 50);
|
||||
npc.setRx1(pos.x - 50);
|
||||
npc.setFh(map.getFootholds().findBelow(pos).getId());
|
||||
map.addMapObject(npc);
|
||||
map.broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> convertToIntegerArray(List<Double> list) {
|
||||
List<Integer> intList = new ArrayList<>();
|
||||
for(Double d: list) intList.add(d.intValue());
|
||||
@@ -603,6 +647,27 @@ public class EventInstanceManager {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void dropExclusiveItems(MapleCharacter chr) {
|
||||
AbstractPlayerInteraction api = new AbstractPlayerInteraction(chr.getClient());
|
||||
|
||||
for(Integer item: exclusiveItems) {
|
||||
api.removeAll(item);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setExclusiveItems(List<Double> items) {
|
||||
List<Integer> exclusive = convertToIntegerArray(items);
|
||||
|
||||
wL.lock();
|
||||
try {
|
||||
for(Integer item: exclusive) {
|
||||
exclusiveItems.add(item);
|
||||
}
|
||||
} finally {
|
||||
wL.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public final void setEventRewards(List<Double> rwds, List<Double> qtys, int expGiven) {
|
||||
setEventRewards(1, rwds, qtys, expGiven);
|
||||
}
|
||||
@@ -697,6 +762,11 @@ public class EventInstanceManager {
|
||||
|
||||
public final void setEventCleared() {
|
||||
eventCleared = true;
|
||||
em.disposeInstance(name);
|
||||
}
|
||||
|
||||
public final boolean isEventCleared() {
|
||||
return eventCleared;
|
||||
}
|
||||
|
||||
public final boolean isEventTeamLackingNow(boolean testLeader, int minPlayers, MapleCharacter quitter) {
|
||||
@@ -725,13 +795,10 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public final void warpEventTeam(int warpTo) {
|
||||
rL.lock();
|
||||
try {
|
||||
for (MapleCharacter chr : chars) {
|
||||
chr.changeMap(warpTo);
|
||||
}
|
||||
} finally {
|
||||
rL.unlock();
|
||||
List<MapleCharacter> players = getPlayerList();
|
||||
|
||||
for (MapleCharacter chr : players) {
|
||||
chr.changeMap(warpTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -56,14 +58,23 @@ public class EventManager {
|
||||
private Invocable iv;
|
||||
private Channel cserv;
|
||||
private Map<String, EventInstanceManager> instances = new HashMap<String, EventInstanceManager>();
|
||||
private Map<String, Integer> instanceLocks = new HashMap<String, Integer>();
|
||||
private List<Boolean> openedLobbys;
|
||||
private Properties props = new Properties();
|
||||
private String name;
|
||||
private ScheduledFuture<?> schedule = null;
|
||||
private Lock l = new ReentrantLock();
|
||||
|
||||
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
||||
private static final long lobbyDelay = 10; // 10 seconds cooldown before reopening a lobby
|
||||
|
||||
public EventManager(Channel cserv, Invocable iv, String name) {
|
||||
this.iv = iv;
|
||||
this.cserv = cserv;
|
||||
this.name = name;
|
||||
|
||||
this.openedLobbys = new ArrayList<>();
|
||||
for(int i = 0; i < maxLobbys; i++) this.openedLobbys.add(false);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
@@ -73,6 +84,23 @@ public class EventManager {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> convertToIntegerArray(List<Double> list) {
|
||||
List<Integer> intList = new ArrayList<>();
|
||||
for(Double d: list) intList.add(d.intValue());
|
||||
|
||||
return intList;
|
||||
}
|
||||
|
||||
private List<Integer> getLobbyRange() {
|
||||
try {
|
||||
return convertToIntegerArray((List<Double>)iv.invokeFunction("setLobbyRange", (Object) null));
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void schedule(String methodName, long delay) {
|
||||
schedule(methodName, null, delay);
|
||||
@@ -125,8 +153,14 @@ public class EventManager {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void disposeInstance(String name) {
|
||||
instances.remove(name);
|
||||
public void disposeInstance(final String name) {
|
||||
TimerManager.getInstance().schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
freeLobbyInstance(name);
|
||||
instances.remove(name);
|
||||
}
|
||||
}, lobbyDelay * 1000);
|
||||
}
|
||||
|
||||
public Invocable getIv() {
|
||||
@@ -148,16 +182,78 @@ public class EventManager {
|
||||
public int getIntProperty(String key) {
|
||||
return Integer.parseInt(props.getProperty(key));
|
||||
}
|
||||
|
||||
private void setLockLobby(int lobbyId, boolean lock) {
|
||||
l.lock();
|
||||
try {
|
||||
openedLobbys.set(lobbyId, lock);
|
||||
} finally {
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean startLobbyInstance(int lobbyId) {
|
||||
l.lock();
|
||||
try {
|
||||
if(!openedLobbys.get(lobbyId)) {
|
||||
openedLobbys.set(lobbyId, true);
|
||||
return true;
|
||||
}
|
||||
} finally {
|
||||
l.unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void freeLobbyInstance(String lobbyName) {
|
||||
Integer i = instanceLocks.get(lobbyName);
|
||||
if(i == null) return;
|
||||
|
||||
instanceLocks.remove(lobbyName);
|
||||
if(i > -1) setLockLobby(i, false);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int availableLobbyInstance() {
|
||||
List<Integer> lr = getLobbyRange();
|
||||
int lb = 0, hb = 0;
|
||||
|
||||
if(lr.size() >= 2) {
|
||||
lb = Math.max(lr.get(0), 0);
|
||||
hb = Math.min(lr.get(1), maxLobbys - 1);
|
||||
}
|
||||
|
||||
for(int i = lb; i <= hb; i++) {
|
||||
if(startLobbyInstance(i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean startInstance(MapleExpedition exped) {
|
||||
return startInstance(-1, exped);
|
||||
}
|
||||
|
||||
//Expedition method: starts an expedition
|
||||
public boolean startInstance(MapleExpedition exped) {
|
||||
public boolean startInstance(int lobbyId, MapleExpedition exped) {
|
||||
try {
|
||||
if(lobbyId > -1) {
|
||||
lobbyId = availableLobbyInstance();
|
||||
if(lobbyId == -1) return false;
|
||||
}
|
||||
|
||||
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
|
||||
if(eim == null) return false;
|
||||
if(eim == null) {
|
||||
if(lobbyId > -1) setLockLobby(lobbyId, false);
|
||||
return false;
|
||||
}
|
||||
instanceLocks.put(eim.getName(), lobbyId);
|
||||
|
||||
eim.registerExpedition(exped);
|
||||
exped.start();
|
||||
@@ -170,9 +266,22 @@ public class EventManager {
|
||||
|
||||
//Regular method: player
|
||||
public boolean startInstance(MapleCharacter chr) {
|
||||
return startInstance(-1, chr);
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, MapleCharacter chr) {
|
||||
try {
|
||||
if(lobbyId > -1) {
|
||||
lobbyId = availableLobbyInstance();
|
||||
if(lobbyId == -1) return false;
|
||||
}
|
||||
|
||||
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
|
||||
if(eim == null) return false;
|
||||
if(eim == null) {
|
||||
if(lobbyId > -1) setLockLobby(lobbyId, false);
|
||||
return false;
|
||||
}
|
||||
instanceLocks.put(eim.getName(), lobbyId);
|
||||
|
||||
eim.registerPlayer(chr);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
@@ -184,9 +293,22 @@ public class EventManager {
|
||||
|
||||
//PQ method: starts a PQ
|
||||
public boolean startInstance(MapleParty party, MapleMap map) {
|
||||
return startInstance(-1, party, map);
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, MapleParty party, MapleMap map) {
|
||||
try {
|
||||
if(lobbyId > -1) {
|
||||
lobbyId = availableLobbyInstance();
|
||||
if(lobbyId == -1) return false;
|
||||
}
|
||||
|
||||
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
|
||||
if(eim == null) return false;
|
||||
if(eim == null) {
|
||||
if(lobbyId > -1) setLockLobby(lobbyId, false);
|
||||
return false;
|
||||
}
|
||||
instanceLocks.put(eim.getName(), lobbyId);
|
||||
|
||||
eim.registerParty(party, map);
|
||||
party.setEligibleMembers(null);
|
||||
@@ -199,9 +321,22 @@ public class EventManager {
|
||||
|
||||
//PQ method: starts a PQ with a difficulty level, requires function setup(difficulty, leaderid) instead of setup()
|
||||
public boolean startInstance(MapleParty party, MapleMap map, int difficulty) {
|
||||
return startInstance(-1, party, map, difficulty);
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, MapleParty party, MapleMap map, int difficulty) {
|
||||
try {
|
||||
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", difficulty, party.getLeader().getId()));
|
||||
if(eim == null) return false;
|
||||
if(lobbyId > -1) {
|
||||
lobbyId = availableLobbyInstance();
|
||||
if(lobbyId == -1) return false;
|
||||
}
|
||||
|
||||
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", difficulty, (lobbyId > -1) ? lobbyId : party.getLeaderId()));
|
||||
if(eim == null) {
|
||||
if(lobbyId > -1) setLockLobby(lobbyId, false);
|
||||
return false;
|
||||
}
|
||||
instanceLocks.put(eim.getName(), lobbyId);
|
||||
|
||||
eim.registerParty(party, map);
|
||||
party.setEligibleMembers(null);
|
||||
@@ -214,8 +349,21 @@ public class EventManager {
|
||||
|
||||
//non-PQ method for starting instance
|
||||
public boolean startInstance(EventInstanceManager eim, String leader) {
|
||||
return startInstance(-1, eim, leader);
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, EventInstanceManager eim, String leader) {
|
||||
try {
|
||||
if(eim == null) return false;
|
||||
if(lobbyId > -1) {
|
||||
lobbyId = availableLobbyInstance();
|
||||
if(lobbyId == -1) return false;
|
||||
}
|
||||
|
||||
if(eim == null) {
|
||||
if(lobbyId > -1) setLockLobby(lobbyId, false);
|
||||
return false;
|
||||
}
|
||||
instanceLocks.put(eim.getName(), lobbyId);
|
||||
|
||||
iv.invokeFunction("setup", eim);
|
||||
eim.setProperty("leader", leader);
|
||||
|
||||
@@ -138,22 +138,13 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
||||
pos.y -= 10;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
public void spawnNpc(int npcId) {
|
||||
spawnNpc(npcId, getPosition());
|
||||
}
|
||||
|
||||
|
||||
public void spawnNpc(int npcId, Point pos) {
|
||||
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
|
||||
if (npc != null) {
|
||||
npc.setPosition(pos);
|
||||
npc.setCy(pos.y);
|
||||
npc.setRx0(pos.x + 50);
|
||||
npc.setRx1(pos.x - 50);
|
||||
npc.setFh(reactor.getMap().getFootholds().findBelow(pos).getId());
|
||||
reactor.getMap().addMapObject(npc);
|
||||
reactor.getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
|
||||
}
|
||||
spawnNpc(npcId, pos, reactor.getMap());
|
||||
}
|
||||
|
||||
public MapleReactor getReactor() {
|
||||
|
||||
@@ -52,7 +52,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import server.TimerManager;
|
||||
import server.life.MapleLifeFactory.BanishInfo;
|
||||
import server.maps.MapleMap;
|
||||
@@ -68,7 +67,6 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
private int hp, mp;
|
||||
private WeakReference<MapleCharacter> controller = new WeakReference<>(null);
|
||||
private boolean controllerHasAggro, controllerKnowsAboutAggro;
|
||||
private EventInstanceManager eventInstance = null;
|
||||
private Collection<MonsterListener> listeners = new LinkedList<>();
|
||||
private EnumMap<MonsterStatus, MonsterStatusEffect> stati = new EnumMap<>(MonsterStatus.class);
|
||||
private ArrayList<MonsterStatus> alreadyBuffed = new ArrayList<MonsterStatus>();
|
||||
@@ -342,8 +340,8 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
|
||||
public void giveExpToCharacter(MapleCharacter attacker, int exp, boolean isKiller, int numExpSharers) {
|
||||
if (isKiller) {
|
||||
if (eventInstance != null) {
|
||||
eventInstance.monsterKilled(attacker, this);
|
||||
if (getMap().getEventInstance() != null) {
|
||||
getMap().getEventInstance().monsterKilled(attacker, this);
|
||||
}
|
||||
}
|
||||
final int partyModifier = numExpSharers > 1 ? (110 + (5 * (numExpSharers - 2))) : 0;
|
||||
@@ -434,17 +432,17 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
System.out.println("[CRITICAL LOSS] toSpawn is null for " + this.getName());
|
||||
}
|
||||
|
||||
if (eventInstance != null) {
|
||||
if (!this.getStats().isFriendly()) {
|
||||
eventInstance.monsterKilled(this);
|
||||
}
|
||||
}
|
||||
|
||||
MapleCharacter looter = map.getCharacterById(getHighestDamagerId());
|
||||
return looter != null ? looter : killer;
|
||||
}
|
||||
|
||||
public void dispatchMonsterKilled() {
|
||||
if (getMap().getEventInstance() != null) {
|
||||
if (!this.getStats().isFriendly()) {
|
||||
getMap().getEventInstance().monsterKilled(this);
|
||||
}
|
||||
}
|
||||
|
||||
for (MonsterListener listener : listeners.toArray(new MonsterListener[listeners.size()])) {
|
||||
listener.monsterKilled(getAnimationTime("die1"));
|
||||
}
|
||||
@@ -564,14 +562,6 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
return MapleMapObjectType.MONSTER;
|
||||
}
|
||||
|
||||
public void setEventInstance(EventInstanceManager eventInstance) {
|
||||
this.eventInstance = eventInstance;
|
||||
}
|
||||
|
||||
public EventInstanceManager getEventInstance() {
|
||||
return eventInstance;
|
||||
}
|
||||
|
||||
public boolean isMobile() {
|
||||
return stats.isMobile();
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ import server.life.SpawnPoint;
|
||||
import server.partyquest.MonsterCarnival;
|
||||
import server.partyquest.MonsterCarnivalParty;
|
||||
import server.partyquest.Pyramid;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import tools.FilePrinter;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
@@ -100,6 +101,7 @@ public class MapleMap {
|
||||
private boolean clock;
|
||||
private boolean boat;
|
||||
private boolean docked = false;
|
||||
private EventInstanceManager event = null;
|
||||
private String mapName;
|
||||
private String streetName;
|
||||
private MapleMapEffect mapEffect = null;
|
||||
@@ -153,6 +155,14 @@ public class MapleMap {
|
||||
objectWLock = objectLock.writeLock();
|
||||
}
|
||||
|
||||
public void setEventInstance(EventInstanceManager eim) {
|
||||
event = eim;
|
||||
}
|
||||
|
||||
public EventInstanceManager getEventInstance() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public void broadcastMessage(MapleCharacter source, final byte[] packet) {
|
||||
chrRLock.lock();
|
||||
try {
|
||||
@@ -1114,12 +1124,7 @@ public class MapleMap {
|
||||
monster.changeDifficulty(difficulty, isPq);
|
||||
|
||||
monster.setMap(this);
|
||||
if (!monster.getMap().getAllPlayer().isEmpty()) {
|
||||
MapleCharacter chr = (MapleCharacter) getAllPlayer().get(0);
|
||||
if (monster.getEventInstance() == null && chr.getEventInstance() != null) {
|
||||
chr.getEventInstance().registerMonster(monster);
|
||||
}
|
||||
}
|
||||
if(getEventInstance() != null) getEventInstance().registerMonster(monster);
|
||||
|
||||
spawnAndAddRangedMapObject(monster, new DelayedPacketCreation() {
|
||||
@Override
|
||||
@@ -1701,6 +1706,10 @@ public class MapleMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastStringMessage(int type, String message) {
|
||||
broadcastMessage(MaplePacketCreator.serverNotice(type, message));
|
||||
}
|
||||
|
||||
public void broadcastMessage(final byte[] packet) {
|
||||
broadcastMessage(null, packet, Double.POSITIVE_INFINITY, null);
|
||||
|
||||
@@ -36,6 +36,7 @@ import server.PortalFactory;
|
||||
import server.life.AbstractLoadedMapleLife;
|
||||
import server.life.MapleLifeFactory;
|
||||
import server.life.MapleMonster;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.StringUtil;
|
||||
|
||||
@@ -43,14 +44,16 @@ public class MapleMapFactory {
|
||||
|
||||
private MapleDataProvider source;
|
||||
private MapleData nameData;
|
||||
private EventInstanceManager event;
|
||||
private Map<Integer, MapleMap> maps = new HashMap<>();
|
||||
private int channel, world;
|
||||
|
||||
public MapleMapFactory(MapleDataProvider source, MapleDataProvider stringSource, int world, int channel) {
|
||||
public MapleMapFactory(EventInstanceManager eim, MapleDataProvider source, MapleDataProvider stringSource, int world, int channel) {
|
||||
this.source = source;
|
||||
this.nameData = stringSource.getData("Map.img");
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
this.event = eim;
|
||||
}
|
||||
|
||||
public MapleMap getMap(int mapid) {
|
||||
@@ -75,6 +78,7 @@ public class MapleMapFactory {
|
||||
monsterRate = ((Float) mobRate.getData()).floatValue();
|
||||
}
|
||||
map = new MapleMap(mapid, world, channel, MapleDataTool.getInt("info/returnMap", mapData), monsterRate);
|
||||
map.setEventInstance(event);
|
||||
|
||||
String onFirstEnter = MapleDataTool.getString(mapData.getChildByPath("info/onFirstUserEnter"), String.valueOf(mapid));
|
||||
map.setOnFirstUserEnter(onFirstEnter.equals("") ? String.valueOf(mapid) : onFirstEnter);
|
||||
@@ -314,4 +318,9 @@ public class MapleMapFactory {
|
||||
public Map<Integer, MapleMap> getMaps() {
|
||||
return maps;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
for(MapleMap map: maps.values()) map.setEventInstance(null);
|
||||
this.event = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public enum SavedLocationType {
|
||||
INTRO,
|
||||
SUNDAY_MARKET,
|
||||
MIRROR,
|
||||
DOJO,
|
||||
BOSSPQ,
|
||||
HAPPYVILLE;
|
||||
|
||||
public static SavedLocationType fromString(String Str) {
|
||||
|
||||
Reference in New Issue
Block a user