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:
ronancpl
2017-05-09 20:02:10 -03:00
parent da00345aec
commit 73557f0d61
59 changed files with 943 additions and 608 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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() {